diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-03-31 23:42:04 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-20 18:37:02 +0000 |
commit | c2d6f267a74f7fdd9422af88e35ade280cf0a3d3 (patch) | |
tree | d671f3d2752c4600785651ca53e227c40999f2a5 /src/quick/handlers | |
parent | 97e2050f1c942da0b4d49df19b408c10a68e14b8 (diff) |
PinchHandler: add centroidVelocity
Change-Id: I34cc9146155bded8311c1173e4b8d34d8b17b034
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/handlers')
-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 |
4 files changed, 15 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; |