diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-06-11 07:38:46 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-19 10:56:06 +0000 |
commit | ca7cdd71ee33f0d77eb6bf1367d2532e26155cb2 (patch) | |
tree | af1b30bffea87bedb23e8cd795f23692f29b50a9 /src/quick/handlers/qquickmultipointhandler.cpp | |
parent | d310ca768bb5f45bae4fcec9a5d8151b6a366b8d (diff) |
Make DragHandler a MultiPointHandler
That is, minimumPointCount can now be set to a value > 1 to require
multiple fingers to do the dragging, or to track the displacement
of multiple fingers to adjust some value (such as the tilt of a map).
Task-number: QTBUG-68106
Change-Id: Ib35823e36deb81c8b277d3070fcc758c7c019564
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickmultipointhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickmultipointhandler.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp index b08b00e5a7..d688058c4e 100644 --- a/src/quick/handlers/qquickmultipointhandler.cpp +++ b/src/quick/handlers/qquickmultipointhandler.cpp @@ -59,10 +59,10 @@ QT_BEGIN_NAMESPACE for any type of handler which requires and acts upon a specific number of multiple touchpoints. */ -QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int minimumPointCount) +QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int minimumPointCount, int maximumPointCount) : QQuickPointerDeviceHandler(parent) , m_minimumPointCount(minimumPointCount) - , m_maximumPointCount(-1) + , m_maximumPointCount(maximumPointCount) { } @@ -117,9 +117,27 @@ void QQuickMultiPointHandler::onActiveChanged() { if (active()) { m_centroid.m_sceneGrabPosition = m_centroid.m_scenePosition; + } else { + // Don't call m_centroid.reset() here, because in a QML onActiveChanged + // callback, we'd like to see what the position _was_, what the velocity _was_, etc. + // (having them undefined is not useful) + // But pressedButtons and pressedModifiers are meant to be more real-time than those + // (which seems a bit inconsistent, from one side). + m_centroid.m_pressedButtons = Qt::NoButton; + m_centroid.m_pressedModifiers = Qt::NoModifier; } } +void QQuickMultiPointHandler::onGrabChanged(QQuickPointerHandler *, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *) +{ + // If another handler or item takes over this set of points, assume it has + // decided that it's the better fit for them. Don't immediately re-grab + // at the next opportunity. This should help to avoid grab cycles + // (e.g. between DragHandler and PinchHandler). + if (stateChange == QQuickEventPoint::UngrabExclusive || stateChange == QQuickEventPoint::CancelGrabExclusive) + m_currentPoints.clear(); +} + QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointerEvent *event) { QVector<QQuickEventPoint *> ret; @@ -279,7 +297,7 @@ bool QQuickMultiPointHandler::grabPoints(QVector<QQuickEventPoint *> points) { bool allowed = true; for (QQuickEventPoint* point : points) { - if (!canGrab(point)) { + if (point->exclusiveGrabber() != this && !canGrab(point)) { allowed = false; break; } @@ -291,4 +309,10 @@ bool QQuickMultiPointHandler::grabPoints(QVector<QQuickEventPoint *> points) return allowed; } +void QQuickMultiPointHandler::moveTarget(QPointF pos) +{ + target()->setPosition(pos); + m_centroid.m_position = target()->mapFromScene(m_centroid.m_scenePosition); +} + QT_END_NAMESPACE |