diff options
-rw-r--r-- | src/quick/items/qquickevents.cpp | 26 | ||||
-rw-r--r-- | tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp | 16 |
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); } |