diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-21 08:00:01 +0300 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-21 08:00:01 +0300 |
commit | 284057d12fea9339744ddc646aa53cfe6c3c95a1 (patch) | |
tree | 61bb12637c56a282830d683e346057b00d332b7a /src/quicktemplates2/qquickrangeslider.cpp | |
parent | 91b2721fdc2aba28d3c45111779fed70f7c4f87d (diff) | |
parent | c8e9b5f25fb12c3b7983658d738165181b4d6672 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/imports/controls/RoundButton.qml
src/imports/controls/universal/RadioDelegate.qml
Change-Id: I4cb14c19bd5f6e19b70b03fb394c76712e6dda08
Diffstat (limited to 'src/quicktemplates2/qquickrangeslider.cpp')
-rw-r--r-- | src/quicktemplates2/qquickrangeslider.cpp | 95 |
1 files changed, 34 insertions, 61 deletions
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index 9996d041..1468d358 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -327,10 +327,12 @@ public: } QQuickRangeSliderNode *pressedNode(int touchId = -1) const; - void handlePress(const QPointF &point, int touchId = -1); - void handleMove(const QPointF &point, int touchId = -1); - void handleRelease(const QPointF &point, int touchId = -1); - void handleUngrab(); + + bool acceptTouch(const QTouchEvent::TouchPoint &point) override; + void handlePress(const QPointF &point) override; + void handleMove(const QPointF &point) override; + void handleRelease(const QPointF &point) override; + void handleUngrab() override; void updateHover(const QPointF &pos); @@ -395,9 +397,23 @@ QQuickRangeSliderNode *QQuickRangeSliderPrivate::pressedNode(int touchId) const return nullptr; } -void QQuickRangeSliderPrivate::handlePress(const QPointF &point, int touchId) +bool QQuickRangeSliderPrivate::acceptTouch(const QTouchEvent::TouchPoint &point) +{ + int firstId = QQuickRangeSliderNodePrivate::get(first)->touchId; + int secondId = QQuickRangeSliderNodePrivate::get(second)->touchId; + + if (((firstId == -1 || secondId == -1) && point.state() == Qt::TouchPointPressed) || point.id() == firstId || point.id() == secondId) { + touchId = point.id(); + return true; + } + + return false; +} + +void QQuickRangeSliderPrivate::handlePress(const QPointF &point) { Q_Q(QQuickRangeSlider); + QQuickControlPrivate::handlePress(point); pressPoint = point; QQuickItem *firstHandle = first->handle(); @@ -453,9 +469,10 @@ void QQuickRangeSliderPrivate::handlePress(const QPointF &point, int touchId) otherNode->handle()->setZ(0); } -void QQuickRangeSliderPrivate::handleMove(const QPointF &point, int touchId) +void QQuickRangeSliderPrivate::handleMove(const QPointF &point) { Q_Q(QQuickRangeSlider); + QQuickControlPrivate::handleMove(point); QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId); if (pressedNode) { qreal pos = positionAt(q, pressedNode->handle(), point); @@ -468,9 +485,10 @@ void QQuickRangeSliderPrivate::handleMove(const QPointF &point, int touchId) } } -void QQuickRangeSliderPrivate::handleRelease(const QPointF &point, int touchId) +void QQuickRangeSliderPrivate::handleRelease(const QPointF &point) { Q_Q(QQuickRangeSlider); + QQuickControlPrivate::handleRelease(point); pressPoint = QPointF(); QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId); @@ -496,6 +514,7 @@ void QQuickRangeSliderPrivate::handleRelease(const QPointF &point, int touchId) void QQuickRangeSliderPrivate::handleUngrab() { + QQuickControlPrivate::handleUngrab(); pressPoint = QPointF(); first->setPressed(false); second->setPressed(false); @@ -982,57 +1001,33 @@ void QQuickRangeSlider::mousePressEvent(QMouseEvent *event) { Q_D(QQuickRangeSlider); QQuickControl::mousePressEvent(event); - d->handlePress(event->localPos()); d->handleMove(event->localPos()); } void QQuickRangeSlider::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickRangeSlider); - QQuickControl::mouseMoveEvent(event); if (!keepMouseGrab()) { if (d->orientation == Qt::Horizontal) setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->localPos().x() - d->pressPoint.x(), Qt::XAxis, event)); else setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->localPos().y() - d->pressPoint.y(), Qt::YAxis, event)); } - if (keepMouseGrab()) - d->handleMove(event->localPos()); -} - -void QQuickRangeSlider::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickRangeSlider); - QQuickControl::mouseReleaseEvent(event); - d->handleRelease(event->localPos()); -} - -void QQuickRangeSlider::mouseUngrabEvent() -{ - Q_D(QQuickRangeSlider); - QQuickControl::mouseUngrabEvent(); - d->handleUngrab(); + QQuickControl::mouseMoveEvent(event); } void QQuickRangeSlider::touchEvent(QTouchEvent *event) { Q_D(QQuickRangeSlider); switch (event->type()) { - case QEvent::TouchBegin: - if (!d->first->isPressed() || !d->second->isPressed()) { - const QTouchEvent::TouchPoint point = event->touchPoints().first(); - d->handlePress(point.pos(), point.id()); - } else { - event->ignore(); - } - break; - case QEvent::TouchUpdate: for (const QTouchEvent::TouchPoint &point : event->touchPoints()) { + if (!d->acceptTouch(point)) + continue; + switch (point.state()) { case Qt::TouchPointPressed: - if (!d->first->isPressed() || !d->second->isPressed()) - d->handlePress(point.pos(), point.id()); + d->handlePress(point.pos()); break; case Qt::TouchPointMoved: if (!keepTouchGrab()) { @@ -1041,14 +1036,11 @@ void QQuickRangeSlider::touchEvent(QTouchEvent *event) else setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - point.startPos().y(), Qt::YAxis, &point)); } - if (point.id() == QQuickRangeSliderNodePrivate::get(d->first)->touchId - || point.id() == QQuickRangeSliderNodePrivate::get(d->second)->touchId) - d->handleMove(point.pos(), point.id()); + if (keepTouchGrab()) + d->handleMove(point.pos()); break; case Qt::TouchPointReleased: - if (point.id() == QQuickRangeSliderNodePrivate::get(d->first)->touchId - || point.id() == QQuickRangeSliderNodePrivate::get(d->second)->touchId) - d->handleRelease(point.pos(), point.id()); + d->handleRelease(point.pos()); break; default: break; @@ -1056,31 +1048,12 @@ void QQuickRangeSlider::touchEvent(QTouchEvent *event) } break; - case QEvent::TouchEnd: - for (const QTouchEvent::TouchPoint &point : event->touchPoints()) { - if (point.id() == QQuickRangeSliderNodePrivate::get(d->first)->touchId - || point.id() == QQuickRangeSliderNodePrivate::get(d->second)->touchId) - d->handleRelease(point.pos(), point.id()); - } - break; - - case QEvent::TouchCancel: - d->handleUngrab(); - break; - default: QQuickControl::touchEvent(event); break; } } -void QQuickRangeSlider::touchUngrabEvent() -{ - Q_D(QQuickRangeSlider); - QQuickControl::touchUngrabEvent(); - d->handleUngrab(); -} - void QQuickRangeSlider::mirrorChange() { Q_D(QQuickRangeSlider); |