aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-09-07 16:54:44 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-08 18:35:14 +0000
commit1a29e946ee809ab32ee508a6823c4ec3ca668b34 (patch)
tree3162cc676c525095566be79c0affadb0a496560e
parentcc0210ade262582534958efd2618a7f312afc604 (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>
-rw-r--r--src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml8
-rw-r--r--src/quick/handlers/qquicktaphandler.cpp25
-rw-r--r--src/quick/handlers/qquicktaphandler_p.h7
-rw-r--r--tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp4
-rw-r--r--tests/manual/pointer/tapHandler.qml9
5 files changed, 31 insertions, 22 deletions
diff --git a/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml b/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml
index deff59d034..2c682df584 100644
--- a/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml
+++ b/src/quick/doc/snippets/pointerHandlers/tapHandlerOnTapped.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -48,7 +48,7 @@
**
****************************************************************************/
//![0]
-import QtQuick 2.12
+import QtQuick
Rectangle {
width: 100
@@ -56,8 +56,8 @@ Rectangle {
TapHandler {
acceptedButtons: Qt.LeftButton | Qt.RightButton
- onTapped: (eventPoint)=> console.log("tapped", eventPoint.event.device.name,
- "button", eventPoint.event.button,
+ onTapped: (eventPoint, button)=> console.log("tapped", eventPoint.device.name,
+ "button", button,
"@", eventPoint.scenePosition)
}
}
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.
*/
/*!
diff --git a/src/quick/handlers/qquicktaphandler_p.h b/src/quick/handlers/qquicktaphandler_p.h
index d75547eee2..2e0c8e211f 100644
--- a/src/quick/handlers/qquicktaphandler_p.h
+++ b/src/quick/handlers/qquicktaphandler_p.h
@@ -97,9 +97,10 @@ Q_SIGNALS:
void timeHeldChanged();
void longPressThresholdChanged();
void gesturePolicyChanged();
- void tapped(QEventPoint eventPoint);
- void singleTapped(QEventPoint eventPoint);
- void doubleTapped(QEventPoint eventPoint);
+ // the second argument (Qt::MouseButton) was added in 6.2: avoid name clashes with IDs by not naming it for now
+ void tapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
+ void singleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
+ void doubleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
void longPressed();
protected:
diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
index 9b1101eb3a..67583fae30 100644
--- a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
@@ -739,8 +739,8 @@ void tst_TapHandler::rightLongPressIgnoreWheel()
QQuickTapHandler *tap = window->rootObject()->findChild<QQuickTapHandler*>();
QVERIFY(tap);
- QSignalSpy tappedSpy(tap, SIGNAL(tapped(QEventPoint *)));
- QSignalSpy longPressedSpy(tap, SIGNAL(longPressed()));
+ QSignalSpy tappedSpy(tap, &QQuickTapHandler::tapped);
+ QSignalSpy longPressedSpy(tap, &QQuickTapHandler::longPressed);
QPoint p1(100, 100);
// Mouse wheel with ScrollBegin phase (because as soon as two fingers are touching
diff --git a/tests/manual/pointer/tapHandler.qml b/tests/manual/pointer/tapHandler.qml
index 6e51fc6fda..c25ea9eb4e 100644
--- a/tests/manual/pointer/tapHandler.qml
+++ b/tests/manual/pointer/tapHandler.qml
@@ -53,14 +53,15 @@ Item {
borderBlink.blinkColor = "red"
borderBlink.start()
}
- onTapped: { // 'eventPoint' is a signal parameter of type QEventPoint*
- console.log("tapped button " + eventPoint.event.button + " @ " + eventPoint.scenePosition +
- " on device '" + eventPoint.event.device.name + "' " + (tapCount > 1 ? (tapCount + " times") : "for the first time"))
+ onTapped: function(point, button) {
+ console.log("tapped button " + button + " @ " + point.scenePosition +
+ " on device '" + point.device.name + "' with modifiers " + handler.point.modifiers +
+ " " + (tapCount > 1 ? (tapCount + " times") : "for the first time"))
if (tapCount > 1) {
tapCountLabel.text = tapCount
flashAnimation.start()
} else {
- borderBlink.tapFeedback(eventPoint.event.button)
+ borderBlink.tapFeedback(button)
}
}
onLongPressed: longPressFeedback.createObject(rect,