diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-02-08 15:58:24 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-03-02 15:38:55 +0000 |
commit | 6b310e5f9a53c366fbb8fb78bd7c343aad4e0cdd (patch) | |
tree | 563d5bb1e5524826593ddcd960d907bdfd6a60dd /src/quick | |
parent | 849324dbdb64edcc7e3c8e83f0a1c6c1afbebe9c (diff) |
TapHandler: add singleTapped and doubleTapped signals
This is for convenience. It's nicer not to need to test tapCount
in JavaScript if you know you want to react on double-click:
onTapped: if (tapCount === 2) doSomething() becomes
onDoubleTapped: doSomething() Neither of these are
guaranteed to be exclusive though: singleTapped occurs first,
then doubleTapped if you tap again quickly, then tapCount
keeps increasing as long as you keep tapping.
Change-Id: I6fff10880831d5be0848b9957141311db8c2c0f0
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/handlers/qquicktaphandler.cpp | 30 | ||||
-rw-r--r-- | src/quick/handlers/qquicktaphandler_p.h | 2 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index f6c19cf314..902ff0df10 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -310,6 +310,10 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi qCDebug(lcTapHandler) << objectName() << "tapped" << m_tapCount << "times"; emit tapped(); emit tapCountChanged(); + if (m_tapCount == 1) + emit singleTapped(); + else if (m_tapCount == 2) + emit doubleTapped(); m_lastTapTimestamp = ts; m_lastTapPos = point->scenePosition(); } else { @@ -353,15 +357,15 @@ void QQuickTapHandler::updateTimeHeld() The number of taps which have occurred within the time and space constraints to be considered a single gesture. For example, to detect - a double-tap, you can write: + a triple-tap, you can write: \qml Rectangle { width: 100; height: 30 - signal doubleTap + signal tripleTap TapHandler { acceptedButtons: Qt.AllButtons - onTapped: if (tapCount == 2) doubleTap() + onTapped: if (tapCount == 3) tripleTap() } } \endqml @@ -382,4 +386,24 @@ void QQuickTapHandler::updateTimeHeld() handler's \l [QML] Item. */ +/*! + \qmlsignal TapHandler::singleTapped + \since 5.11 + + This signal is emitted when the \l target is tapped once. After an amount + of time greater than QStyleHints::mouseDoubleClickInterval, it can be + tapped again; but if the time until the next tap is less, \l tapCount + will increase. +*/ + +/*! + \qmlsignal TapHandler::doubleTapped + \since 5.11 + + This signal is emitted when the \l target is tapped twice within a short + span of time (QStyleHints::mouseDoubleClickInterval) and distance + (QPlatformTheme::MouseDoubleClickDistance or + QPlatformTheme::TouchDoubleTapDistance). This signal always occurs + after singleTapped, tapped and tapCountChanged. +*/ QT_END_NAMESPACE diff --git a/src/quick/handlers/qquicktaphandler_p.h b/src/quick/handlers/qquicktaphandler_p.h index e92d2029ba..b7c1895926 100644 --- a/src/quick/handlers/qquicktaphandler_p.h +++ b/src/quick/handlers/qquicktaphandler_p.h @@ -96,6 +96,8 @@ Q_SIGNALS: void longPressThresholdChanged(); void gesturePolicyChanged(); void tapped(); + void singleTapped(); + void doubleTapped(); void longPressed(); protected: |