From 0c02691f7ba646e782b04347fde3d75f9582b317 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 5 Apr 2019 15:00:59 +0200 Subject: If DragHandler is dragged within its margin, don't jump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not being pressed inside the target is a necessary but not sufficient reason to reset m_pressTargetPos to the center of the target. The intention was rather to make the target jump into position when the parent was a different item: e.g. if a Slider has a DragHandler whose target is the slider's knob, you can start dragging anywhere on the whole Slider but you want the knob to jump to the cursor position when the drag begins. While we're at it, both branches of the if in onGrabChanged() are checking that target() isn't null, so we can move that check out. Fixes: QTBUG-74966 Change-Id: I05be11d27422b070d941b9e43d4e1157e071c3a5 Reviewed-by: Jan Arve Sæther --- src/quick/handlers/qquickdraghandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/quick/handlers/qquickdraghandler.cpp') diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 48f0599284..e5531369cf 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -112,14 +112,13 @@ QPointF QQuickDragHandler::targetCentroidPosition() void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) { QQuickMultiPointHandler::onGrabChanged(grabber, transition, point); - if (grabber == this && transition == QQuickEventPoint::GrabExclusive) { + if (grabber == this && transition == QQuickEventPoint::GrabExclusive && target()) { // In case the grab got handed over from another grabber, we might not get the Press. if (!m_pressedInsideTarget) { - if (target()) + if (target() != parentItem()) m_pressTargetPos = QPointF(target()->width(), target()->height()) / 2; } else if (m_pressTargetPos.isNull()) { - if (target()) - m_pressTargetPos = targetCentroidPosition(); + m_pressTargetPos = targetCentroidPosition(); } } } -- cgit v1.2.3