added new commpanent (ViewPort)

This commit is contained in:
Andrei Yankovich 2020-05-10 01:05:31 +03:00
parent 603caac3c4
commit d085fe74b7
11 changed files with 139 additions and 4 deletions

View File

@ -25,7 +25,15 @@ file(GLOB SOURCE_CPP
)
add_executable(${PROJECT_NAME} ${SOURCE_CPP})
if(ANDROID)
add_library(${PROJECT_NAME} SHARED ${SOURCE_CPP})
else()
add_executable(${PROJECT_NAME} ${SOURCE_CPP})
endif()
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE ViewSolutions)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")

View File

@ -8,7 +8,8 @@ Page {
ImageView {
anchors.fill: parent
soucre: "qrc:/img/res/LOGO.png"
text: "QuasarApp group"
text: "QuasarApp"
toolTip: "QuasarApp Group"
anchors.margins: 20
borderColor: "#00a4e1"
}

View File

@ -0,0 +1,26 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import ViewSolutionsModule 1.0
Page {
id: root
ListModel {
id: myModel
ListElement { type: "Dog"; age: 8 }
ListElement { type: "Cat"; age: 5 }
}
ViewPortContainer {
anchors.fill: parent
viewPortDelegat: ViewPortDelegat {
background: "qrc:/img/res/LOGO.png"
anchors.margins: 20
}
model: myModel
}
}

View File

@ -82,6 +82,7 @@ ApplicationWindow {
model: ListModel {
ListElement { title: "ImageView"; source: "qrc:/ImageViewPage.qml" }
ListElement { title: "ViewPortContainer"; source: "qrc:/ViewPortContainerPage.qml" }
}

View File

@ -3,6 +3,7 @@
<file>main.qml</file>
<file>ImageViewPage.qml</file>
<file>qtquickcontrols2.conf</file>
<file>ViewPortContainerPage.qml</file>
</qresource>
<qresource prefix="/img">
<file>res/LOGO.png</file>

View File

@ -36,4 +36,9 @@ add_library(${PROJECT_NAME} SHARED ${SOURCE_CPP})
target_link_libraries(${PROJECT_NAME} PUBLIC Qt5::Core Qt5::Quick Qt5::QuickControls2)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
set(QML_IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "Qt Creator extra qml import paths")

View File

@ -12,7 +12,7 @@ Item {
property bool presed: false
property string toolTip: ""
property color background: Material.foreground
property color background: Material.background
property color borderColor: "#00000000"
signal clicked(var mouse);
@ -68,7 +68,7 @@ Item {
}
Text {
Label {
text: root.text
Layout.preferredHeight: root.height * 0.1
Layout.fillWidth: true

View File

@ -0,0 +1,38 @@
import QtQuick 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import QtQuick.Controls.Universal 2.14
ListView {
id: root
property var viewPortDelegat: null
onViewPortDelegatChanged: {
if (viewPortDelegat && viewPortDelegat instanceof ViewPortDelegat) {
viewPortDelegat.viewground = root
if (delegateItem)
viewPortDelegat.parent = delegateItem
}
}
Component {
id: baseDelegate
Item {
id: delegateItem
width: viewPortDelegat.width
height: viewPortDelegat.height
Component.onCompleted: {
if (viewPortDelegat)
viewPortDelegat.parent = delegateItem
}
}
}
delegate: baseDelegate
}

View File

@ -0,0 +1,51 @@
import QtQuick 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import QtQuick.Controls.Universal 2.14
Item {
id: root
property string background: ""
property var viewground: null
onXChanged: updatePos;
onYChanged: updatePos;
Flickable {
id: flickable
contentWidth: (viewground)? viewground.width: image.width
contentHeight: (viewground)? viewground.height: image.height
contentX: 0
contentY: 0
clip: true
interactive: false
function updatePos() {
if (!viewground) {
return {x: 0, y : 0};
}
const viewGlobal = root.mapToGlobal(viewground.x, viewground.y);
const img = image.mapFromGlobal(viewGlobal.x, viewGlobal.y);
flickable.contentX = img.x;
flickable.contentY = img.y;
}
Image {
id: image;
source: background
height: root.contentH
fillMode: Image.PreserveAspectFit
width: root.contentW
}
anchors.fill: parent
}
}

View File

@ -1,2 +1,4 @@
module ViewSolutionsModule
ImageView 1.0 ImageView.qml
ViewPortContainer 1.0 ViewPortContainer.qml
ViewPortDelegat 1.0 ViewPortDelegat.qml

View File

@ -2,6 +2,8 @@
<qresource prefix="/">
<file>ViewSolutionsModule/qmldir</file>
<file>ViewSolutionsModule/ImageView.qml</file>
<file>ViewSolutionsModule/ViewPortContainer.qml</file>
<file>ViewSolutionsModule/ViewPortDelegat.qml</file>
</qresource>
<qresource prefix="/img"/>
</RCC>