| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2022 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 QtQml |
| 10 |
import QtQuick |
| 11 |
import QtQuick.Layouts |
| 12 |
import QtQuick.Controls |
| 13 |
import QtQuick.Dialogs |
| 14 |
|
| 15 |
import org.kde.kirigami as Kirigami |
| 16 |
import org.kde.kquickcontrols |
| 17 |
import org.kde.haruna |
| 18 |
|
| 19 |
SettingsBasePage { |
| 20 |
id: root |
| 21 |
|
| 22 |
required property ProxyActionsModel m_proxyActionsModel |
| 23 |
|
| 24 |
onVisibleChanged: { |
| 25 |
if (!visible) { |
| 26 |
root.m_proxyActionsModel.setNameFilter("") |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
header: ToolBar { |
| 31 |
width: parent.width |
| 32 |
|
| 33 |
RowLayout { |
| 34 |
anchors.fill: parent |
| 35 |
|
| 36 |
Kirigami.SearchField { |
| 37 |
id: searchField |
| 38 |
|
| 39 |
focus: true |
| 40 |
onAccepted: root.m_proxyActionsModel.setNameFilter(text) |
| 41 |
Layout.fillWidth: true |
| 42 |
KeyNavigation.up: actionsListView |
| 43 |
KeyNavigation.down: actionsListView |
| 44 |
Component.onCompleted: forceActiveFocus() |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
ListView { |
| 49 |
id: actionsListView |
| 50 |
|
| 51 |
model: root.m_proxyActionsModel |
| 52 |
reuseItems: true |
| 53 |
delegate: ItemDelegate { |
| 54 |
id: delegate |
| 55 |
|
| 56 |
required property int index |
| 57 |
required property string actionName |
| 58 |
required property string actionText |
| 59 |
required property string actionDescription |
| 60 |
required property string actionShortcut |
| 61 |
required property string actionIcon |
| 62 |
required property string actionType |
| 63 |
|
| 64 |
width: actionsListView.width |
| 65 |
|
| 66 |
contentItem: RowLayout { |
| 67 |
Kirigami.IconTitleSubtitle { |
| 68 |
title: delegate.actionText |
| 69 |
icon.name: delegate.actionIcon |
| 70 |
|
| 71 |
Layout.fillWidth: true |
| 72 |
} |
| 73 |
|
| 74 |
KeySequenceItem { |
| 75 |
checkForConflictsAgainst: ShortcutType.None |
| 76 |
modifierlessAllowed: true |
| 77 |
keySequence: delegate.actionShortcut |
| 78 |
|
| 79 |
onKeySequenceModified: { |
| 80 |
if (keySequence.toString() === "" ) { |
| 81 |
return |
| 82 |
} |
| 83 |
|
| 84 |
if (keySequence.toString() !== delegate.actionShortcut) { |
| 85 |
if (!root.m_proxyActionsModel.saveShortcut(delegate.index, keySequence)) { |
| 86 |
keySequence = delegate.actionShortcut |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
KeyNavigation.down: searchField |
| 94 |
KeyNavigation.up: searchField |
| 95 |
Keys.onPressed: function (event) { |
| 96 |
if (event.key === Qt.Key_End) { |
| 97 |
actionsListView.currentIndex = actionsListView.count - 1 |
| 98 |
actionsListView.positionViewAtIndex(actionsListView.currentIndex,ListView.Center) |
| 99 |
} |
| 100 |
if (event.key === Qt.Key_Home) { |
| 101 |
actionsListView.currentIndex = 0 |
| 102 |
actionsListView.positionViewAtIndex(actionsListView.currentIndex,ListView.Center) |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |