on xenial help sign in
better scrolle calc
13f6ed1Nick Dedekind
qml/Components/ScrollCalculator.qml+13−38
@@ -19,9 +19,6 @@ import QtQuick 2.0
19Item {
19Item {
20 id: scrollArea
20 id: scrollArea
21
21
22− property real __previousMouseX: -1
23− property real __progression: 0
24− property real __previousMouseXHelper: -1
25 property real thresholdAreaWidth: units.gu(1)
22 property real thresholdAreaWidth: units.gu(1)
26 property bool showDebugRectangles: false
23 property bool showDebugRectangles: false
27 property int direction: Qt.LeftToRight
24 property int direction: Qt.LeftToRight
@@ -47,33 +44,29 @@ Item {
47 rotation: direction == Qt.LeftToRight ? 0 : 180
44 rotation: direction == Qt.LeftToRight ? 0 : 180
48
45
49 function handleEnter() {
46 function handleEnter() {
50− thresholdRect.x = -scrollArea.thresholdAreaWidth
47+ d.threasholdAreaX = -scrollArea.thresholdAreaWidth
51 scrollTimer.restart()
48 scrollTimer.restart()
52 }
49 }
53 onLateralPositionChanged: {
50 onLateralPositionChanged: {
54 if (scrollArea.areaActive) {
51 if (scrollArea.areaActive) {
55
52
56− // store the previous x value
57− __previousMouseX = __previousMouseXHelper
58− __previousMouseXHelper = lateralPosition
59−
60 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
53 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
61− thresholdRect.x = width * (1 - forceScrollingPercentage)
54+ d.threasholdAreaX = width * (1 - forceScrollingPercentage)
62 if (!scrollTimer.running) scrollTimer.restart()
55 if (!scrollTimer.running) scrollTimer.restart()
63− } else if (lateralPosition > thresholdRect.x + thresholdRect.width) {
56+ } else if (lateralPosition > d.threasholdAreaX + scrollArea.thresholdAreaWidth) {
64− thresholdRect.x = lateralPosition - thresholdRect.width
57+ d.threasholdAreaX = lateralPosition - scrollArea.thresholdAreaWidth
65 if (!scrollTimer.running) scrollTimer.restart()
58 if (!scrollTimer.running) scrollTimer.restart()
66− } else if (lateralPosition < thresholdRect.x) {
59+ } else if (lateralPosition < d.threasholdAreaX) {
67− thresholdRect.x = lateralPosition
60+ d.threasholdAreaX = lateralPosition
68 scrollTimer.stop()
61 scrollTimer.stop()
69 }
62 }
70
63
71− __progression = lateralPosition / width
64+ d.progression = lateralPosition / width
72 }
65 }
73 }
66 }
74
67
75 function handleExit() {
68 function handleExit() {
76− thresholdRect.x = -scrollArea.thresholdAreaWidth
69+ d.threasholdAreaX = -scrollArea.thresholdAreaWidth
77 scrollTimer.stop()
70 scrollTimer.stop()
78 }
71 }
79
72
@@ -81,31 +74,13 @@ Item {
81 id: scrollTimer
74 id: scrollTimer
82 interval: 5
75 interval: 5
83 repeat: true
76 repeat: true
84− onTriggered: scrollArea.scroll(scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount*scrollArea.__progression)
77+ onTriggered: scrollArea.scroll(scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression)
85− }
86−
87− Rectangle {
88− color: "yellow"
89− opacity: 0.2
90− anchors.fill: scrollArea
91− visible: showDebugRectangles
92 }
78 }
93
79
94− Rectangle {
80+ QtObject {
95− color: "red"
81+ id: d
96− opacity: 0.2
97− height: scrollArea.height
98− width: scrollArea.width * forceScrollingPercentage
99− anchors.right: parent.right
100− visible: showDebugRectangles
101− }
102
82
103− Rectangle {
83+ property real progression: 0
104− id: thresholdRect
105− opacity: 0.4
106− height: parent.height
107− width: scrollArea.thresholdAreaWidth
108− x: -scrollArea.thresholdAreaWidth
84+ property real threasholdAreaX: -scrollArea.thresholdAreaWidth
109− color: showDebugRectangles ? "blue" : "transparent"
110 }
85 }
111}
86}