diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-01-03 16:05:46 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-01-03 18:26:08 +0000 |
commit | 28a9f66ea4910657b98cd4db548d84b298cf844e (patch) | |
tree | a397993c9cf1cf1ac0000d47e37c26228cb653b8 /src/quicktemplates2/qquickdial.cpp | |
parent | 0b290018b52bc15534bedebe39f183e74eaee24e (diff) |
QQuickDial: handle touch events
In comparison to handling synthesized mouse events, handling touch
events has the advantage that it gives multi-touch support. That is,
it is possible to move multiple dials at the same time, each handling
its own touch point.
Change-Id: Icabd971147f291fa4df00c6215c847d7976fda5f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickdial.cpp')
-rw-r--r-- | src/quicktemplates2/qquickdial.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp index bd59f057..3f37a73b 100644 --- a/src/quicktemplates2/qquickdial.cpp +++ b/src/quicktemplates2/qquickdial.cpp @@ -96,6 +96,7 @@ class QQuickDialPrivate : public QQuickControlPrivate public: QQuickDialPrivate() : + touchId(-1), from(0), to(1), value(0), @@ -122,6 +123,7 @@ public: void handleRelease(const QPointF &point); void handleUngrab(); + int touchId; qreal from; qreal to; qreal value; @@ -241,12 +243,14 @@ void QQuickDialPrivate::handleRelease(const QPointF &point) q->setPressed(false); pressPoint = QPointF(); + touchId = -1; } void QQuickDialPrivate::handleUngrab() { Q_Q(QQuickDial); pressPoint = QPointF(); + touchId = -1; q->setPressed(false); } @@ -685,6 +689,64 @@ void QQuickDial::mouseUngrabEvent() d->handleUngrab(); } +void QQuickDial::touchEvent(QTouchEvent *event) +{ + Q_D(QQuickDial); + switch (event->type()) { + case QEvent::TouchBegin: + if (d->touchId == -1) { + const QTouchEvent::TouchPoint point = event->touchPoints().first(); + d->touchId = point.id(); + d->handlePress(point.pos()); + } else { + event->ignore(); + } + break; + + case QEvent::TouchUpdate: + for (const QTouchEvent::TouchPoint &point : event->touchPoints()) { + if (point.id() != d->touchId) + continue; + + if (!keepMouseGrab()) { + bool overXDragThreshold = QQuickWindowPrivate::dragOverThreshold(point.pos().x() - d->pressPoint.x(), Qt::XAxis, &point); + setKeepMouseGrab(overXDragThreshold); + + if (!overXDragThreshold) { + bool overYDragThreshold = QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point); + setKeepMouseGrab(overYDragThreshold); + } + } + d->handleMove(point.pos()); + } + break; + + case QEvent::TouchEnd: + for (const QTouchEvent::TouchPoint &point : event->touchPoints()) { + if (point.id() != d->touchId) + continue; + + d->handleRelease(point.pos()); + } + break; + + case QEvent::TouchCancel: + d->handleUngrab(); + break; + + default: + QQuickControl::touchEvent(event); + break; + } +} + +void QQuickDial::touchUngrabEvent() +{ + Q_D(QQuickDial); + QQuickControl::touchUngrabEvent(); + d->handleUngrab(); +} + void QQuickDial::wheelEvent(QWheelEvent *event) { Q_D(QQuickDial); |