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/qquickmultipointtoucharea.cpp | |
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/qquickmultipointtoucharea.cpp')
-rw-r--r-- | src/quick/items/qquickmultipointtoucharea.cpp | 37 |
1 files changed, 19 insertions, 18 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(); } |