diff options
author | Caroline Chao <caroline.chao@digia.com> | 2013-04-02 18:24:46 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-06 10:10:17 +0200 |
commit | d01e595d362fcc8347f410eecdf055f80dd5423f (patch) | |
tree | 40779340e02d54458ef17b5117be5a4c5fa66950 /tests/auto/qmltest | |
parent | 8fe9280556897a0d37831aa5169f2a76aa8686d2 (diff) |
TestLib: Add more mouseMove in mouseDrag implementation
So the cursor has intermediate states while dragging instead of
jumping to the final position.
This is for example useful for testing the behavior of a control
during the drag.
Add autotest.
Change-Id: I061dd18ef7ac389aa4da4a5b60f9e128ee8c08d0
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/qmltest')
-rw-r--r-- | tests/auto/qmltest/events/tst_drag.qml | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/auto/qmltest/events/tst_drag.qml b/tests/auto/qmltest/events/tst_drag.qml index 70e0ea2096..7db1e1e1b2 100644 --- a/tests/auto/qmltest/events/tst_drag.qml +++ b/tests/auto/qmltest/events/tst_drag.qml @@ -51,6 +51,17 @@ Rectangle{ id: util } + SignalSpy { + id: spyX + target: container2 + signalName: "posXChanged" + } + SignalSpy { + id: spyY + target: container2 + signalName: "posYChanged" + } + Rectangle { id:container width:20 @@ -66,6 +77,55 @@ Rectangle{ } } + Rectangle { + id: container2 + x: 25 + y: 25 + width:100 + height:100 + color: "red" + property bool updatePositionWhileDragging: false + property var posX: 0 + property var posY: 0 + + function reset() { + fakeHandle.x = 0 + fakeHandle.y = 0 + spyX.clear() + spyY.clear() + } + + Binding { + when: container2.updatePositionWhileDragging + target: container2 + property: "posX" + value: fakeHandle.x + } + + Binding { + when: container2.updatePositionWhileDragging + target: container2 + property: "posY" + value: fakeHandle.y + } + + Item { id: fakeHandle } + + MouseArea { + anchors.fill : container2 + drag.maximumX: 180 + drag.maximumY: 180 + drag.minimumX: 0 + drag.minimumY: 0 + drag.target: fakeHandle + + onReleased: if (!container2.updatePositionWhileDragging) { + container2.posX = mouse.x; + container2.posY = mouse.y + } + } + } + TestCase { name:"mouserelease" when:windowShown @@ -74,5 +134,47 @@ Rectangle{ compare(container.x, 20 - util.dragThreshold - 1); compare(container.y, 30 - util.dragThreshold - 1); } + + function test_doSomethingWhileDragging() { + container2.updatePositionWhileDragging = false + // dx and dy are superior to 3 times util.dragThreshold. + // but here the dragging does not update posX and posY + // posX and posY are only updated on mouseRelease + container2.reset() + mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 10*util.dragThreshold); + compare(spyX.count, 1) + compare(spyY.count, 1) + + container2.updatePositionWhileDragging = true + // dx and dy are superior to 3 times util.dragThreshold. + // 3 intermediate mouseMove when dragging + container2.reset() + mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 10*util.dragThreshold); + compare(spyX.count, 3) + compare(spyY.count, 3) + + // dx and dy are inferior to 3 times util.dragThreshold. + // No intermediate mouseMove when dragging, only one mouseMove + container2.reset() + mouseDrag(container2, container2.x + 10, container2.y + 10, 2*util.dragThreshold, 2*util.dragThreshold); + compare(spyX.count, 1) + compare(spyY.count, 1) + + // dx is superior to 3 times util.dragThreshold. + // 3 intermediate mouseMove when dragging on x axis + // no move on the y axis + container2.reset() + mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 0); + compare(spyX.count, 3) + compare(spyY.count, 0) + + // dy is inferior to 3 times util.dragThreshold. + // No intermediate mouseMove when dragging, only one mouseMove on y axis + // no move on the x axis + container2.reset() + mouseDrag(container2, container2.x + 10, container2.y + 10, 0, 2*util.dragThreshold); + compare(spyX.count, 0) + compare(spyY.count, 1) + } } } |