From 6b310e5f9a53c366fbb8fb78bd7c343aad4e0cdd Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 8 Feb 2018 15:58:24 +0100 Subject: TapHandler: add singleTapped and doubleTapped signals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/quick/handlers/qquicktaphandler.cpp | 30 +++++++++++++++++++++++++++--- src/quick/handlers/qquicktaphandler_p.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/quick') 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: -- cgit v1.2.3