From 4f69895cf15b9ff76b9a4404709a28153d34de5e Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Mon, 19 Dec 2016 16:19:09 +0100 Subject: Fixed bug in DragHandler when dragging in scaled coordinate system Calculate the new position in the target items' parent coordinate system in order to not be affected by any transformations applied on the target item. And after all, the item's position is specified in parent coordinates. Also check target() and target()->parentItem() rather than assuming that they are non-null. Change-Id: Ib00c72cce7b324b508884287e4070bedaf02b95e Reviewed-by: Shawn Rutledge --- src/quick/handlers/qquickdraghandler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index dadf8bba04..f2a1b74d6c 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -82,7 +82,8 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point) point->setAccepted(); switch (point->state()) { case QQuickEventPoint::Pressed: - m_startPos = target()->mapToScene(QPointF()); + if (target() && target()->parentItem()) + m_startPos = target()->parentItem()->mapToScene(target()->position()); break; case QQuickEventPoint::Updated: { QPointF delta = point->scenePos() - point->scenePressPos(); @@ -91,9 +92,11 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point) if (!m_yAxis.enabled()) delta.setY(0); if (m_dragging) { - QPointF pos = target()->parentItem()->mapFromScene(m_startPos) + delta; - enforceAxisConstraints(&pos); - target()->setPosition(pos); + if (target() && target()->parentItem()) { + QPointF pos = target()->parentItem()->mapFromScene(m_startPos + delta); + enforceAxisConstraints(&pos); + target()->setPosition(pos); + } } else if ((m_xAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point)) || (m_yAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point))) { m_dragging = true; -- cgit v1.2.3