Skip to content

Commit 4c6d0b2

Browse files
committed
doc: Customize and update docs for PointHandler
Many of the inherited docs were inappropriate or insufficiently specific to PointHandler. Now we have more snippets with more ideas for how it can be used. As a drive-by, fix a typo in the docs for PointerDeviceHandler::acceptedPointerTypes and add a link to the new PointerDevice page added in e283c05 Pick-to: 6.2 6.4 6.5 6.5.0 Fixes: QTBUG-74020 Fixes: QTBUG-106878 Change-Id: I028e1577ac5d4ef0b927c94259d6ab25b6028885 Reviewed-by: Doris Verria <doris.verria@qt.io>
1 parent f0f274e commit 4c6d0b2

File tree

7 files changed

+275
-5
lines changed

7 files changed

+275
-5
lines changed

src/quick/doc/snippets/pointerHandlers/pointHandler.qml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (C) 2017 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
33
//![0]
4-
import QtQuick 2.12
5-
import QtQuick.Window 2.2
4+
import QtQuick
65

76
Window {
87
width: 480
@@ -14,6 +13,7 @@ Window {
1413
z: 10000
1514
anchors.fill: parent
1615

16+
//![1]
1717
PointHandler {
1818
id: handler
1919
acceptedDevices: PointerDevice.TouchScreen | PointerDevice.TouchPad
@@ -26,6 +26,7 @@ Window {
2626
width: 20; height: width; radius: width / 2
2727
}
2828
}
29+
//![1]
2930
}
3031
}
3132
//![0]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2023 Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3+
//![0]
4+
import QtQuick
5+
6+
Item {
7+
width: 480; height: 320
8+
9+
Rectangle {
10+
color: handler.active ? "tomato" : "wheat"
11+
x: handler.point.position.x - width / 2
12+
y: handler.point.position.y - height / 2
13+
width: 20; height: width; radius: width / 2
14+
}
15+
16+
PointHandler {
17+
id: handler
18+
acceptedButtons: Qt.MiddleButton | Qt.RightButton
19+
}
20+
}
21+
//![0]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2023 Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3+
//![0]
4+
import QtQuick
5+
6+
Item {
7+
id: feedbackPane
8+
width: 480; height: 320
9+
10+
PointHandler {
11+
id: control
12+
acceptedModifiers: Qt.ControlModifier
13+
cursorShape: Qt.PointingHandCursor
14+
target: Rectangle {
15+
parent: feedbackPane
16+
color: control.active ? "indianred" : "khaki"
17+
x: control.point.position.x - width / 2
18+
y: control.point.position.y - height / 2
19+
width: 20; height: width; radius: width / 2
20+
}
21+
}
22+
23+
PointHandler {
24+
id: shift
25+
acceptedModifiers: Qt.ShiftModifier | Qt.MetaModifier
26+
cursorShape: Qt.CrossCursor
27+
target: Rectangle {
28+
parent: feedbackPane
29+
color: shift.active ? "darkslateblue" : "lightseagreen"
30+
x: shift.point.position.x - width / 2
31+
y: shift.point.position.y - height / 2
32+
width: 30; height: width; radius: width / 2
33+
}
34+
}
35+
}
36+
//![0]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2023 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3+
4+
//![0]
5+
import QtQuick
6+
7+
Canvas {
8+
id: canvas
9+
width: 800
10+
height: 600
11+
antialiasing: true
12+
renderTarget: Canvas.FramebufferObject
13+
property var points: []
14+
onPaint: {
15+
if (points.length < 2)
16+
return
17+
var ctx = canvas.getContext('2d');
18+
ctx.save()
19+
ctx.strokeStyle = stylusHandler.active ? "blue" : "white"
20+
ctx.lineCap = "round"
21+
ctx.beginPath()
22+
ctx.moveTo(points[0].x, points[0].y)
23+
for (var i = 1; i < points.length; i++)
24+
ctx.lineTo(points[i].x, points[i].y)
25+
ctx.lineWidth = 3
26+
ctx.stroke()
27+
points = points.slice(points.length - 2, 1)
28+
ctx.restore()
29+
}
30+
31+
PointHandler {
32+
id: stylusHandler
33+
acceptedPointerTypes: PointerDevice.Pen
34+
onPointChanged: {
35+
canvas.points.push(point.position)
36+
canvas.requestPaint()
37+
}
38+
}
39+
40+
PointHandler {
41+
id: eraserHandler
42+
acceptedPointerTypes: PointerDevice.Eraser
43+
onPointChanged: {
44+
canvas.points.push(point.position)
45+
canvas.requestPaint()
46+
}
47+
}
48+
49+
Rectangle {
50+
width: 10; height: 10
51+
color: stylusHandler.active ? "green" : eraserHandler.active ? "red" : "beige"
52+
}
53+
}
54+
//![0]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2023 Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3+
//![0]
4+
import QtQuick
5+
6+
Item {
7+
width: 480; height: 320
8+
9+
Rectangle {
10+
anchors.fill: handlingContainer
11+
anchors.margins: -handler.margin
12+
color: "beige"
13+
}
14+
15+
Rectangle {
16+
id: handlingContainer
17+
width: 200; height: 200
18+
anchors.centerIn: parent
19+
border.color: "green"
20+
color: handler.active ? "lightsteelblue" : "khaki"
21+
22+
Text {
23+
text: "X"
24+
x: handler.point.position.x - width / 2
25+
y: handler.point.position.y - height / 2
26+
visible: handler.active
27+
}
28+
29+
PointHandler {
30+
id: handler
31+
margin: 30
32+
}
33+
}
34+
35+
}
36+
//![0]

src/quick/handlers/qquickpointerdevicehandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void QQuickPointerDeviceHandler::setAcceptedDevices(QPointingDevice::DeviceTypes
139139
By default, this property is set to
140140
\l {QPointingDevice::PointerType} {PointerDevice.AllPointerTypes}.
141141
If you set it to an OR combination of device types, it will ignore events
142-
from non-matching events.
142+
from non-matching \l {PointerDevice}{devices}.
143143
144144
For example, a control could be made to respond to mouse, touch, and stylus clicks
145145
in some way, but delete itself if tapped with an eraser tool on a graphics tablet,

src/quick/handlers/qquickpointhandler.cpp

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ QT_BEGIN_NAMESPACE
6666
PointHandler will not automatically manipulate the \c target item in any way.
6767
You need to use bindings to make it react to the \l point.
6868
69-
\note On macOS, PointHandler does not react to the trackpad by default.
69+
\note On macOS, PointHandler does not react to multiple fingers on the
70+
trackpad by default, although it does react to a pressed point (mouse position).
7071
That is because macOS can provide either native gesture recognition, or raw
7172
touchpoints, but not both. We prefer to use the native gesture event in
7273
PinchHandler, so we do not want to disable it by enabling touch. However
@@ -75,7 +76,7 @@ QT_BEGIN_NAMESPACE
7576
want to react to all the touchpoints but do not require the smooth
7677
native-gesture experience.
7778
78-
\sa MultiPointTouchArea, {Pointer Handlers Example}
79+
\sa MultiPointTouchArea, HoverHandler, {Pointer Handlers Example}
7980
*/
8081

8182
QQuickPointHandler::QQuickPointHandler(QQuickItem *parent)
@@ -128,6 +129,127 @@ QVector2D QQuickPointHandler::translation() const
128129
return QVector2D(point().position() - point().pressPosition());
129130
}
130131

132+
/*!
133+
\qmlproperty flags PointHandler::acceptedButtons
134+
135+
The mouse buttons that can activate this PointHandler.
136+
137+
By default, this property is set to \l {QtQuick::MouseEvent::button} {Qt.LeftButton}.
138+
It can be set to an OR combination of mouse buttons, and will ignore events
139+
in which other buttons are pressed or held.
140+
141+
\snippet pointerHandlers/pointHandlerAcceptedButtons.qml 0
142+
143+
\note On a touchscreen, there are no buttons, so this property does not
144+
prevent PointHandler from reacting to touchpoints.
145+
*/
146+
147+
/*!
148+
\qmlproperty flags PointHandler::acceptedDevices
149+
150+
The types of pointing devices that can activate this PointHandler.
151+
152+
By default, this property is set to
153+
\l{QInputDevice::DeviceType}{PointerDevice.AllDevices}.
154+
If you set it to an OR combination of device types, it will ignore events
155+
from non-matching \l {PointerDevice}{devices}:
156+
157+
\snippet pointerHandlers/pointHandler.qml 1
158+
*/
159+
160+
/*!
161+
\qmlproperty flags PointHandler::acceptedPointerTypes
162+
163+
The types of pointing instruments (finger, stylus, eraser, etc.)
164+
that can activate this PointHandler.
165+
166+
By default, this property is set to
167+
\l {QPointingDevice::PointerType} {PointerDevice.AllPointerTypes}.
168+
If you set it to an OR combination of device types, it will ignore events
169+
from non-matching \l {PointerDevice}{devices}:
170+
171+
\snippet pointerHandlers/pointHandlerCanvasDrawing.qml 0
172+
173+
The \l {Pointer Handlers Example} includes a more complex example for
174+
drawing on a Canvas with a graphics tablet.
175+
*/
176+
177+
/*!
178+
\qmlproperty flags PointHandler::acceptedModifiers
179+
180+
If this property is set, PointHandler requires the given keyboard modifiers
181+
to be pressed in order to react to \l {PointerEvent}{PointerEvents}, and
182+
otherwise ignores them.
183+
184+
If this property is set to \c Qt.KeyboardModifierMask (the default value),
185+
then PointHandler ignores the modifier keys.
186+
187+
For example, an \l [QML] Item could have two handlers, one of which is
188+
enabled only if the required keyboard modifier is pressed:
189+
190+
\snippet pointerHandlers/pointHandlerAcceptedModifiers.qml 0
191+
192+
If you set \c acceptedModifiers to an OR combination of modifier keys,
193+
it means \e all of those modifiers must be pressed to activate the handler.
194+
195+
The available modifiers are as follows:
196+
197+
\value NoModifier No modifier key is allowed.
198+
\value ShiftModifier A Shift key on the keyboard must be pressed.
199+
\value ControlModifier A Ctrl key on the keyboard must be pressed.
200+
\value AltModifier An Alt key on the keyboard must be pressed.
201+
\value MetaModifier A Meta key on the keyboard must be pressed.
202+
\value KeypadModifier A keypad button must be pressed.
203+
\value GroupSwitchModifier X11 only (unless activated on Windows by a command line argument).
204+
A Mode_switch key on the keyboard must be pressed.
205+
\value KeyboardModifierMask The handler does not care which modifiers are pressed.
206+
207+
\sa Qt::KeyboardModifier
208+
*/
209+
210+
/*!
211+
\readonly
212+
\qmlproperty bool PointHandler::active
213+
214+
This holds \c true whenever the constraints are satisfied and this
215+
PointHandler is reacting. This means that it is keeping its properties
216+
up-to-date according to the movements of the \l {eventPoint}{eventPoints}
217+
that satisfy the constraints.
218+
*/
219+
220+
/*!
221+
\internal
222+
\qmlproperty flags PointHandler::dragThreshold
223+
224+
This property is not used in PointHandler.
225+
*/
226+
227+
/*!
228+
\qmlproperty real PointHandler::margin
229+
230+
The margin beyond the bounds of the \l {PointerHandler::parent}{parent}
231+
item within which an \l eventPoint can activate this handler.
232+
233+
The default value is \c 0.
234+
235+
\snippet pointerHandlers/pointHandlerMargin.qml 0
236+
*/
237+
238+
/*!
239+
\qmlproperty real PointHandler::target
240+
241+
A property that can conveniently hold an Item to be manipulated or to show
242+
feedback. Unlike other \l {Qt Quick Input Handlers}{Pointer Handlers},
243+
PointHandler does not do anything with the \c target on its own: you
244+
usually need to create reactive bindings to properties such as
245+
\l SinglePointHandler::point and \l PointHandler::active. If you declare
246+
an Item instance here, you need to explicitly set its \l {Item::}{parent},
247+
because PointHandler is not an Item.
248+
249+
By default, it is the same as the \l {PointerHandler::}{parent}, the Item
250+
within which the handler is declared.
251+
*/
252+
131253
QT_END_NAMESPACE
132254

133255
#include "moc_qquickpointhandler_p.cpp"

0 commit comments

Comments
 (0)