From 9ed9a14be80b377e6681db8076dce31316ded144 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 25 Feb 2021 13:47:37 +0100 Subject: QQuickSinglePointHandler: don't reset the point in hover handlers A HoverHandler should not reset the reported position when it receives a mouse release. As it stands, a HoverHandler, like all the other SinglPointHandlers, will emit a position change of (0, 0) when clicking on it. This patch will factor the reset code into the virtual handleEventPoint(). By doing so, the subclasses can choose to call the base implementation to opt in for the "reset" logic. This patch will let all the subclasses, except HoverHandler, do that. Fixes: QTBUG-83980 Change-Id: Idc5720a2aad2b0b5714807965e0edc4e8325bfdc Reviewed-by: Shawn Rutledge (cherry picked from commit 79cde77f23358adbe57ab8ce08730d2de5bb1288) Reviewed-by: Qt Cherry-pick Bot --- src/quick/handlers/qquickpointhandler.cpp | 1 + src/quick/handlers/qquicksinglepointhandler.cpp | 16 ++++++++++++---- src/quick/handlers/qquicksinglepointhandler_p.h | 2 +- src/quick/handlers/qquicktaphandler.cpp | 2 ++ src/quick/handlers/qquickwheelhandler.cpp | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src/quick') diff --git a/src/quick/handlers/qquickpointhandler.cpp b/src/quick/handlers/qquickpointhandler.cpp index c3dd997e4a..147724e5b3 100644 --- a/src/quick/handlers/qquickpointhandler.cpp +++ b/src/quick/handlers/qquickpointhandler.cpp @@ -156,6 +156,7 @@ void QQuickPointHandler::handleEventPoint(QPointerEvent *event, QEventPoint &poi } point.setAccepted(false); // Just lurking... don't interfere with propagation emit translationChanged(); + QQuickSinglePointHandler::handleEventPoint(event, point); } QVector2D QQuickPointHandler::translation() const diff --git a/src/quick/handlers/qquicksinglepointhandler.cpp b/src/quick/handlers/qquicksinglepointhandler.cpp index 6289177894..aa650654eb 100644 --- a/src/quick/handlers/qquicksinglepointhandler.cpp +++ b/src/quick/handlers/qquicksinglepointhandler.cpp @@ -136,13 +136,21 @@ void QQuickSinglePointHandler::handlePointerEventImpl(QPointerEvent *event) Q_ASSERT(currentPoint); d->pointInfo.reset(event, *currentPoint); handleEventPoint(event, *currentPoint); - if (currentPoint->state() == QEventPoint::Released && (static_cast(event)->buttons() & acceptedButtons()) == Qt::NoButton) { - setExclusiveGrab(event, *currentPoint, false); - d->reset(); - } emit pointChanged(); } +void QQuickSinglePointHandler::handleEventPoint(QPointerEvent *event, QEventPoint &point) +{ + if (point.state() != QEventPoint::Released) + return; + + const Qt::MouseButtons releasedButtons = static_cast(event)->buttons(); + if ((releasedButtons & acceptedButtons()) == Qt::NoButton) { + setExclusiveGrab(event, point, false); + d_func()->reset(); + } +} + void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) { Q_D(QQuickSinglePointHandler); diff --git a/src/quick/handlers/qquicksinglepointhandler_p.h b/src/quick/handlers/qquicksinglepointhandler_p.h index 85ab4f24d4..fd0351b3db 100644 --- a/src/quick/handlers/qquicksinglepointhandler_p.h +++ b/src/quick/handlers/qquicksinglepointhandler_p.h @@ -76,7 +76,7 @@ protected: bool wantsPointerEvent(QPointerEvent *event) override; void handlePointerEventImpl(QPointerEvent *event) override; - virtual void handleEventPoint(QPointerEvent *event, QEventPoint &point) = 0; + virtual void handleEventPoint(QPointerEvent *event, QEventPoint &point); QEventPoint ¤tPoint(QPointerEvent *ev); void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override; diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index e71738c2d2..0a7cc7e075 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -162,6 +162,8 @@ void QQuickTapHandler::handleEventPoint(QPointerEvent *event, QEventPoint &point default: break; } + + QQuickSinglePointHandler::handleEventPoint(event, point); } /*! diff --git a/src/quick/handlers/qquickwheelhandler.cpp b/src/quick/handlers/qquickwheelhandler.cpp index b598e43439..7045f10d8e 100644 --- a/src/quick/handlers/qquickwheelhandler.cpp +++ b/src/quick/handlers/qquickwheelhandler.cpp @@ -387,6 +387,8 @@ bool QQuickWheelHandler::wantsPointerEvent(QPointerEvent *event) void QQuickWheelHandler::handleEventPoint(QPointerEvent *ev, QEventPoint &point) { Q_D(QQuickWheelHandler); + QQuickSinglePointHandler::handleEventPoint(ev, point); + if (ev->type() != QEvent::Wheel) return; const QWheelEvent *event = static_cast(ev); -- cgit v1.2.3