diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-09-12 11:00:33 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-09-12 09:51:43 +0000 |
commit | 6fef83c37b2e4c1369a1f5cf7c68c54c9c5a27e9 (patch) | |
tree | 9e2f581949d71a18d29fbe2c68fdfabb4a960891 | |
parent | 7f61147d534757daf24bc2459eac49864985dd8b (diff) |
PinchHandler: make the properties useful when target is null
An example is forthcoming in the form of a documentation snippet.
Also, translation is a relative measurement, so its type is now
QVector2D rather than QPointF. This doesn't change the QML API:
x and y properties are still defined.
Change-Id: I00f9a02a45c30899a568fe827f47cae9b4cc0f42
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 33 | ||||
-rw-r--r-- | src/quick/handlers/qquickpinchhandler_p.h | 6 |
2 files changed, 21 insertions, 18 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 92bcc643f3..b1a5779981 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -198,23 +198,26 @@ void QQuickPinchHandler::setMaximumY(qreal maxY) void QQuickPinchHandler::onActiveChanged() { if (active()) { + m_startMatrix = QMatrix4x4(); + m_startCentroid = touchPointCentroid(); + m_startAngles = angles(m_startCentroid); + m_startDistance = averageTouchPointDistance(m_startCentroid); + m_activeRotation = 0; + m_activeTranslation = QVector2D(); if (const QQuickItem *t = target()) { m_startScale = t->scale(); // TODO incompatible with independent x/y scaling m_startRotation = t->rotation(); - m_startCentroid = touchPointCentroid(); - m_startAngles = angles(m_startCentroid); - m_startDistance = averageTouchPointDistance(m_startCentroid); QVector3D xformOrigin(t->transformOriginPoint()); - m_startMatrix = QMatrix4x4(); m_startMatrix.translate(t->x(), t->y()); m_startMatrix.translate(xformOrigin); m_startMatrix.scale(m_startScale); m_startMatrix.rotate(m_startRotation, 0, 0, -1); m_startMatrix.translate(-xformOrigin); - m_activeRotation = 0; - m_activeTranslation = QPointF(0,0); - qCInfo(lcPinchHandler) << "activated with starting scale" << m_startScale << "rotation" << m_startRotation; + } else { + m_startScale = 1; + m_startRotation = 0; } + qCInfo(lcPinchHandler) << "activated with starting scale" << m_startScale << "rotation" << m_startRotation; } else { qCInfo(lcPinchHandler) << "deactivated with scale" << m_activeScale << "rotation" << m_activeRotation; } @@ -271,7 +274,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) if (target() && target()->parentItem()) { // 3. Drag/translate const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(m_startCentroid); - m_activeTranslation = centroidParentPos - centroidStartParentPos; + m_activeTranslation = QVector2D(centroidParentPos - centroidStartParentPos); // apply rotation + scaling around the centroid - then apply translation. QMatrix4x4 mat; @@ -293,15 +296,15 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) target()->setRotation(rotation); target()->setScale(scale); - // TODO some translation inadvertently happens; try to hold the chosen pinch origin in place - - qCDebug(lcPinchHandler) << "centroid" << m_startCentroid << "->" << m_centroid - << ", distance" << m_startDistance << "->" << dist - << ", startScale" << m_startScale << "->" << scale - << ", activeRotation" << m_activeRotation - << ", rotation" << rotation; + } else { + m_activeTranslation = QVector2D(m_centroid - m_startCentroid); } + qCDebug(lcPinchHandler) << "centroid" << m_startCentroid << "->" << m_centroid + << ", distance" << m_startDistance << "->" << dist + << ", startScale" << m_startScale << "->" << scale + << ", activeRotation" << m_activeRotation + << ", rotation" << rotation; if (!containsReleasedPoints) acceptPoints(m_currentPoints); diff --git a/src/quick/handlers/qquickpinchhandler_p.h b/src/quick/handlers/qquickpinchhandler_p.h index 356cc0eed3..b1ece494a5 100644 --- a/src/quick/handlers/qquickpinchhandler_p.h +++ b/src/quick/handlers/qquickpinchhandler_p.h @@ -70,7 +70,7 @@ class Q_AUTOTEST_EXPORT QQuickPinchHandler : public QQuickMultiPointHandler Q_PROPERTY(QVector2D centroidVelocity READ centroidVelocity NOTIFY updated) Q_PROPERTY(qreal scale READ scale NOTIFY updated) Q_PROPERTY(qreal rotation READ rotation NOTIFY updated) - Q_PROPERTY(QPointF translation READ translation NOTIFY updated) + Q_PROPERTY(QVector2D translation READ translation NOTIFY updated) Q_PROPERTY(qreal minimumX READ minimumX WRITE setMinimumX NOTIFY minimumXChanged) Q_PROPERTY(qreal maximumX READ maximumX WRITE setMaximumX NOTIFY maximumXChanged) Q_PROPERTY(qreal minimumY READ minimumY WRITE setMinimumY NOTIFY minimumYChanged) @@ -100,7 +100,7 @@ public: PinchOrigin pinchOrigin() const { return m_pinchOrigin; } void setPinchOrigin(PinchOrigin pinchOrigin); - QPointF translation() const { return m_activeTranslation; } + QVector2D translation() const { return m_activeTranslation; } qreal scale() const { return m_activeScale; } qreal rotation() const { return m_activeRotation; } QPointF centroid() const { return m_centroid; } @@ -136,7 +136,7 @@ private: // properties qreal m_activeScale; qreal m_activeRotation; - QPointF m_activeTranslation; + QVector2D m_activeTranslation; QPointF m_centroid; QVector2D m_centroidVelocity; |