diff options
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); } } |