diff options
5 files changed, 56 insertions, 25 deletions
diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp index 2ced136026..d0b4edf0ac 100644 --- a/src/quick/handlers/qquickmultipointhandler.cpp +++ b/src/quick/handlers/qquickmultipointhandler.cpp @@ -59,9 +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 requiredPointCount) +QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int minimumPointCount) : QQuickPointerDeviceHandler(parent) - , m_requiredPointCount(requiredPointCount) + , m_minimumPointCount(minimumPointCount) + , m_maximumPointCount(-1) , m_pointDistanceThreshold(0) { } @@ -79,7 +80,7 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *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; @@ -109,28 +110,52 @@ QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointe } /*! - \qmlproperty int MultiPointHandler::requiredPointCount + \qmlproperty int MultiPointHandler::minimumPointCount - The number of touchpoints that are required to activate this handler. If - a smaller number of touchpoints are in contact with the - \l {PointerHandler::parent}{parent}, they will be ignored. If a larger number - of touchpoints are in contact, 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, which have different constraints, on the same Item or on other - Items. + 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::setRequiredPointCount(int c) +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 diff --git a/src/quick/handlers/qquickmultipointhandler_p.h b/src/quick/handlers/qquickmultipointhandler_p.h index 97e3383331..05c3876246 100644 --- a/src/quick/handlers/qquickmultipointhandler_p.h +++ b/src/quick/handlers/qquickmultipointhandler_p.h @@ -60,21 +60,26 @@ QT_BEGIN_NAMESPACE class Q_AUTOTEST_EXPORT QQuickMultiPointHandler : public QQuickPointerDeviceHandler { Q_OBJECT - Q_PROPERTY(int requiredPointCount READ requiredPointCount WRITE setRequiredPointCount NOTIFY requiredPointCountChanged) + Q_PROPERTY(int minimumPointCount READ minimumPointCount WRITE setMinimumPointCount NOTIFY minimumPointCountChanged) + Q_PROPERTY(int maximumPointCount READ maximumPointCount WRITE setMaximumPointCount NOTIFY maximumPointCountChanged) Q_PROPERTY(qreal pointDistanceThreshold READ pointDistanceThreshold WRITE setPointDistanceThreshold NOTIFY pointDistanceThresholdChanged) public: - explicit QQuickMultiPointHandler(QObject *parent = 0, int requiredPointCount = 2); + explicit QQuickMultiPointHandler(QObject *parent = 0, int minimumPointCount = 2); ~QQuickMultiPointHandler(); - int requiredPointCount() const { return m_requiredPointCount; } - void setRequiredPointCount(int c); + int minimumPointCount() const { return m_minimumPointCount; } + void setMinimumPointCount(int c); + + int maximumPointCount() const { return m_maximumPointCount >= 0 ? m_maximumPointCount : m_minimumPointCount; } + void setMaximumPointCount(int maximumPointCount); qreal pointDistanceThreshold() const { return m_pointDistanceThreshold; } void setPointDistanceThreshold(qreal pointDistanceThreshold); signals: - void requiredPointCountChanged(); + void minimumPointCountChanged(); + void maximumPointCountChanged(); void pointDistanceThresholdChanged(); protected: @@ -101,7 +106,8 @@ protected: protected: QVector<QQuickEventPoint *> m_currentPoints; - int m_requiredPointCount; + int m_minimumPointCount; + int m_maximumPointCount; qreal m_pointDistanceThreshold; }; diff --git a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/data/pinchDragMPTA.qml b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/data/pinchDragMPTA.qml index d479882d38..5446377f9c 100644 --- a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/data/pinchDragMPTA.qml +++ b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/data/pinchDragMPTA.qml @@ -106,7 +106,7 @@ Rectangle { id: pinch3 objectName: "3-finger pinch" target: container - requiredPointCount: 3 + minimumPointCount: 3 minimumScale: 0.1 maximumScale: 10 } diff --git a/tests/manual/pointer/pinchDragFlingMPTA.qml b/tests/manual/pointer/pinchDragFlingMPTA.qml index 6446a17873..07b2dc2c45 100644 --- a/tests/manual/pointer/pinchDragFlingMPTA.qml +++ b/tests/manual/pointer/pinchDragFlingMPTA.qml @@ -75,7 +75,7 @@ Rectangle { id: pinch3 objectName: "3-finger pinch" target: container - requiredPointCount: 3 + minimumPointCount: 3 minimumScale: 0.1 maximumScale: 10 onActiveChanged: if (!active) fling.restart(centroidVelocity) diff --git a/tests/manual/pointer/pinchHandler.qml b/tests/manual/pointer/pinchHandler.qml index 71cdd98e4f..1102f33618 100644 --- a/tests/manual/pointer/pinchHandler.qml +++ b/tests/manual/pointer/pinchHandler.qml @@ -118,7 +118,7 @@ Rectangle { PinchHandler { id: pinch3 objectName: "3-finger pinch" - requiredPointCount: 3 + minimumPointCount: 3 minimumScale: 0.1 maximumScale: 10 onActiveChanged: { |