on xenial help sign in
properly reset the drawer state when cancelling a horizontal drag (LP: #1669536)
fe7f3cfMichael Zanetti
qml/Launcher/Drawer.qml+4−1
@@ -212,13 +212,16 @@ FocusScope {
212 root.dragDistance += diff;
212 root.dragDistance += diff;
213 oldX = mouseX
213 oldX = mouseX
214 }
214 }
215− onReleased: {
215+ onReleased: reset();
216+ onCanceled: reset();
217+ function reset() {
216 if (root.draggingHorizontally) {
218 if (root.draggingHorizontally) {
217 root.draggingHorizontally = false;
219 root.draggingHorizontally = false;
218 parent.interactive = true;
220 parent.interactive = true;
219 }
221 }
220 reactivateTimer.start();
222 reactivateTimer.start();
221 }
223 }
224+
222 Timer {
225 Timer {
223 id: reactivateTimer
226 id: reactivateTimer
224 interval: 0
227 interval: 0
qml/Launcher/Launcher.qml+9−10
@@ -120,7 +120,14 @@ FocusScope {
120 }
120 }
121 return;
121 return;
122 }
122 }
123+ if (root.lockedVisible) {
124+ // Due to binding updates when switching between modes
125+ // it could happen that our request to show will be overwritten
126+ // with a hide request. Rewrite it when we know hiding is not allowed.
127+ switchToNextState("visible")
128+ } else {
123− switchToNextState("")
129+ switchToNextState("")
130+ }
124 }
131 }
125
132
126 function fadeOut() {
133 function fadeOut() {
@@ -258,13 +265,6 @@ FocusScope {
258 interval: 1
265 interval: 1
259 property string nextState: ""
266 property string nextState: ""
260 onTriggered: {
267 onTriggered: {
261− if (root.lockedVisible && nextState == "") {
262− // Due to binding updates when switching between modes
263− // it could happen that our request to show will be overwritten
264− // with a hide request. Rewrite it when we know hiding is not allowed.
265− nextState = "visible"
266− }
267−
268 // switching to an intermediate state here to make sure all the
268 // switching to an intermediate state here to make sure all the
269 // values are restored, even if we were already in the target state
269 // values are restored, even if we were already in the target state
270 root.state = "tmp"
270 root.state = "tmp"
@@ -383,8 +383,7 @@ FocusScope {
383 }
383 }
384
384
385 Keys.onEscapePressed: {
385 Keys.onEscapePressed: {
386− switchToNextState("");
386+ root.hide()
387− root.focus = false;
388 }
387 }
389
388
390 onDragDistanceChanged: {
389 onDragDistanceChanged: {
tests/qmltests/Launcher/tst_Drawer.qml+18
@@ -328,5 +328,23 @@ StyledItem {
328
328
329 tryCompare(launcher, "state", "visibleTemporary");
329 tryCompare(launcher, "state", "visibleTemporary");
330 }
330 }
331+
332+ function test_closeWhileDragging() {
333+ launcher.openDrawer(true);
334+ waitForRendering(launcher);
335+ waitUntilTransitionsEnd(launcher);
336+
337+ var drawer = findChild(launcher, "drawer");
338+ tryCompare(drawer.anchors, "rightMargin", -drawer.width);
339+
340+ mousePress(drawer, drawer.width / 2, drawer.height / 2);
341+ mouseMove(drawer, drawer.width / 4, drawer.height / 2);
342+ tryCompare(drawer, "draggingHorizontally", true);
343+
344+ keyPress(Qt.Key_Escape);
345+
346+ tryCompare(launcher, "state", "");
347+ tryCompare(drawer, "draggingHorizontally", false);
348+ }
331 }
349 }
332}
350}