diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-10-14 20:44:39 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-10-27 00:47:05 +0200 |
commit | e783ef04fbbaa9a53121a6f575414b48043a10d2 (patch) | |
tree | 092412514fbe8373a49061021dea4d64e2926a2d | |
parent | 319c21e6117f1fdb06d82c1201f5d0001e3aeb48 (diff) |
Deal with QEvent::setAccepted() calling QEventPoint::setAccepted()
Traditionally, a QQuickItem subclass could override touchEvent();
if the event is still accepted when it returns, that meant the item
handled all the points, so completely that the item should get an
implicit grab of those points, and they should not be delivered further
to any other items underneath. But it's often not so simple in
multi-touch UIs, which is why each QEventPoint has its own accept flag.
QPointerEvent::setAccepted() now iterates the points and calls
QEventPoint::setAccepted() on each; so QQuickWindow doesn't need to do
anything to make that happen anymore.
Change-Id: Idbe7abf278411ee2fea598c1a1939f4bdb214aa0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/quick/items/qquickpincharea.cpp | 7 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 15 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index 6a5dda483d..8de9071b21 100644 --- a/src/quick/items/qquickpincharea.cpp +++ b/src/quick/items/qquickpincharea.cpp @@ -335,9 +335,12 @@ void QQuickPinchArea::touchEvent(QTouchEvent *event) case QEvent::TouchBegin: case QEvent::TouchUpdate: d->touchPoints.clear(); - for (auto &tp : event->points()) { - if (!(tp.state() & QEventPoint::State::Released)) + for (int i = 0; i < event->pointCount(); ++i) { + auto &tp = event->point(i); + if (!(tp.state() & QEventPoint::State::Released)) { d->touchPoints << tp; + tp.setAccepted(); + } } updatePinch(); break; diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 5011564fa5..ab01465e4f 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -866,7 +866,7 @@ QMouseEvent QQuickWindowPrivate::touchToMouseEvent(QEvent::Type type, const QEve (type == QEvent::MouseMove ? Qt::NoButton : Qt::LeftButton), (type == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton), event->modifiers(), Qt::MouseEventSynthesizedByQt); - ret.setAccepted(true); + ret.setAccepted(true); // this now causes the persistent touchpoint to be accepted too ret.setTimestamp(event->timestamp()); static_assert(sizeof(QMutableSinglePointEvent) == sizeof(QMouseEvent)); return *static_cast<QMouseEvent*>(static_cast<QSinglePointEvent*>(&ret)); @@ -2825,11 +2825,8 @@ bool QQuickWindowPrivate::deliverPressOrReleaseEvent(QPointerEvent *event, bool for (QQuickItem *item : targetItems) { hasFiltered.clear(); if (!handlersOnly && sendFilteredPointerEvent(event, item)) { - if (event->isAccepted()) { - for (int i = 0; i < event->pointCount(); ++i) - event->point(i).setAccepted(); + if (event->isAccepted()) return true; - } skipDelivery.append(item); } @@ -2885,7 +2882,6 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, bool isG } else if (item->isEnabled() && item->isVisible()) { pointerEvent->setExclusiveGrabber(point, item); } - point.setAccepted(true); } return; } @@ -2927,7 +2923,6 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, bool isG bool isPressOrRelease = pointerEvent->isBeginEvent() || pointerEvent->isEndEvent(); for (int i = 0; i < touchEvent.pointCount(); ++i) { auto &point = QMutableEventPoint::from(touchEvent.point(i)); - point.setAccepted(); if (isPressOrRelease) pointerEvent->setExclusiveGrabber(point, item); } @@ -3218,11 +3213,8 @@ bool QQuickWindowPrivate::sendFilteredPointerEventImpl(QPointerEvent *event, QQu if (filteringParent->childMouseEventFilter(receiver, &filteringParentTouchEvent)) { qCDebug(DBG_TOUCH) << "touch event intercepted by childMouseEventFilter of " << filteringParent; skipDelivery.append(filteringParent); - for (qsizetype i = 0; i < filteringParentTouchEvent.pointCount(); ++i) { - auto &point = QMutableEventPoint::from(filteringParentTouchEvent.point(i)); - point.setAccepted(); + for (auto point : filteringParentTouchEvent.points()) te->setExclusiveGrabber(point, filteringParent); - } return true; } else if (Q_LIKELY(QCoreApplication::testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents))) { @@ -3270,6 +3262,7 @@ bool QQuickWindowPrivate::sendFilteredPointerEventImpl(QPointerEvent *event, QQu // Now that we're done sending a synth mouse event, and it wasn't grabbed, // the touchpoint is no longer acting as a synthetic mouse. Restore previous state. cancelTouchMouseSynthesis(); + mouseEvent.point(0).setAccepted(false); // because touchToMouseEvent() set it true } // Only one touchpoint can be treated as a synthetic mouse, so after childMouseEventFilter // has been called once, we're done with this loop over the touchpoints. |