diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-09-07 16:54:44 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-08 18:35:14 +0000 |
commit | 1a29e946ee809ab32ee508a6823c4ec3ca668b34 (patch) | |
tree | 3162cc676c525095566be79c0affadb0a496560e /src/quick/handlers/qquicktaphandler.cpp | |
parent | cc0210ade262582534958efd2618a7f312afc604 (diff) |
Add button argument to the TapHandler.[single|double|]tapped signals
It would be better to emit the whole pointer event (by pointer because
it's non-copyable, or make it copyable and emit by value), but we can't.
So we just add the button being tapped; more information is available
from the eventpoint argument and TapHandler's point property.
To avoid name clashes with anything that's already called "button" in
anyone's QML (which is quite likely, actually), the new signal argument
is unnamed, so that users will be required to write a function signature
that gives it a name rather than relying on context injection.
[ChangeLog][QtQuick][Event Handlers] TapHandler's tapped(), singleTapped()
and doubleTapped() signals now have two arguments: the QEventPoint instance,
and the button being tapped. If you need it, you should write an explicit
function for the signal handler: onTapped: function(point, button) { ... }
or onDoubleTapped: (point, button)=> ...
Fixes: QTBUG-91350
Task-number: QTBUG-64847
Change-Id: I6d25300cbfceb56f27452eac4b29b66bd1b2a41a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 5864644ac8bc3c561696ffef5d033b1cab7d950f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quick/handlers/qquicktaphandler.cpp')
-rw-r--r-- | src/quick/handlers/qquicktaphandler.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index f1620f4c41..c7be6631c7 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -310,12 +310,13 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QPointerEvent *event, else m_tapCount = 1; qCDebug(lcTapHandler) << objectName() << "tapped" << m_tapCount << "times"; - emit tapped(point); + auto button = event->isSinglePointEvent() ? static_cast<QSinglePointEvent *>(event)->button() : Qt::NoButton; + emit tapped(point, button); emit tapCountChanged(); if (m_tapCount == 1) - emit singleTapped(point); + emit singleTapped(point, button); else if (m_tapCount == 2) - emit doubleTapped(point); + emit doubleTapped(point, button); m_lastTapTimestamp = ts; m_lastTapPos = point.scenePosition(); } else { @@ -399,7 +400,7 @@ void QQuickTapHandler::updateTimeHeld() */ /*! - \qmlsignal QtQuick::TapHandler::tapped(EventPoint eventPoint) + \qmlsignal QtQuick::TapHandler::tapped(EventPoint eventPoint, Qt::MouseButton button) This signal is emitted each time the \c parent Item is tapped. @@ -407,24 +408,28 @@ void QQuickTapHandler::updateTimeHeld() period less than \l longPressThreshold, while any movement does not exceed the drag threshold, then the \c tapped signal will be emitted at the time of release. The \a eventPoint signal parameter contains information - from the release event about the point that was tapped: + from the release event about the point that was tapped, and \a button + is the \l {Qt::MouseButton}{mouse button} that was clicked, or \c NoButton + on a touchscreen. \snippet pointerHandlers/tapHandlerOnTapped.qml 0 */ /*! - \qmlsignal QtQuick::TapHandler::singleTapped(EventPoint eventPoint) + \qmlsignal QtQuick::TapHandler::singleTapped(EventPoint eventPoint, Qt::MouseButton button) \since 5.11 This signal is emitted when the \c parent Item 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. The \a eventPoint signal parameter contains - information from the release event about the point that was tapped. + information from the release event about the point that was tapped, and + \a button is the \l {Qt::MouseButton}{mouse button} that was clicked, or + \c NoButton on a touchscreen. */ /*! - \qmlsignal QtQuick::TapHandler::doubleTapped(EventPoint eventPoint) + \qmlsignal QtQuick::TapHandler::doubleTapped(EventPoint eventPoint, Qt::MouseButton button) \since 5.11 This signal is emitted when the \c parent Item is tapped twice within a @@ -433,7 +438,9 @@ void QQuickTapHandler::updateTimeHeld() QStyleHints::touchDoubleTapDistance()). This signal always occurs after \l singleTapped, \l tapped, and \l tapCountChanged. The \a eventPoint signal parameter contains information from the release event about the - point that was tapped. + point that was tapped, and \a button is the + \l {Qt::MouseButton}{mouse button} that was clicked, or \c NoButton + on a touchscreen. */ /*! |