diff options
Diffstat (limited to 'src/quick/handlers/qquickmultipointhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickmultipointhandler.cpp | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp index 41d8b228a1..ff4914394c 100644 --- a/src/quick/handlers/qquickmultipointhandler.cpp +++ b/src/quick/handlers/qquickmultipointhandler.cpp @@ -46,13 +46,23 @@ QT_BEGIN_NAMESPACE /*! + \qmltype MultiPointHandler + \since 5.10 + \preliminary + \instantiates QQuickMultiPointHandler + \inherits PointerDeviceHandler + \inqmlmodule Qt.labs.handlers + \ingroup qtquick-handlers + \brief Abstract handler for multi-point Pointer Events. + An intermediate class (not registered as a QML type) - for the type of handler which requires and acts upon a specific number + for any type of handler which requires and acts upon a specific number of multiple touchpoints. */ -QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int requiredPointCount) +QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int minimumPointCount) : QQuickPointerDeviceHandler(parent) - , m_requiredPointCount(requiredPointCount) + , m_minimumPointCount(minimumPointCount) + , m_maximumPointCount(-1) , m_pointDistanceThreshold(0) { } @@ -66,11 +76,14 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) if (!QQuickPointerDeviceHandler::wantsPointerEvent(event)) return false; + if (event->asPointerNativeGestureEvent()) + return true; + if (sameAsCurrentPoints(event)) return true; const QVector<QQuickEventPoint *> candidatePoints = eligiblePoints(event); - const bool ret = (candidatePoints.size() == m_requiredPointCount); + const bool ret = (candidatePoints.size() >= minimumPointCount() && candidatePoints.size() <= maximumPointCount()); if (ret) m_currentPoints = candidatePoints; return ret; @@ -99,15 +112,68 @@ QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointe return ret; } -void QQuickMultiPointHandler::setRequiredPointCount(int c) +/*! + \qmlproperty int MultiPointHandler::minimumPointCount + + The minimum number of touchpoints required to activate this handler. + + If a smaller number of touchpoints are in contact with the + \l {PointerHandler::parent}{parent}, they will be ignored. + + Any ignored points are eligible to activate other Pointer Handlers that + have different constraints, on the same Item or on other Items. + + The default value is 2. +*/ +void QQuickMultiPointHandler::setMinimumPointCount(int c) { - if (m_requiredPointCount == c) + if (m_minimumPointCount == c) return; - m_requiredPointCount = c; - emit requiredPointCountChanged(); + m_minimumPointCount = c; + emit minimumPointCountChanged(); + if (m_maximumPointCount < 0) + emit maximumPointCountChanged(); } +/*! + \qmlproperty int MultiPointHandler::maximumPointCount + + The maximum number of touchpoints this handler can utilize. + + If a larger number of touchpoints are in contact with the + \l {PointerHandler::parent}{parent}, the required number of points will be + chosen in the order that they are pressed, and the remaining points will + be ignored. + + Any ignored points are eligible to activate other Pointer Handlers that + have different constraints, on the same Item or on other Items. + + The default value is the same as \l minimumPointCount. +*/ +void QQuickMultiPointHandler::setMaximumPointCount(int maximumPointCount) +{ + if (m_maximumPointCount == maximumPointCount) + return; + + m_maximumPointCount = maximumPointCount; + emit maximumPointCountChanged(); +} + +/*! + \qmlproperty real MultiPointHandler::pointDistanceThreshold + + The margin beyond the bounds of the \l {PointerHandler::parent}{parent} + item within which a touch point can activate this handler. For example, on + a PinchHandler where the \l {PointerHandler::target}{target} is also the + \c parent, it's useful to set this to a distance at least half the width + of a typical user's finger, so that if the \c parent has been scaled down + to a very small size, the pinch gesture is still possible. + + The default value is 0. + + \image pointDistanceThreshold.png +*/ void QQuickMultiPointHandler::setPointDistanceThreshold(qreal pointDistanceThreshold) { if (m_pointDistanceThreshold == pointDistanceThreshold) |