optimise the ViewPortPage cmpanent

This commit is contained in:
Andrei Yankovich 2020-10-09 23:36:22 +03:00
parent c37366eb19
commit cea929e9cb
5 changed files with 14 additions and 27 deletions

View File

@ -18,6 +18,10 @@ include(ViewSolutions/CMake/ccache.cmake)
add_subdirectory(ViewSolutions)
if ( NOT DEFINED DISABLE_EXAMPLES )
set(DISABLE_EXAMPLES OFF)
endif()
if ( NOT DISABLE_EXAMPLES )
message("DISABLE_EXAMPLES = ${DISABLE_EXAMPLES}")
add_subdirectory(Examples)
endif()

View File

@ -13,19 +13,18 @@ Page {
anchors.fill: parent
delegate: Component {
ViewPortGradientPage {
scrollPos: viewPort.globalPos
source: modelData
viewground: root
height: root.height / 3
title: "Test ViewPortPage"
text: "Test ViewPortPage. General text and <i>html code</i>"
contentX: viewPort.contentX
contentY: viewPort.contentY
}
}
ScrollBar.vertical: ScrollBar {
onPositionChanged: {
viewPort.globalPos = position
}
}

View File

@ -18,6 +18,7 @@ Page {
width: viewPort.width
title: "Test ViewPortPage"
text: "Test ViewPortPage. General text and <i>html code</i>"
}
}

View File

@ -13,23 +13,19 @@ Page {
anchors.fill: parent
delegate: Component {
ViewPortPage {
scrollPos: viewPort.globalPos
source: modelData
viewground: root
height: root.height / 3
contentX: viewPort.contentX
contentY: viewPort.contentY
title: "Test ViewPortPage"
text: "Test ViewPortPage. General text and <i>html code</i>"
}
}
ScrollBar.vertical: ScrollBar {
onPositionChanged: {
viewPort.globalPos = position
}
}
model: [
"qrc:/img/res/LOGO.png",
"qrc:/img/res/LOGO-GREAN.png",

View File

@ -11,7 +11,6 @@ ViewSolutionsControl {
property alias imageSource: image
property var viewground: null
property real scrollPos: 0
property int imageMrgin: 5
property var theme: Material.theme
@ -22,6 +21,8 @@ ViewSolutionsControl {
property int viewPortDelegatW: 0
property int viewPortDelegatH: 0
property real contentX: 0
property real contentY: 0
background: Rectangle {
border.color: "black"
@ -32,24 +33,11 @@ ViewSolutionsControl {
width: (viewPortDelegatW)? viewPortDelegatW: (viewground)? viewground.width : 0
height: (viewPortDelegatH)? viewPortDelegatH: (viewground)?viewground.height * 0.1 : 0
onScrollPosChanged: {
updatePos();
}
function updatePos() {
if (!viewground) {
return ;
}
const viewGlobal = viewground.mapToGlobal(0, 0);
const img = flickable.mapFromGlobal(viewGlobal.x, viewGlobal.y);
flickable.contentX = -img.x;
flickable.contentY = -img.y;
}
Flickable {
id: flickable
contentY: -(parent.contentY - delegateItem.y)
contentX: -(parent.contentX - delegateItem.x)
contentWidth: viewground.width
contentHeight: viewground.height
@ -62,7 +50,6 @@ ViewSolutionsControl {
fillMode: Image.PreserveAspectFit
anchors.fill: parent
}
anchors.fill: parent