Debian Codegraph @

src/qml/Haruna/Components/SelectActionPopup.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 pragma ComponentBehavior: Bound
8
9 import QtQuick
10 import QtQuick.Controls
11 import QtQuick.Layouts
12
13 import org.kde.kirigami as Kirigami
14 import org.kde.kitemmodels as KItemModels
15
16 import org.kde.haruna
17
18 Kirigami.SearchDialog {
19 id: root
20
21 signal actionSelected(string actionName)
22
23 onActionSelected: function(actionName) {
24 close()
25 }
26
27 emptyText: i18nc("@info:placeholder", "No action found.")
28 model: KItemModels.KSortFilterProxyModel {
29 id: sortModel
30
31 sourceModel: ActionsModel {}
32 filterRoleName: "searchString"
33 filterCaseSensitivity: Qt.CaseInsensitive
34 sortRoleName: "actionText"
35 sortOrder: Qt.AscendingOrder
36 }
37
38 onTextChanged: {
39 sortModel.filterString = text
40 }
41
42 delegate: Loader {
43 id: actionDelegateLoader
44
45 required property int index
46 required property string actionName
47 required property string actionText
48 required property string actionShortcut
49 required property string actionDescription
50 required property string actionType
51
52 active: true
53 asynchronous: true
54 width: ListView.view.width
55 height: actionDescription === "" ? Kirigami.Units.gridUnit * 2 : Kirigami.Units.gridUnit * 3
56
57 Keys.forwardTo: [item]
58
59 sourceComponent: ItemDelegate {
60 id: actionDelegate
61
62 highlighted: actionDelegateLoader.ListView.view.currentIndex === actionDelegateLoader.index
63
64 onClicked: root.actionSelected(actionDelegateLoader.actionName)
65 Keys.onEnterPressed: root.actionSelected(actionDelegateLoader.actionName)
66 Keys.onReturnPressed: root.actionSelected(actionDelegateLoader.actionName)
67
68 contentItem: RowLayout {
69
70 ColumnLayout {
71 Layout.fillWidth: true
72
73 Label {
74 id: shortcutTextLabel
75
76 text: actionDelegateLoader.actionText
77 Layout.fillWidth: true
78 }
79 Label {
80 text: actionDelegateLoader.actionDescription
81 visible: text !== ""
82 opacity: 0.9
83 font.pointSize: shortcutTextLabel.font.pointSize - 1
84 }
85 }
86
87 Repeater {
88 model: actionDelegateLoader.actionShortcut.split("+")
89 delegate: Kirigami.Chip {
90 id: shortcutDelgate
91
92 required property string modelData
93
94 Layout.preferredWidth: actionShortcutLabel.width + Kirigami.Units.largeSpacing
95 Layout.preferredHeight: actionShortcutLabel.height + Kirigami.Units.largeSpacing
96
97 closable: false
98 checkable: false
99
100 Label {
101 id: actionShortcutLabel
102
103 text: shortcutDelgate.modelData
104 anchors.centerIn: parent
105 }
106 }
107 }
108 }
109 }
110 }
111 }