diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2011-12-22 10:53:25 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-23 00:16:26 +0100 |
commit | 9e61464c9026c4b766e05ea8c784f8e6a615adba (patch) | |
tree | 97592742db7067472bbcb2063b1c8831ef2a7037 /src/quick/items | |
parent | 5c22d958fb7cd5e9729518a6fdd0a9a18a9a7481 (diff) |
Add a pressed property to TouchPoint.
Remove the valid property, and replace it with pressed. The semantics
have changed slightly for a release -- pressed will immediately become
false, whereas valid remained true until the next touch event.
Also make sure touch information is correctly updated on release.
Change-Id: Ic61e1b6884c67f19100a6f8fc218b8b05b291ff0
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickmultipointtoucharea.cpp | 37 | ||||
-rw-r--r-- | src/quick/items/qquickmultipointtoucharea_p.h | 20 |
2 files changed, 31 insertions, 26 deletions
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index c94abc6c9d..78bc31fa84 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -124,19 +124,16 @@ void QQuickTouchPoint::setArea(const QRectF &area) } /*! - \qmlproperty bool QtQuick2::TouchPoint::valid + \qmlproperty bool QtQuick2::TouchPoint::pressed - This property holds whether the touch point is valid. - - An invalid touch point is one that has not yet been pressed, - or has already been released. + This property holds whether the touch point is currently pressed. */ -void QQuickTouchPoint::setValid(bool valid) +void QQuickTouchPoint::setPressed(bool pressed) { - if (_valid == valid) + if (_pressed == pressed) return; - _valid = valid; - emit validityChanged(); + _pressed = pressed; + emit pressedChanged(); } /*! @@ -417,25 +414,28 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) QList<QTouchEvent::TouchPoint> touchPoints = e->touchPoints(); int numTouchPoints = touchPoints.count(); //always remove released touches, and make sure we handle all releases before adds. - foreach (QTouchEvent::TouchPoint p, touchPoints) { + foreach (const QTouchEvent::TouchPoint &p, touchPoints) { Qt::TouchPointState touchPointState = p.state(); int id = p.id(); if (touchPointState & Qt::TouchPointReleased) { QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints.value(id)); if (!dtp) continue; + updateTouchPoint(dtp, &p); + dtp->setPressed(false); _releasedTouchPoints.append(dtp); _touchPoints.remove(id); ended = true; } } if (numTouchPoints >= _minimumTouchPoints && numTouchPoints <= _maximumTouchPoints) { - foreach (QTouchEvent::TouchPoint p, touchPoints) { + foreach (const QTouchEvent::TouchPoint &p, touchPoints) { Qt::TouchPointState touchPointState = p.state(); int id = p.id(); if (touchPointState & Qt::TouchPointReleased) { //handled above } else if (!_touchPoints.contains(id)) { //could be pressed, moved, or stationary + // (we may have just obtained enough points to start tracking them -- in that case moved or stationary count as newly pressed) addTouchPoint(&p); started = true; } else if (touchPointState & Qt::TouchPointMoved) { @@ -491,7 +491,7 @@ void QQuickMultiPointTouchArea::clearTouchLists() if (!dtp->isQmlDefined()) delete dtp; else - dtp->setValid(false); + dtp->setInUse(false); } _releasedTouchPoints.clear(); _pressedTouchPoints.clear(); @@ -502,8 +502,8 @@ void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) { QQuickTouchPoint *dtp = 0; foreach (QQuickTouchPoint* tp, _touchPrototypes) { - if (!tp->isValid()) { - tp->setValid(true); + if (!tp->inUse()) { + tp->setInUse(true); dtp = tp; break; } @@ -513,10 +513,9 @@ void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) dtp = new QQuickTouchPoint(false); dtp->setPointId(p->id()); updateTouchPoint(dtp,p); + dtp->setPressed(true); _touchPoints.insert(p->id(),dtp); - //we may have just obtained enough points to start tracking them -- in that case moved or stationary count as newly pressed - if (p->state() & Qt::TouchPointPressed || p->state() & Qt::TouchPointMoved || p->state() & Qt::TouchPointStationary) - _pressedTouchPoints.append(dtp); + _pressedTouchPoints.append(dtp); } void QQuickMultiPointTouchArea::addTouchPrototype(QQuickTouchPoint *prototype) @@ -586,6 +585,8 @@ void QQuickMultiPointTouchArea::ungrab() setKeepMouseGrab(false); } setKeepTouchGrab(false); + foreach (QObject *obj, _touchPoints) + static_cast<QQuickTouchPoint*>(obj)->setPressed(false); emit touchPointsCanceled(_touchPoints.values()); clearTouchLists(); foreach (QObject *obj, _touchPoints) { @@ -593,7 +594,7 @@ void QQuickMultiPointTouchArea::ungrab() if (!dtp->isQmlDefined()) delete dtp; else - dtp->setValid(false); + dtp->setInUse(false); } _touchPoints.clear(); } diff --git a/src/quick/items/qquickmultipointtoucharea_p.h b/src/quick/items/qquickmultipointtoucharea_p.h index aee18a376b..dbce42853b 100644 --- a/src/quick/items/qquickmultipointtoucharea_p.h +++ b/src/quick/items/qquickmultipointtoucharea_p.h @@ -58,8 +58,8 @@ class QQuickMultiPointTouchArea; class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject { Q_OBJECT - Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged) Q_PROPERTY(int pointId READ pointId NOTIFY pointIdChanged) + Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(qreal x READ x NOTIFY xChanged) Q_PROPERTY(qreal y READ y NOTIFY yChanged) Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) @@ -78,7 +78,8 @@ public: _x(0.0), _y(0.0), _pressure(0.0), _qmlDefined(qmlDefined), - _valid(!qmlDefined), + _inUse(false), + _pressed(false), _previousX(0.0), _previousY(0.0), _sceneX(0.0), _sceneY(0.0) {} @@ -98,10 +99,13 @@ public: QRectF area() const { return _area; } void setArea(const QRectF &area); - bool isQmlDefined() { return _qmlDefined; } + bool isQmlDefined() const { return _qmlDefined; } - bool isValid() { return _valid; } - void setValid(bool valid); + bool inUse() const { return _inUse; } + void setInUse(bool inUse) { _inUse = inUse; } + + bool pressed() const { return _pressed; } + void setPressed(bool pressed); qreal startX() const { return _startX; } void setStartX(qreal startX); @@ -121,14 +125,13 @@ public: qreal sceneY() const { return _sceneY; } void setSceneY(qreal sceneY); - Q_SIGNALS: + void pressedChanged(); void pointIdChanged(); void xChanged(); void yChanged(); void pressureChanged(); void areaChanged(); - void validityChanged(); void startXChanged(); void startYChanged(); void previousXChanged(); @@ -144,7 +147,8 @@ private: qreal _pressure; QRectF _area; bool _qmlDefined; - bool _valid; + bool _inUse; //whether the point is currently in use (only valid when _qmlDefined == true) + bool _pressed; qreal _startX; qreal _startY; qreal _previousX; |