aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-10-24 11:40:47 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-11-14 05:10:55 +0000
commit38a016c7b1337d83d77879f45b4a2e6fec11d049 (patch)
tree13781c4ad0503fa5e664a9fbd3537c8ffe0a7232
parent5885841150f36ffb44f592512513cec2fafffb0b (diff)
QQuickEventPoint: make ungrab/cancel notifications more consistent
setGrabberPointerHandler is now implemented more similarly to setGrabberItem. One improvement is that in tests/manual/pointer/pinchDragFlingMPTA.qml the MPTA deactivates when the PinchHandler takes over its touchpoint grabs. Change-Id: I0bd4f143b5f25f1b393839f86c2a7802f1fa1886 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/quick/items/qquickevents.cpp26
-rw-r--r--tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp16
2 files changed, 20 insertions, 22 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 8653d758de..35ace7592f 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -800,7 +800,7 @@ void QQuickEventPoint::setGrabberItem(QQuickItem *grabber)
m_grabberIsHandler = false;
m_sceneGrabPos = m_scenePos;
if (oldGrabberHandler)
- oldGrabberHandler->onGrabChanged(oldGrabberHandler, CancelGrabExclusive, this);
+ oldGrabberHandler->onGrabChanged(oldGrabberHandler, (grabber ? CancelGrabExclusive : UngrabExclusive), this);
else if (oldGrabberItem && oldGrabberItem != grabber && grabber && pointerEvent()->asPointerTouchEvent())
oldGrabberItem->touchUngrabEvent();
for (QPointer<QQuickPointerHandler> passiveGrabber : m_passiveGrabbers)
@@ -837,26 +837,24 @@ void QQuickEventPoint::setGrabberPointerHandler(QQuickPointerHandler *grabber, b
}
if (exclusive) {
if (grabber != m_exclusiveGrabber.data()) {
+ QQuickPointerHandler *oldGrabberHandler = grabberPointerHandler();
+ QQuickItem *oldGrabberItem = grabberItem();
+ m_exclusiveGrabber = QPointer<QObject>(grabber);
+ m_grabberIsHandler = true;
+ m_sceneGrabPos = m_scenePos;
if (grabber) {
- // set variables before notifying the new grabber
- m_exclusiveGrabber = QPointer<QObject>(grabber);
- m_grabberIsHandler = true;
- m_sceneGrabPos = m_scenePos;
grabber->onGrabChanged(grabber, GrabExclusive, this);
for (QPointer<QQuickPointerHandler> passiveGrabber : m_passiveGrabbers) {
if (passiveGrabber != grabber)
passiveGrabber->onGrabChanged(grabber, OverrideGrabPassive, this);
}
- } else if (QQuickPointerHandler *oldGrabberPointerHandler = qmlobject_cast<QQuickPointerHandler *>(m_exclusiveGrabber.data())) {
- oldGrabberPointerHandler->onGrabChanged(oldGrabberPointerHandler, UngrabExclusive, this);
- } else if (!m_exclusiveGrabber.isNull()) {
- // If there is a previous grabber and it's not a PointerHandler, it must be an Item.
- QQuickItem *oldGrabberItem = static_cast<QQuickItem *>(m_exclusiveGrabber.data());
- // If this point came from a touchscreen, notify that previous grabber Item that it's losing its touch grab.
- if (pointerEvent()->asPointerTouchEvent())
- oldGrabberItem->touchUngrabEvent();
}
- // set variables after notifying the old grabber
+ if (oldGrabberHandler)
+ oldGrabberHandler->onGrabChanged(oldGrabberHandler, (grabber ? CancelGrabExclusive : UngrabExclusive), this);
+ else if (oldGrabberItem && pointerEvent()->asPointerTouchEvent())
+ oldGrabberItem->touchUngrabEvent();
+ // touchUngrabEvent() can result in the grabber being set to null (MPTA does that, for example).
+ // So set it again to ensure that final state is what we want.
m_exclusiveGrabber = QPointer<QObject>(grabber);
m_grabberIsHandler = true;
m_sceneGrabPos = m_scenePos;
diff --git a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
index 09a3c36b6d..c6990f5656 100644
--- a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
+++ b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
@@ -182,12 +182,12 @@ void tst_MptaInterop::touchesThenPinch()
touch.move(1, p1).move(2, p2).commit();
}
- // Press a third touchpoint: PinchHandler grabs, MPTA doesn't
+ // Press a third touchpoint: PinchHandler grabs, MPTA loses its grabs
QPoint p3 = mpta->mapToScene(QPointF(110, 200)).toPoint();
touch.stationary(1).stationary(2).press(3, p3).commit();
QQuickTouchUtils::flush(window);
- QCOMPARE(tp.at(0)->property("pressed").toBool(), true);
- QCOMPARE(tp.at(1)->property("pressed").toBool(), true);
+ QCOMPARE(tp.at(0)->property("pressed").toBool(), false);
+ QCOMPARE(tp.at(1)->property("pressed").toBool(), false);
QCOMPARE(tp.at(2)->property("pressed").toBool(), false);
QCOMPARE(mptaPressedSpy.count(), 1);
QTRY_COMPARE(pointerEvent->point(2)->exclusiveGrabber(), pinch);
@@ -199,9 +199,9 @@ void tst_MptaInterop::touchesThenPinch()
p2 += QPoint(4, 4);
p3 += QPoint(-4, 4);
touch.move(1, p1).move(2, p2).move(3, p3).commit();
-// QTRY_COMPARE(tp.at(0)->property("pressed").toBool(), false); // TODO fails; MPTA doesn't know it lost its grabs
-// QCOMPARE(tp.at(1)->property("pressed").toBool(), false);
-// QCOMPARE(tp.at(2)->property("pressed").toBool(), false);
+ QTRY_COMPARE(tp.at(0)->property("pressed").toBool(), false);
+ QCOMPARE(tp.at(1)->property("pressed").toBool(), false);
+ QCOMPARE(tp.at(2)->property("pressed").toBool(), false);
}
qCDebug(lcPointerTests) << "scale" << pinch->scale() << "rot" << pinch->rotation();
QTRY_VERIFY(pinch->rotation() > 10);
@@ -224,8 +224,8 @@ void tst_MptaInterop::touchesThenPinch()
// QCOMPARE(pointerEvent->point(1)->exclusiveGrabber(), nullptr);
// QCOMPARE(pointerEvent->point(2)->exclusiveGrabber(), nullptr);
// QCOMPARE(pointerEvent->point(3)->exclusiveGrabber(), mpta);
- QCOMPARE(tp.at(0)->property("pressed").toBool(), true);
- QCOMPARE(tp.at(1)->property("pressed").toBool(), true);
+// QCOMPARE(tp.at(0)->property("pressed").toBool(), true);
+// QCOMPARE(tp.at(1)->property("pressed").toBool(), true);
// QCOMPARE(tp.at(2)->property("pressed").toBool(), true);
// QCOMPARE(tp.at(3)->property("pressed").toBool(), true);
}