aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp15
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml49
2 files changed, 64 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 5430a4de..d4688867 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -737,6 +737,21 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *item, QMous
const bool hadGrabbedMouse = q->keepMouseGrab();
q->setKeepMouseGrab(false);
+ // Animations for the background and contentItem delegates are typically
+ // only enabled when !control.down, so that the animations aren't running
+ // when the user is swiping. To ensure that the animations are enabled
+ // *before* the positions of these delegates change (via the swipe.setPosition() calls below),
+ // we must cancel the press. QQuickAbstractButton::mouseUngrabEvent() does this
+ // for us, but by then it's too late.
+ if (hadGrabbedMouse) {
+ // TODO: this is copied from QQuickAbstractButton::mouseUngrabEvent().
+ // Eventually it should be moved into a private helper so that we don't have to duplicate it.
+ q->setPressed(false);
+ stopPressRepeat();
+ stopPressAndHold();
+ emit q->canceled();
+ }
+
// The control can be exposed by either swiping past the halfway mark, or swiping fast enough.
const qreal swipeVelocity = swipePrivate->velocityCalculator.velocity().x();
if (swipePrivate->position > 0.5 ||
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index 92f25e2a..7a2ad44d 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -1367,4 +1367,53 @@ TestCase {
control.destroy();
}
+
+ Component {
+ id: animationSwipeDelegateComponent
+
+ SwipeDelegate {
+ id: control
+ text: "SwipeDelegate"
+ width: 150
+ swipe.left: greenLeftComponent
+ swipe.right: redRightComponent
+
+ property alias behavior: xBehavior
+ property alias animation: numberAnimation
+
+ background: Rectangle {
+ color: control.down ? "#ccc" : "#fff"
+
+ Behavior on x {
+ id: xBehavior
+ enabled: !control.down
+
+ NumberAnimation {
+ id: numberAnimation
+ easing.type: Easing.InOutCubic
+ duration: 400
+ }
+ }
+ }
+ }
+ }
+
+ function test_animations() {
+ // Test that animations are run when releasing from a drag.
+ var control = animationSwipeDelegateComponent.createObject(testCase);
+ verify(control);
+
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton);
+ mouseMove(control, control.width - 1, control.height / 2, Qt.LeftButton);
+ verify(control.down);
+ verify(!control.behavior.enabled);
+ verify(!control.animation.running);
+
+ mouseRelease(control, control.width - 1, control.height / 2, Qt.LeftButton);
+ verify(!control.down);
+ verify(control.behavior.enabled);
+ verify(control.animation.running);
+
+ control.destroy();
+ }
}