Add velocity data to TouchPoint
authorMichael Brasser <michael.brasser@nokia.com>
Wed, 8 Feb 2012 03:17:56 +0000 (13:17 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 17 Feb 2012 03:29:47 +0000 (04:29 +0100)
Change-Id: I0555b3ad41e8c08563188e1ba9190e54d4bb3784
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/quick/items/qquickmultipointtoucharea.cpp
src/quick/items/qquickmultipointtoucharea_p.h

index 766ce67..c1c60c1 100644 (file)
@@ -102,14 +102,19 @@ void QQuickTouchPoint::setY(qreal y)
 
 /*!
     \qmlproperty real QtQuick2::TouchPoint::pressure
+    \qmlproperty vector2d QtQuick2::TouchPoint::velocity
     \qmlproperty rectangle QtQuick2::TouchPoint::area
 
     These properties hold additional information about the current state of the touch point.
 
     \list
     \i \c pressure is a value in the range of 0.0 to 1.0.
+    \i \c velocity is a vector with magnitude reported in pixels per second.
     \i \c area is a rectangle covering the area of the touch point, centered on the current position of the touch point.
     \endlist
+
+    Not all touch devices support velocity. If velocity is not supported, it will be reported
+    as 0,0.
 */
 void QQuickTouchPoint::setPressure(qreal pressure)
 {
@@ -119,6 +124,14 @@ void QQuickTouchPoint::setPressure(qreal pressure)
     emit pressureChanged();
 }
 
+void QQuickTouchPoint::setVelocity(const QVector2D &velocity)
+{
+    if (_velocity == velocity)
+        return;
+    _velocity = velocity;
+    emit velocityChanged();
+}
+
 void QQuickTouchPoint::setArea(const QRectF &area)
 {
     if (_area == area)
@@ -548,6 +561,7 @@ void QQuickMultiPointTouchArea::updateTouchPoint(QQuickTouchPoint *dtp, const QT
     dtp->setX(p->pos().x());
     dtp->setY(p->pos().y());
     dtp->setPressure(p->pressure());
+    dtp->setVelocity(p->velocity());
     dtp->setArea(p->rect());
     dtp->setStartX(p->startPos().x());
     dtp->setStartY(p->startPos().y());
index e611ce3..ccb086f 100644 (file)
@@ -63,6 +63,7 @@ class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject
     Q_PROPERTY(qreal x READ x NOTIFY xChanged)
     Q_PROPERTY(qreal y READ y NOTIFY yChanged)
     Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged)
+    Q_PROPERTY(QVector2D velocity READ velocity NOTIFY velocityChanged)
     Q_PROPERTY(QRectF area READ area NOTIFY areaChanged)
 
     Q_PROPERTY(qreal startX READ startX NOTIFY startXChanged)
@@ -96,6 +97,9 @@ public:
     qreal pressure() const { return _pressure; }
     void setPressure(qreal pressure);
 
+    QVector2D velocity() const { return _velocity; }
+    void setVelocity(const QVector2D &velocity);
+
     QRectF area() const { return _area; }
     void setArea(const QRectF &area);
 
@@ -131,6 +135,7 @@ Q_SIGNALS:
     void xChanged();
     void yChanged();
     void pressureChanged();
+    void velocityChanged();
     void areaChanged();
     void startXChanged();
     void startYChanged();
@@ -145,6 +150,7 @@ private:
     qreal _x;
     qreal _y;
     qreal _pressure;
+    QVector2D _velocity;
     QRectF _area;
     bool _qmlDefined;
     bool _inUse;    //whether the point is currently in use (only valid when _qmlDefined == true)