diff options
-rw-r--r-- | src/quick/handlers/qquickmultipointerhandler.cpp | 10 | ||||
-rw-r--r-- | src/quick/handlers/qquickmultipointerhandler_p.h | 1 | ||||
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 1 | ||||
-rw-r--r-- | src/quick/handlers/qquickpinchhandler_p.h | 3 | ||||
-rw-r--r-- | tests/manual/pointer/pinchHandler.qml | 7 |
5 files changed, 22 insertions, 0 deletions
diff --git a/src/quick/handlers/qquickmultipointerhandler.cpp b/src/quick/handlers/qquickmultipointerhandler.cpp index c6534e6bb6..d1394e9516 100644 --- a/src/quick/handlers/qquickmultipointerhandler.cpp +++ b/src/quick/handlers/qquickmultipointerhandler.cpp @@ -152,6 +152,16 @@ QPointF QQuickMultiPointerHandler::touchPointCentroid() return ret / m_currentPoints.size(); } +QVector2D QQuickMultiPointerHandler::touchPointCentroidVelocity() +{ + QVector2D ret; + if (Q_UNLIKELY(m_currentPoints.size() == 0)) + return ret; + for (QQuickEventPoint *point : qAsConst(m_currentPoints)) + ret += point->velocity(); + return ret / m_currentPoints.size(); +} + qreal QQuickMultiPointerHandler::averageTouchPointDistance(const QPointF &ref) { qreal ret = 0; diff --git a/src/quick/handlers/qquickmultipointerhandler_p.h b/src/quick/handlers/qquickmultipointerhandler_p.h index d6d660ec04..be92a39631 100644 --- a/src/quick/handlers/qquickmultipointerhandler_p.h +++ b/src/quick/handlers/qquickmultipointerhandler_p.h @@ -90,6 +90,7 @@ protected: bool sameAsCurrentPoints(QQuickPointerEvent *event); QVector<QQuickEventPoint *> pointsInsideOrNearTarget(QQuickPointerEvent *event); QPointF touchPointCentroid(); + QVector2D touchPointCentroidVelocity(); qreal averageTouchPointDistance(const QPointF &ref); qreal averageStartingDistance(const QPointF &ref); qreal averageTouchPointAngle(const QPointF &ref); diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 5469df206c..67d32cdb18 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -242,6 +242,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) } // TODO check m_pinchOrigin: right now it acts like it's set to PinchCenter m_centroid = touchPointCentroid(); + m_centroidVelocity = touchPointCentroidVelocity(); QRectF bounds(m_minimumX, m_minimumY, m_maximumX, m_maximumY); // avoid mapping the minima and maxima, as they might have unmappable values // such as -inf/+inf. Because of this we perform the bounding to min/max in local coords. diff --git a/src/quick/handlers/qquickpinchhandler_p.h b/src/quick/handlers/qquickpinchhandler_p.h index d788e2cb36..6768196909 100644 --- a/src/quick/handlers/qquickpinchhandler_p.h +++ b/src/quick/handlers/qquickpinchhandler_p.h @@ -67,6 +67,7 @@ class Q_AUTOTEST_EXPORT QQuickPinchHandler : public QQuickMultiPointerHandler Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged) Q_PROPERTY(PinchOrigin pinchOrigin READ pinchOrigin WRITE setPinchOrigin NOTIFY pinchOriginChanged) Q_PROPERTY(QPointF centroid READ centroid NOTIFY updated) + 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) @@ -103,6 +104,7 @@ public: qreal scale() const { return m_activeScale; } qreal rotation() const { return m_activeRotation; } QPointF centroid() const { return m_centroid; } + QVector2D centroidVelocity() const { return m_centroidVelocity; } qreal minimumX() const { return m_minimumX; } void setMinimumX(qreal minX); @@ -136,6 +138,7 @@ private: qreal m_activeRotation; QPointF m_activeTranslation; QPointF m_centroid; + QVector2D m_centroidVelocity; qreal m_minimumScale; qreal m_maximumScale; diff --git a/tests/manual/pointer/pinchHandler.qml b/tests/manual/pointer/pinchHandler.qml index 7f2f9bd70f..1d0a859564 100644 --- a/tests/manual/pointer/pinchHandler.qml +++ b/tests/manual/pointer/pinchHandler.qml @@ -40,6 +40,7 @@ import QtQuick 2.8 import Qt.labs.handlers 1.0 +import "content" Rectangle { width: 1024; height: 600 @@ -119,7 +120,13 @@ Rectangle { requiredPointCount: 3 minimumScale: 0.1 maximumScale: 10 + onActiveChanged: { + if (!active) + anim.restart(centroidVelocity) + } } + + MomentumAnimation { id: anim; target: rect3 } } } Rectangle { |