From 994319a35eac6c9574068f1d37a993f587c771da Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Nov 2016 14:38:39 +0100 Subject: AbstractButton: fix press-and-hold for checkable buttons Don't toggle the checked state on release after press-and-hold. Change-Id: I06b6a0e86dc02c171eef10f3c0d564ff605796f0 Reviewed-by: Mitch Curtis --- tests/auto/controls/data/tst_abstractbutton.qml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index 27fc4525..83ca7980 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -60,6 +60,11 @@ TestCase { Item { } } + Component { + id: signalSpy + SignalSpy { } + } + function test_text() { var control = button.createObject(testCase); verify(control); @@ -103,4 +108,21 @@ TestCase { control.destroy() } + + function test_pressAndHold() { + var control = button.createObject(testCase, {checkable: true}) + verify(control) + + var pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) + verify(pressAndHoldSpy.valid) + + mousePress(control) + pressAndHoldSpy.wait() + compare(control.checked, false) + + mouseRelease(control) + compare(control.checked, false) + + control.destroy() + } } -- cgit v1.2.3 From 08ba34d6a8cf7e7ab21ce51ca6aa7d812d035a67 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 22 Nov 2016 14:21:08 +0100 Subject: SwipeDelegate: fix broken swiping after calling SwipeDelegate.close() Reset the internal state when close() is called to ensure that it's consistent. Task-number: QTBUG-57243 Change-Id: Id52724e0eb296c3f8a4fc0a0587a04558b1d1ab6 Reviewed-by: J-P Nurmi --- tests/auto/controls/data/tst_swipedelegate.qml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index fa2d218f..067fed1e 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1054,17 +1054,17 @@ TestCase { text: "SwipeDelegate" width: 150 - onClicked: close() - swipe.right: Item { width: parent.width height: parent.height + + SwipeDelegate.onClicked: swipe.close() } } } function test_close() { - var control = swipeDelegateComponent.createObject(testCase); + var control = closeSwipeDelegateComponent.createObject(testCase); verify(control); swipe(control, 0.0, -1.0); @@ -1073,6 +1073,16 @@ TestCase { compare(control.swipe.rightItem.x, 0); tryCompare(control.swipe.rightItem, "x", control.background.x + control.background.width); + mousePress(control); + verify(control.swipe.rightItem.SwipeDelegate.pressed); + + mouseRelease(control); + verify(!control.swipe.rightItem.SwipeDelegate.pressed); + tryCompare(control.swipe, "position", 0); + + // Swiping after closing should work as normal. + swipe(control, 0.0, -1.0); + control.destroy(); } -- cgit v1.2.3 From 261e84c3e333574b300ea0b09f87fccc88c4a0ea Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 22 Nov 2016 14:51:05 +0100 Subject: Use tryVerify() instead of wait() where possible This may help with the flaky tst_tooltip test, and makes tst_tumbler a little bit cleaner. Task-number: QTBUG-57258 Change-Id: Ida987fb9d60392aba4142e4711131aded56d425d Reviewed-by: J-P Nurmi --- tests/auto/controls/data/tst_tooltip.qml | 3 +-- tests/auto/controls/data/tst_tumbler.qml | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index d9c95dbf..51601d66 100644 --- a/tests/auto/controls/data/tst_tooltip.qml +++ b/tests/auto/controls/data/tst_tooltip.qml @@ -240,8 +240,7 @@ TestCase { else control.visible = false verify(control.exit.running) - wait(100) // TODO: replace with tryVerify() in 5.8 - verify(control.opacity < 1) + tryVerify(function() { return control.opacity < 1; }) if (data.imperative) control.open() diff --git a/tests/auto/controls/data/tst_tumbler.qml b/tests/auto/controls/data/tst_tumbler.qml index b3230ca4..01d5cdee 100644 --- a/tests/auto/controls/data/tst_tumbler.qml +++ b/tests/auto/controls/data/tst_tumbler.qml @@ -83,16 +83,10 @@ TestCase { } function cleanup() { - var destroyed = false; - cleanupItem.Component.destruction.connect(function() { destroyed = true; }); - cleanupItem.destroy(); - // Waiting until it's deleted before continuing makes debugging // test failures much easier, because there aren't unrelated items hanging around. - // TODO: Replace with tryVerify(!tumbler) in 5.8. - while (!destroyed) - wait(0) + tryVerify(function() { return !tumbler; }); } function createTumbler(args) { -- cgit v1.2.3 From 9812a9cc1e71b0a3d8f25c0db2457f8673e53054 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 4 Oct 2016 11:21:46 +0200 Subject: 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 --- tests/auto/controls/data/tst_swipedelegate.qml | 46 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'tests') 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); + } } -- cgit v1.2.3 From aa06a424c5b40d7961a3928e12e59a0aff855675 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 23 Nov 2016 17:14:14 +0100 Subject: SwipeDelegate: fix swipes that begin over a child item of a delegate If the mouse was pressed over a child item of the delegate, the event's position will be for that item, rather than the entire control. To fix this, we need to set the correct pressPoint. To avoid duplicating QQuickAbstractButton::mousePressEvent()'s code, we simply set the correct pressPoint after calling it in QQuickSwipeDelegatePrivate::handleMousePressEvent(). Task-number: QTBUG-57271 Change-Id: I7204d6176c755512eeeb0b1a57a920fbab40392c Reviewed-by: J-P Nurmi --- tests/auto/controls/data/tst_swipedelegate.qml | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 42bbd00b..92f25e2a 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1292,4 +1292,79 @@ TestCase { mouseRelease(control, control.width + 10, control.height / 2, Qt.LeftButton); verify(mouseSignalSequenceSpy.success); } + + Component { + id: leftRightWithLabelsComponent + + SwipeDelegate { + id: delegate + text: "SwipeDelegate" + width: 150 + + background.opacity: 0.5 + + swipe.left: Rectangle { + width: parent.width + height: parent.height + color: SwipeDelegate.pressed ? Qt.darker("green") : "green" + + property alias label: label + + Label { + id: label + text: "Left" + color: "white" + anchors.margins: 10 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + } + + SwipeDelegate.onClicked: delegate.swipe.close() + } + + swipe.right: Rectangle { + width: parent.width + height: parent.height + anchors.right: parent.right + color: SwipeDelegate.pressed ? Qt.darker("green") : "red" + + property alias label: label + + Label { + id: label + text: "Right" + color: "white" + anchors.margins: 10 + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + } + + SwipeDelegate.onClicked: delegate.swipe.close() + } + } + } + + function test_beginSwipeOverRightItem() { + var control = leftRightWithLabelsComponent.createObject(testCase); + verify(control); + + // Swipe to the left, exposing the right item. + swipe(control, 0.0, -1.0); + + // Click to close it and go back to a position of 0. + mouseClick(control); + + // TODO: Swipe to the left, with the mouse over the Label in the right item. + // The left item should not become visible at any point. + var rightLabel = control.swipe.rightItem.label; + var overDragDistance = Math.round(dragDistance * 1.1); + mousePress(rightLabel, rightLabel.width / 2, rightLabel.height / 2, Qt.rightButton); + mouseMove(rightLabel, rightLabel.width / 2 - overDragDistance, rightLabel.height / 2, Qt.LeftButton); + verify(!control.swipe.leftItem); + + mouseRelease(rightLabel, rightLabel.width / 2 - overDragDistance, control.height / 2, Qt.LeftButton); + verify(!control.swipe.leftItem); + + control.destroy(); + } } -- cgit v1.2.3