Debian Codegraph @

app/qml/Settings/SettingsShortcutsSection.qml

raw
1 /*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Florian Boucault <[email protected]>
17 */
18
19 import QtQuick 2.4
20 import QtQuick.Layouts 1.3
21 import QtQml.Models 2.2
22 import Lomiri.Components 1.3
23
24 SettingsSection {
25 id: section
26 margins: units.gu(4)
27
28 ColumnLayout {
29 anchors {
30 right: parent.right
31 left: parent.left
32 top: parent.top
33 margins: section.margins
34 }
35 height: Math.min(parent.height - section.margins * 2, units.gu(60))
36 spacing: units.gu(2)
37
38 RowLayout {
39 Layout.fillWidth: true
40 Layout.preferredHeight: searchField.height
41 spacing: units.gu(2)
42
43 TextFieldStyled {
44 id: searchField
45 primaryItem: Icon {
46 height: parent.height / 2
47 width: height
48 name: "find"
49 asynchronous: true
50 color: theme.palette.normal.baseText
51 }
52 }
53
54 Label {
55 Layout.fillWidth: true
56 verticalAlignment: Text.AlignVCenter
57 text: i18n.tr("Showing %1 of %2").arg(shortcutsList.count)
58 .arg(allShortcutsModel.count)
59 elide: Text.ElideRight
60 color: theme.palette.normal.base
61 visible: searchField.text
62 }
63 }
64
65 ListView {
66 id: shortcutsList
67 Layout.fillHeight: true
68 Layout.fillWidth: true
69
70 Rectangle {
71 anchors.fill: parent
72 radius: units.dp(3)
73 border.color: theme.palette.normal.base
74 border.width: units.dp(1)
75 color: "transparent"
76 }
77 clip: true
78
79 Scrollbar {
80 flickableItem: shortcutsList
81 align: Qt.AlignTrailing
82 }
83
84 focus: true
85 section {
86 property: "section"
87 delegate: Item {
88 width: parent.width
89 implicitHeight: units.gu(4)
90 Label {
91 anchors {
92 fill: parent
93 leftMargin: units.gu(2)
94 }
95 verticalAlignment: Text.AlignVCenter
96 text: i18n.tr(section)
97 elide: Text.ElideRight
98 }
99 Rectangle {
100 anchors {
101 left: parent.left
102 right: parent.right
103 bottom: parent.bottom
104 }
105 height: units.dp(1)
106 color: theme.palette.normal.base
107 }
108 }
109 }
110
111 model: DelegateModel {
112 filterOnGroup: filteringGroup.criteria ? "filtered" : ""
113 groups: [
114 DelegateModelGroup {
115 id: filteringGroup
116 includeByDefault: true
117 name: "filtered"
118 property string criteria: searchField.text
119 onCriteriaChanged: update()
120
121 function update() {
122 if (count != 0) {
123 remove(0, count);
124 }
125 for ( var i=0; i<allShortcutsModel.count; i++ ) {
126 var item = allShortcutsModel.get(i);
127 var label = i18n.tr(item.actionLabel).toLowerCase();
128 if(label.indexOf(criteria.toLowerCase()) !== -1) {
129 insert(item);
130 }
131 }
132 }
133 }
134 ]
135
136 model: ListModel {
137 id: allShortcutsModel
138 ListElement {
139 section: QT_TR_NOOP("File")
140 actionLabel: QT_TR_NOOP("New window")
141 shortcutSetting: "shortcutNewWindow"
142 }
143 ListElement {
144 section: QT_TR_NOOP("File")
145 actionLabel: QT_TR_NOOP("New tab")
146 shortcutSetting: "shortcutNewTab"
147 }
148 ListElement {
149 section: QT_TR_NOOP("File")
150 actionLabel: QT_TR_NOOP("Close terminal")
151 shortcutSetting: "shortcutCloseTab"
152 }
153 ListElement {
154 section: QT_TR_NOOP("File")
155 actionLabel: QT_TR_NOOP("Close all terminals")
156 shortcutSetting: "shortcutCloseAllTabs"
157 }
158 ListElement {
159 section: QT_TR_NOOP("File")
160 actionLabel: QT_TR_NOOP("Previous tab")
161 shortcutSetting: "shortcutPreviousTab"
162 }
163 ListElement {
164 section: QT_TR_NOOP("File")
165 actionLabel: QT_TR_NOOP("Next tab")
166 shortcutSetting: "shortcutNextTab"
167 }
168 ListElement {
169 section: QT_TR_NOOP("File")
170 actionLabel: QT_TR_NOOP("Previous active tab")
171 shortcutSetting: "shortcutPreviousActiveTab"
172 }
173 ListElement {
174 section: QT_TR_NOOP("Edit")
175 actionLabel: QT_TR_NOOP("Copy")
176 shortcutSetting: "shortcutCopy"
177 }
178 ListElement {
179 section: QT_TR_NOOP("Edit")
180 actionLabel: QT_TR_NOOP("Paste")
181 shortcutSetting: "shortcutPaste"
182 }
183 ListElement {
184 section: QT_TR_NOOP("View")
185 actionLabel: QT_TR_NOOP("Toggle fullscreen")
186 shortcutSetting: "shortcutFullscreen"
187 }
188 ListElement {
189 section: QT_TR_NOOP("View")
190 actionLabel: QT_TR_NOOP("Split terminal horizontally")
191 shortcutSetting: "shortcutSplitHorizontally"
192 }
193 ListElement {
194 section: QT_TR_NOOP("View")
195 actionLabel: QT_TR_NOOP("Split terminal vertically")
196 shortcutSetting: "shortcutSplitVertically"
197 }
198 ListElement {
199 section: QT_TR_NOOP("View")
200 actionLabel: QT_TR_NOOP("Navigate to terminal above")
201 shortcutSetting: "shortcutMoveToTileAbove"
202 }
203 ListElement {
204 section: QT_TR_NOOP("View")
205 actionLabel: QT_TR_NOOP("Navigate to terminal below")
206 shortcutSetting: "shortcutMoveToTileBelow"
207 }
208 ListElement {
209 section: QT_TR_NOOP("View")
210 actionLabel: QT_TR_NOOP("Navigate to terminal on the left")
211 shortcutSetting: "shortcutMoveToTileLeft"
212 }
213 ListElement {
214 section: QT_TR_NOOP("View")
215 actionLabel: QT_TR_NOOP("Navigate to terminal on the right")
216 shortcutSetting: "shortcutMoveToTileRight"
217 }
218 ListElement {
219 section: QT_TR_NOOP("View")
220 actionLabel: QT_TR_NOOP("Resize the terminal down")
221 shortcutSetting: "shortcutTileResizeDown"
222 }
223 ListElement {
224 section: QT_TR_NOOP("View")
225 actionLabel: QT_TR_NOOP("Resize the terminal up")
226 shortcutSetting: "shortcutTileResizeUp"
227 }
228 ListElement {
229 section: QT_TR_NOOP("View")
230 actionLabel: QT_TR_NOOP("Resize the terminal left")
231 shortcutSetting: "shortcutTileResizeLeft"
232 }
233 ListElement {
234 section: QT_TR_NOOP("View")
235 actionLabel: QT_TR_NOOP("Resize the terminal right")
236 shortcutSetting: "shortcutTileResizeRight"
237 }
238 }
239
240 delegate: ShortcutRow {
241 width: parent.width
242 actionLabel: i18n.tr(model.actionLabel)
243 shortcutSetting: model.shortcutSetting
244 index: filteringGroup.criteria ? DelegateModel.filteredIndex : model.index
245
246 Rectangle {
247 id: sectionBottomLine
248 anchors {
249 left: parent.left
250 right: parent.right
251 bottom: parent.bottom
252 }
253 height: units.dp(1)
254 color: theme.palette.normal.base
255 visible: index == shortcutsList.count-1 || parent.ListView.nextSection
256 && parent.ListView.nextSection != parent.ListView.section
257 }
258 }
259 }
260 }
261 }
262 }