aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-07-08 15:53:50 +0200
committerMitch Curtis <mitch.curtis@qt.io>2016-07-08 14:35:07 +0000
commit38f7d855f2485cfb6a3a4328c1d31bac44ee0ae0 (patch)
treeebffd16a478d9f79983d16d97466208ee925151a
parent780200919d4e5d68aad3d91845877515e10cbc03 (diff)
SwipeDelegate: only consume child events if we grabbed the mouse
Change-Id: Ie808d06824e3bbdb36111625fbb5c59ee9d4e2a4 Task-number: QTBUG-54648 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp12
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml24
2 files changed, 31 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 140dd728..1edc5018 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -545,7 +545,7 @@ bool QQuickSwipeDelegatePrivate::handleMousePressEvent(QQuickItem *item, QMouseE
{
Q_Q(QQuickSwipeDelegate);
QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&swipe);
- // If the position is 0, we want to handle events ourself - we don't want child items to steal them.
+ // If the position is 0, we want to handle events ourselves - we don't want child items to steal them.
// This code will only get called when a child item has been created;
// events will go through the regular channels (mousePressEvent()) until then.
if (qFuzzyIsNull(swipePrivate->position)) {
@@ -618,7 +618,7 @@ bool QQuickSwipeDelegatePrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEv
// If the control was exposed before the drag begun, the distance should be inverted.
// For example, if the control had been swiped to the right, the position would be 1.0.
- // If the control was then swiped the left by a distance of -20 pixels, the normalized
+ // If the control was then swiped to the left by a distance of -20 pixels, the normalized
// distance might be -0.2, for example, which cannot be used as the position; the swipe
// started from the right, so we account for that by adding the position.
if (qFuzzyIsNull(normalizedDistance)) {
@@ -658,6 +658,9 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *, QMouseEve
QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&swipe);
swipePrivate->velocityCalculator.stopMeasuring(event->pos(), event->timestamp());
+ const bool hadGrabbedMouse = q->keepMouseGrab();
+ q->setKeepMouseGrab(false);
+
// 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 ||
@@ -676,9 +679,8 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *, QMouseEve
swipePrivate->wasComplete = false;
}
- q->setKeepMouseGrab(false);
-
- return true;
+ // Only consume child events if we had grabbed the mouse.
+ return hadGrabbedMouse;
}
void QQuickSwipeDelegatePrivate::resizeContent()
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index 6666589f..f89893c3 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -426,25 +426,49 @@ TestCase {
}
}
+ Component {
+ id: signalSpyComponent
+
+ SignalSpy {}
+ }
+
function test_eventsToLeftAndRight() {
var control = swipeDelegateWithButtonComponent.createObject(testCase);
verify(control);
// The button should be pressed instead of the SwipeDelegate.
mouseDrag(control, control.width / 2, control.height / 2, -control.width, 0);
+ // Mouse has been released by this stage.
verify(!control.pressed);
compare(control.swipe.position, -1.0);
verify(control.swipe.rightItem);
verify(control.swipe.rightItem.visible);
compare(control.swipe.rightItem.parent, control);
+ var buttonPressedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "pressed" });
+ verify(buttonPressedSpy);
+ verify(buttonPressedSpy.valid);
+ var buttonReleasedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "released" });
+ verify(buttonReleasedSpy);
+ verify(buttonReleasedSpy.valid);
+ var buttonClickedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "clicked" });
+ verify(buttonClickedSpy);
+ verify(buttonClickedSpy.valid);
+
+ // Now press the button.
mousePress(control, control.width / 2, control.height / 2);
verify(!control.pressed);
var button = control.swipe.rightItem;
verify(button.pressed);
+ compare(buttonPressedSpy.count, 1);
+ compare(buttonReleasedSpy.count, 0);
+ compare(buttonClickedSpy.count, 0);
mouseRelease(control, control.width / 2, control.height / 2);
verify(!button.pressed);
+ compare(buttonPressedSpy.count, 1);
+ compare(buttonReleasedSpy.count, 1);
+ compare(buttonClickedSpy.count, 1);
// Returning back to a position of 0 and pressing on the control should
// result in the control being pressed.