diff options
Diffstat (limited to 'src/quick/items/qquickmultipointtoucharea.cpp')
-rw-r--r-- | src/quick/items/qquickmultipointtoucharea.cpp | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index 9d8e7aedd4..706980cd13 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -362,7 +362,7 @@ QQuickMultiPointTouchArea::QQuickMultiPointTouchArea(QQuickItem *parent) QQuickMultiPointTouchArea::~QQuickMultiPointTouchArea() { clearTouchLists(); - foreach (QObject *obj, _touchPoints) { + for (QObject *obj : qAsConst(_touchPoints)) { QQuickTouchPoint *dtp = static_cast<QQuickTouchPoint*>(obj); if (!dtp->isQmlDefined()) delete dtp; @@ -448,20 +448,12 @@ void QQuickMultiPointTouchArea::touchEvent(QTouchEvent *event) } } updateTouchData(event); - if (event->type() == QEvent::TouchEnd) { - //TODO: move to window - _stealMouse = false; - setKeepMouseGrab(false); - setKeepTouchGrab(false); - ungrabTouchPoints(); - } + if (event->type() == QEvent::TouchEnd) + ungrab(); break; } case QEvent::TouchCancel: - _stealMouse = false; - setKeepMouseGrab(false); - setKeepTouchGrab(false); - ungrabTouchPoints(); + ungrab(); break; default: QQuickItem::touchEvent(event); @@ -478,8 +470,10 @@ void QQuickMultiPointTouchArea::grabGesture() QVector<int> ids; ids.reserve(_touchPoints.size()); - for (auto it = _touchPoints.keyBegin(), end = _touchPoints.keyEnd(); it != end; ++it) - ids.append(*it); + for (auto it = _touchPoints.keyBegin(), end = _touchPoints.keyEnd(); it != end; ++it) { + if (*it != -1) // -1 might be the mouse-point, but we already grabbed the mouse above. + ids.append(*it); + } grabTouchPoints(ids); setKeepTouchGrab(true); } @@ -532,7 +526,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) } int numTouchPoints = touchPoints.count(); //always remove released touches, and make sure we handle all releases before adds. - foreach (const QTouchEvent::TouchPoint &p, touchPoints) { + for (const QTouchEvent::TouchPoint &p : qAsConst(touchPoints)) { Qt::TouchPointState touchPointState = p.state(); int id = p.id(); if (touchPointState & Qt::TouchPointReleased) { @@ -547,7 +541,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) } } if (numTouchPoints >= _minimumTouchPoints && numTouchPoints <= _maximumTouchPoints) { - foreach (const QTouchEvent::TouchPoint &p, touchPoints) { + for (const QTouchEvent::TouchPoint &p : qAsConst(touchPoints)) { Qt::TouchPointState touchPointState = p.state(); int id = p.id(); if (touchPointState & Qt::TouchPointReleased) { @@ -557,13 +551,13 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) addTouchPoint(&p); started = true; } else if (touchPointState & Qt::TouchPointMoved) { - QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints[id]); + QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints.value(id)); Q_ASSERT(dtp); _movedTouchPoints.append(dtp); updateTouchPoint(dtp,&p); moved = true; } else { - QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints[id]); + QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints.value(id)); Q_ASSERT(dtp); updateTouchPoint(dtp,&p); } @@ -573,7 +567,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) if (!_stealMouse /* !ignoring gesture*/) { bool offerGrab = false; const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); - foreach (const QTouchEvent::TouchPoint &p, touchPoints) { + for (const QTouchEvent::TouchPoint &p : qAsConst(touchPoints)) { if (p.state() == Qt::TouchPointReleased) continue; const QPointF ¤tPos = p.scenePos(); @@ -607,7 +601,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) void QQuickMultiPointTouchArea::clearTouchLists() { - foreach (QObject *obj, _releasedTouchPoints) { + for (QObject *obj : qAsConst(_releasedTouchPoints)) { QQuickTouchPoint *dtp = static_cast<QQuickTouchPoint*>(obj); if (!dtp->isQmlDefined()) { _touchPoints.remove(dtp->pointId()); @@ -624,7 +618,7 @@ void QQuickMultiPointTouchArea::clearTouchLists() void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) { QQuickTouchPoint *dtp = 0; - foreach (QQuickTouchPoint* tp, _touchPrototypes) { + for (QQuickTouchPoint* tp : qAsConst(_touchPrototypes)) { if (!tp->inUse()) { tp->setInUse(true); dtp = tp; @@ -644,7 +638,7 @@ void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) void QQuickMultiPointTouchArea::addTouchPoint(const QMouseEvent *e) { QQuickTouchPoint *dtp = 0; - foreach (QQuickTouchPoint *tp, _touchPrototypes) + for (QQuickTouchPoint *tp : qAsConst(_touchPrototypes)) if (!tp->inUse()) { tp->setInUse(true); dtp = tp; @@ -784,18 +778,17 @@ void QQuickMultiPointTouchArea::mouseReleaseEvent(QMouseEvent *event) void QQuickMultiPointTouchArea::ungrab() { + _stealMouse = false; + setKeepMouseGrab(false); + setKeepTouchGrab(false); + ungrabTouchPoints(); + if (_touchPoints.count()) { - QQuickWindow *c = window(); - if (c && c->mouseGrabberItem() == this) { - _stealMouse = false; - setKeepMouseGrab(false); - } - setKeepTouchGrab(false); - foreach (QObject *obj, _touchPoints) + for (QObject *obj : qAsConst(_touchPoints)) static_cast<QQuickTouchPoint*>(obj)->setPressed(false); emit canceled(_touchPoints.values()); clearTouchLists(); - foreach (QObject *obj, _touchPoints) { + for (QObject *obj : qAsConst(_touchPoints)) { QQuickTouchPoint *dtp = static_cast<QQuickTouchPoint*>(obj); if (!dtp->isQmlDefined()) delete dtp; @@ -861,10 +854,10 @@ bool QQuickMultiPointTouchArea::sendMouseEvent(QMouseEvent *event) return false; } -bool QQuickMultiPointTouchArea::childMouseEventFilter(QQuickItem *i, QEvent *event) +bool QQuickMultiPointTouchArea::childMouseEventFilter(QQuickItem *receiver, QEvent *event) { if (!isEnabled() || !isVisible()) - return QQuickItem::childMouseEventFilter(i, event); + return QQuickItem::childMouseEventFilter(receiver, event); switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseMove: @@ -881,17 +874,13 @@ bool QQuickMultiPointTouchArea::childMouseEventFilter(QQuickItem *i, QEvent *eve if (!shouldFilter(event)) return false; updateTouchData(event); - //TODO: verify this behavior - _stealMouse = false; - setKeepMouseGrab(false); - setKeepTouchGrab(false); - ungrabTouchPoints(); + ungrab(); } break; default: break; } - return QQuickItem::childMouseEventFilter(i, event); + return QQuickItem::childMouseEventFilter(receiver, event); } bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event) @@ -914,7 +903,7 @@ bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *te = static_cast<QTouchEvent*>(event); - foreach (const QTouchEvent::TouchPoint &point, te->touchPoints()) { + for (const QTouchEvent::TouchPoint &point : te->touchPoints()) { if (contains(mapFromScene(point.scenePos()))) { containsPoint = true; break; @@ -940,8 +929,8 @@ QSGNode *QQuickMultiPointTouchArea::updatePaintNode(QSGNode *oldNode, UpdatePain if (!qmlVisualTouchDebugging()) return 0; - QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode); - if (!rectangle) rectangle = QQuickItemPrivate::get(this)->sceneGraphContext()->createRectangleNode(); + QSGInternalRectangleNode *rectangle = static_cast<QSGInternalRectangleNode *>(oldNode); + if (!rectangle) rectangle = QQuickItemPrivate::get(this)->sceneGraphContext()->createInternalRectangleNode(); rectangle->setRect(QRectF(0, 0, width(), height())); rectangle->setColor(QColor(255, 0, 0, 50)); |