blob: 5f60ef879e309494555edac2ae5e5e7a8ef42534 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
Item {
width: 480
height: 480
property alias feedbackText: feedback.text
Rectangle {
id: rect
anchors.fill: parent; anchors.margins: 40
color: tapHandler.active ? "lightgrey" : "darkgrey"
TapHandler {
id: tapHandler
gesturePolicy: TapHandler.DragWithinBounds
onPressedChanged: if (pressed) {
menu.x = point.position.x - menu.width / 2
menu.y = point.position.y - menu.height / 2
} else {
if (menu.highlightedMenuItem !== "")
feedback.text = menu.highlightedMenuItem
}
onCanceled: feedback.text = "canceled"
}
Column {
id: menu
visible: tapHandler.pressed
opacity: Math.min(1, tapHandler.timeHeld)
property string highlightedMenuItem: ""
Repeater {
model: [ "top", "middle", "bottom" ]
delegate: Rectangle {
property bool highlighted: tapHandler.pressed &&
contains(mapFromItem(rect, tapHandler.point.position))
onHighlightedChanged: {
if (highlighted)
menu.highlightedMenuItem = menuItemText.text
else if (menu.highlightedMenuItem === menuItemText.text)
menu.highlightedMenuItem = ""
}
width: 100
height: 20
color: highlighted ? "lightsteelblue" : "aliceblue"
Text {
id: menuItemText
anchors.centerIn: parent
text: modelData
}
}
}
}
Text {
id: feedback
x: 6; y: 6
textFormat: Text.MarkdownText
text: "hold for context menu"
}
}
}
|