on xenial help sign in
scroll tweaks. velocity calculator improvements
45dbe19Nick Dedekind
qml/Components/ScrollCalculator.qml+36−13
@@ -19,8 +19,7 @@ import QtQuick 2.0
19Item {
19Item {
20 id: scrollArea
20 id: scrollArea
21
21
22− property real thresholdAreaWidth: units.gu(1)
22+ property real stopScrollThreshold: units.gu(2)
23− property bool showDebugRectangles: false
24 property int direction: Qt.LeftToRight
23 property int direction: Qt.LeftToRight
25 property real baseScrollAmount: units.dp(2)
24 property real baseScrollAmount: units.dp(2)
26 property real maximumScrollAmount: units.dp(6)
25 property real maximumScrollAmount: units.dp(6)
@@ -44,17 +43,16 @@ Item {
44 rotation: direction == Qt.LeftToRight ? 0 : 180
43 rotation: direction == Qt.LeftToRight ? 0 : 180
45
44
46 function handleEnter() {
45 function handleEnter() {
47− d.threasholdAreaX = -scrollArea.thresholdAreaWidth;
46+ d.threasholdAreaX = -scrollArea.stopScrollThreshold;
48 scrollTimer.restart();
47 scrollTimer.restart();
49 }
48 }
50 onLateralPositionChanged: {
49 onLateralPositionChanged: {
51 if (scrollArea.areaActive) {
50 if (scrollArea.areaActive) {
52−
53 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
51 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
54 d.threasholdAreaX = width * (1 - forceScrollingPercentage);
52 d.threasholdAreaX = width * (1 - forceScrollingPercentage);
55 if (!scrollTimer.running) scrollTimer.restart();
53 if (!scrollTimer.running) scrollTimer.restart();
56− } else if (lateralPosition > d.threasholdAreaX + scrollArea.thresholdAreaWidth) {
54+ } else if (lateralPosition > d.threasholdAreaX + scrollArea.stopScrollThreshold) {
57− d.threasholdAreaX = lateralPosition - scrollArea.thresholdAreaWidth;
55+ d.threasholdAreaX = lateralPosition - scrollArea.stopScrollThreshold;
58 if (!scrollTimer.running) scrollTimer.restart();
56 if (!scrollTimer.running) scrollTimer.restart();
59 } else if (lateralPosition < d.threasholdAreaX) {
57 } else if (lateralPosition < d.threasholdAreaX) {
60 d.threasholdAreaX = lateralPosition;
58 d.threasholdAreaX = lateralPosition;
@@ -66,7 +64,7 @@ Item {
66 }
64 }
67
65
68 function handleExit() {
66 function handleExit() {
69− d.threasholdAreaX = -scrollArea.thresholdAreaWidth;
67+ d.threasholdAreaX = -scrollArea.stopScrollThreshold;
70 scrollTimer.stop();
68 scrollTimer.stop();
71 }
69 }
72
70
@@ -74,19 +72,44 @@ Item {
74 id: scrollTimer
72 id: scrollTimer
75 interval: 5
73 interval: 5
76 repeat: true
74 repeat: true
75+
76+ property int iter: 0
77 onTriggered: {
77 onTriggered: {
78− scrollArea.scroll(scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression);
78+ var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
79+ scrollArea.scroll(scrollAmount);
79 }
80 }
80 }
81 }
81
82
82 QtObject {
83 QtObject {
83 id: d
84 id: d
84
85
85− property real progression: 0
86+ property real lastLateralPosition: lateralPosition
86− property real threasholdAreaX: -scrollArea.thresholdAreaWidth
87
87
88− Behavior on progression {
88+ property real progression: 0
89− SmoothedAnimation { velocity: 2.0 }
89+ property real threasholdAreaX: -scrollArea.stopScrollThreshold
90− }
91 }
90 }
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+// }
92}
115}
qml/Panel/IndicatorsMenu.qml+13−10
@@ -144,8 +144,8 @@ Showable {
144 anchors.left: bar.left
144 anchors.left: bar.left
145 height: bar.height
145 height: bar.height
146
146
147− forceScrollingPercentage: 0.3
147+ forceScrollingPercentage: 0.33
148− thresholdAreaWidth: units.gu(0.5)
148+ stopScrollThreshold: units.gu(0.75)
149 direction: Qt.RightToLeft
149 direction: Qt.RightToLeft
150 lateralPosition: -1
150 lateralPosition: -1
151
151
@@ -158,8 +158,8 @@ Showable {
158 anchors.right: bar.right
158 anchors.right: bar.right
159 height: bar.height
159 height: bar.height
160
160
161− forceScrollingPercentage: 0.3
161+ forceScrollingPercentage: 0.33
162− thresholdAreaWidth: units.gu(0.5)
162+ stopScrollThreshold: units.gu(0.75)
163 direction: Qt.LeftToRight
163 direction: Qt.LeftToRight
164 lateralPosition: -1
164 lateralPosition: -1
165
165
@@ -197,8 +197,12 @@ Showable {
197 distanceThreshold: 0
197 distanceThreshold: 0
198 }
198 }
199
199
200− AxisVelocityCalculator {
200+ PanelVelocityCalculator {
201 id: yVelocityCalculator
201 id: yVelocityCalculator
202+ velocityThreashold: 0.5
203+ trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
204+
205+ onVelocityThreasholdTriggered: bar.updateItemFromLateralPosition(bar.lateralPosition);
202 }
206 }
203
207
204 Connections {
208 Connections {
@@ -206,7 +210,7 @@ Showable {
206 onRunningChanged: {
210 onRunningChanged: {
207 if (showAnimation.running) {
211 if (showAnimation.running) {
208 root.state = "commit";
212 root.state = "commit";
209− bar.alignLeft();
213+ bar.alignIndicatorsToLeft();
210 }
214 }
211 }
215 }
212 }
216 }
@@ -281,8 +285,7 @@ Showable {
281 if (!d.activeDragHandle) return false;
285 if (!d.activeDragHandle) return false;
282 if (!d.activeDragHandle.dragging) return false;
286 if (!d.activeDragHandle.dragging) return false;
283
287
284− yVelocityCalculator.trackedPosition = d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0;
285− return Math.abs(yVelocityCalculator.calculate()) < 0.4;
288+ return !yVelocityCalculator.stopLateralChanges;
286 }
289 }
287 }
290 }
288 // left scroll bar handling
291 // left scroll bar handling
@@ -293,7 +296,7 @@ Showable {
293 if (!d.activeDragHandle.dragging) return -1;
296 if (!d.activeDragHandle.dragging) return -1;
294
297
295 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
298 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
296− return mapped.x
299+ return mapped.x;
297 }
300 }
298 }
301 }
299 // right scroll bar handling
302 // right scroll bar handling
@@ -304,7 +307,7 @@ Showable {
304 if (!d.activeDragHandle.dragging) return -1;
307 if (!d.activeDragHandle.dragging) return -1;
305
308
306 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
309 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
307− return mapped.x
310+ return mapped.x;
308 }
311 }
309 }
312 }
310 },
313 },
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+}