aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/snippets/pointerHandlers/tapHandlerGrabChanged.qml
blob: 73631d35511d0ab3d74f8fbd260215545172d69c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick

Rectangle {
    width: 100
    height: 100

    //![0]
    TapHandler {
        gesturePolicy: TapHandler.ReleaseWithinBounds // exclusive grab on press
        onGrabChanged:
            (transition, eventPoint) => {
                switch (transition) {
                    case PointerDevice.GrabExclusive:
                        console.log("took exclusive grab of point", eventPoint.id,
                                    "on", eventPoint.device.name)
                        break
                    case PointerDevice.UngrabExclusive:
                        console.log("gave up exclusive grab of point", eventPoint.id,
                                    "on", eventPoint.device.name)
                        break
                    case PointerDevice.CancelGrabExclusive:
                        console.log("exclusive grab of point", eventPoint.id,
                                    "on", eventPoint.device.name, "has been cancelled")
                        break
                }

                switch (eventPoint.state) {
                    case EventPoint.Pressed:
                        console.log("on press @", eventPoint.position);
                        break
                    case EventPoint.Updated:
                        console.log("on update @", eventPoint.position);
                        break
                    case EventPoint.Released:
                        console.log("on release @", eventPoint.position);
                        break
                    default:
                        console.log(eventPoint.position, "state", eventPoint.state)
                        break
                }
            }
    }
    //![0]
}