aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data/tst_swipedelegate.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-10-04 11:21:46 +0200
committerMitch Curtis <mitch.curtis@qt.io>2016-11-23 10:48:32 +0000
commit9812a9cc1e71b0a3d8f25c0db2457f8673e53054 (patch)
tree0a7df0e367508a64728d5994b7500c7f3f08ad06 /tests/auto/controls/data/tst_swipedelegate.qml
parent2202d79b39ff90eed19fb8106f79d4604e47acfd (diff)
SwipeDelegate: don't emit clicked when released outside
If there are no delegates and hence the mouse hasn't been grabbed, we should clear the pressed state when the mouse is dragged outside the control. We can do so by falling back to the event handling of the base class (QQuickItemDelegate) when we have no delegates. This also ensures that the canceled() signal is emitted. A similar thing is done for controls with delegates, except that only the vertical position of the mouse is checked, as we still want to initiate swipes horizontally. Change-Id: I7738f5b9e8e8b6ce4a733008fa4ff73596e854ea Task-number: QTBUG-56312 Task-number: QTBUG-57285 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_swipedelegate.qml')
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml46
1 files changed, 43 insertions, 3 deletions
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index 21bb1a37..0404fd86 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -361,7 +361,7 @@ TestCase {
verify(control.swipe.rightItem);
verify(!control.swipe.rightItem.visible);
- mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "released", "clicked"];
+ mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"];
mouseRelease(control, control.width / 2, control.height / 2);
verify(!control.pressed);
compare(control.swipe.position, 1.0);
@@ -388,7 +388,8 @@ TestCase {
verify(!control.swipe.complete);
compare(control.swipe.position, 1.0 - overDragDistance / control.width);
- mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "released", "clicked"];
+ // Since we went over the drag distance, we should expect canceled() to be emitted.
+ mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"];
mouseRelease(control, control.width * 0.4, control.height / 2);
verify(!control.pressed);
compare(control.swipe.position, 1.0);
@@ -409,7 +410,7 @@ TestCase {
verify(!control.swipe.complete);
compare(control.swipe.position, 0.4);
- mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "released", "clicked"];
+ mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"];
mouseRelease(control, control.width * -0.1, control.height / 2);
verify(!control.pressed);
compare(control.swipe.position, 0.0);
@@ -1033,4 +1034,43 @@ TestCase {
control.destroy();
}
+
+ function test_releaseOutside_data() {
+ return [
+ { tag: "no delegates", component: emptySwipeDelegateComponent },
+ { tag: "delegates", component: swipeDelegateComponent },
+ ];
+ }
+
+ function test_releaseOutside(data) {
+ var control = data.component.createObject(testCase);
+ verify(control);
+
+ // Press and then release below the control.
+ mouseSignalSequenceSpy.target = control;
+ mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], "pressed", ["pressedChanged", { "pressed": false }]];
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton);
+ mouseMove(control, control.width / 2, control.height + 10, Qt.LeftButton);
+ verify(mouseSignalSequenceSpy.success);
+
+ mouseSignalSequenceSpy.expectedSequence = ["canceled"];
+ mouseRelease(control, control.width / 2, control.height + 10, Qt.LeftButton);
+ verify(mouseSignalSequenceSpy.success);
+
+ // Press and then release to the right of the control.
+ var hasDelegates = control.swipe.left || control.swipe.right || control.swipe.behind;
+ mouseSignalSequenceSpy.target = control;
+ mouseSignalSequenceSpy.expectedSequence = hasDelegates
+ ? [["pressedChanged", { "pressed": true }], "pressed"]
+ : [["pressedChanged", { "pressed": true }], "pressed", ["pressedChanged", { "pressed": false }]];
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton);
+ mouseMove(control, control.width + 10, control.height / 2, Qt.LeftButton);
+ if (hasDelegates)
+ verify(control.swipe.position > 0);
+ verify(mouseSignalSequenceSpy.success);
+
+ mouseSignalSequenceSpy.expectedSequence = hasDelegates ? [["pressedChanged", { "pressed": false }], "canceled"] : ["canceled"];
+ mouseRelease(control, control.width + 10, control.height / 2, Qt.LeftButton);
+ verify(mouseSignalSequenceSpy.success);
+ }
}