-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathShortcuts.qml
More file actions
490 lines (436 loc) · 19.5 KB
/
Shortcuts.qml
File metadata and controls
490 lines (436 loc) · 19.5 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls 2.3
import QtQuick.Layouts
import org.deepin.dcc 1.0
import org.deepin.dtk 1.0 as D
import org.deepin.dtk.style 1.0 as DS
DccObject {
id: shortcutSettingsView
name: "shortcutSettingsView"
parentName: "keyboard"
displayName: qsTr("Shortcuts")
description: qsTr("System shortcut, custom shortcut")
icon: "keyboard_fn"
weight: parent.weight // 300
property int searchEditWidth: 600
property var viewScrollbar: ScrollBar {
width: 10
}
PropertyAnimation {
id: scrollbarAnimation
target: viewScrollbar
property: "opacity"
duration: 200
from: 0
to: 1
onFinished: viewScrollbar.increase()
}
page: DccSettingsView {
ScrollBar.vertical: viewScrollbar
}
Connections {
target: shortcutSettingsView
function onDeactive() {
shortcutSettingsBody.conflictAccels = ""
shortcutSettingsBody.isEditing = false
}
}
DccObject {
id: shortcutSettingsBody
property bool isEditing: false
property string conflictAccels
name: "shortcutSettingsBody"
parentName: "shortcutSettingsView"
weight: 30
pageType: DccObject.Item
signal requestRestore
page: ColumnLayout {
spacing: 10
Timer {
id: timer
interval: 100
onTriggered: {
shortcutView.model.setFilterFixedString(searchEdit.text);
}
}
D.SearchEdit {
id: searchEdit
Layout.topMargin: 10
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
placeholder: qsTr("Search shortcuts")
onTextChanged: {
timer.start()
}
onEditingFinished: {
timer.start()
}
Component.onCompleted: {
// clear
shortcutView.model.setFilterWildcard("");
shortcutSettingsView.searchEditWidth = Qt.binding(function() { return width; });
}
}
ListView {
id: shortcutView
property Item editItem
property Item conflictText
clip: true
interactive: false // 外层有滚动了,listview 就别滚了
implicitHeight: contentHeight
implicitWidth: 600
Layout.fillWidth: true
model: dccData.shortcutSearchModel()
section.property: "section"
section.criteria: ViewSection.FullString
section.delegate: RowLayout {
width: ListView.view.width
height: childrenRect.height
required property string section
Label {
text: parent.section
font.bold: true
font.pointSize: 13
leftPadding: 20
bottomPadding: 10
topPadding: 16
}
D.Button {
id: button
focusPolicy: Qt.NoFocus
visible: parent.section === qsTranslate("dccV25::ShortcutModel", "Custom")
checkable: true
checked: shortcutSettingsBody.isEditing
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
Layout.rightMargin: 10
text: shortcutSettingsBody.isEditing ? qsTr("done") : qsTr("edit")
font: D.DTK.fontManager.t8
background: null
textColor: D.Palette {
normal {
common: D.DTK.makeColor(D.Color.Highlight)
crystal: D.DTK.makeColor(D.Color.Highlight)
}
}
onCheckedChanged: {
shortcutSettingsBody.isEditing = button.checked
if (!shortcutView.editItem)
return
shortcutView.editItem.keys = shortcutView.editItem.keySequence
shortcutView.editItem.focus = false
shortcutView.conflictText.visible = false
shortcutView.editItem = null
shortcutView.conflictText = null
}
}
}
delegate: ItemDelegate {
id: editorDelegate
checkable: false
implicitWidth: ListView.view.width
topInset: 0
bottomInset: 0
backgroundVisible: true
Layout.fillWidth: true
corners: model.corners
background: DccItemBackground {
id: background
separatorVisible: true
backgroundType: DccObject.Normal
}
contentItem: ColumnLayout {
KeySequenceDisplay {
id: edit
text: model.display
keys: model.keySequence
placeholderText: qsTr("please enter a new shortcut key")
background.visible: conflictText.visible
backgroundColor: conflictText.visible ? DS.Style.edit.alertBackground : DS.Style.keySequenceEdit.background
Layout.alignment: Qt.AlignRight
Layout.bottomMargin: conflictText.visible ? 8 : 0
Layout.fillWidth: true
showEditButtons: shortcutSettingsBody.isEditing && model.isCustom
showWarnning: model.accels.length > 0 && shortcutSettingsBody.conflictAccels === model.accels
Connections{
target: model
function onKeySequenceChanged() {
edit.keys= model.keySequence
}
}
onRequestKeys: {
if (shortcutView.editItem) {
shortcutView.editItem.restore()
// return
}
edit.keys = ""
dccData.updateKey(model.id, model.type)
shortcutView.editItem = edit
shortcutView.conflictText = conflictText
shortcutSettingsBody.isEditing = false
}
onRequestEditKeys: {
dialogloader.active = true
}
onRequestDeleteKeys: {
console.log("onRequestDeleteKeys", model.id)
dccData.deleteCustomShortcut(model.id)
}
function modifyShortcut(accels) {
console.log("modifyShortcut", model.id, accels, model.type)
if (accels.length > 0)
dccData.modifyShortcut(model.id, accels, model.type)
}
function clearShortcut() {
dccData.clearShortcut(model.id, model.type)
focus = false
keys = dccData.formatKeys("")
conflictText.visible = false
shortcutSettingsBody.conflictAccels = ""
shortcutView.editItem = null
shortcutView.conflictText = null
}
function restore() {
edit.keys = model.keySequence
conflictText.visible = false
shortcutSettingsBody.conflictAccels = ""
shortcutView.editItem = null
shortcutView.conflictText = null
}
Loader {
id: dialogloader
active: false
sourceComponent: ShortcutSettingDialog {
onClosing: {
dialogloader.active = false
conflictText.visible = false
shortcutSettingsBody.conflictAccels = ""
shortcutView.editItem = null
shortcutView.conflictText = null
}
}
onLoaded: {
edit.restore()
item.keyId = model.id
item.keyName = model.display
item.cmdName = model.command
item.keySequence = model.keySequence
if (model.keySequence.length > 0) {
item.saveKeys = model.keySequence
}
item.accels = model.accels
item.saveAccels = item.accels
item.saveKeyName = item.keyName
item.saveCmdName = item.cmdName
item.show()
}
}
}
Item {
id: conflictText
visible: false
implicitHeight: 20
implicitWidth: row.implicitWidth
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 20
Layout.fillWidth: true
onVisibleChanged : {
if (visible && model.index === (shortcutView.count - 1)) {
scrollbarAnimation.start()
}
}
RowLayout {
id: row
width: parent.width
spacing: 3
Label {
id: conflictTextLabel
text: dccData.conflictText + ","
elide: Text.ElideLeft
Layout.fillWidth: true
horizontalAlignment: Text.AlignRight
HoverHandler { id: conflictHandler }
ToolTip.visible: conflictHandler.hovered
ToolTip.text: conflictTextLabel.text + clickLabel.text + " " + cancelLabel.text + " " + orLabel.text + " " + replaceLabel.text
ToolTip.delay: 500
ToolTip.timeout: 4000
}
Label {
id: clickLabel
text: qsTr("Click")
}
Label {
id: cancelLabel
text: qsTr("Cancel")
color: palette.highlight
MouseArea {
anchors.fill: parent
onClicked: {
edit.restore()
}
}
}
Label {
id: orLabel
text: qsTr("or")
}
Label {
id: replaceLabel
text: qsTr("Replace")
color: palette.highlight
MouseArea {
anchors.fill: parent
onClicked: {
edit.modifyShortcut(shortcutSettingsBody.conflictAccels)
shortcutSettingsBody.conflictAccels = ""
}
}
}
}
}
}
}
function restoreShortcutView() {
if (!shortcutView.editItem)
return
shortcutView.editItem.restore()
}
Connections {
target: shortcutSettingsBody
function onRequestRestore() {
shortcutView.restoreShortcutView()
}
}
Connections {
target: dccData
function onRequestRestore() {
shortcutView.restoreShortcutView()
}
function onRequestClear() {
shortcutView.editItem.clearShortcut()
}
function onKeyConflicted(oldAccels, newAccels) {
if (shortcutView.conflictText)
shortcutView.conflictText.visible = true
shortcutSettingsBody.conflictAccels = newAccels
}
function onKeyDone(accels) {
if (!shortcutView.editItem)
return
shortcutView.editItem.focus = false
shortcutView.editItem.keys = dccData.formatKeys(accels)
shortcutView.conflictText.visible = false
shortcutView.editItem.modifyShortcut(accels)
shortcutView.editItem = null
shortcutView.conflictText = null
}
function onKeyEvent(accels) {
if (!shortcutView.editItem)
return
shortcutView.editItem.focus = false
shortcutView.editItem.keys = dccData.formatKeys(accels)
}
}
}
}
}
DccObject {
id: bottomAreaFoot
name: "bottomAreaFoot"
parentName: "shortcutSettingsView"
weight: 40
pageType: DccObject.Item
property int restoreButtonWidth: DS.Style.button.width
DccObject {
name: "bottomAreaRestoreButton"
parentName: "bottomAreaFoot"
pageType: DccObject.Item
page: Button {
id: restoreButton
text: qsTr("Restore default")
implicitWidth: {
const totalPadding = leftPadding + rightPadding
const contentWidth = implicitContentWidth + totalPadding
const minWidth = DS.Style.button.width
const maxWidth = shortcutSettingsView.searchEditWidth / 2 - totalPadding
return Math.min(Math.max(contentWidth, minWidth), maxWidth)
}
Text {
id: restoreHiddenText
text: restoreButton.text
font: restoreButton.font
visible: false
}
ToolTip.visible: {
const contentWidth = restoreHiddenText.width + leftPadding + rightPadding
return width < contentWidth && hovered
}
ToolTip.text: text
onClicked: {
shortcutSettingsBody.isEditing = false
shortcutSettingsBody.requestRestore()
dccData.resetAllShortcuts()
}
Component.onCompleted: {
bottomAreaFoot.restoreButtonWidth = Qt.binding(function() { return implicitWidth; })
}
}
}
DccObject {
name: "bottomAreaSpacer"
parentName: "bottomAreaFoot"
pageType: DccObject.Item
page: Item {
Layout.fillWidth: true
}
}
DccObject {
name: "bottomAreaAddButton"
parentName: "bottomAreaFoot"
pageType: DccObject.Item
page: Button {
id: addButton
property bool needShowDialog: false
text: qsTr("Add custom shortcut")
implicitWidth: {
const totalPadding = leftPadding + rightPadding
const contentWidth = implicitContentWidth + totalPadding
const minWidth = DS.Style.button.width
const maxWidth = shortcutSettingsView.searchEditWidth - bottomAreaFoot.restoreButtonWidth - 2*totalPadding - DS.Style.control.spacing
return Math.min(Math.max(contentWidth, minWidth), maxWidth)
}
Text {
id: hiddenText
text: addButton.text
font: addButton.font
visible: false
}
ToolTip.visible: {
const contentWidth = hiddenText.width + leftPadding + rightPadding
return width < contentWidth && hovered
}
ToolTip.text: text
Loader {
id: loader
active: addButton.needShowDialog
sourceComponent: ShortcutSettingDialog {
id: shortcutSettingDialog
onClosing: {
addButton.needShowDialog = false
shortcutSettingsBody.conflictAccels = ""
}
}
onLoaded: {
item.show()
}
}
onClicked: {
shortcutSettingsBody.isEditing = false
shortcutSettingsBody.requestRestore()
addButton.needShowDialog = true
}
}
}
}
}