diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2019-03-13 13:24:49 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-04-02 14:24:32 +0000 |
commit | 57c783152f54ea18d0a5a347e9f653bf07c2f446 (patch) | |
tree | 774a1b4936ef032df54f03af6e7356191976aa4b /src/quick/items/qquickitem.cpp | |
parent | 6a21c23bbb33afe3d318e425a6ea676ec260f716 (diff) |
Refactor transform code in pinchhandler to a separate function
This is needed in order for the wheel handler to have the same behavior.
Change-Id: I42851789787b8da96618d82227b34c53ace15e9b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index ec6bf5a1b8..7469fee72b 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -5122,6 +5122,40 @@ void QQuickItemPrivate::transformChanged() #endif } +QPointF QQuickItemPrivate::adjustedPosForTransform(const QPointF ¢roidParentPos, + const QPointF &startPos, + const QVector2D &activeTranslation, //[0,0] means no additional translation from startPos + qreal startScale, + qreal activeScale, // 1.0 means no additional scale from startScale + qreal startRotation, + qreal activeRotation) // 0.0 means no additional rotation from startRotation +{ + Q_Q(QQuickItem); + QVector3D xformOrigin(q->transformOriginPoint()); + QMatrix4x4 startMatrix; + startMatrix.translate(float(startPos.x()), float(startPos.y())); + startMatrix.translate(xformOrigin); + startMatrix.scale(float(startScale)); + startMatrix.rotate(float(startRotation), 0, 0, -1); + startMatrix.translate(-xformOrigin); + + const QVector3D centroidParentVector(centroidParentPos); + QMatrix4x4 mat; + mat.translate(centroidParentVector); + mat.rotate(float(activeRotation), 0, 0, 1); + mat.scale(float(activeScale)); + mat.translate(-centroidParentVector); + mat.translate(QVector3D(activeTranslation)); + + mat = mat * startMatrix; + + QPointF xformOriginPoint = q->transformOriginPoint(); + QPointF pos = mat * xformOriginPoint; + pos -= xformOriginPoint; + + return pos; +} + bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e, bool post) { if (!extra.isAllocated() || !extra->keyHandler) |