From 781f76176239bfbfe6041f2676e2f2804337d312 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 16 Feb 2017 11:26:23 +0100 Subject: notify a PointerHandler when it loses grab due to Item::grabTouchPoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and move more notification responsibility into QQuickEventPoint, thus simplifying QQuickWindowPrivate::grabTouchPoints() which is the implementation behind QQuickItem::grabTouchPoints. It's important for QQuickEventPoint::setGrabberItem to change local state first and then notify, to prevent recursive notify/ungrab loops. MPTA for example does an ungrab when it receives touchUngrabEvent, which then notifies again if the first ungrab was not already fully completed. Change-Id: I6f7b939c8cd76ac5f2d1ddda8b210fa3d31d619a Reviewed-by: Jan Arve Sæther --- src/quick/items/qquickevents.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/quick/items/qquickevents.cpp') diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index bbea32f905..97183c55bc 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -609,13 +609,20 @@ void QQuickEventPoint::setGrabberItem(QQuickItem *grabber) qCDebug(lcPointerGrab) << pointDeviceName(this) << "point" << hex << m_pointId << pointStateString(this) << ": grab" << m_exclusiveGrabber << "->" << grabber; } - if (auto handler = grabberPointerHandler()) - handler->onGrabChanged(handler, CancelGrabExclusive, this); - for (QPointer passiveGrabber : m_passiveGrabbers) - passiveGrabber->onGrabChanged(passiveGrabber, OverrideGrabPassive, this); + QQuickPointerHandler *oldGrabberHandler = grabberPointerHandler(); + QQuickItem *oldGrabberItem = grabberItem(); m_exclusiveGrabber = QPointer(grabber); m_grabberIsHandler = false; m_sceneGrabPos = m_scenePos; + if (oldGrabberHandler) + oldGrabberHandler->onGrabChanged(oldGrabberHandler, CancelGrabExclusive, this); + else if (oldGrabberItem && oldGrabberItem != grabber) { + auto pte = pointerEvent()->asPointerTouchEvent(); + if (pte && pte->asTouchEvent() && pte->asTouchEvent()->touchPointStates() == Qt::TouchPointReleased) + oldGrabberItem->touchUngrabEvent(); + } + for (QPointer passiveGrabber : m_passiveGrabbers) + passiveGrabber->onGrabChanged(passiveGrabber, OverrideGrabPassive, this); } } @@ -656,7 +663,14 @@ void QQuickEventPoint::setGrabberPointerHandler(QQuickPointerHandler *grabber, b } } else if (QQuickPointerHandler *oldGrabberPointerHandler = qmlobject_cast(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(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(); } + m_exclusiveGrabber = QPointer(grabber); m_grabberIsHandler = true; m_sceneGrabPos = m_scenePos; -- cgit v1.2.3