aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-07-26 08:14:13 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-07-27 13:24:32 +0000
commitb8fd580cb3453b3850c36765c4b2537538d2f4f8 (patch)
treeca1ae25bf2535a1405ee534ed1fa634ad77b1f13 /tests/manual
parentf2ba3bd9792500b4d3fcfd23b03098a32641ef4f (diff)
TapHandler: emit eventPoint from the tapped signals
Any JS callback using one of these signals probably needs to know which button was tapped. We do not want to require TapHandler.point.pressedButtons to tell a lie (temporarily hold the previous state even though a button was actually released). We could add a releasedButtons property, but it would be a bit weird to have it holding state indefinitely between events. We could add just a button parameter to these signals, which would not be so bad, but emitting the whole eventPoint opens up other possibilities, like doing filtering in JS based on the device. To be able to get the device property of the event in QML, it must not be a const pointer. Q_PROPERTY(const type* ...) is so far unprecedented in Qt Quick; and the device has only const properties anyway. This reverts 8dc02aab72a714b5195ccc641fbfb534c3ae9e98 Task-number: QTBUG-61749 Task-number: QTBUG-64847 Change-Id: I09067498b22cc86e9f68c5ff13d6aa5447faba3d Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/pointer/tapHandler.qml34
1 files changed, 21 insertions, 13 deletions
diff --git a/tests/manual/pointer/tapHandler.qml b/tests/manual/pointer/tapHandler.qml
index 08cf987293..8c1fac9a2f 100644
--- a/tests/manual/pointer/tapHandler.qml
+++ b/tests/manual/pointer/tapHandler.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the manual tests of the Qt Toolkit.
@@ -53,18 +53,20 @@ Item {
borderBlink.blinkColor = "red"
borderBlink.start()
}
- onTapped: { // 'point' is an implicit parameter referencing to a QQuickEventPoint instance
+ onTapped: { // 'eventPoint' is a signal parameter of type QQuickEventPoint*
+ console.log("tapped button " + eventPoint.event.button + " @ " + eventPoint.scenePosition +
+ " on device '" + eventPoint.event.device.name + "' " + (tapCount > 1 ? (tapCount + " times") : "for the first time"))
if (tapCount > 1) {
tapCountLabel.text = tapCount
flashAnimation.start()
} else {
- borderBlink.start()
+ borderBlink.tapFeedback(eventPoint.event.button)
}
}
onLongPressed: longPressFeedback.createObject(rect,
{"x": point.position.x, "y": point.position.y,
- "text": Math.round(handler.timeHeld).toFixed(3) + " sec",
- "color": borderBlink.blinkColor})
+ "text": handler.timeHeld.toFixed(3) + " sec",
+ "color": buttonToBlinkColor(point.pressedButtons)})
}
Text {
@@ -99,7 +101,7 @@ Item {
radius: handler.timeHeld * 100
visible: radius > 0 && handler.pressed
border.width: 3
- border.color: borderBlink.blinkColor
+ border.color: buttonToBlinkColor(handler.point.pressedButtons)
color: "transparent"
width: radius * 2
height: radius * 2
@@ -115,13 +117,11 @@ Item {
SequentialAnimation {
id: borderBlink
- property color blinkColor: (function(pbtns) {
- switch (pbtns) {
- case Qt.MiddleButton: return "orange";
- case Qt.RightButton: return "magenta";
- default: return "green";
- }
- })(handler.point.pressedButtons)
+ property color blinkColor: "red"
+ function tapFeedback(button) {
+ blinkColor = buttonToBlinkColor(button);
+ start();
+ }
loops: 3
ScriptAction { script: rect.border.color = borderBlink.blinkColor }
PauseAnimation { duration: 100 }
@@ -130,6 +130,14 @@ Item {
}
}
+ function buttonToBlinkColor(button) {
+ switch (button) {
+ case Qt.MiddleButton: return "orange";
+ case Qt.RightButton: return "magenta";
+ default: return "green";
+ }
+ }
+
Row {
spacing: 6
Text { text: "accepted mouse clicks:"; anchors.verticalCenter: leftAllowedCB.verticalCenter }