summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-11-29 10:28:33 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-11-30 12:37:40 +0000
commit838fd79152957f457a47cd30970961a27f086848 (patch)
tree5024d2ec2375e2eac05c534aed00dc0bb992e345
parent6aa97038e26bab96455b2fc3febc5d358a5e7599 (diff)
SwipeDelegate: fix animations when releasing from a drag5.7
9812a9c changed the order in which the pressed and position state is set. Before, when releasing after swiping, it would be: set pressed to false => set position After 9812a9c, it became: set position => set pressed to false The original order is necessary to ensure that animations can rely on being enabled *before* position changes, as their enabled expression typically looks something like this: enabled: !control.down This patch duplicates the contents of QQuickAbstractButton::mouseUngrabEvent() for now, with a TODO comment to ensure that it's moved into a private helper that we can call later on. Task-number: QTBUG-57350 Change-Id: I31af7a665fb2d0e37548df31560ed7bbb0c3cadb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp15
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml50
2 files changed, 65 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 0eac7fe1..f07b107e 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -698,6 +698,21 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *, QMouseEve
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 0404fd86..6d017dc8 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -1073,4 +1073,54 @@ TestCase {
mouseRelease(control, control.width + 10, control.height / 2, Qt.LeftButton);
verify(mouseSignalSequenceSpy.success);
}
+
+
+ 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();
+ }
}