diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-07-23 13:56:26 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-09-18 20:56:25 +0200 |
commit | a97759a336c597327cb82eebc9f45c793aec32c9 (patch) | |
tree | 632bbee8568d38af56974e02df5810afcf48aedc /src/quick/items/qquickmultipointtoucharea.cpp | |
parent | 39f4d687fc37f48cbc181f42797c42be91b4a345 (diff) |
Remove QQuickPointerEvent etc.; deliver QPointerEvents directly
QEventPoint does not have an accessor to get the QPointerEvent that it
came from, because that's inconsistent with the idea that QPointerEvent
instances are temporary, stack-allocated and movable (the pointer would
often be wrong or null, therefore could not be relied upon).
So most functions that worked directly with QQuickEventPoint before
(which fortunately are still private API) now need to receive the
QPointerEvent too, which we choose to pass by pointer. QEventPoint is
always passed by reference (const where possible) to be consistent with
functions in QPointerEvent that take QEventPoint by reference.
QEventPoint::velocity() should be always in scene coordinates now, which
saves us the trouble of transforming it to each item's coordinate system
during delivery, but means that it will need to be done in handlers or
applications sometimes. If we were going to transform it, it would be
important to also store the sceneVelocity separately in QEventPoint
so that the transformation could be done repeatedly for different items.
Task-number: QTBUG-72173
Change-Id: I7ee164d2e6893c4e407fb7d579c75aa32843933a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quick/items/qquickmultipointtoucharea.cpp')
-rw-r--r-- | src/quick/items/qquickmultipointtoucharea.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index cebfe74df0..8b666628e3 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -45,6 +45,7 @@ #include <private/qquickwindow_p.h> #include <private/qguiapplication_p.h> #include <QtGui/private/qevent_p.h> +#include <QtGui/private/qpointingdevice_p.h> #include <QEvent> #include <QMouseEvent> #include <QDebug> @@ -553,20 +554,19 @@ void QQuickMultiPointTouchArea::touchEvent(QTouchEvent *event) } } -void QQuickMultiPointTouchArea::grabGesture() +void QQuickMultiPointTouchArea::grabGesture(QPointingDevice *dev) { _stealMouse = true; grabMouse(); setKeepMouseGrab(true); - QList<int> ids; - ids.reserve(_touchPoints.size()); + QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(dev); for (auto it = _touchPoints.keyBegin(), end = _touchPoints.keyEnd(); it != end; ++it) { if (*it != -1) // -1 might be the mouse-point, but we already grabbed the mouse above. - ids.append(*it); + if (auto pt = devPriv->queryPointById(*it)) + pt->exclusiveGrabber = this; } - grabTouchPoints(ids); setKeepTouchGrab(true); } @@ -579,13 +579,17 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) clearTouchLists(); QList<QEventPoint> touchPoints; QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window()); + QPointingDevice *dev = nullptr; switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: - case QEvent::TouchEnd: - touchPoints = static_cast<QTouchEvent*>(event)->touchPoints(); + case QEvent::TouchEnd: { + QTouchEvent* te = static_cast<QTouchEvent*>(event); + touchPoints = te->points(); + dev = const_cast<QPointingDevice *>(te->pointingDevice()); break; + } case QEvent::MouseButtonPress: _mouseQpaTouchPoint = QEventPoint(windowPriv->touchMouseId); _touchMouseDevice = windowPriv->touchMouseDevice; @@ -593,7 +597,8 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) case QEvent::MouseMove: case QEvent::MouseButtonRelease: { QMouseEvent *me = static_cast<QMouseEvent*>(event); - _mouseQpaTouchPoint = me->point(0); + _mouseQpaTouchPoint = me->points().first(); + dev = const_cast<QPointingDevice *>(me->pointingDevice()); if (event->type() == QEvent::MouseButtonPress) { addTouchPoint(me); started = true; @@ -623,7 +628,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) } } if (numTouchPoints >= _minimumTouchPoints && numTouchPoints <= _maximumTouchPoints) { - for (const QEventPoint &p : qAsConst(touchPoints)) { + for (QEventPoint &p : touchPoints) { QEventPoint::State touchPointState = p.state(); int id = p.id(); if (touchPointState & QEventPoint::State::Released) { @@ -633,7 +638,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) addTouchPoint(&p); started = true; } else if ((touchPointState & QEventPoint::State::Updated) || - QMutableEventPoint::from(const_cast<QEventPoint &>(p)).stationaryWithModifiedProperty()) { + QMutableEventPoint::from(p).stationaryWithModifiedProperty()) { // React to a stationary point with a property change (velocity, pressure) as if the point moved. (QTBUG-77142) QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints.value(id)); Q_ASSERT(dtp); @@ -668,8 +673,8 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) QQuickGrabGestureEvent event; event._touchPoints = _touchPoints.values(); emit gestureStarted(&event); - if (event.wantsGrab()) - grabGesture(); + if (event.wantsGrab() && dev) + grabGesture(dev); } } @@ -957,7 +962,7 @@ bool QQuickMultiPointTouchArea::childMouseEventFilter(QQuickItem *receiver, QEve _lastFilterableTouchPointIds.clear(); Q_FALLTHROUGH(); case QEvent::TouchUpdate: - for (auto tp : static_cast<QTouchEvent*>(event)->touchPoints()) { + for (const auto &tp : static_cast<QTouchEvent*>(event)->points()) { if (tp.state() == QEventPoint::State::Pressed) _lastFilterableTouchPointIds << tp.id(); } @@ -998,7 +1003,7 @@ bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *te = static_cast<QTouchEvent*>(event); - for (const QEventPoint &point : te->touchPoints()) { + for (const QEventPoint &point : te->points()) { if (contains(mapFromScene(point.scenePosition()))) { containsPoint = true; break; |