diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2018-07-31 17:45:27 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-02 17:48:28 +0000 |
commit | ae6a3811758672c970713d4d460d13f4dd281c22 (patch) | |
tree | 9492f4201bb04de2dc798a8da5869174e08ec22e | |
parent | 64ee8b948a8380c805729cc3006507c1e260abd3 (diff) |
Let axis bounds restrict the target position instead of the centroid
Change-Id: I09442cfd5ea1e3bee06dd448118f2f42bedb2760
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 1c3dbf9902..58cd91476d 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -464,19 +464,13 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) acceptPoints(chosenPoints); } - QPointF centroidParentPos; - QRectF bounds(QPointF(xAxis()->minimum(), yAxis()->minimum()), QPointF(xAxis()->maximum(), yAxis()->maximum()) ); - if (target() && target()->parentItem()) { - centroidParentPos = target()->parentItem()->mapFromScene(m_centroid.scenePosition()); - centroidParentPos = QPointF(qBound(bounds.left(), centroidParentPos.x(), bounds.right()), - qBound(bounds.top(), centroidParentPos.y(), bounds.bottom())); - } const qreal totalRotation = m_startRotation + m_activeRotation; const qreal rotation = qBound(m_minimumRotation, totalRotation, m_maximumRotation); m_activeRotation += (rotation - totalRotation); //adjust for the potential bounding above m_accumulatedScale = m_startScale * m_activeScale; if (target() && target()->parentItem()) { + const QPointF centroidParentPos = target()->parentItem()->mapFromScene(m_centroid.scenePosition()); // 3. Drag/translate const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(m_centroid.sceneGrabPosition()); m_activeTranslation = QVector2D(centroidParentPos - centroidStartParentPos); @@ -500,6 +494,11 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) QPointF pos = mat * xformOriginPoint; pos -= xformOriginPoint; + if (xAxis()->enabled()) + pos.setX(qBound(xAxis()->minimum(), pos.x(), xAxis()->maximum())); + if (yAxis()->enabled()) + pos.setY(qBound(yAxis()->minimum(), pos.y(), yAxis()->maximum())); + target()->setPosition(pos); target()->setRotation(rotation); target()->setScale(m_accumulatedScale); |