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/handlers/qquickpinchhandler.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/handlers/qquickpinchhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 8413b8b721..b1dca9a905 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -153,15 +153,16 @@ void QQuickPinchHandler::setMaximumRotation(qreal maximumRotation) emit maximumRotationChanged(); } -bool QQuickPinchHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickPinchHandler::wantsPointerEvent(QPointerEvent *event) { if (!QQuickMultiPointHandler::wantsPointerEvent(event)) return false; #if QT_CONFIG(gestures) - if (const auto gesture = event->asPointerNativeGestureEvent()) { + if (event->type() == QEvent::NativeGesture) { + const auto gesture = static_cast<const QNativeGestureEvent *>(event); if (minimumPointCount() == 2) { - switch (gesture->type()) { + switch (gesture->gestureType()) { case Qt::BeginNativeGesture: case Qt::EndNativeGesture: case Qt::ZoomNativeGesture: @@ -243,7 +244,7 @@ void QQuickPinchHandler::onActiveChanged() } } -void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) +void QQuickPinchHandler::handlePointerEventImpl(QPointerEvent *event) { if (Q_UNLIKELY(lcPinchHandler().isDebugEnabled())) { for (const QQuickHandlerPoint &p : currentPoints()) @@ -253,9 +254,10 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) qreal dist = 0; #if QT_CONFIG(gestures) - if (const auto gesture = event->asPointerNativeGestureEvent()) { - mutableCentroid().reset(event->point(0)); - switch (gesture->type()) { + if (event->type() == QEvent::NativeGesture) { + const auto gesture = static_cast<const QNativeGestureEvent *>(event); + mutableCentroid().reset(event, event->point(0)); + switch (gesture->gestureType()) { case Qt::EndNativeGesture: m_activeScale = 1; m_activeRotation = 0; @@ -283,11 +285,12 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) } else #endif // QT_CONFIG(gestures) { - const bool containsReleasedPoints = event->isReleaseEvent(); - QVector<QQuickEventPoint *> chosenPoints; + const bool containsReleasedPoints = event->isEndEvent(); + QVector<QEventPoint> chosenPoints; for (const QQuickHandlerPoint &p : currentPoints()) { - QQuickEventPoint *ep = event->pointById(p.id()); - chosenPoints << ep; + auto ep = event->pointById(p.id()); + Q_ASSERT(ep); + chosenPoints << *ep; } if (!active()) { // Verify that at least one of the points has moved beyond threshold needed to activate the handler @@ -300,14 +303,14 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) const int dragThresholdSquared = dragThreshold * dragThreshold; double accumulatedCentroidDistance = 0; // Used to detect scale - if (event->isPressEvent()) + if (event->isBeginEvent()) m_accumulatedStartCentroidDistance = 0; // Used to detect scale float accumulatedMovementMagnitude = 0; - for (QQuickEventPoint *point : qAsConst(chosenPoints)) { + for (auto &point : chosenPoints) { if (!containsReleasedPoints) { - accumulatedDrag += QVector2D(point->scenePressPosition() - point->scenePosition()); + accumulatedDrag += QVector2D(point.scenePressPosition() - point.scenePosition()); /* In order to detect a drag, we want to check if all points have moved more or less in the same direction. @@ -341,20 +344,20 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) was moved, but the relative position between each finger remained very much the same). This is then used to rule out if there is a rotation or scale. */ - QVector2D pressCentroidRelativePosition = QVector2D(point->scenePosition()) - currentCentroid; - QVector2D currentCentroidRelativePosition = QVector2D(point->scenePressPosition()) - pressCentroid; + QVector2D pressCentroidRelativePosition = QVector2D(point.scenePosition()) - currentCentroid; + QVector2D currentCentroidRelativePosition = QVector2D(point.scenePressPosition()) - pressCentroid; QVector2D centroidRelativeMovement = currentCentroidRelativePosition - pressCentroidRelativePosition; accumulatedMovementMagnitude += centroidRelativeMovement.length(); accumulatedCentroidDistance += qreal(pressCentroidRelativePosition.length()); - if (event->isPressEvent()) - m_accumulatedStartCentroidDistance += qreal((QVector2D(point->scenePressPosition()) - pressCentroid).length()); + if (event->isBeginEvent()) + m_accumulatedStartCentroidDistance += qreal((QVector2D(point.scenePressPosition()) - pressCentroid).length()); } else { - setPassiveGrab(point); + setPassiveGrab(event, point); } - if (point->state() == QQuickEventPoint::Pressed) { - point->setAccepted(false); // don't stop propagation - setPassiveGrab(point); + if (point.state() == QEventPoint::Pressed) { + point.setAccepted(false); // don't stop propagation + setPassiveGrab(event, point); } Q_D(QQuickMultiPointHandler); if (d->dragOverThreshold(point)) @@ -376,17 +379,17 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) if (numberOfPointsDraggedOverThreshold >= 1) { if (requiredNumberOfPointsDraggedOverThreshold && avgDrag.lengthSquared() >= dragThresholdSquared && accumulatedMovementMagnitude < dragThreshold) { // Drag - if (grabPoints(chosenPoints)) + if (grabPoints(event, chosenPoints)) setActive(true); } else if (distanceToCentroidDelta > dragThreshold) { // all points should in accumulation have been moved beyond threshold (?) // Scale - if (grabPoints(chosenPoints)) + if (grabPoints(event, chosenPoints)) setActive(true); } else if (distanceToCentroidDelta < dragThreshold && (centroidMovementDelta < dragThreshold)) { // Rotate // Since it wasn't a scale and if we exceeded the dragthreshold, and the // centroid didn't moved much, the points must have been moved around the centroid. - if (grabPoints(chosenPoints)) + if (grabPoints(event, chosenPoints)) setActive(true); } } |