on xenial help sign in
delay move operations if the start dragging operation is running

This prevents items to left in wrong places when transitions clash. Approved by PS Jenkins bot, Albert Astals Cid.

commit691883c5d8829354a3a5edf55855fd1872a70f28 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 22 Aug 2013, 14:59 (13 years ago) parentbbab3ce3dfabbd
2 files changed+63−17
Launcher/LauncherPanel.qml+30−4 tests/qmltests/Launcher/tst_Launcher.qml+33−13
Launcher/LauncherPanel.qml+30−4
@@ -121,6 +121,12 @@ Item {
121121 property real realContentY: contentY - originY + topMargin
122122 property int realItemHeight: itemHeight + spacing
123123
124+ // In case the start dragging transition is running, we need to delay the
125+ // move because the displaced transition would clash with it and cause items
126+ // to be moved to wrong places
127+ property bool draggingTransitionRunning: false
128+ property int scheduledMoveTo: -1
129+
124130 displaced: Transition {
125131 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
126132 }
@@ -202,10 +208,26 @@ Item {
202208 UbuntuNumberAnimation { properties: "angle,offset" }
203209 },
204210 Transition {
211+ id: draggingTransition
205212 from: "selected"
206213 to: "dragging"
207− UbuntuNumberAnimation { properties: "height" }
208− NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
214+ SequentialAnimation {
215+ PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
216+ ParallelAnimation {
217+ UbuntuNumberAnimation { properties: "height" }
218+ NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
219+ }
220+ ScriptAction {
221+ script: {
222+ if (launcherListView.scheduledMoveTo > -1) {
223+ launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
224+ dndArea.draggedIndex = launcherListView.scheduledMoveTo
225+ launcherListView.scheduledMoveTo = -1
226+ }
227+ }
228+ }
229+ PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
230+ }
209231 },
210232 Transition {
211233 from: "dragging"
@@ -387,8 +409,12 @@ Item {
387409 }
388410
389411 if (newIndex >= 0 && newIndex < launcherListView.count) {
390− launcherListView.model.move(draggedIndex, newIndex)
391− draggedIndex = newIndex
412+ if (launcherListView.draggingTransitionRunning) {
413+ launcherListView.scheduledMoveTo = newIndex
414+ } else {
415+ launcherListView.model.move(draggedIndex, newIndex)
416+ draggedIndex = newIndex
417+ }
392418 }
393419 }
394420 }
tests/qmltests/Launcher/tst_Launcher.qml+33−13
@@ -277,8 +277,9 @@ Item {
277277
278278 function test_dragndrop_data() {
279279 return [
280− {tag: "startDrag", fullDrag: false},
281− {tag: "fullDrag", fullDrag: true},
280+ {tag: "startDrag", fullDrag: false },
281+ {tag: "fullDrag horizontal", fullDrag: true, orientation: ListView.Horizontal },
282+ {tag: "fullDrag vertical", fullDrag: true, orientation: ListView.Vertical },
282283 ];
283284 }
284285
@@ -288,8 +289,8 @@ Item {
288289 var item0 = findChild(launcher, "launcherDelegate0")
289290 var fakeDragItem = findChild(launcher, "fakeDragItem")
290291 var initialItemHeight = draggedItem.height
291− var item5Name = LauncherModel.get(5).iconName
292− var item4Name = LauncherModel.get(4).iconName
292+ var item5 = LauncherModel.get(5).appId
293+ var item4 = LauncherModel.get(4).appId
293294
294295 // Initial state
295296 compare(draggedItem.itemOpacity, 1, "Item's opacity is not 1 at beginning")
@@ -297,28 +298,43 @@ Item {
297298 tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)
298299
299300 // Doing longpress
300− mousePress(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
301+ var currentMouseX = draggedItem.width / 2
302+ var currentMouseY = draggedItem.height / 2
303+ mousePress(draggedItem, currentMouseX, currentMouseY)
301304 // DraggedItem needs to hide and fakeDragItem become visible
302305 tryCompare(draggedItem, "itemOpacity", 0)
303306 tryCompare(fakeDragItem, "visible", true)
304307
305308 // Dragging a bit (> 1.5 gu)
306− mouseMove(draggedItem, -units.gu(2), draggedItem.height / 2)
309+ currentMouseX -= units.gu(2)
310+ mouseMove(draggedItem, currentMouseX, currentMouseY)
307311 // Other items need to expand and become 0.6 opaque
308312 tryCompare(item0, "angle", 0)
309313 tryCompare(item0, "itemOpacity", 0.6)
310314
311315 if (data.fullDrag) {
312316 // Dragging a bit more
313− mouseMove(draggedItem, -units.gu(15), draggedItem.height / 2, 100)
314− tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
315− tryCompare(draggedItem, "height", units.gu(1))
317+ if (data.orientation == ListView.Horizontal) {
318+ currentMouseX -= units.gu(15)
319+ mouseMove(draggedItem, currentMouseX, currentMouseY, 100)
320+
321+ tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
322+ tryCompare(draggedItem, "height", units.gu(1))
323+
324+ // Dragging downwards. Item needs to move in the model
325+ currentMouseY -= initialItemHeight * 1.5
326+ mouseMove(draggedItem, currentMouseX, currentMouseY)
327+ } else if (data.orientation == ListView.Vertical) {
328+ currentMouseY -= initialItemHeight * 1.5
329+ mouseMove(draggedItem, currentMouseX, currentMouseY, 100)
330+
331+ tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
332+ tryCompare(draggedItem, "height", units.gu(1))
333+ }
316334
317− // Dragging downwards. Item needs to move in the model
318− mouseMove(draggedItem, -units.gu(15), -initialItemHeight)
319335 waitForRendering(draggedItem)
320− compare(LauncherModel.get(5).iconName, item4Name)
321− compare(LauncherModel.get(5).iconName, item5Name)
336+ compare(LauncherModel.get(5).appId, item4)
337+ compare(LauncherModel.get(4).appId, item5)
322338 }
323339
324340 // Releasing and checking if initial values are restored
@@ -326,6 +342,10 @@ Item {
326342 tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)
327343 tryCompare(draggedItem, "itemOpacity", 1)
328344 tryCompare(fakeDragItem, "visible", false)
345+
346+ // Click somewhere in the empty space to make it hide in case it isn't
347+ mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
348+ revealer.waitUntilLauncherDisappears();
329349 }
330350
331351 function test_quicklist_dismiss() {