summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@qt.io>2016-12-19 16:19:09 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2016-12-27 11:54:41 +0000
commit4f69895cf15b9ff76b9a4404709a28153d34de5e (patch)
treeb5107139e2b0e3b062496bfb0a7328bf9d0a3ef8
parentf7d7cf58330ea0b2d6687a227c7e7302709ca47f (diff)
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 <shawn.rutledge@qt.io>
-rw-r--r--src/quick/handlers/qquickdraghandler.cpp11
1 files 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;