diff options
Diffstat (limited to 'src/quick/handlers')
23 files changed, 384 insertions, 336 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 492897b68b..0794b86b11 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -110,10 +110,10 @@ QPointF QQuickDragHandler::targetCentroidPosition() return pos; } -void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) +void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) { - QQuickMultiPointHandler::onGrabChanged(grabber, transition, point); - if (grabber == this && transition == QQuickEventPoint::GrabExclusive && target()) { + QQuickMultiPointHandler::onGrabChanged(grabber, transition, event, point); + if (grabber == this && transition == QPointingDevice::GrabExclusive && target()) { // In case the grab got handed over from another grabber, we might not get the Press. auto isDescendant = [](QQuickItem *parent, QQuickItem *target) { @@ -162,7 +162,7 @@ void QQuickDragHandler::onActiveChanged() QQuickMultiPointHandler::onActiveChanged(); if (active()) { if (auto parent = parentItem()) { - if (currentEvent()->asPointerTouchEvent()) + if (QQuickWindowPrivate::isTouchEvent(currentEvent())) parent->setKeepTouchGrab(true); // tablet and mouse are treated the same by Item's legacy event handling, and // touch becomes synth-mouse for Flickable, so we need to prevent stealing @@ -179,7 +179,7 @@ void QQuickDragHandler::onActiveChanged() } } -void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) +void QQuickDragHandler::handlePointerEventImpl(QPointerEvent *event) { QQuickMultiPointHandler::handlePointerEventImpl(event); event->setAccepted(true); @@ -199,18 +199,19 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) // and in approximately the same direction qreal minAngle = 361; qreal maxAngle = -361; - bool allOverThreshold = !event->isReleaseEvent(); - QVector <QQuickEventPoint *> chosenPoints; + bool allOverThreshold = !event->isEndEvent(); + QVector<QEventPoint> chosenPoints; - if (event->isPressEvent()) + if (event->isBeginEvent()) m_pressedInsideTarget = target() && currentPoints().count() > 0; for (const QQuickHandlerPoint &p : currentPoints()) { if (!allOverThreshold) break; - QQuickEventPoint *point = event->pointById(p.id()); - chosenPoints << point; - setPassiveGrab(point); + auto point = event->pointById(p.id()); + Q_ASSERT(point); + chosenPoints << *point; + setPassiveGrab(event, *point); // Calculate drag delta, taking into account the axis enabled constraint // i.e. if xAxis is not enabled, then ignore the horizontal component of the actual movement QVector2D accumulatedDragDelta = QVector2D(point->scenePosition() - point->scenePressPosition()); @@ -237,7 +238,7 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) if (allOverThreshold && !overThreshold) allOverThreshold = false; - if (event->isPressEvent()) { + if (event->isBeginEvent()) { // m_pressedInsideTarget should stay true iff ALL points in which DragHandler is interested // have been pressed inside the target() Item. (E.g. in a Slider the parent might be the // whole control while the target is just the knob.) @@ -250,7 +251,7 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) // (That affects behavior for mouse but not for touch, because Flickable only handles mouse.) // So we have to compensate by accepting the event here to avoid any parent Flickable from // getting the event via direct delivery and grabbing too soon. - point->setAccepted(event->asPointerMouseEvent()); // stop propagation iff it's a mouse event + point->setAccepted(QQuickWindowPrivate::isMouseEvent(event)); // stop propagation iff it's a mouse event } } if (allOverThreshold) { @@ -258,7 +259,7 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) if (angleDiff > 180) angleDiff = 360 - angleDiff; qCDebug(lcDragHandler) << "angle min" << minAngle << "max" << maxAngle << "range" << angleDiff; - if (angleDiff < DragAngleToleranceDegrees && grabPoints(chosenPoints)) + if (angleDiff < DragAngleToleranceDegrees && grabPoints(event, chosenPoints)) setActive(true); } } diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h index 1315f79114..c1ff108e13 100644 --- a/src/quick/handlers/qquickdraghandler_p.h +++ b/src/quick/handlers/qquickdraghandler_p.h @@ -77,7 +77,7 @@ public: explicit QQuickDragHandler(QQuickItem *parent = nullptr); - void handlePointerEventImpl(QQuickPointerEvent *event) override; + void handlePointerEventImpl(QPointerEvent *event) override; QQuickDragAxis *xAxis() { return &m_xAxis; } QQuickDragAxis *yAxis() { return &m_yAxis; } @@ -95,7 +95,7 @@ Q_SIGNALS: protected: void onActiveChanged() override; - void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override; + void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override; private: void ungrab(); diff --git a/src/quick/handlers/qquickhandlerpoint.cpp b/src/quick/handlers/qquickhandlerpoint.cpp index 2990215719..3cd1bccbfc 100644 --- a/src/quick/handlers/qquickhandlerpoint.cpp +++ b/src/quick/handlers/qquickhandlerpoint.cpp @@ -49,7 +49,7 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_TOUCH_TARGET) \inqmlmodule QtQuick \brief An event point. - A QML representation of a QQuickEventPoint. + A QML representation of a QEventPoint. It's possible to make bindings to properties of a handler's current \l {SinglePointHandler::point}{point} or @@ -98,46 +98,44 @@ void QQuickHandlerPoint::reset() m_pressedModifiers = Qt::NoModifier; } -void QQuickHandlerPoint::reset(const QQuickEventPoint *point) +void QQuickHandlerPoint::reset(const QPointerEvent *event, const QEventPoint &point) { - m_id = point->pointId(); - m_device = point->pointerEvent()->device(); - const QQuickPointerEvent *event = point->pointerEvent(); - switch (point->state()) { - case QQuickEventPoint::Pressed: - m_pressPosition = point->position(); - m_scenePressPosition = point->scenePosition(); - m_pressedButtons = event->buttons(); + m_id = point.id(); + m_device = event->pointingDevice(); + switch (point.state()) { + case QEventPoint::Pressed: + m_pressPosition = point.position(); + m_scenePressPosition = point.scenePosition(); break; default: break; } - m_scenePressPosition = point->scenePressPosition(); - m_pressedButtons = event->buttons(); + const bool isTouch = QQuickWindowPrivate::isTouchEvent(event); + if (!isTouch) + m_pressedButtons = static_cast<const QSinglePointEvent *>(event)->buttons(); m_pressedModifiers = event->modifiers(); - if (event->asPointerTouchEvent()) { - const QQuickEventTouchPoint *tp = static_cast<const QQuickEventTouchPoint *>(point); - m_uniqueId = tp->uniqueId(); - m_rotation = tp->rotation(); - m_pressure = tp->pressure(); - m_ellipseDiameters = tp->ellipseDiameters(); + if (isTouch) { + m_uniqueId = point.uniqueId(); + m_rotation = point.rotation(); + m_pressure = point.pressure(); + m_ellipseDiameters = point.ellipseDiameters(); #if QT_CONFIG(tabletevent) - } else if (event->asPointerTabletEvent()) { - m_uniqueId = event->device()->uniqueId(); - m_rotation = static_cast<const QQuickEventTabletPoint *>(point)->rotation(); - m_pressure = static_cast<const QQuickEventTabletPoint *>(point)->pressure(); + } else if (QQuickWindowPrivate::isTabletEvent(event)) { + m_uniqueId = event->pointingDevice()->uniqueId(); + m_rotation = point.rotation(); + m_pressure = point.pressure(); m_ellipseDiameters = QSizeF(); #endif } else { - m_uniqueId = event->device()->uniqueId(); + m_uniqueId = event->pointingDevice()->uniqueId(); m_rotation = 0; - m_pressure = event->buttons() ? 1 : 0; + m_pressure = m_pressedButtons ? 1 : 0; m_ellipseDiameters = QSizeF(); } - m_position = point->position(); - m_scenePosition = point->scenePosition(); - if (point->state() == QQuickEventPoint::Updated) - m_velocity = point->velocity(); + m_position = point.position(); + m_scenePosition = point.scenePosition(); + if (point.state() == QEventPoint::Updated) + m_velocity = point.velocity(); } void QQuickHandlerPoint::reset(const QVector<QQuickHandlerPoint> &points) diff --git a/src/quick/handlers/qquickhandlerpoint_p.h b/src/quick/handlers/qquickhandlerpoint_p.h index fd3b365e32..8e175281f2 100644 --- a/src/quick/handlers/qquickhandlerpoint_p.h +++ b/src/quick/handlers/qquickhandlerpoint_p.h @@ -96,7 +96,7 @@ public: void localize(QQuickItem *item); void reset(); - void reset(const QQuickEventPoint *point); + void reset(const QPointerEvent *event, const QEventPoint &point); void reset(const QVector<QQuickHandlerPoint> &points); private: diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp index 76e5bc0605..cdb9b2578c 100644 --- a/src/quick/handlers/qquickhoverhandler.cpp +++ b/src/quick/handlers/qquickhoverhandler.cpp @@ -89,12 +89,12 @@ void QQuickHoverHandler::componentComplete() QQuickItemPrivate::get(parentItem())->setHasHoverInChild(true); } -bool QQuickHoverHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickHoverHandler::wantsPointerEvent(QPointerEvent *event) { - QQuickEventPoint *point = event->point(0); - if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(point) && parentContains(point)) { + auto &point = event->point(0); + if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(event, point) && parentContains(point)) { // assume this is a mouse or tablet event, so there's only one point - setPointId(point->pointId()); + setPointId(point.id()); return true; } @@ -106,22 +106,22 @@ bool QQuickHoverHandler::wantsPointerEvent(QQuickPointerEvent *event) // the hovered property to transition to false prematurely. // If a QQuickPointerTabletEvent caused the hovered property to become true, // then only another QQuickPointerTabletEvent can make it become false. - if (!(m_hoveredTablet && event->asPointerMouseEvent())) + if (!(m_hoveredTablet && QQuickWindowPrivate::isMouseEvent(event))) setHovered(false); return false; } -void QQuickHoverHandler::handleEventPoint(QQuickEventPoint *point) +void QQuickHoverHandler::handleEventPoint(QPointerEvent *ev, QEventPoint &point) { bool hovered = true; - if (point->state() == QQuickEventPoint::Released && - point->pointerEvent()->device()->pointerType() == QPointingDevice::PointerType::Finger) + if (point.state() == QEventPoint::Released && + ev->pointingDevice()->pointerType() == QPointingDevice::PointerType::Finger) hovered = false; - else if (point->pointerEvent()->asPointerTabletEvent()) + else if (QQuickWindowPrivate::isTabletEvent(ev)) m_hoveredTablet = true; setHovered(hovered); - setPassiveGrab(point); + setPassiveGrab(ev, point); } /*! diff --git a/src/quick/handlers/qquickhoverhandler_p.h b/src/quick/handlers/qquickhoverhandler_p.h index 4b9d0a9f39..fe9a3bcde3 100644 --- a/src/quick/handlers/qquickhoverhandler_p.h +++ b/src/quick/handlers/qquickhoverhandler_p.h @@ -76,8 +76,8 @@ Q_SIGNALS: protected: void componentComplete() override; - bool wantsPointerEvent(QQuickPointerEvent *event) override; - void handleEventPoint(QQuickEventPoint *point) override; + bool wantsPointerEvent(QPointerEvent *event) override; + void handleEventPoint(QPointerEvent *ev, QEventPoint &point) override; private: void setHovered(bool hovered); diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp index f404788de4..97cb958aa6 100644 --- a/src/quick/handlers/qquickmultipointhandler.cpp +++ b/src/quick/handlers/qquickmultipointhandler.cpp @@ -64,18 +64,18 @@ QQuickMultiPointHandler::QQuickMultiPointHandler(QQuickItem *parent, int minimum { } -bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickMultiPointHandler::wantsPointerEvent(QPointerEvent *event) { Q_D(QQuickMultiPointHandler); if (!QQuickPointerDeviceHandler::wantsPointerEvent(event)) return false; - if (event->asPointerScrollEvent()) + if (event->type() == QEvent::Wheel) return false; bool ret = false; #if QT_CONFIG(gestures) - if (event->asPointerNativeGestureEvent() && event->point(0)->state() != QQuickEventPoint::Released) + if (event->type() == QEvent::NativeGesture && event->point(0).state() != QEventPoint::Released) ret = true; #endif @@ -86,7 +86,7 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) // are all still there in the event, we're good to go (do not reset // currentPoints, because we don't want to lose the pressPosition, and do // not want to reshuffle the order either). - const QVector<QQuickEventPoint *> candidatePoints = eligiblePoints(event); + const auto candidatePoints = eligiblePoints(event); if (candidatePoints.count() != d->currentPoints.count()) { d->currentPoints.clear(); if (active()) { @@ -103,7 +103,7 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) const int c = candidatePoints.count(); d->currentPoints.resize(c); for (int i = 0; i < c; ++i) { - d->currentPoints[i].reset(candidatePoints[i]); + d->currentPoints[i].reset(event, candidatePoints[i]); d->currentPoints[i].localize(parentItem()); } } else { @@ -112,7 +112,7 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) return ret; } -void QQuickMultiPointHandler::handlePointerEventImpl(QQuickPointerEvent *event) +void QQuickMultiPointHandler::handlePointerEventImpl(QPointerEvent *event) { Q_D(QQuickMultiPointHandler); QQuickPointerHandler::handlePointerEventImpl(event); @@ -120,9 +120,8 @@ void QQuickMultiPointHandler::handlePointerEventImpl(QQuickPointerEvent *event) // is _not_ a shallow copy of the QQuickPointerTouchEvent::m_touchPoints vector. // So we have to update our currentPoints instances based on the given event. for (QQuickHandlerPoint &p : d->currentPoints) { - const QQuickEventPoint *ep = event->pointById(p.id()); - if (ep) - p.reset(ep); + if (const QEventPoint *ep = event->pointById(p.id())) + p.reset(event, *ep); } QPointF sceneGrabPos = d->centroid.sceneGrabPosition(); d->centroid.reset(d->currentPoints); @@ -146,36 +145,35 @@ void QQuickMultiPointHandler::onActiveChanged() } } -void QQuickMultiPointHandler::onGrabChanged(QQuickPointerHandler *, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *) +void QQuickMultiPointHandler::onGrabChanged(QQuickPointerHandler *, QPointingDevice::GrabTransition transition, QPointerEvent *, QEventPoint &) { Q_D(QQuickMultiPointHandler); // If another handler or item takes over this set of points, assume it has // decided that it's the better fit for them. Don't immediately re-grab // at the next opportunity. This should help to avoid grab cycles // (e.g. between DragHandler and PinchHandler). - if (transition == QQuickEventPoint::UngrabExclusive || transition == QQuickEventPoint::CancelGrabExclusive) + if (transition == QPointingDevice::UngrabExclusive || transition == QPointingDevice::CancelGrabExclusive) d->currentPoints.clear(); } -QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointerEvent *event) +QVector<QEventPoint> QQuickMultiPointHandler::eligiblePoints(QPointerEvent *event) { - QVector<QQuickEventPoint *> ret; - int c = event->pointCount(); + QVector<QEventPoint> ret; // If one or more points are newly pressed or released, all non-released points are candidates for this handler. // In other cases however, check whether it would be OK to steal the grab if the handler chooses to do that. - bool stealingAllowed = event->isPressEvent() || event->isReleaseEvent(); - for (int i = 0; i < c; ++i) { - QQuickEventPoint *p = event->point(i); - if (QQuickPointerMouseEvent *me = event->asPointerMouseEvent()) { - if (me->buttons() == Qt::NoButton) + bool stealingAllowed = event->isBeginEvent() || event->isEndEvent(); + for (int i = 0; i < event->pointCount(); ++i) { + auto &p = QMutableEventPoint::from(event->point(i)); + if (QQuickWindowPrivate::isMouseEvent(event)) { + if (static_cast<QMouseEvent *>(event)->buttons() == Qt::NoButton) continue; } if (!stealingAllowed) { - QObject *exclusiveGrabber = p->exclusiveGrabber(); - if (exclusiveGrabber && exclusiveGrabber != this && !canGrab(p)) + QObject *exclusiveGrabber = event->exclusiveGrabber(p); + if (exclusiveGrabber && exclusiveGrabber != this && !canGrab(event, p)) continue; } - if (p->state() != QQuickEventPoint::Released && wantsEventPoint(p)) + if (p.state() != QEventPoint::Released && wantsEventPoint(event, p)) ret << p; } return ret; @@ -274,7 +272,7 @@ QVector<QQuickHandlerPoint> &QQuickMultiPointHandler::currentPoints() return d->currentPoints; } -bool QQuickMultiPointHandler::hasCurrentPoints(QQuickPointerEvent *event) +bool QQuickMultiPointHandler::hasCurrentPoints(QPointerEvent *event) { Q_D(const QQuickMultiPointHandler); if (event->pointCount() < d->currentPoints.size() || d->currentPoints.size() == 0) @@ -282,10 +280,10 @@ bool QQuickMultiPointHandler::hasCurrentPoints(QQuickPointerEvent *event) // TODO optimize: either ensure the points are sorted, // or use std::equal with a predicate for (const QQuickHandlerPoint &p : qAsConst(d->currentPoints)) { - const QQuickEventPoint *ep = event->pointById(p.id()); + const QEventPoint *ep = event->pointById(p.id()); if (!ep) return false; - if (ep->state() == QQuickEventPoint::Released) + if (ep->state() == QEventPoint::Released) return false; } return true; @@ -358,26 +356,28 @@ qreal QQuickMultiPointHandler::averageAngleDelta(const QVector<PointData> &old, return avgAngleDelta; } -void QQuickMultiPointHandler::acceptPoints(const QVector<QQuickEventPoint *> &points) +void QQuickMultiPointHandler::acceptPoints(const QVector<QEventPoint> &points) { - for (QQuickEventPoint* point : points) - point->setAccepted(); + // "auto point" is a copy, but it's OK because + // setAccepted() changes QEventPointPrivate::accept via the shared d-pointer + for (auto point : points) + point.setAccepted(); } -bool QQuickMultiPointHandler::grabPoints(const QVector<QQuickEventPoint *> &points) +bool QQuickMultiPointHandler::grabPoints(QPointerEvent *event, const QVector<QEventPoint> &points) { if (points.isEmpty()) return false; bool allowed = true; - for (QQuickEventPoint* point : points) { - if (point->exclusiveGrabber() != this && !canGrab(point)) { + for (auto &point : points) { + if (event->exclusiveGrabber(point) != this && !canGrab(event, point)) { allowed = false; break; } } if (allowed) { - for (QQuickEventPoint* point : points) - setExclusiveGrab(point); + for (auto point : points) + setExclusiveGrab(event, point); } return allowed; } diff --git a/src/quick/handlers/qquickmultipointhandler_p.h b/src/quick/handlers/qquickmultipointhandler_p.h index c0751aa5c5..01cd78f9db 100644 --- a/src/quick/handlers/qquickmultipointhandler_p.h +++ b/src/quick/handlers/qquickmultipointhandler_p.h @@ -91,22 +91,22 @@ protected: qreal angle; }; - bool wantsPointerEvent(QQuickPointerEvent *event) override; - void handlePointerEventImpl(QQuickPointerEvent *event) override; + bool wantsPointerEvent(QPointerEvent *event) override; + void handlePointerEventImpl(QPointerEvent *event) override; void onActiveChanged() override; - void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override; - QVector<QQuickHandlerPoint> ¤tPoints(); + void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override; + QList<QQuickHandlerPoint> ¤tPoints(); QQuickHandlerPoint &mutableCentroid(); - bool hasCurrentPoints(QQuickPointerEvent *event); - QVector<QQuickEventPoint *> eligiblePoints(QQuickPointerEvent *event); + bool hasCurrentPoints(QPointerEvent *event); + QVector<QEventPoint> eligiblePoints(QPointerEvent *event); qreal averageTouchPointDistance(const QPointF &ref); qreal averageStartingDistance(const QPointF &ref); qreal averageTouchPointAngle(const QPointF &ref); qreal averageStartingAngle(const QPointF &ref); QVector<PointData> angles(const QPointF &ref) const; static qreal averageAngleDelta(const QVector<PointData> &old, const QVector<PointData> &newAngles); - void acceptPoints(const QVector<QQuickEventPoint *> &points); - bool grabPoints(const QVector<QQuickEventPoint *> &points); + void acceptPoints(const QVector<QEventPoint> &points); + bool grabPoints(QPointerEvent *event, const QVector<QEventPoint> &points); void moveTarget(QPointF pos); Q_DECLARE_PRIVATE(QQuickMultiPointHandler) 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); } } diff --git a/src/quick/handlers/qquickpinchhandler_p.h b/src/quick/handlers/qquickpinchhandler_p.h index b4e9fa0336..8099982d46 100644 --- a/src/quick/handlers/qquickpinchhandler_p.h +++ b/src/quick/handlers/qquickpinchhandler_p.h @@ -106,9 +106,9 @@ signals: void updated(); protected: - bool wantsPointerEvent(QQuickPointerEvent *event) override; + bool wantsPointerEvent(QPointerEvent *event) override; void onActiveChanged() override; - void handlePointerEventImpl(QQuickPointerEvent *event) override; + void handlePointerEventImpl(QPointerEvent *event) override; private: // properties diff --git a/src/quick/handlers/qquickpointerdevicehandler.cpp b/src/quick/handlers/qquickpointerdevicehandler.cpp index 592abb6660..a27aec7d56 100644 --- a/src/quick/handlers/qquickpointerdevicehandler.cpp +++ b/src/quick/handlers/qquickpointerdevicehandler.cpp @@ -290,7 +290,7 @@ void QQuickPointerDeviceHandler::setAcceptedModifiers(Qt::KeyboardModifiers acce emit acceptedModifiersChanged(); } -bool QQuickPointerDeviceHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickPointerDeviceHandler::wantsPointerEvent(QPointerEvent *event) { Q_D(QQuickPointerDeviceHandler); if (!QQuickPointerHandler::wantsPointerEvent(event)) @@ -301,14 +301,15 @@ bool QQuickPointerDeviceHandler::wantsPointerEvent(QQuickPointerEvent *event) << "modifiers" << d->acceptedModifiers; if (!d->acceptedDevices.testFlag(event->device()->type())) return false; - if (!d->acceptedPointerTypes.testFlag(event->device()->pointerType())) + if (!d->acceptedPointerTypes.testFlag(event->pointingDevice()->pointerType())) return false; if (d->acceptedModifiers != Qt::KeyboardModifierMask && event->modifiers() != d->acceptedModifiers) return false; // HoverHandler sets acceptedButtons to Qt::NoButton to indicate that button state is irrelevant. - if (event->device()->pointerType() != QPointingDevice::PointerType::Finger && acceptedButtons() != Qt::NoButton && - (event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0 - && !event->asPointerScrollEvent()) + if (event->pointingDevice()->pointerType() != QPointingDevice::PointerType::Finger && + acceptedButtons() != Qt::NoButton && event->type() != QEvent::Wheel && + (static_cast<QSinglePointEvent *>(event)->buttons() & acceptedButtons()) == 0 && + (static_cast<QSinglePointEvent *>(event)->button() & acceptedButtons()) == 0) return false; return true; } diff --git a/src/quick/handlers/qquickpointerdevicehandler_p.h b/src/quick/handlers/qquickpointerdevicehandler_p.h index 28c88db2b7..6091646c14 100644 --- a/src/quick/handlers/qquickpointerdevicehandler_p.h +++ b/src/quick/handlers/qquickpointerdevicehandler_p.h @@ -87,7 +87,7 @@ Q_SIGNALS: protected: QQuickPointerDeviceHandler(QQuickPointerDeviceHandlerPrivate &dd, QQuickItem *parent = nullptr); - bool wantsPointerEvent(QQuickPointerEvent *event) override; + bool wantsPointerEvent(QPointerEvent *event) override; Q_DECLARE_PRIVATE(QQuickPointerDeviceHandler) }; diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index ce59a35b62..0dc2435b4e 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -247,31 +247,32 @@ bool QQuickPointerHandler::isCursorShapeExplicitlySet() const call its parent class's implementation in addition to (usually after) whatever custom behavior it implements. */ -void QQuickPointerHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) +void QQuickPointerHandler::onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, + QPointerEvent *event, QEventPoint &point) { + Q_UNUSED(event); qCDebug(lcPointerHandlerGrab) << point << transition << grabber; - Q_ASSERT(point); if (grabber == this) { bool wasCanceled = false; switch (transition) { - case QQuickEventPoint::GrabPassive: - case QQuickEventPoint::GrabExclusive: + case QPointingDevice::GrabPassive: + case QPointingDevice::GrabExclusive: break; - case QQuickEventPoint::CancelGrabPassive: - case QQuickEventPoint::CancelGrabExclusive: + case QPointingDevice::CancelGrabPassive: + case QPointingDevice::CancelGrabExclusive: wasCanceled = true; // the grab was stolen by something else Q_FALLTHROUGH(); - case QQuickEventPoint::UngrabPassive: - case QQuickEventPoint::UngrabExclusive: + case QPointingDevice::UngrabPassive: + case QPointingDevice::UngrabExclusive: setActive(false); - point->setAccepted(false); + point.setAccepted(false); if (auto par = parentItem()) { Q_D(const QQuickPointerHandler); par->setKeepMouseGrab(d->hadKeepMouseGrab); par->setKeepTouchGrab(d->hadKeepTouchGrab); } break; - case QQuickEventPoint::OverrideGrabPassive: + case QPointingDevice::OverrideGrabPassive: // Passive grab is still there, but we won't receive point updates right now. // No need to notify about this. return; @@ -297,13 +298,13 @@ void QQuickPointerHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEv grab, or it may acquire an exclusive grab if the gesture clearly must not be interpreted in another way by another handler. */ -void QQuickPointerHandler::setPassiveGrab(QQuickEventPoint *point, bool grab) +void QQuickPointerHandler::setPassiveGrab(QPointerEvent *event, const QEventPoint &point, bool grab) { qCDebug(lcPointerHandlerGrab) << point << grab; if (grab) { - point->setGrabberPointerHandler(this, false); + event->addPassiveGrabber(point, this); } else { - point->removePassiveGrabber(this); + event->removePassiveGrabber(point, this); } } @@ -318,11 +319,11 @@ void QQuickPointerHandler::setPassiveGrab(QQuickEventPoint *point, bool grab) also calls approveGrabTransition() on the handler which is about to lose its grab. Either one can deny the takeover. */ -bool QQuickPointerHandler::canGrab(QQuickEventPoint *point) +bool QQuickPointerHandler::canGrab(QPointerEvent *event, const QEventPoint &point) { - QQuickPointerHandler *existingPhGrabber = point->grabberPointerHandler(); - return approveGrabTransition(point, this) && - (existingPhGrabber ? existingPhGrabber->approveGrabTransition(point, this) : true); + QQuickPointerHandler *existingPhGrabber = qobject_cast<QQuickPointerHandler *>(event->exclusiveGrabber(point)); + return approveGrabTransition(event, point, this) && + (existingPhGrabber ? existingPhGrabber->approveGrabTransition(event, point, this) : true); } /*! @@ -331,15 +332,15 @@ bool QQuickPointerHandler::canGrab(QQuickEventPoint *point) will take the grab, and once on the instance which would thereby lose its grab, in case of a takeover scenario. */ -bool QQuickPointerHandler::approveGrabTransition(QQuickEventPoint *point, QObject *proposedGrabber) +bool QQuickPointerHandler::approveGrabTransition(QPointerEvent *event, const QEventPoint &point, QObject *proposedGrabber) { Q_D(const QQuickPointerHandler); bool allowed = false; if (proposedGrabber == this) { - QObject* existingGrabber = point->exclusiveGrabber(); + QObject* existingGrabber = event->exclusiveGrabber(point); allowed = (existingGrabber == nullptr) || ((d->grabPermissions & CanTakeOverFromAnything) == CanTakeOverFromAnything); if (existingGrabber) { - if (QQuickPointerHandler *existingPhGrabber = point->grabberPointerHandler()) { + if (QQuickPointerHandler *existingPhGrabber = qobject_cast<QQuickPointerHandler *>(event->exclusiveGrabber(point))) { if (!allowed && (d->grabPermissions & CanTakeOverFromHandlersOfDifferentType) && existingPhGrabber->metaObject()->className() != metaObject()->className()) allowed = true; @@ -347,9 +348,9 @@ bool QQuickPointerHandler::approveGrabTransition(QQuickEventPoint *point, QObjec existingPhGrabber->metaObject()->className() == metaObject()->className()) allowed = true; } else if ((d->grabPermissions & CanTakeOverFromItems)) { - QQuickItem * existingItemGrabber = point->grabberItem(); - if (existingItemGrabber && !((existingItemGrabber->keepMouseGrab() && point->pointerEvent()->asPointerMouseEvent()) || - (existingItemGrabber->keepTouchGrab() && point->pointerEvent()->asPointerTouchEvent()))) { + QQuickItem * existingItemGrabber = qobject_cast<QQuickItem *>(event->exclusiveGrabber(point)); + if (existingItemGrabber && !((existingItemGrabber->keepMouseGrab() && QQuickWindowPrivate::isMouseEvent(event)) || + (existingItemGrabber->keepTouchGrab() && QQuickWindowPrivate::isTouchEvent(event)))) { allowed = true; // If the handler wants to steal the exclusive grab from an Item, the Item can usually veto // by having its keepMouseGrab flag set. But an exception is if that Item is a parent that @@ -361,8 +362,8 @@ bool QQuickPointerHandler::approveGrabTransition(QQuickEventPoint *point, QObjec if (existingItemGrabber->keepMouseGrab() && !(existingItemGrabber->filtersChildMouseEvents() && existingItemGrabber->isAncestorOf(parentItem()))) { QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(parentItem()->window()); - if (winPriv->isDeliveringTouchAsMouse() && point->pointId() == winPriv->touchMouseId) { - qCDebug(lcPointerHandlerGrab) << this << "wants to grab touchpoint" << point->pointId() + if (winPriv->isDeliveringTouchAsMouse() && point.id() == winPriv->touchMouseId) { + qCDebug(lcPointerHandlerGrab) << this << "wants to grab touchpoint" << point.id() << "but declines to steal grab from touch-mouse grabber with keepMouseGrab=true" << existingItemGrabber; allowed = false; } @@ -388,7 +389,7 @@ bool QQuickPointerHandler::approveGrabTransition(QQuickEventPoint *point, QObjec allowed = true; } } - qCDebug(lcPointerHandlerGrab) << "point" << Qt::hex << point->pointId() << "permission" << + qCDebug(lcPointerHandlerGrab) << "point" << Qt::hex << point.id() << "permission" << QMetaEnum::fromType<GrabPermissions>().valueToKeys(grabPermissions()) << ':' << this << (allowed ? "approved to" : "denied to") << proposedGrabber; return allowed; @@ -449,7 +450,7 @@ void QQuickPointerHandler::componentComplete() { } -QQuickPointerEvent *QQuickPointerHandler::currentEvent() +QPointerEvent *QQuickPointerHandler::currentEvent() { Q_D(const QQuickPointerHandler); return d->currentEvent; @@ -463,52 +464,60 @@ QQuickPointerEvent *QQuickPointerHandler::currentEvent() specified. Returns false if permission is denied either by this handler or by the handler or item from which this handler would take over */ -bool QQuickPointerHandler::setExclusiveGrab(QQuickEventPoint *point, bool grab) +bool QQuickPointerHandler::setExclusiveGrab(QPointerEvent *ev, const QEventPoint &point, bool grab) { - if ((grab && point->exclusiveGrabber() == this) || (!grab && point->exclusiveGrabber() != this)) + if ((grab && ev->exclusiveGrabber(point) == this) || (!grab && ev->exclusiveGrabber(point) != this)) return true; // TODO m_hadKeepMouseGrab m_hadKeepTouchGrab bool allowed = true; if (grab) { - allowed = canGrab(point); + allowed = canGrab(ev, point); } else { - QQuickPointerHandler *existingPhGrabber = point->grabberPointerHandler(); + QQuickPointerHandler *existingPhGrabber = qobject_cast<QQuickPointerHandler *>(ev->exclusiveGrabber(point)); // Ask before allowing one handler to cancel another's grab - if (existingPhGrabber && existingPhGrabber != this && !existingPhGrabber->approveGrabTransition(point, nullptr)) + if (existingPhGrabber && existingPhGrabber != this && !existingPhGrabber->approveGrabTransition(ev, point, nullptr)) allowed = false; } qCDebug(lcPointerHandlerGrab) << point << (grab ? "grab" : "ungrab") << (allowed ? "allowed" : "forbidden") << - point->exclusiveGrabber() << "->" << (grab ? this : nullptr); + ev->exclusiveGrabber(point) << "->" << (grab ? this : nullptr); if (allowed) - point->setGrabberPointerHandler(grab ? this : nullptr, true); + ev->setExclusiveGrabber(point, grab ? this : nullptr); return allowed; } /*! Cancel any existing grab of the given \a point. */ -void QQuickPointerHandler::cancelAllGrabs(QQuickEventPoint *point) +void QQuickPointerHandler::cancelAllGrabs(QPointerEvent *event, QEventPoint &point) { qCDebug(lcPointerHandlerGrab) << point; - point->cancelAllGrabs(this); + if (event->exclusiveGrabber(point) == this) { + event->setExclusiveGrabber(point, nullptr); + onGrabChanged(this, QPointingDevice::CancelGrabExclusive, event, point); + } + if (event->removePassiveGrabber(point, this)) + onGrabChanged(this, QPointingDevice::CancelGrabPassive, event, point); } -QPointF QQuickPointerHandler::eventPos(const QQuickEventPoint *point) const +QPointF QQuickPointerHandler::eventPos(const QEventPoint &point) const { - return (target() ? target()->mapFromScene(point->scenePosition()) : point->scenePosition()); + return (target() ? target()->mapFromScene(point.scenePosition()) : point.scenePosition()); } -bool QQuickPointerHandler::parentContains(const QQuickEventPoint *point) const +bool QQuickPointerHandler::parentContains(const QEventPoint &point) const +{ + return parentContains(point.scenePosition()); +} + +bool QQuickPointerHandler::parentContains(const QPointF &scenePosition) const { - if (!point) - return false; if (QQuickItem *par = parentItem()) { if (par->window()) { - QPoint screenPosition = par->window()->mapToGlobal(point->scenePosition().toPoint()); + QPoint screenPosition = par->window()->mapToGlobal(scenePosition.toPoint()); if (!par->window()->geometry().contains(screenPosition)) return false; } - QPointF p = par->mapFromScene(point->scenePosition()); + QPointF p = par->mapFromScene(scenePosition); qreal m = margin(); if (m > 0) return p.x() >= -m && p.y() >= -m && p.x() <= par->width() + m && p.y() <= par->height() + m; @@ -582,7 +591,29 @@ QQuickItem *QQuickPointerHandler::target() const return d->target; } -void QQuickPointerHandler::handlePointerEvent(QQuickPointerEvent *event) +/*! \internal + Pointer Handlers do most of their work in implementations of virtual functions + that are called directly from QQuickItem, not by direct event handling. + But it's convenient to deliver TouchCancel events via QCoreApplication::sendEvent(). + Perhaps it will turn out that more events could be delivered this way. +*/ +bool QQuickPointerHandler::event(QEvent *e) +{ + switch (e->type()) { + case QEvent::TouchCancel: { + auto te = static_cast<QTouchEvent *>(e); + for (int i = 0; i < te->pointCount(); ++i) + onGrabChanged(this, QPointingDevice::CancelGrabExclusive, te, te->point(i)); + return true; + break; + } + default: + return QObject::event(e); + break; + } +} + +void QQuickPointerHandler::handlePointerEvent(QPointerEvent *event) { bool wants = wantsPointerEvent(event); qCDebug(lcPointerHandlerDispatch) << metaObject()->className() << objectName() @@ -592,27 +623,30 @@ void QQuickPointerHandler::handlePointerEvent(QQuickPointerEvent *event) handlePointerEventImpl(event); } else { setActive(false); - int pCount = event->pointCount(); - for (int i = 0; i < pCount; ++i) { - QQuickEventPoint *pt = event->point(i); - if (pt->grabberPointerHandler() == this && pt->state() != QQuickEventPoint::Stationary) - pt->cancelExclusiveGrab(); + for (int i = 0; i < event->pointCount(); ++i) { + auto &pt = event->point(i); + if (event->exclusiveGrabber(pt) == this && pt.state() != QEventPoint::Stationary) { + event->setExclusiveGrabber(pt, nullptr); + onGrabChanged(this, QPointingDevice::CancelGrabExclusive, event, pt); + } } } QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).append(this); } -bool QQuickPointerHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickPointerHandler::wantsPointerEvent(QPointerEvent *event) { Q_D(const QQuickPointerHandler); Q_UNUSED(event); return d->enabled; } -bool QQuickPointerHandler::wantsEventPoint(QQuickEventPoint *point) +bool QQuickPointerHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) { - bool ret = point->exclusiveGrabber() == this || point->passiveGrabbers().contains(this) || parentContains(point); - qCDebug(lcPointerHandlerDispatch) << Qt::hex << point->pointId() << "@" << point->scenePosition() + Q_UNUSED(event); + bool ret = event->exclusiveGrabber(point) == this || + event->passiveGrabbers(point).contains(this) || parentContains(point); + qCDebug(lcPointerHandlerDispatch) << Qt::hex << point.id() << "@" << point.scenePosition() << metaObject()->className() << objectName() << ret; return ret; } @@ -638,7 +672,7 @@ void QQuickPointerHandler::setActive(bool active) } } -void QQuickPointerHandler::handlePointerEventImpl(QQuickPointerEvent *event) +void QQuickPointerHandler::handlePointerEventImpl(QPointerEvent *event) { Q_D(QQuickPointerHandler); d->currentEvent = event; @@ -689,14 +723,14 @@ QQuickPointerHandlerPrivate::QQuickPointerHandlerPrivate() } template <typename TEventPoint> -bool QQuickPointerHandlerPrivate::dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint *p) const +bool QQuickPointerHandlerPrivate::dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint &p) const { Q_Q(const QQuickPointerHandler); QStyleHints *styleHints = qApp->styleHints(); bool overThreshold = qAbs(d) > q->dragThreshold(); const bool dragVelocityLimitAvailable = (styleHints->startDragVelocity() > 0); if (!overThreshold && dragVelocityLimitAvailable) { - qreal velocity = qreal(axis == Qt::XAxis ? p->velocity().x() : p->velocity().y()); + qreal velocity = qreal(axis == Qt::XAxis ? p.velocity().x() : p.velocity().y()); overThreshold |= qAbs(velocity) > styleHints->startDragVelocity(); } return overThreshold; @@ -709,9 +743,9 @@ bool QQuickPointerHandlerPrivate::dragOverThreshold(QVector2D delta) const return qAbs(delta.x()) > threshold || qAbs(delta.y()) > threshold; } -bool QQuickPointerHandlerPrivate::dragOverThreshold(const QQuickEventPoint *point) const +bool QQuickPointerHandlerPrivate::dragOverThreshold(const QEventPoint &point) const { - QPointF delta = point->scenePosition() - point->scenePressPosition(); + QPointF delta = point.scenePosition() - point.scenePressPosition(); return (dragOverThreshold(delta.x(), Qt::XAxis, point) || dragOverThreshold(delta.y(), Qt::YAxis, point)); } diff --git a/src/quick/handlers/qquickpointerhandler_p.h b/src/quick/handlers/qquickpointerhandler_p.h index 3e7876b3d9..8d7fdcdcad 100644 --- a/src/quick/handlers/qquickpointerhandler_p.h +++ b/src/quick/handlers/qquickpointerhandler_p.h @@ -110,7 +110,7 @@ public: QQuickItem * parentItem() const; - void handlePointerEvent(QQuickPointerEvent *event); + void handlePointerEvent(QPointerEvent *event); GrabPermissions grabPermissions() const; void setGrabPermissions(GrabPermissions grabPermissions); @@ -135,9 +135,9 @@ Q_SIGNALS: void targetChanged(); void marginChanged(); Q_REVISION(2, 15) void dragThresholdChanged(); - void grabChanged(QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point); + void grabChanged(QPointingDevice::GrabTransition transition, QEventPoint point); void grabPermissionChanged(); - void canceled(QQuickEventPoint *point); + void canceled(QEventPoint point); #if QT_CONFIG(cursor) Q_REVISION(2, 15) void cursorShapeChanged(); #endif @@ -147,24 +147,26 @@ protected: void classBegin() override; void componentComplete() override; + bool event(QEvent *) override; - QQuickPointerEvent *currentEvent(); - virtual bool wantsPointerEvent(QQuickPointerEvent *event); - virtual bool wantsEventPoint(QQuickEventPoint *point); - virtual void handlePointerEventImpl(QQuickPointerEvent *event); + QPointerEvent *currentEvent(); + virtual bool wantsPointerEvent(QPointerEvent *event); + virtual bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point); + virtual void handlePointerEventImpl(QPointerEvent *event); void setActive(bool active); virtual void onTargetChanged(QQuickItem *oldTarget) { Q_UNUSED(oldTarget); } virtual void onActiveChanged() { } - virtual void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point); - virtual bool canGrab(QQuickEventPoint *point); - virtual bool approveGrabTransition(QQuickEventPoint *point, QObject *proposedGrabber); - void setPassiveGrab(QQuickEventPoint *point, bool grab = true); - bool setExclusiveGrab(QQuickEventPoint *point, bool grab = true); - void cancelAllGrabs(QQuickEventPoint *point); - QPointF eventPos(const QQuickEventPoint *point) const; - bool parentContains(const QQuickEventPoint *point) const; - - friend class QQuickEventPoint; + virtual void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, + QPointerEvent *event, QEventPoint &point); + virtual bool canGrab(QPointerEvent *event, const QEventPoint &point); + virtual bool approveGrabTransition(QPointerEvent *event, const QEventPoint &point, QObject *proposedGrabber); + void setPassiveGrab(QPointerEvent *event, const QEventPoint &point, bool grab = true); + bool setExclusiveGrab(QPointerEvent *ev, const QEventPoint &point, bool grab = true); + void cancelAllGrabs(QPointerEvent *event, QEventPoint &point); + QPointF eventPos(const QEventPoint &point) const; + bool parentContains(const QEventPoint &point) const; + bool parentContains(const QPointF &scenePosition) const; + friend class QQuickItemPrivate; friend class QQuickWindowPrivate; diff --git a/src/quick/handlers/qquickpointerhandler_p_p.h b/src/quick/handlers/qquickpointerhandler_p_p.h index 03b36c6dae..99120523d8 100644 --- a/src/quick/handlers/qquickpointerhandler_p_p.h +++ b/src/quick/handlers/qquickpointerhandler_p_p.h @@ -69,14 +69,14 @@ public: QQuickPointerHandlerPrivate(); template<typename TEventPoint> - bool dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint *p) const; + bool dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint &p) const; bool dragOverThreshold(QVector2D delta) const; - bool dragOverThreshold(const QQuickEventPoint *point) const; + bool dragOverThreshold(const QEventPoint &point) const; static QVector<QObject *> &deviceDeliveryTargets(const QInputDevice *device); - QQuickPointerEvent *currentEvent = nullptr; + QPointerEvent *currentEvent = nullptr; QQuickItem *target = nullptr; qreal m_margin = 0; qint16 dragThreshold = -1; // -1 means use the platform default diff --git a/src/quick/handlers/qquickpointhandler.cpp b/src/quick/handlers/qquickpointhandler.cpp index 30f62332ba..c3dd997e4a 100644 --- a/src/quick/handlers/qquickpointhandler.cpp +++ b/src/quick/handlers/qquickpointhandler.cpp @@ -120,11 +120,11 @@ QQuickPointHandler::QQuickPointHandler(QQuickItem *parent) setIgnoreAdditionalPoints(); } -bool QQuickPointHandler::wantsEventPoint(QQuickEventPoint *pt) +bool QQuickPointHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) { // On press, we want it unless a sibling of the same type also does. - if (pt->state() == QQuickEventPoint::Pressed && QQuickSinglePointHandler::wantsEventPoint(pt)) { - for (const QQuickPointerHandler *grabber : pt->passiveGrabbers()) { + if (point.state() == QEventPoint::Pressed && QQuickSinglePointHandler::wantsEventPoint(event, point)) { + for (const QObject *grabber : event->passiveGrabbers(point)) { if (grabber && grabber->parent() == parent() && grabber->metaObject()->className() == metaObject()->className()) return false; @@ -132,28 +132,29 @@ bool QQuickPointHandler::wantsEventPoint(QQuickEventPoint *pt) return true; } // If we've already been interested in a point, stay interested, even if it has strayed outside bounds. - return (pt->state() != QQuickEventPoint::Pressed && point().id() == pt->pointId()); + return (point.state() != QEventPoint::Pressed && + QQuickSinglePointHandler::point().id() == point.id()); } -void QQuickPointHandler::handleEventPoint(QQuickEventPoint *point) +void QQuickPointHandler::handleEventPoint(QPointerEvent *event, QEventPoint &point) { - switch (point->state()) { - case QQuickEventPoint::Pressed: - if (point->pointerEvent()->asPointerTouchEvent() || - (point->pointerEvent()->buttons() & acceptedButtons()) != Qt::NoButton) { - setPassiveGrab(point); + switch (point.state()) { + case QEventPoint::Pressed: + if (QQuickWindowPrivate::isTouchEvent(event) || + (static_cast<const QSinglePointEvent *>(event)->buttons() & acceptedButtons()) != Qt::NoButton) { + setPassiveGrab(event, point); setActive(true); } break; - case QQuickEventPoint::Released: - if (point->pointerEvent()->asPointerTouchEvent() || - (point->pointerEvent()->buttons() & acceptedButtons()) == Qt::NoButton) + case QEventPoint::Released: + if (QQuickWindowPrivate::isTouchEvent(event) || + (static_cast<const QSinglePointEvent *>(event)->buttons() & acceptedButtons()) == Qt::NoButton) setActive(false); break; default: break; } - point->setAccepted(false); // Just lurking... don't interfere with propagation + point.setAccepted(false); // Just lurking... don't interfere with propagation emit translationChanged(); } diff --git a/src/quick/handlers/qquickpointhandler_p.h b/src/quick/handlers/qquickpointhandler_p.h index cedbc1c539..cec48b193d 100644 --- a/src/quick/handlers/qquickpointhandler_p.h +++ b/src/quick/handlers/qquickpointhandler_p.h @@ -71,8 +71,8 @@ Q_SIGNALS: void translationChanged(); protected: - bool wantsEventPoint(QQuickEventPoint *pt) override; - void handleEventPoint(QQuickEventPoint *point) override; + bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override; + void handleEventPoint(QPointerEvent *event, QEventPoint &point) override; }; QT_END_NAMESPACE diff --git a/src/quick/handlers/qquicksinglepointhandler.cpp b/src/quick/handlers/qquicksinglepointhandler.cpp index 89081b4e84..18636991e6 100644 --- a/src/quick/handlers/qquicksinglepointhandler.cpp +++ b/src/quick/handlers/qquicksinglepointhandler.cpp @@ -69,7 +69,7 @@ QQuickSinglePointHandler::QQuickSinglePointHandler(QQuickSinglePointHandlerPriva { } -bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickSinglePointHandler::wantsPointerEvent(QPointerEvent *event) { Q_D(QQuickSinglePointHandler); if (!QQuickPointerDeviceHandler::wantsPointerEvent(event)) @@ -81,17 +81,16 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event) // If we no longer want it, cancel the grab. int candidatePointCount = 0; bool missing = true; - QQuickEventPoint *point = nullptr; - int c = event->pointCount(); - for (int i = 0; i < c; ++i) { - QQuickEventPoint *p = event->point(i); - const bool found = (p->pointId() == d->pointInfo.id()); + QEventPoint *point = nullptr; + for (int i = 0; i < event->pointCount(); ++i) { + auto &p = event->point(i); + const bool found = (p.id() == d->pointInfo.id()); if (found) missing = false; - if (wantsEventPoint(p)) { + if (wantsEventPoint(event, p)) { ++candidatePointCount; if (found) - point = p; + point = &p; } } if (missing) @@ -102,7 +101,7 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event) point->setAccepted(); return true; } else { - point->cancelAllGrabs(this); + cancelAllGrabs(event, *point); } } else { return false; @@ -110,62 +109,63 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event) } else { // We have not yet chosen a point; choose the first one for which wantsEventPoint() returns true. int candidatePointCount = 0; - int c = event->pointCount(); - QQuickEventPoint *chosen = nullptr; - for (int i = 0; i < c && !chosen; ++i) { - QQuickEventPoint *p = event->point(i); - if (!p->exclusiveGrabber() && wantsEventPoint(p)) { - if (!chosen) - chosen = p; + QEventPoint *chosen = nullptr; + for (int i = 0; i < event->pointCount(); ++i) { + auto &p = event->point(i); + if (!event->exclusiveGrabber(p) && wantsEventPoint(event, p)) { ++candidatePointCount; + if (!chosen) { + chosen = &p; + break; + } } } if (chosen && candidatePointCount == 1) { - setPointId(chosen->pointId()); + setPointId(chosen->id()); chosen->setAccepted(); } } return d->pointInfo.id() != -1; } -void QQuickSinglePointHandler::handlePointerEventImpl(QQuickPointerEvent *event) +void QQuickSinglePointHandler::handlePointerEventImpl(QPointerEvent *event) { Q_D(QQuickSinglePointHandler); QQuickPointerDeviceHandler::handlePointerEventImpl(event); - QQuickEventPoint *currentPoint = event->pointById(d->pointInfo.id()); + QEventPoint *currentPoint = const_cast<QEventPoint *>(event->pointById(d->pointInfo.id())); Q_ASSERT(currentPoint); - d->pointInfo.reset(currentPoint); - handleEventPoint(currentPoint); - if (currentPoint->state() == QQuickEventPoint::Released && (event->buttons() & acceptedButtons()) == Qt::NoButton) { - setExclusiveGrab(currentPoint, false); + d->pointInfo.reset(event, *currentPoint); + handleEventPoint(event, *currentPoint); + if (currentPoint->state() == QEventPoint::Released && (static_cast<QSinglePointEvent *>(event)->buttons() & acceptedButtons()) == Qt::NoButton) { + setExclusiveGrab(event, *currentPoint, false); d->reset(); } emit pointChanged(); } -void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) +void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) { Q_D(QQuickSinglePointHandler); if (grabber != this) return; switch (transition) { - case QQuickEventPoint::GrabExclusive: - d->pointInfo.m_sceneGrabPosition = point->sceneGrabPosition(); + case QPointingDevice::GrabExclusive: + d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition(); setActive(true); - QQuickPointerHandler::onGrabChanged(grabber, transition, point); + QQuickPointerHandler::onGrabChanged(grabber, transition, event, point); break; - case QQuickEventPoint::GrabPassive: - d->pointInfo.m_sceneGrabPosition = point->sceneGrabPosition(); - QQuickPointerHandler::onGrabChanged(grabber, transition, point); + case QPointingDevice::GrabPassive: + d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition(); + QQuickPointerHandler::onGrabChanged(grabber, transition, event, point); break; - case QQuickEventPoint::OverrideGrabPassive: + case QPointingDevice::OverrideGrabPassive: return; // don't emit - case QQuickEventPoint::UngrabPassive: - case QQuickEventPoint::UngrabExclusive: - case QQuickEventPoint::CancelGrabPassive: - case QQuickEventPoint::CancelGrabExclusive: + case QPointingDevice::UngrabPassive: + case QPointingDevice::UngrabExclusive: + case QPointingDevice::CancelGrabPassive: + case QPointingDevice::CancelGrabExclusive: // the grab is lost or relinquished, so the point is no longer relevant - QQuickPointerHandler::onGrabChanged(grabber, transition, point); + QQuickPointerHandler::onGrabChanged(grabber, transition, event, point); d->reset(); break; } @@ -177,11 +177,11 @@ void QQuickSinglePointHandler::setIgnoreAdditionalPoints(bool v) d->ignoreAdditionalPoints = v; } -void QQuickSinglePointHandler::moveTarget(QPointF pos, QQuickEventPoint *point) +void QQuickSinglePointHandler::moveTarget(QPointF pos, QEventPoint &point) { Q_D(QQuickSinglePointHandler); target()->setPosition(pos); - d->pointInfo.m_scenePosition = point->scenePosition(); + d->pointInfo.m_scenePosition = point.scenePosition(); d->pointInfo.m_position = target()->mapFromScene(d->pointInfo.m_scenePosition); } diff --git a/src/quick/handlers/qquicksinglepointhandler_p.h b/src/quick/handlers/qquicksinglepointhandler_p.h index edc55aaaf6..85ab4f24d4 100644 --- a/src/quick/handlers/qquicksinglepointhandler_p.h +++ b/src/quick/handlers/qquicksinglepointhandler_p.h @@ -74,16 +74,16 @@ Q_SIGNALS: protected: QQuickSinglePointHandler(QQuickSinglePointHandlerPrivate &dd, QQuickItem *parent); - bool wantsPointerEvent(QQuickPointerEvent *event) override; - void handlePointerEventImpl(QQuickPointerEvent *event) override; - virtual void handleEventPoint(QQuickEventPoint *point) = 0; + bool wantsPointerEvent(QPointerEvent *event) override; + void handlePointerEventImpl(QPointerEvent *event) override; + virtual void handleEventPoint(QPointerEvent *event, QEventPoint &point) = 0; - QQuickEventPoint *currentPoint(QQuickPointerEvent *ev); - void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override; + QEventPoint ¤tPoint(QPointerEvent *ev); + void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override; void setIgnoreAdditionalPoints(bool v = true); - void moveTarget(QPointF pos, QQuickEventPoint *point); + void moveTarget(QPointF pos, QEventPoint &point); void setPointId(int id); diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index 2fabd39709..c8525cfcb0 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -97,11 +97,10 @@ QQuickTapHandler::QQuickTapHandler(QQuickItem *parent) } } -bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) +bool QQuickTapHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) { - if (!point->pointerEvent()->asPointerMouseEvent() && - !point->pointerEvent()->asPointerTouchEvent() && - !point->pointerEvent()->asPointerTabletEvent() ) + if (!QQuickWindowPrivate::isMouseEvent(event) && !QQuickWindowPrivate::isTouchEvent(event) && + !QQuickWindowPrivate::isTabletEvent(event)) return false; // If the user has not violated any constraint, it could be a tap. // Otherwise we want to give up the grab so that a competing handler @@ -113,12 +112,12 @@ bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) m_longPressTimer.stop(); m_holdTimer.invalidate(); } - switch (point->state()) { - case QQuickEventPoint::Pressed: - case QQuickEventPoint::Released: + switch (point.state()) { + case QEventPoint::Pressed: + case QEventPoint::Released: ret = parentContains(point); break; - case QQuickEventPoint::Updated: + case QEventPoint::Updated: switch (m_gesturePolicy) { case DragThreshold: ret = !overThreshold && parentContains(point); @@ -127,35 +126,39 @@ bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) ret = parentContains(point); break; case ReleaseWithinBounds: - ret = point->pointId() == this->point().id(); + ret = point.id() == this->point().id(); break; } break; - case QQuickEventPoint::Stationary: + case QEventPoint::Stationary: // If the point hasn't moved since last time, the return value should be the same as last time. // If we return false here, QQuickPointerHandler::handlePointerEvent() will call setActive(false). - ret = point->pointId() == this->point().id(); + ret = point.id() == this->point().id(); + break; + case QEventPoint::Unknown: break; } // If this is the grabber, returning false from this function will cancel the grab, // so onGrabChanged(this, CancelGrabExclusive, point) and setPressed(false) will be called. // But when m_gesturePolicy is DragThreshold, we don't get an exclusive grab, but // we still don't want to be pressed anymore. - if (!ret && point->pointId() == this->point().id()) - setPressed(false, true, point); + if (!ret && point.id() == this->point().id()) + setPressed(false, true, const_cast<QPointerEvent *>(event), const_cast<QEventPoint &>(point)); return ret; } -void QQuickTapHandler::handleEventPoint(QQuickEventPoint *point) +void QQuickTapHandler::handleEventPoint(QPointerEvent *event, QEventPoint &point) { - switch (point->state()) { - case QQuickEventPoint::Pressed: - setPressed(true, false, point); + switch (point.state()) { + case QEventPoint::Pressed: + setPressed(true, false, event, point); break; - case QQuickEventPoint::Released: - if ((point->pointerEvent()->buttons() & acceptedButtons()) == Qt::NoButton) - setPressed(false, false, point); + case QEventPoint::Released: { + if (QQuickWindowPrivate::isTouchEvent(event) || + (static_cast<const QSinglePointEvent *>(event)->buttons() & acceptedButtons()) == Qt::NoButton) + setPressed(false, false, event, point); break; + } default: break; } @@ -253,7 +256,7 @@ void QQuickTapHandler::setGesturePolicy(QQuickTapHandler::GesturePolicy gestureP \l gesturePolicy. When the event point is released or the policy is violated, \e pressed will change to false. */ -void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *point) +void QQuickTapHandler::setPressed(bool press, bool cancel, QPointerEvent *event, QEventPoint &point) { if (m_pressed != press) { qCDebug(lcTapHandler) << objectName() << "pressed" << m_pressed << "->" << press << (cancel ? "CANCEL" : "") << point; @@ -270,17 +273,17 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi if (press) { // on press, grab before emitting changed signals if (m_gesturePolicy == DragThreshold) - setPassiveGrab(point, press); + setPassiveGrab(event, point, press); else - setExclusiveGrab(point, press); + setExclusiveGrab(event, point, press); } if (!cancel && !press && parentContains(point)) { - if (point->timeHeld() < longPressThreshold()) { + if (point.timeHeld() < longPressThreshold()) { // Assuming here that pointerEvent()->timestamp() is in ms. - qreal ts = point->pointerEvent()->timestamp() / 1000.0; + qreal ts = event->timestamp() / 1000.0; if (ts - m_lastTapTimestamp < m_multiTapInterval && - QVector2D(point->scenePosition() - m_lastTapPos).lengthSquared() < - (point->pointerEvent()->device()->type() == QInputDevice::DeviceType::Mouse ? + QVector2D(point.scenePosition() - m_lastTapPos).lengthSquared() < + (event->device()->type() == QInputDevice::DeviceType::Mouse ? m_mouseMultiClickDistanceSquared : m_touchMultiTapDistanceSquared)) ++m_tapCount; else @@ -293,19 +296,19 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi else if (m_tapCount == 2) emit doubleTapped(point); m_lastTapTimestamp = ts; - m_lastTapPos = point->scenePosition(); + m_lastTapPos = point.scenePosition(); } else { - qCDebug(lcTapHandler) << objectName() << "tap threshold" << longPressThreshold() << "exceeded:" << point->timeHeld(); + qCDebug(lcTapHandler) << objectName() << "tap threshold" << longPressThreshold() << "exceeded:" << point.timeHeld(); } } emit pressedChanged(); if (!press && m_gesturePolicy != DragThreshold) { // on release, ungrab after emitting changed signals - setExclusiveGrab(point, press); + setExclusiveGrab(event, point, press); } if (cancel) { emit canceled(point); - setExclusiveGrab(point, false); + setExclusiveGrab(event, point, false); // In case there is a filtering parent (Flickable), we should not give up the passive grab, // so that it can continue to filter future events. d_func()->reset(); @@ -314,12 +317,13 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi } } -void QQuickTapHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) +void QQuickTapHandler::onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, + QPointerEvent *ev, QEventPoint &point) { - QQuickSinglePointHandler::onGrabChanged(grabber, transition, point); - bool isCanceled = transition == QQuickEventPoint::CancelGrabExclusive || transition == QQuickEventPoint::CancelGrabPassive; - if (grabber == this && (isCanceled || point->state() == QQuickEventPoint::Released)) - setPressed(false, isCanceled, point); + QQuickSinglePointHandler::onGrabChanged(grabber, transition, ev, point); + bool isCanceled = transition == QPointingDevice::CancelGrabExclusive || transition == QPointingDevice::CancelGrabPassive; + if (grabber == this && (isCanceled || point.state() == QEventPoint::Released)) + setPressed(false, isCanceled, ev, point); } void QQuickTapHandler::connectPreRenderSignal(bool conn) diff --git a/src/quick/handlers/qquicktaphandler_p.h b/src/quick/handlers/qquicktaphandler_p.h index d5c16b071f..d75547eee2 100644 --- a/src/quick/handlers/qquicktaphandler_p.h +++ b/src/quick/handlers/qquicktaphandler_p.h @@ -97,19 +97,20 @@ Q_SIGNALS: void timeHeldChanged(); void longPressThresholdChanged(); void gesturePolicyChanged(); - void tapped(QQuickEventPoint *eventPoint); - void singleTapped(QQuickEventPoint *eventPoint); - void doubleTapped(QQuickEventPoint *eventPoint); + void tapped(QEventPoint eventPoint); + void singleTapped(QEventPoint eventPoint); + void doubleTapped(QEventPoint eventPoint); void longPressed(); protected: - void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override; + void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, + QPointerEvent *ev, QEventPoint &point) override; void timerEvent(QTimerEvent *event) override; - bool wantsEventPoint(QQuickEventPoint *point) override; - void handleEventPoint(QQuickEventPoint *point) override; + bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override; + void handleEventPoint(QPointerEvent *event, QEventPoint &point) override; private: - void setPressed(bool press, bool cancel, QQuickEventPoint *point); + void setPressed(bool press, bool cancel, QPointerEvent *event, QEventPoint &point); int longPressThresholdMilliseconds() const; void connectPreRenderSignal(bool conn = true); void updateTimeHeld(); diff --git a/src/quick/handlers/qquickwheelhandler.cpp b/src/quick/handlers/qquickwheelhandler.cpp index b55d9aa27b..b9c112a0d2 100644 --- a/src/quick/handlers/qquickwheelhandler.cpp +++ b/src/quick/handlers/qquickwheelhandler.cpp @@ -360,60 +360,62 @@ void QQuickWheelHandler::setTargetTransformAroundCursor(bool ttac) emit targetTransformAroundCursorChanged(); } -bool QQuickWheelHandler::wantsPointerEvent(QQuickPointerEvent *event) +bool QQuickWheelHandler::wantsPointerEvent(QPointerEvent *event) { if (!event) return false; - QQuickPointerScrollEvent *scroll = event->asPointerScrollEvent(); - if (!scroll) + if (event->type() != QEvent::Wheel) return false; + QWheelEvent *we = static_cast<QWheelEvent *>(event); if (!acceptedDevices().testFlag(QPointingDevice::DeviceType::TouchPad) - && scroll->synthSource() != Qt::MouseEventNotSynthesized) + && we->source() != Qt::MouseEventNotSynthesized) return false; if (!active()) { switch (orientation()) { case Qt::Horizontal: - if (qFuzzyIsNull(scroll->angleDelta().x()) && qFuzzyIsNull(scroll->pixelDelta().x())) + if (!(we->angleDelta().x()) && !(we->pixelDelta().x())) return false; break; case Qt::Vertical: - if (qFuzzyIsNull(scroll->angleDelta().y()) && qFuzzyIsNull(scroll->pixelDelta().y())) + if (!(we->angleDelta().y()) && !(we->pixelDelta().y())) return false; break; } } - QQuickEventPoint *point = event->point(0); - if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(point) && parentContains(point)) { - setPointId(point->pointId()); + auto &point = event->point(0); + if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(event, point) && parentContains(point)) { + setPointId(point.id()); return true; } return false; } -void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point) +void QQuickWheelHandler::handleEventPoint(QPointerEvent *ev, QEventPoint &point) { Q_D(QQuickWheelHandler); - QQuickPointerScrollEvent *event = point->pointerEvent()->asPointerScrollEvent(); + if (ev->type() != QEvent::Wheel) + return; + const QWheelEvent *event = static_cast<const QWheelEvent *>(ev); setActive(true); // ScrollEnd will not happen unless it was already active (see setActive(false) below) - point->setAccepted(); + point.setAccepted(); qreal inversion = !d->invertible && event->isInverted() ? -1 : 1; qreal angleDelta = inversion * qreal(orientation() == Qt::Horizontal ? event->angleDelta().x() : event->angleDelta().y()) / 8; d->rotation += angleDelta; emit rotationChanged(); - emit wheel(event); + emit wheel(*event); if (!d->propertyName.isEmpty() && target()) { QQuickItem *t = target(); // writing target()'s property is done via QMetaProperty::write() so that any registered interceptors can react. if (d->propertyName == QLatin1String("scale")) { qreal multiplier = qPow(d->targetScaleMultiplier, angleDelta * d->rotationScale / 15); // wheel "clicks" - const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition()); + const QPointF centroidParentPos = t->parentItem()->mapFromScene(point.scenePosition()); const QPointF positionWas = t->position(); const qreal scaleWas = t->scale(); const qreal activePropertyValue = scaleWas * multiplier; qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta() - << "@" << point->position() << "in parent" << centroidParentPos - << "in scene" << point->scenePosition() + << "@" << point.position() << "in parent" << centroidParentPos + << "in scene" << point.scenePosition() << "multiplier" << multiplier << "scale" << scaleWas << "->" << activePropertyValue; d->targetMetaProperty().write(t, activePropertyValue); @@ -429,10 +431,10 @@ void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point) const QPointF positionWas = t->position(); const qreal rotationWas = t->rotation(); const qreal activePropertyValue = rotationWas + angleDelta * d->rotationScale; - const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition()); + const QPointF centroidParentPos = t->parentItem()->mapFromScene(point.scenePosition()); qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta() - << "@" << point->position() << "in parent" << centroidParentPos - << "in scene" << point->scenePosition() << "rotation" << t->rotation() + << "@" << point.position() << "in parent" << centroidParentPos + << "in scene" << point.scenePosition() << "rotation" << t->rotation() << "->" << activePropertyValue; d->targetMetaProperty().write(t, activePropertyValue); if (d->targetTransformAroundCursor) { @@ -444,8 +446,9 @@ void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point) t->setPosition(adjPos); } } else { - qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "scaled" << angleDelta << "total" << d->rotation << "pixel delta" << event->pixelDelta() - << "@" << point->position() << "in scene" << point->scenePosition() << "rotation" << t->rotation(); + qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "scaled" << angleDelta + << "total" << d->rotation << "pixel delta" << event->pixelDelta() + << "@" << point.position() << "in scene" << point.scenePosition() << "rotation" << t->rotation(); qreal delta = 0; if (event->hasPixelDelta()) { delta = inversion * d->rotationScale * qreal(orientation() == Qt::Horizontal ? event->pixelDelta().x() : event->pixelDelta().y()); diff --git a/src/quick/handlers/qquickwheelhandler_p.h b/src/quick/handlers/qquickwheelhandler_p.h index 021cd23679..b1688a3c2a 100644 --- a/src/quick/handlers/qquickwheelhandler_p.h +++ b/src/quick/handlers/qquickwheelhandler_p.h @@ -103,7 +103,7 @@ public: void setTargetTransformAroundCursor(bool ttac); Q_SIGNALS: - void wheel(QQuickPointerScrollEvent *event); + void wheel(QWheelEvent event); void orientationChanged(); void invertibleChanged(); @@ -115,8 +115,8 @@ Q_SIGNALS: void targetTransformAroundCursorChanged(); protected: - bool wantsPointerEvent(QQuickPointerEvent *event) override; - void handleEventPoint(QQuickEventPoint *point) override; + bool wantsPointerEvent(QPointerEvent *event) override; + void handleEventPoint(QPointerEvent *event, QEventPoint &point) override; void onTargetChanged(QQuickItem *oldTarget) override; void onActiveChanged() override; void timerEvent(QTimerEvent *event) override; |