diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/handlers/qquickdraghandler.cpp | 43 | ||||
-rw-r--r-- | src/quick/handlers/qquickdraghandler_p.h | 13 | ||||
-rw-r--r-- | src/quick/handlers/qquickhandlerpoint.cpp | 9 |
3 files changed, 51 insertions, 14 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 809adfd043..233516c3a3 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -165,6 +165,7 @@ void QQuickDragHandler::onActiveChanged() // mouse grab too, whenever dragging occurs in an enabled direction parent->setKeepMouseGrab(true); } + m_startTranslation = m_persistentTranslation; } else { m_pressTargetPos = QPointF(); m_pressedInsideTarget = false; @@ -210,7 +211,7 @@ void QQuickDragHandler::handlePointerEventImpl(QPointerEvent *event) accumulatedDragDelta.setX(0); if (!m_yAxis.enabled()) accumulatedDragDelta.setY(0); - setTranslation(accumulatedDragDelta); + setActiveTranslation(accumulatedDragDelta); } else { // Check that all points have been dragged past the drag threshold, // to the extent that the constraints allow, @@ -316,11 +317,24 @@ void QQuickDragHandler::enforceAxisConstraints(QPointF *localPos) localPos->setY(qBound(m_yAxis.minimum(), localPos->y(), m_yAxis.maximum())); } -void QQuickDragHandler::setTranslation(const QVector2D &trans) +void QQuickDragHandler::setPersistentTranslation(const QVector2D &trans) { - if (trans == m_translation) // fuzzy compare? + if (trans == m_persistentTranslation) return; - m_translation = trans; + + m_persistentTranslation = trans; + emit translationChanged(); +} + +void QQuickDragHandler::setActiveTranslation(const QVector2D &trans) +{ + if (trans == m_activeTranslation) + return; + + m_activeTranslation = trans; + m_persistentTranslation = m_startTranslation + trans; + qCDebug(lcDragHandler) << "translation: start" << m_startTranslation + << "active" << m_activeTranslation << "accumulated" << m_persistentTranslation; emit translationChanged(); } @@ -357,8 +371,27 @@ void QQuickDragHandler::setTranslation(const QVector2D &trans) /*! \readonly \qmlproperty QVector2D QtQuick::DragHandler::translation + \deprecated Use activeTranslation +*/ + +/*! + \qmlproperty QVector2D QtQuick::DragHandler::persistentTranslation + + The translation to be applied to the \l target if it is not \c null. + Otherwise, bindings can be used to do arbitrary things with this value. + While the drag gesture is being performed, \l activeTranslation is + continuously added to it; after the gesture ends, it stays the same. +*/ + +/*! + \readonly + \qmlproperty QVector2D QtQuick::DragHandler::activeTranslation - The translation since the gesture began. + The translation while the drag gesture is being performed. + It is \c {0, 0} when the gesture begins, and increases as the event + point(s) are dragged downward and to the right. After the gesture ends, it + stays the same; and when the next drag gesture begins, it is reset to + \c {0, 0} again. */ QT_END_NAMESPACE diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h index a0dce10314..a42281819c 100644 --- a/src/quick/handlers/qquickdraghandler_p.h +++ b/src/quick/handlers/qquickdraghandler_p.h @@ -62,6 +62,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickDragHandler : public QQuickMultiPointHandler Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT) Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT) Q_PROPERTY(QVector2D translation READ translation NOTIFY translationChanged) + Q_PROPERTY(QVector2D activeTranslation READ activeTranslation NOTIFY translationChanged REVISION(6, 2)) + Q_PROPERTY(QVector2D persistentTranslation READ persistentTranslation WRITE setPersistentTranslation NOTIFY translationChanged REVISION(6, 2)) Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged REVISION(2, 14)) QML_NAMED_ELEMENT(DragHandler) QML_ADDED_IN_VERSION(2, 12) @@ -82,8 +84,11 @@ public: QQuickDragAxis *xAxis() { return &m_xAxis; } QQuickDragAxis *yAxis() { return &m_yAxis; } - QVector2D translation() const { return m_translation; } - void setTranslation(const QVector2D &trans); + QVector2D translation() const { return m_activeTranslation; } + QVector2D activeTranslation() const { return m_activeTranslation; } + void setActiveTranslation(const QVector2D &trans); + QVector2D persistentTranslation() const { return m_persistentTranslation; } + void setPersistentTranslation(const QVector2D &trans); QQuickDragHandler::SnapMode snapMode() const; void setSnapMode(QQuickDragHandler::SnapMode mode); @@ -107,7 +112,9 @@ private: QPointF m_pressTargetPos; // We must also store the local targetPos, because we cannot deduce // the press target pos from the scene pos in case there was e.g a // flick in one of the ancestors during the drag. - QVector2D m_translation; + QVector2D m_activeTranslation; + QVector2D m_persistentTranslation; + QVector2D m_startTranslation; QQuickDragAxis m_xAxis; QQuickDragAxis m_yAxis; diff --git a/src/quick/handlers/qquickhandlerpoint.cpp b/src/quick/handlers/qquickhandlerpoint.cpp index 54951b82b3..c3149983c0 100644 --- a/src/quick/handlers/qquickhandlerpoint.cpp +++ b/src/quick/handlers/qquickhandlerpoint.cpp @@ -100,17 +100,14 @@ void QQuickHandlerPoint::reset() void QQuickHandlerPoint::reset(const QPointerEvent *event, const QEventPoint &point) { + const bool isTouch = QQuickDeliveryAgentPrivate::isTouchEvent(event); m_id = point.id(); m_device = event->pointingDevice(); - switch (point.state()) { - case QEventPoint::Pressed: + const auto state = (isTouch ? static_cast<const QTouchEvent *>(event)->touchPointStates() : point.state()); + if (state.testFlag(QEventPoint::Pressed)) { m_pressPosition = point.position(); m_scenePressPosition = point.scenePosition(); - break; - default: - break; } - const bool isTouch = QQuickDeliveryAgentPrivate::isTouchEvent(event); if (!isTouch) m_pressedButtons = static_cast<const QSinglePointEvent *>(event)->buttons(); m_pressedModifiers = event->modifiers(); |