diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-11-18 16:32:25 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2019-11-26 11:59:43 +0000 |
commit | b3de744dba87fd8d5c2bdb9ed4c56a3e5455188b (patch) | |
tree | 7ef6f858219f52442f92dd112c2441b3c14406d0 | |
parent | 8ecc00ff54d987ddd8cfbd45a9f2a5bfe18aad80 (diff) |
mouseDrag(): ensure that intermediate moves are done for all drags
The code checking if the intermediate move distance was less than
the drag threshold, but without accounting for negative distances.
Since the negative distances were naturally less than the drag
threshold, the intermediate distances were set to zero and the
intermediate moves were never done.
In practice, this means that mouseDrag() never did intermediate
moves (i.e. what happens during a drag in real life) for drags
that go from right to left or upwards.
Task-number: QTBUG-80152
Change-Id: Ic27021f5ce5ba2937e95fb2dfb532bd2136f4205
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit fad8ef3e4133538e3785d7067c35c652bc894711)
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
-rw-r--r-- | src/imports/testlib/TestCase.qml | 18 | ||||
-rw-r--r-- | tests/auto/qmltest/events/tst_drag.qml | 30 |
2 files changed, 39 insertions, 9 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index fff375b49a..20c5ce6418 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -1417,12 +1417,12 @@ Item { // Divide dx and dy to have intermediate mouseMove while dragging // Fractions of dx/dy need be superior to the dragThreshold // to make the drag works though - var ddx = Math.round(dx/3) - if (ddx < (util.dragThreshold + 1)) - ddx = 0 - var ddy = Math.round(dy/3) - if (ddy < (util.dragThreshold + 1)) - ddy = 0 + var intermediateDx = Math.round(dx/3) + if (Math.abs(intermediateDx) < (util.dragThreshold + 1)) + intermediateDx = 0 + var intermediateDy = Math.round(dy/3) + if (Math.abs(intermediateDy) < (util.dragThreshold + 1)) + intermediateDy = 0 mousePress(item, x, y, button, modifiers, delay) @@ -1431,9 +1431,9 @@ Item { var dragTriggerXDistance = dx > 0 ? (util.dragThreshold + 1) : 0 var dragTriggerYDistance = dy > 0 ? (util.dragThreshold + 1) : 0 mouseMove(item, x + dragTriggerXDistance, y + dragTriggerYDistance, moveDelay, button) - if (ddx > 0 || ddy > 0) { - mouseMove(item, x + ddx, y + ddy, moveDelay, button) - mouseMove(item, x + 2*ddx, y + 2*ddy, moveDelay, button) + if (intermediateDx !== 0 || intermediateDy !== 0) { + mouseMove(item, x + intermediateDx, y + intermediateDy, moveDelay, button) + mouseMove(item, x + 2*intermediateDx, y + 2*intermediateDy, moveDelay, button) } mouseMove(item, x + dx, y + dy, moveDelay, button) mouseRelease(item, x + dx, y + dy, button, modifiers, delay) diff --git a/tests/auto/qmltest/events/tst_drag.qml b/tests/auto/qmltest/events/tst_drag.qml index 2653848adc..5c5b885e6c 100644 --- a/tests/auto/qmltest/events/tst_drag.qml +++ b/tests/auto/qmltest/events/tst_drag.qml @@ -150,6 +150,15 @@ Rectangle{ SignalSpy {} } + Component { + id: mouseAreaComponent + + MouseArea { + anchors.fill: parent + hoverEnabled: true + } + } + TestCase { name:"mouserelease" when:windowShown @@ -295,5 +304,26 @@ Rectangle{ else verify(contentYSpy.count > 0) } + + function test_negativeDragDistance_data() { + return [ + { tag: "horizontal", startX: 100, startY: 100, xDistance: -90, yDistance: 0 }, + { tag: "vertical", startX: 100, startY: 100, xDistance: 0, yDistance: -90 } + ] + } + + // Tests that dragging to the left or top actually results in intermediate mouse moves. + function test_negativeDragDistance(data) { + let mouseArea = createTemporaryObject(mouseAreaComponent, root) + verify(mouseArea) + + let positionSpy = signalSpyComponent.createObject(mouseArea, + { target: mouseArea, signalName: "positionChanged" }) + verify(positionSpy) + verify(positionSpy.valid) + + mouseDrag(mouseArea, data.startX, data.startY, data.xDistance, data.yDistance) + verify(positionSpy.count > 2, "Expected more than 2 mouse position changes, but only got " + positionSpy.count) + } } } |