blob: e6d2266408372acd4c676f90ec5b7e1fd24a771c (
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
65
66
67
68
69
70
71
72
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//![0]
import QtQuick
Rectangle {
id: rect
width: 140; height: 100
//![1]
TapHandler {
id: menuPopupHandler
gesturePolicy: TapHandler.DragWithinBounds
onPressedChanged:
if (pressed) {
menu.x = point.position.x - menu.width / 2
menu.y = point.position.y - menu.height / 2
} else {
feedback.text = menu.highlightedMenuItem
selectFlash.start()
}
onCanceled: feedback.text = "canceled"
}
//![1]
Column {
id: menu
visible: menuPopupHandler.pressed
opacity: Math.min(1, menuPopupHandler.timeHeld)
property string highlightedMenuItem: ""
Repeater {
model: [ "top", "middle", "bottom" ]
delegate: Rectangle {
property bool highlighted: menuPopupHandler.pressed &&
contains(mapFromItem(rect, menuPopupHandler.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
y: 6; anchors.horizontalCenter: parent.horizontalCenter
textFormat: Text.MarkdownText
text: "hold for context menu"
SequentialAnimation on font.weight {
id: selectFlash
running: false
loops: 3
PropertyAction { value: Font.Black }
PauseAnimation { duration: 100 }
PropertyAction { value: Font.Normal }
PauseAnimation { duration: 100 }
}
}
}
//![0]
|