2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2015-07-28 13:24:29 +00:00
|
|
|
|
2021-09-06 19:40:18 +00:00
|
|
|
import QtQuick
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
import QtQuick.Layouts
|
2021-09-06 19:40:18 +00:00
|
|
|
import "components"
|
2015-07-28 13:24:29 +00:00
|
|
|
|
|
|
|
Item {
|
2023-03-07 12:21:35 +00:00
|
|
|
width: 1024
|
2021-09-06 19:40:18 +00:00
|
|
|
height: 480
|
2015-07-28 13:24:29 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: rect
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
anchors.fill: parent; anchors.margins: 40; anchors.topMargin: 60
|
2023-03-07 12:21:35 +00:00
|
|
|
border.width: 4; border.color: "transparent"
|
|
|
|
color: handler.pressed ? "lightsteelblue" : "aliceblue"
|
2015-07-28 13:24:29 +00:00
|
|
|
|
|
|
|
TapHandler {
|
|
|
|
id: handler
|
|
|
|
acceptedButtons: (leftAllowedCB.checked ? Qt.LeftButton : Qt.NoButton) |
|
|
|
|
(middleAllowedCB.checked ? Qt.MiddleButton : Qt.NoButton) |
|
|
|
|
(rightAllowedCB.checked ? Qt.RightButton : Qt.NoButton)
|
2023-03-07 12:21:35 +00:00
|
|
|
exclusiveSignals: (singleExclusiveCB.checked ? TapHandler.SingleTap : TapHandler.NotExclusive) |
|
|
|
|
(doubleExclusiveCB.checked ? TapHandler.DoubleTap : TapHandler.NotExclusive)
|
2016-10-18 16:45:49 +00:00
|
|
|
gesturePolicy: (policyDragThresholdCB.checked ? TapHandler.DragThreshold :
|
|
|
|
policyWithinBoundsCB.checked ? TapHandler.WithinBounds :
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
policyDragWithinBoundsCB.checked ? TapHandler.DragWithinBounds :
|
2016-10-18 16:45:49 +00:00
|
|
|
TapHandler.ReleaseWithinBounds)
|
2017-02-24 15:42:47 +00:00
|
|
|
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
onCanceled: function(point) {
|
2017-02-24 15:42:47 +00:00
|
|
|
console.log("canceled @ " + point.position)
|
2015-07-28 13:24:29 +00:00
|
|
|
borderBlink.blinkColor = "red"
|
|
|
|
borderBlink.start()
|
|
|
|
}
|
2023-03-07 12:21:35 +00:00
|
|
|
onSingleTapped: function(point, button) {
|
|
|
|
console.log("single-tapped button " + button + " @ " + point.scenePosition)
|
|
|
|
rect.border.width = 4
|
|
|
|
borderBlink.tapFeedback(button)
|
|
|
|
}
|
|
|
|
onDoubleTapped: function(point, button) {
|
|
|
|
console.log("double-tapped button " + button + " @ " + point.scenePosition)
|
|
|
|
rect.border.width = 12
|
|
|
|
borderBlink.tapFeedback(button)
|
|
|
|
}
|
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
Pick-to: 6.2 6.2.0
Change-Id: I6d25300cbfceb56f27452eac4b29b66bd1b2a41a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-09-07 14:54:44 +00:00
|
|
|
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"))
|
2015-07-28 13:24:29 +00:00
|
|
|
if (tapCount > 1) {
|
|
|
|
tapCountLabel.text = tapCount
|
|
|
|
flashAnimation.start()
|
|
|
|
}
|
|
|
|
}
|
2016-11-18 14:02:18 +00:00
|
|
|
onLongPressed: longPressFeedback.createObject(rect,
|
2017-02-24 15:42:47 +00:00
|
|
|
{"x": point.position.x, "y": point.position.y,
|
2021-09-06 19:40:18 +00:00
|
|
|
"text": "long press after\n" + handler.timeHeld.toFixed(3) + " sec",
|
2018-07-26 06:14:13 +00:00
|
|
|
"color": buttonToBlinkColor(point.pressedButtons)})
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: tapCountLabel
|
|
|
|
anchors.centerIn: parent
|
|
|
|
font.pixelSize: 72
|
|
|
|
font.weight: Font.Black
|
|
|
|
SequentialAnimation {
|
|
|
|
id: flashAnimation
|
|
|
|
PropertyAction { target: tapCountLabel; property: "visible"; value: true }
|
|
|
|
PropertyAction { target: tapCountLabel; property: "opacity"; value: 1.0 }
|
|
|
|
PropertyAction { target: tapCountLabel; property: "scale"; value: 1.0 }
|
|
|
|
ParallelAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
target: tapCountLabel
|
|
|
|
property: "opacity"
|
|
|
|
to: 0
|
|
|
|
duration: 500
|
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
target: tapCountLabel
|
|
|
|
property: "scale"
|
|
|
|
to: 1.5
|
|
|
|
duration: 500
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 10:45:48 +00:00
|
|
|
Rectangle {
|
|
|
|
id: expandingCircle
|
|
|
|
radius: handler.timeHeld * 100
|
2017-08-28 14:23:20 +00:00
|
|
|
visible: radius > 0 && handler.pressed
|
2015-08-05 10:45:48 +00:00
|
|
|
border.width: 3
|
2018-07-26 06:14:13 +00:00
|
|
|
border.color: buttonToBlinkColor(handler.point.pressedButtons)
|
2015-08-05 10:45:48 +00:00
|
|
|
color: "transparent"
|
|
|
|
width: radius * 2
|
|
|
|
height: radius * 2
|
2017-02-24 15:42:47 +00:00
|
|
|
x: handler.point.pressPosition.x - radius
|
|
|
|
y: handler.point.pressPosition.y - radius
|
2015-08-05 10:45:48 +00:00
|
|
|
opacity: 0.25
|
|
|
|
}
|
|
|
|
|
2016-11-18 14:02:18 +00:00
|
|
|
Component {
|
|
|
|
id: longPressFeedback
|
|
|
|
Text { }
|
|
|
|
}
|
|
|
|
|
2015-07-28 13:24:29 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
id: borderBlink
|
2018-07-26 06:14:13 +00:00
|
|
|
property color blinkColor: "red"
|
|
|
|
function tapFeedback(button) {
|
2023-03-07 12:21:35 +00:00
|
|
|
stop();
|
2018-07-26 06:14:13 +00:00
|
|
|
blinkColor = buttonToBlinkColor(button);
|
|
|
|
start();
|
|
|
|
}
|
2015-07-28 13:24:29 +00:00
|
|
|
ScriptAction { script: rect.border.color = borderBlink.blinkColor }
|
|
|
|
PauseAnimation { duration: 100 }
|
|
|
|
ScriptAction { script: rect.border.color = "transparent" }
|
|
|
|
PauseAnimation { duration: 100 }
|
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
|
|
|
|
Text {
|
|
|
|
text: "tap, click with different buttons, double-click, long press in this area"
|
|
|
|
anchors {
|
|
|
|
bottom: parent.bottom
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
margins: 6
|
|
|
|
}
|
|
|
|
}
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 06:14:13 +00:00
|
|
|
function buttonToBlinkColor(button) {
|
|
|
|
switch (button) {
|
|
|
|
case Qt.MiddleButton: return "orange";
|
|
|
|
case Qt.RightButton: return "magenta";
|
|
|
|
default: return "green";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
GridLayout {
|
|
|
|
columnSpacing: 6; rowSpacing: 6
|
2021-09-06 19:40:18 +00:00
|
|
|
Text {
|
|
|
|
text: "accepted mouse clicks:"
|
|
|
|
}
|
|
|
|
CheckBox {
|
2015-07-28 13:24:29 +00:00
|
|
|
id: leftAllowedCB
|
|
|
|
checked: true
|
2021-09-06 19:40:18 +00:00
|
|
|
text: "left"
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
CheckBox {
|
2015-07-28 13:24:29 +00:00
|
|
|
id: middleAllowedCB
|
2021-09-06 19:40:18 +00:00
|
|
|
text: "middle"
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
CheckBox {
|
2015-07-28 13:24:29 +00:00
|
|
|
id: rightAllowedCB
|
2021-09-06 19:40:18 +00:00
|
|
|
text: "right"
|
|
|
|
}
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
|
2023-03-07 12:21:35 +00:00
|
|
|
Text {
|
|
|
|
text: "exclusive signals:"
|
|
|
|
}
|
|
|
|
CheckBox {
|
|
|
|
id: singleExclusiveCB
|
|
|
|
text: "single"
|
|
|
|
}
|
|
|
|
CheckBox {
|
|
|
|
id: doubleExclusiveCB
|
|
|
|
text: "double"
|
|
|
|
}
|
|
|
|
|
2021-09-06 19:40:18 +00:00
|
|
|
Text {
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
text: "gesture policy:"
|
|
|
|
horizontalAlignment: Text.AlignRight
|
|
|
|
Layout.row: 1
|
|
|
|
Layout.fillWidth: true
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
CheckBox {
|
2016-10-18 16:45:49 +00:00
|
|
|
id: policyDragThresholdCB
|
|
|
|
text: "drag threshold"
|
|
|
|
onCheckedChanged: if (checked) {
|
|
|
|
policyWithinBoundsCB.checked = false;
|
|
|
|
policyReleaseWithinBoundsCB.checked = false;
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
policyDragWithinBoundsCB.checked = false;
|
2016-10-18 16:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
CheckBox {
|
2016-10-18 16:45:49 +00:00
|
|
|
id: policyWithinBoundsCB
|
|
|
|
text: "within bounds"
|
|
|
|
onCheckedChanged: if (checked) {
|
|
|
|
policyDragThresholdCB.checked = false;
|
|
|
|
policyReleaseWithinBoundsCB.checked = false;
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
policyDragWithinBoundsCB.checked = false;
|
2016-10-18 16:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-06 19:40:18 +00:00
|
|
|
CheckBox {
|
2016-10-18 16:45:49 +00:00
|
|
|
id: policyReleaseWithinBoundsCB
|
|
|
|
checked: true
|
|
|
|
text: "release within bounds"
|
|
|
|
onCheckedChanged: if (checked) {
|
|
|
|
policyDragThresholdCB.checked = false;
|
|
|
|
policyWithinBoundsCB.checked = false;
|
Add TapHandler.gesturePolicy: DragWithinBounds enum value; examples
On a touchscreen, right-clicking is not directly possible; so sometimes
a long-press gesture is used as a substitute. The next thing a UI
designer would want would then be a way of showing feedback that a
long-press is in progress, rather than simply waiting for the long-press
to occur and then surprising the user with some instant action.
For example, a menu might begin to open as the user holds down the
touchpoint; but before the long-press gesture is complete, the user can
simply release, to cancel the gesture and close the menu. The timeHeld
property could drive the animation, to avoid needing a separate
animation type; in fact the reason timeHeld exists is to make it easy
to emulate this sort of touch-press animation, like one that occurs on
touchscreens since Windows 7.
But after the menu is open, the user would probably expect to be able to
drag the finger to a menu item and release, to select the menu item. For
such a purpose, the existing gesture policies weren't very useful: each
of them resets the timeHeld property if the user drags beyond the drag
threshold; so if the user expects to drag and release over a menu item,
then the timeHeld property cannot drive the menu-opening animation,
because the menu would disappear as soon as the user drags a little.
So it makes more sense to have a gesturePolicy that acts like
WithinBounds, but also applies the same policy to the timeHeld property
and the longPressed signal. We don't care about the drag threshold:
if the user is holding down a finger, it's considered to be a
long-press-in-progress, regardless of how far it has moved since press
(as long as it stays within the parent's bounds).
An example of such a menu is added. The menu must have TapHandler as
its root object, because it reacts to press-and-drag within some larger
item, larger than the menu itself. For example such a menu could be
used in a canvas-like application (drawing, diagramming, dragging things
like photos or file icons, or something like that): dragging items on
the canvas is possible, but long-pressing anywhere will open a context
menu. But in this example so far, only the menu is implemented.
It's a pie menu, because those are particularly touch-friendly; but
perhaps for the mouse, a conventional context menu would be used.
[ChangeLog][QtQuick][Event Handlers] TapHandler now has one more
gesturePolicy value: DragWithinBounds; it is similar to WithinBounds,
except that timeHeld is not reset during dragging, and the longPressed
signal can be emitted regardless of the drag threshold. This is useful
for implementing press-drag-release components such as menus, while
using timeHeld to directly drive an "opening" animation.
Change-Id: I298f8b1ad8f8d7d3c241ef4fdd68e7ec8d8b5bdd
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-10-07 20:27:32 +00:00
|
|
|
policyDragWithinBoundsCB.checked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CheckBox {
|
|
|
|
id: policyDragWithinBoundsCB
|
|
|
|
text: "drag within bounds"
|
|
|
|
onCheckedChanged: if (checked) {
|
|
|
|
policyDragThresholdCB.checked = false;
|
|
|
|
policyWithinBoundsCB.checked = false;
|
|
|
|
policyReleaseWithinBoundsCB.checked = false;
|
2016-10-18 16:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 13:24:29 +00:00
|
|
|
}
|
|
|
|
}
|