on xenial help sign in
better indicator switch detection
commit5387d8d65c50909953986102ac75f12717c06b81 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 21 Oct 2014, 09:04 (12 years ago) parentcf7ba9c
1 file changed+42−15
qml/Panel/IndicatorsMenu.qml+42−15
qml/Panel/IndicatorsMenu.qml+42−15
@@ -57,17 +57,7 @@ Showable {
5757
5858 height: minimizedPanelHeight
5959
60− onUnitProgressChanged: {
61− if (!showAnimation.running && !hideAnimation.running) {
62− if (unitProgress <= 0) {
63− root.state = "initial";
64− } else if (unitProgress >= 0.9 && d.hasCommitted) {
65− root.state = "locked";
66− } else {
67− root.state = "reveal";
68− }
69− }
70− }
60+ onUnitProgressChanged: d.updateState()
7161 clip: root.partiallyOpened
7262
7363 // eater
@@ -196,12 +186,21 @@ Showable {
196186 stretch: true
197187 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
198188 distanceThreshold: 0
189+
190+ onTouchSceneXChanged: {
191+ if (root.state === "locked") {
192+ d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
193+ d.lastHideTouchSceneX = touchSceneX;
194+ }
195+ }
199196 }
200197
201198 PanelVelocityCalculator {
202199 id: yVelocityCalculator
203− velocityThreshold: 0.5
200+ velocityThreshold: d.hasCommitted ? 0.1 : 0.3
204201 trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
202+
203+ onVelocityAboveThresholdChanged: d.updateState()
205204 }
206205
207206 Connections {
@@ -226,11 +225,27 @@ Showable {
226225 id: d
227226 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
228227 property bool hasCommitted: false
228+ property real lastHideTouchSceneX: 0
229+ property real xDisplacementSinceLock: 0
230+ onXDisplacementSinceLockChanged: d.updateState()
229231
230232 property real rowMappedLateralPosition: {
231233 if (!d.activeDragHandle) return -1;
232234 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
233235 }
236+
237+ function updateState() {
238+ if (!showAnimation.running && !hideAnimation.running) {
239+ if (unitProgress <= 0) {
240+ root.state = "initial";
241+ // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
242+ } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(1) || yVelocityCalculator.velocityAboveThreshold)) {
243+ root.state = "locked";
244+ } else {
245+ root.state = "reveal";
246+ }
247+ }
248+ }
234249 }
235250
236251 states: [
@@ -244,7 +259,8 @@ Showable {
244259 script: {
245260 yVelocityCalculator.reset();
246261 // initial item selection
247− bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
262+ if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
263+ d.hasCommitted = false;
248264 }
249265 }
250266 PropertyChanges {
@@ -274,17 +290,28 @@ Showable {
274290 return mapped.x;
275291 }
276292 }
277− PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
278293 },
279294 State {
280295 name: "locked"
296+ StateChangeScript {
297+ script: {
298+ d.xDisplacementSinceLock = 0;
299+ d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
300+ }
301+ }
281302 PropertyChanges { target: bar; expanded: true }
282303 },
283304 State {
284305 name: "commit"
285306 extend: "locked"
286307 PropertyChanges { target: bar; interactive: true }
287− PropertyChanges { target: d; hasCommitted: true; restoreEntryValues: false }
308+ PropertyChanges {
309+ target: d;
310+ hasCommitted: true
311+ lastHideTouchSceneX: 0
312+ xDisplacementSinceLock: 0
313+ restoreEntryValues: false
314+ }
288315 }
289316 ]
290317 state: "initial"