diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2019-03-13 13:31:57 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-04-02 14:24:08 +0000 |
commit | c370bea6b11a16ee83290411b0e2b63b241c1aee (patch) | |
tree | 06a179c6281e9f16aec81bf3ae5dd25724cb2593 /src/quick/handlers/qquickpinchhandler.cpp | |
parent | 4e5ff56a18dc7bb13680a8fbe30ba5aae2dfa206 (diff) |
Get rid of m_startMatrix as a member variable
This is needed in order to refactor out the calculation of the items
position due to rotation and scale around an arbitrary origin.
Instead we calculate it on-demand for each touch update.
Change-Id: I06ace836061c6881fe9bb58bff462d1f407b6365
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpinchhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 9ae2116d39..d6aa39dc0d 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -267,7 +267,6 @@ void QQuickPinchHandler::onActiveChanged() { QQuickMultiPointHandler::onActiveChanged(); if (active()) { - m_startMatrix = QMatrix4x4(); m_startAngles = angles(m_centroid.sceneGrabPosition()); m_startDistance = averageTouchPointDistance(m_centroid.sceneGrabPosition()); m_activeRotation = 0; @@ -275,12 +274,7 @@ void QQuickPinchHandler::onActiveChanged() if (const QQuickItem *t = target()) { m_startScale = t->scale(); // TODO incompatible with independent x/y scaling m_startRotation = t->rotation(); - QVector3D xformOrigin(t->transformOriginPoint()); - m_startMatrix.translate(float(t->x()), float(t->y())); - m_startMatrix.translate(xformOrigin); - m_startMatrix.scale(float(m_startScale)); - m_startMatrix.rotate(float(m_startRotation), 0, 0, -1); - m_startMatrix.translate(-xformOrigin); + m_startPos = t->position(); } else { m_startScale = m_accumulatedScale; m_startRotation = 0; @@ -470,7 +464,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(m_centroid.sceneGrabPosition()); m_activeTranslation = QVector2D(centroidParentPos - centroidStartParentPos); // apply rotation + scaling around the centroid - then apply translation. - QMatrix4x4 mat; + QMatrix4x4 mat, startMatrix; const QVector3D centroidParentVector(centroidParentPos); mat.translate(centroidParentVector); @@ -479,7 +473,14 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) mat.translate(-centroidParentVector); mat.translate(QVector3D(m_activeTranslation)); - mat = mat * m_startMatrix; + QVector3D xformOrigin(target()->transformOriginPoint()); + startMatrix.translate(float(m_startPos.x()), float(m_startPos.y())); + startMatrix.translate(xformOrigin); + startMatrix.scale(float(m_startScale)); + startMatrix.rotate(float(m_startRotation), 0, 0, -1); + startMatrix.translate(-xformOrigin); + + mat = mat * startMatrix; QPointF xformOriginPoint = target()->transformOriginPoint(); QPointF pos = mat * xformOriginPoint; |