diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2016-09-02 17:07:57 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-09-16 14:46:13 +0000 |
commit | c364b935f06256ec7adfaf486ef35b3996152804 (patch) | |
tree | 7d78f8fcfa14d772c9365ac7c37a20ca752e0de1 /src/quick/handlers/qquickpinchhandler_p.h | |
parent | b8106804c87f70c3be034dc3e191966293a8b877 (diff) |
Fix rotation in PinchHandler
If we want to allow rotation with more than 2 fingers, its not
straightforward to calculate the rotation angle, because we cannot anymore
calculate the angle between the two touchpoints.
The approach chosen was to calculate the angle between the centroid and
the touchpoints, and take the average between the angles.
Then, for the next event we calculated the new average of the angles.
However, this is not really reliable in some scenarios, suppose we have
these three angles:
0 120 240, avg = 360/3 = 120
next, touch points rotate clockwise with 2 degrees, and we get these
angles:
358 118 238, avg = 714/3 = 238
So, just by rotating all fingers by 2 degrees, we got a jump by 118
degrees "in average".
Instead we need to track the angles of *all* touch points, and when the
next touch event is received we calculate how much the angle has changed
per touch point. We then take the average of those angles as the effective
"rotation" of the PinchHandler
Change-Id: I2bfdf80b886751177efe81bcc7b698af0d2938e3
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpinchhandler_p.h')
-rw-r--r-- | src/quick/handlers/qquickpinchhandler_p.h | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/src/quick/handlers/qquickpinchhandler_p.h b/src/quick/handlers/qquickpinchhandler_p.h index 0a66d5e02e..338b930373 100644 --- a/src/quick/handlers/qquickpinchhandler_p.h +++ b/src/quick/handlers/qquickpinchhandler_p.h @@ -66,9 +66,14 @@ class Q_AUTOTEST_EXPORT QQuickPinchHandler : public QQuickMultiPointerHandler Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged) Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged) Q_PROPERTY(PinchOrigin pinchOrigin READ pinchOrigin WRITE setPinchOrigin NOTIFY pinchOriginChanged) - Q_PROPERTY(QPointF center READ center NOTIFY updated) + Q_PROPERTY(QPointF centroid READ centroid 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(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) + Q_PROPERTY(qreal maximumY READ maximumY WRITE setMaximumY NOTIFY maximumYChanged) public: enum PinchOrigin { @@ -94,9 +99,19 @@ public: PinchOrigin pinchOrigin() const { return m_pinchOrigin; } void setPinchOrigin(PinchOrigin pinchOrigin); - QPointF center() const { return m_scaleTransform.origin().toPointF(); } - qreal scale() const { return m_scaleTransform.xScale(); } - qreal rotation() const { return m_rotationTransform.angle(); } + QPointF translation() const { return m_translation; } + qreal scale() const { return m_scale; } + qreal rotation() const { return m_rotation; } + QPointF centroid() const { return m_centroid; } + + qreal minimumX() const { return m_minimumX; } + void setMinimumX(qreal minX); + qreal maximumX() const { return m_maximumX; } + void setMaximumX(qreal maxX); + qreal minimumY() const { return m_minimumY; } + void setMinimumY(qreal minY); + qreal maximumY() const { return m_maximumY; } + void setMaximumY(qreal maxY); signals: void requiredPointCountChanged(); @@ -104,6 +119,10 @@ signals: void maximumScaleChanged(); void minimumRotationChanged(); void maximumRotationChanged(); + void minimumXChanged(); + void maximumXChanged(); + void minimumYChanged(); + void maximumYChanged(); void pinchOriginChanged(); void updated(); @@ -113,15 +132,34 @@ protected: void handlePointerEventImpl(QQuickPointerEvent *event) override; private: - qreal m_startScale; - qreal m_startRotation; + // properties + qreal m_scale; + qreal m_rotation; + QPointF m_translation; + QPointF m_centroid; + qreal m_minimumScale; qreal m_maximumScale; + qreal m_minimumRotation; qreal m_maximumRotation; + + qreal m_minimumX; + qreal m_maximumX; + qreal m_minimumY; + qreal m_maximumY; + PinchOrigin m_pinchOrigin; - QQuickScale m_scaleTransform; - QQuickRotation m_rotationTransform; + + // internal + qreal m_startScale; + qreal m_startRotation; + qreal m_activeRotation; + + QVector<PointData> m_startAngles; + QMatrix4x4 m_startMatrix; + QQuickMatrix4x4 m_transform; + }; QT_END_NAMESPACE |