From 6fef83c37b2e4c1369a1f5cf7c68c54c9c5a27e9 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 12 Sep 2017 11:00:33 +0200 Subject: PinchHandler: make the properties useful when target is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/quick/handlers/qquickpinchhandler.cpp | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/quick/handlers/qquickpinchhandler.cpp') 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); -- cgit v1.2.3