on xenial help sign in
make spread reversible Fixes: #1355284, #1368668, #1368677

Approved by: Albert Astals Cid

commit16b7d9a61792e78e34e3ec5b741c9b4fc8f8526a authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 2 Dec 2014, 09:26 (12 years ago) parentd6b5b2f32a5698
4 files changed+31−51
qml/Stages/PhoneStage.qml+17−33 qml/Stages/TabletStage.qml+5−14 tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+1−1 tests/qmltests/Stages/tst_PhoneStage.qml+8−3
qml/Stages/PhoneStage.qml+17−33
@@ -145,16 +145,16 @@ Rectangle {
145145
146146 // Those markers mark the various positions in the spread (ratio to screen width from right to left):
147147 // 0 - 1: following finger, snap back to the beginning on release
148− property real positionMarker1: 0.3
148+ property real positionMarker1: 0.2
149149 // 1 - 2: curved snapping movement, snap to app 1 on release
150− property real positionMarker2: 0.45
150+ property real positionMarker2: 0.3
151151 // 2 - 3: movement follows finger, snaps back to app 1 on release
152− property real positionMarker3: 0.6
152+ property real positionMarker3: 0.35
153153 // passing 3, we detach movement from the finger and snap to 4
154154 property real positionMarker4: 0.9
155155
156156 // This is where the first app snaps to when bringing it in from the right edge.
157− property real snapPosition: 0.75
157+ property real snapPosition: 0.7
158158
159159 // Phase of the animation:
160160 // 0: Starting from right edge, a new app (index 1) comes in from the right
@@ -178,7 +178,7 @@ Rectangle {
178178 case 1:
179179 if (shiftedContentX < width * positionMarker2) {
180180 phase = 0;
181− } else if (shiftedContentX >= width * positionMarker4) {
181+ } else if (shiftedContentX >= width * positionMarker4 && !spreadDragArea.dragging) {
182182 phase = 2;
183183 }
184184 break;
@@ -270,6 +270,7 @@ Rectangle {
270270
271271 Repeater {
272272 id: spreadRepeater
273+ objectName: "spreadRepeater"
273274 model: ApplicationManager
274275 delegate: TransformedSpreadDelegate {
275276 id: appDelegate
@@ -367,8 +368,9 @@ Rectangle {
367368 if (spreadView.phase == 0 && index < 2) {
368369 if (progress < spreadView.positionMarker1) {
369370 return progress;
370− } else if (progress < spreadView.positionMarker1 + snappingCurve.period){
371− return spreadView.positionMarker1 + snappingCurve.value * 3;
371+ } else if (progress < spreadView.positionMarker1 + 0.05){
372+ // p : 0.05 = x : pm2
373+ return spreadView.positionMarker1 + (progress - spreadView.positionMarker1) * (spreadView.positionMarker2 - spreadView.positionMarker1) / 0.05
372374 } else {
373375 return spreadView.positionMarker2;
374376 }
@@ -380,13 +382,6 @@ Rectangle {
380382 visible: (progress >= 0 && progress < 1.7) ||
381383 (isDash && priv.focusedAppDelegate.x !== 0)
382384
383− EasingCurve {
384− id: snappingCurve
385− type: EasingCurve.Linear
386− period: 0.05
387− progress: appDelegate.progress - spreadView.positionMarker1
388− }
389−
390385 Binding {
391386 target: appDelegate
392387 property: "orientation"
@@ -425,16 +420,11 @@ Rectangle {
425420 id: spreadDragArea
426421 objectName: "spreadDragArea"
427422 direction: Direction.Leftwards
428− enabled: spreadView.phase != 2 && root.spreadEnabled
423+ enabled: (spreadView.phase != 2 && root.spreadEnabled) || dragging
429424
430425 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
431426 width: root.dragAreaWidth
432427
433− // Sitting at the right edge of the screen, this EdgeDragArea directly controls the spreadView when
434− // attachedToView is true. When the finger movement passes positionMarker3 we detach it from the
435− // spreadView and make the spreadView snap to positionMarker4.
436− property bool attachedToView: true
437−
438428 property var gesturePoints: new Array()
439429
440430 onTouchXChanged: {
@@ -443,15 +433,13 @@ Rectangle {
443433 spreadView.phase = 0;
444434 spreadView.contentX = -spreadView.shift;
445435 }
446− if (dragging && status == DirectionalDragArea.Recognized && attachedToView) {
436+ if (dragging && status == DirectionalDragArea.Recognized) {
447437 // Gesture recognized. Let's move the spreadView with the finger
448− var finalX = Math.min(touchX + width, width);
449− spreadView.contentX = -finalX + spreadDragArea.width - spreadView.shift;
450− }
451− if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
452− // We passed positionMarker3. Detach from spreadView and snap it.
453− attachedToView = false;
454− spreadView.snap();
438+ var dragX = Math.min(touchX + width, width); // Prevent dragging rightwards
439+ dragX = -dragX + spreadDragArea.width - spreadView.shift;
440+ // Don't allow dragging further than the animation crossing with phase2's animation
441+ var maxMovement = spreadView.width * spreadView.positionMarker4 - spreadView.shift;
442+ spreadView.contentX = Math.min(dragX, maxMovement);
455443 }
456444 gesturePoints.push(touchX);
457445 }
@@ -462,10 +450,6 @@ Rectangle {
462450 onStatusChanged: {
463451 previousStatus = currentStatus;
464452 currentStatus = status;
465−
466− if (status == DirectionalDragArea.Recognized) {
467− attachedToView = true;
468− }
469453 }
470454
471455 onDraggingChanged: {
@@ -493,7 +477,7 @@ Rectangle {
493477 // If it was a short one-way movement, do the Alt+Tab switch
494478 // no matter if we didn't cross positionMarker1 yet.
495479 spreadView.snapTo(1);
496− } else if (!dragging && attachedToView) {
480+ } else if (!dragging) {
497481 // otherwise snap to the closest snap position we can find
498482 // (might be back to start, to app 1 or to spread)
499483 spreadView.snap();
qml/Stages/TabletStage.qml+5−14
@@ -590,7 +590,6 @@ Rectangle {
590590 width: root.dragAreaWidth
591591 direction: Direction.Leftwards
592592
593− property bool attachedToView: false
594593 property var gesturePoints: new Array()
595594
596595 onTouchXChanged: {
@@ -599,22 +598,14 @@ Rectangle {
599598 spreadView.contentX = -spreadView.shift;
600599 }
601600
602− if (dragging && attachedToView) {
603− spreadView.contentX = -touchX + spreadDragArea.width - spreadView.shift;
604− if (spreadView.shiftedContentX > spreadView.phase0Width + spreadView.phase1Width / 2) {
605− attachedToView = false;
606− spreadView.snap();
607− }
601+ if (dragging) {
602+ var dragX = -touchX + spreadDragArea.width - spreadView.shift;
603+ var maxDrag = spreadView.width * spreadView.positionMarker4 - spreadView.shift;
604+ spreadView.contentX = Math.min(dragX, maxDrag);
608605 }
609606 gesturePoints.push(touchX);
610607 }
611608
612− onStatusChanged: {
613− if (status == DirectionalDragArea.Recognized) {
614− attachedToView = true;
615− }
616− }
617−
618609 onDraggingChanged: {
619610 if (dragging) {
620611 // Gesture recognized. Start recording this gesture
@@ -630,7 +621,7 @@ Rectangle {
630621 // If it was a short one-way movement, do the Alt+Tab switch
631622 // no matter if we didn't cross positionMarker1 yet.
632623 spreadView.snapTo(spreadView.nextInStack);
633− } else if (!dragging && attachedToView) {
624+ } else if (!dragging) {
634625 if (spreadView.shiftedContentX < spreadView.width * spreadView.positionMarker1) {
635626 spreadView.snap();
636627 } else if (spreadView.shiftedContentX < spreadView.width * spreadView.positionMarker2) {
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+1−1
@@ -47,7 +47,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
4747 height = self.main_window.height
4848 start_x = width
4949 start_y = int(height/2)
50− end_x = int(width/2)
50+ end_x = int(width*3/4)
5151 end_y = start_y
5252
5353 logger.info("Swiping screen from the right edge")
tests/qmltests/Stages/tst_PhoneStage.qml+8−3
@@ -128,17 +128,20 @@ Item {
128128 var startX = phoneStage.width - 2;
129129 var startY = phoneStage.height / 2;
130130 var endY = startY;
131− var endX = units.gu(2);
131+ var endX = phoneStage.width / 2;
132132
133133 touchFlick(phoneStage, startX, startY, endX, endY,
134134 true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
135+
136+ tryCompare(spreadView, "phase", 2);
137+ waitForRendering(phoneStage);
135138 }
136139
137140 function test_shortFlick() {
138141 addApps(2)
139142 var startX = phoneStage.width - units.gu(1);
140143 var startY = phoneStage.height / 2;
141− var endX = phoneStage.width / 2;
144+ var endX = startX - units.gu(4);
142145 var endY = startY;
143146
144147 var activeApp = ApplicationManager.get(0);
@@ -164,7 +167,7 @@ Item {
164167 {tag: "<position2 (non-linear)", positionMarker: "positionMarker2", linear: false, offset: -1, endPhase: 0, targetPhase: 0, newFocusedIndex: 1 },
165168 {tag: ">position2", positionMarker: "positionMarker2", linear: true, offset: +1, endPhase: 1, targetPhase: 0, newFocusedIndex: 1 },
166169 {tag: "<position3", positionMarker: "positionMarker3", linear: true, offset: -1, endPhase: 1, targetPhase: 0, newFocusedIndex: 1 },
167− {tag: ">position3", positionMarker: "positionMarker3", linear: true, offset: +1, endPhase: 2, targetPhase: 2, newFocusedIndex: 2 },
170+ {tag: ">position3", positionMarker: "positionMarker3", linear: true, offset: +1, endPhase: 1, targetPhase: 2, newFocusedIndex: 2 },
168171 ];
169172 }
170173
@@ -386,6 +389,8 @@ Item {
386389 compare(dragArea0.enabled, false);
387390 compare(dragArea1.enabled, false);
388391 compare(dragArea2.enabled, false);
392+
393+ tryCompare(spreadView, "contentX", -spreadView.shift)
389394 }
390395 }
391396}