Repository navigation
Expand file tree
/
Copy pathRowMenu.qml
More file actions
134 lines (124 loc) · 4.25 KB
/
Copy pathRowMenu.qml
File metadata and controls
134 lines (124 loc) · 4.25 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC
import "../design"
import "../design/controls"
// The actions a provider offers on one of its sidebar rows — the row's
// `menu` (docs/providers.md) — opened at the pointer by a right-click.
// Choosing an item only reports it: what the item does is the host's to run.
// An item the provider marks `enabled: false` is dimmed and cannot be chosen.
QQC.Menu {
id: menu
palette: ControlPalette {}
// The row the menu was opened on; its `menu` is what the menu lists.
property var row: null
property color accent: Color.accent
property string fontFamily: Style.font.menuFamily
readonly property var items: menu.row ? menu.row.menu || [] : []
readonly property ChromePopupStyle popupStyle: ChromePopupStyle {}
readonly property real iconColumnWidth: menu.items.some(function(item) {
return !!item.icon
}) ? Style.font.icon : 0
signal chosen(var row, var item)
function openFor(row) {
menu.row = row
menu.popup()
}
// The item chosen, reported once the menu has closed: closing hands the
// keyboard back, and what an item opens next — a dialog asking for a name
// — must take it after that, not before.
property var picked: null
onClosed: {
var item = menu.picked
menu.picked = null
if (item) {
menu.chosen(menu.row, item)
}
}
objectName: "rowMenu"
popupType: QQC.Popup.Item
margins: Style.spacing.xxs
implicitWidth: {
var widest = 0
for (var i = 0; i < count; i++) {
var entry = itemAt(i)
if (entry) {
widest = Math.max(widest, entry.implicitWidth)
}
}
return Math.ceil(widest) + leftPadding + rightPadding
}
implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
leftPadding: Border.width(popupStyle.borderSpec) + popupStyle.padding
rightPadding: leftPadding
topPadding: leftPadding
bottomPadding: leftPadding
background: BorderSurface {
color: menu.popupStyle.fill
borderSpec: menu.popupStyle.borderSpec
radius: menu.popupStyle.radius
}
contentItem: ListView {
implicitHeight: contentHeight
model: menu.contentModel
currentIndex: menu.currentIndex
spacing: 0
clip: true
boundsBehavior: Flickable.StopAtBounds
}
Instantiator {
model: menu.items
delegate: QQC.MenuItem {
id: entry
required property var modelData
objectName: "rowMenu-" + entry.modelData.id
text: entry.modelData.title
enabled: entry.modelData.enabled !== false
hoverEnabled: true
implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
implicitHeight: Math.max(menu.popupStyle.rowHeight, contentItem.implicitHeight + topPadding + bottomPadding)
topPadding: menu.popupStyle.verticalPadding
bottomPadding: topPadding
leftPadding: menu.popupStyle.horizontalPadding
rightPadding: menu.popupStyle.horizontalPadding
font.family: menu.fontFamily
font.pixelSize: Style.font.body
contentItem: RowLayout {
spacing: Style.spacing.controlGap
opacity: entry.enabled ? 1 : 0.45
Text {
visible: menu.iconColumnWidth > 0
Layout.preferredWidth: menu.iconColumnWidth
Layout.alignment: Qt.AlignVCenter
text: entry.modelData.icon || ""
textFormat: Text.PlainText
horizontalAlignment: Text.AlignHCenter
color: entryLabel.color
font.family: Style.font.family
font.pixelSize: Style.font.icon
}
Text {
id: entryLabel
Layout.fillWidth: true
text: entry.text
textFormat: Text.PlainText
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
font: entry.font
color: entry.highlighted ? Style.hoverStateColor(menu.popupStyle.text, menu.accent) : menu.popupStyle.text
}
}
background: Rectangle {
radius: menu.popupStyle.rowRadius
color: entry.highlighted ? Style.hoverFillFor(menu.popupStyle.text, menu.accent) : "transparent"
}
onTriggered: menu.picked = entry.modelData
}
onObjectAdded: function(index, object) {
menu.insertItem(index, object)
}
onObjectRemoved: function(index, object) {
menu.removeItem(object)
}
}
}