on xenial help sign in
scroll tweaks. velocity calculator improvements
commit45dbe19eecf816d5af67e452f314a608ab650fa6 authorNick Dedekind <nick.dedekind@canonical.com> dateThu 9 Oct 2014, 10:52 (12 years ago) parent7148200
3 files changed+108−23
qml/Components/ScrollCalculator.qml+36−13 qml/Panel/IndicatorsMenu.qml+13−10 qml/Panel/PanelVelocityCalculator.qml+59
qml/Components/ScrollCalculator.qml+36−13
@@ -19,8 +19,7 @@ import QtQuick 2.0
1919Item {
2020 id: scrollArea
2121
22− property real thresholdAreaWidth: units.gu(1)
23− property bool showDebugRectangles: false
22+ property real stopScrollThreshold: units.gu(2)
2423 property int direction: Qt.LeftToRight
2524 property real baseScrollAmount: units.dp(2)
2625 property real maximumScrollAmount: units.dp(6)
@@ -44,17 +43,16 @@ Item {
4443 rotation: direction == Qt.LeftToRight ? 0 : 180
4544
4645 function handleEnter() {
47− d.threasholdAreaX = -scrollArea.thresholdAreaWidth;
46+ d.threasholdAreaX = -scrollArea.stopScrollThreshold;
4847 scrollTimer.restart();
4948 }
5049 onLateralPositionChanged: {
5150 if (scrollArea.areaActive) {
52−
5351 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
5452 d.threasholdAreaX = width * (1 - forceScrollingPercentage);
5553 if (!scrollTimer.running) scrollTimer.restart();
56− } else if (lateralPosition > d.threasholdAreaX + scrollArea.thresholdAreaWidth) {
57− d.threasholdAreaX = lateralPosition - scrollArea.thresholdAreaWidth;
54+ } else if (lateralPosition > d.threasholdAreaX + scrollArea.stopScrollThreshold) {
55+ d.threasholdAreaX = lateralPosition - scrollArea.stopScrollThreshold;
5856 if (!scrollTimer.running) scrollTimer.restart();
5957 } else if (lateralPosition < d.threasholdAreaX) {
6058 d.threasholdAreaX = lateralPosition;
@@ -66,7 +64,7 @@ Item {
6664 }
6765
6866 function handleExit() {
69− d.threasholdAreaX = -scrollArea.thresholdAreaWidth;
67+ d.threasholdAreaX = -scrollArea.stopScrollThreshold;
7068 scrollTimer.stop();
7169 }
7270
@@ -74,19 +72,44 @@ Item {
7472 id: scrollTimer
7573 interval: 5
7674 repeat: true
75+
76+ property int iter: 0
7777 onTriggered: {
78− scrollArea.scroll(scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression);
78+ var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
79+ scrollArea.scroll(scrollAmount);
7980 }
8081 }
8182
8283 QtObject {
8384 id: d
8485
85− property real progression: 0
86− property real threasholdAreaX: -scrollArea.thresholdAreaWidth
86+ property real lastLateralPosition: lateralPosition
8787
88− Behavior on progression {
89− SmoothedAnimation { velocity: 2.0 }
90− }
88+ property real progression: 0
89+ property real threasholdAreaX: -scrollArea.stopScrollThreshold
9190 }
91+
92+// // Debugging Rectangles.
93+// Rectangle {
94+// color: "yellow"
95+// opacity: 0.2
96+// anchors.fill: scrollArea
97+// }
98+
99+// Rectangle {
100+// color: "red"
101+// opacity: 0.2
102+// height: scrollArea.height
103+// width: scrollArea.width * forceScrollingPercentage
104+// anchors.right: parent.right
105+// }
106+
107+// Rectangle {
108+// id: thresholdRect
109+// opacity: 0.4
110+// height: parent.height
111+// width: scrollArea.stopScrollThreshold
112+// x: d.threasholdAreaX
113+// color: "blue"
114+// }
92115}
qml/Panel/IndicatorsMenu.qml+13−10
@@ -144,8 +144,8 @@ Showable {
144144 anchors.left: bar.left
145145 height: bar.height
146146
147− forceScrollingPercentage: 0.3
148− thresholdAreaWidth: units.gu(0.5)
147+ forceScrollingPercentage: 0.33
148+ stopScrollThreshold: units.gu(0.75)
149149 direction: Qt.RightToLeft
150150 lateralPosition: -1
151151
@@ -158,8 +158,8 @@ Showable {
158158 anchors.right: bar.right
159159 height: bar.height
160160
161− forceScrollingPercentage: 0.3
162− thresholdAreaWidth: units.gu(0.5)
161+ forceScrollingPercentage: 0.33
162+ stopScrollThreshold: units.gu(0.75)
163163 direction: Qt.LeftToRight
164164 lateralPosition: -1
165165
@@ -197,8 +197,12 @@ Showable {
197197 distanceThreshold: 0
198198 }
199199
200− AxisVelocityCalculator {
200+ PanelVelocityCalculator {
201201 id: yVelocityCalculator
202+ velocityThreashold: 0.5
203+ trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
204+
205+ onVelocityThreasholdTriggered: bar.updateItemFromLateralPosition(bar.lateralPosition);
202206 }
203207
204208 Connections {
@@ -206,7 +210,7 @@ Showable {
206210 onRunningChanged: {
207211 if (showAnimation.running) {
208212 root.state = "commit";
209− bar.alignLeft();
213+ bar.alignIndicatorsToLeft();
210214 }
211215 }
212216 }
@@ -281,8 +285,7 @@ Showable {
281285 if (!d.activeDragHandle) return false;
282286 if (!d.activeDragHandle.dragging) return false;
283287
284− yVelocityCalculator.trackedPosition = d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0;
285− return Math.abs(yVelocityCalculator.calculate()) < 0.4;
288+ return !yVelocityCalculator.stopLateralChanges;
286289 }
287290 }
288291 // left scroll bar handling
@@ -293,7 +296,7 @@ Showable {
293296 if (!d.activeDragHandle.dragging) return -1;
294297
295298 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
296− return mapped.x
299+ return mapped.x;
297300 }
298301 }
299302 // right scroll bar handling
@@ -304,7 +307,7 @@ Showable {
304307 if (!d.activeDragHandle.dragging) return -1;
305308
306309 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
307− return mapped.x
310+ return mapped.x;
308311 }
309312 }
310313 },
qml/Panel/PanelVelocityCalculator.qmlnew file+59
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Gestures 0.1
19+
20+Item {
21+ id: root
22+ property real trackedValue: 0
23+ property bool stopLateralChanges: false
24+ property real velocityThreashold: 0.4
25+
26+ signal velocityThreasholdTriggered
27+
28+ function reset() {
29+ stopLateralChanges = false;
30+ calc.reset();
31+ }
32+
33+ onTrackedValueChanged: {
34+ calc.trackedPosition = trackedValue;
35+ velocityTimer.start();
36+ }
37+
38+ AxisVelocityCalculator {
39+ id: calc
40+ onTrackedPositionChanged: {
41+ var velocity = Math.abs(calc.calculate());
42+ stopLateralChanges = velocity > velocityThreashold;
43+ }
44+ }
45+
46+ Timer {
47+ id: velocityTimer
48+ interval: 50
49+ onTriggered: {
50+ calc.trackedPosition = trackedValue;
51+ root.stopLateralChanges = Math.abs(calc.calculate()) > velocityThreashold;
52+ if (root.stopLateralChanges) {
53+ velocityTimer.start();
54+ } else {
55+ velocityThreasholdTriggered();
56+ }
57+ }
58+ }
59+}