9import QtQuick.Controls as QQC2
12import org.kde.kirigami as Kirigami
13import org.kde.kirigamiaddons.statefulapp.private
14import org.kde.kirigamiaddons.formcard as FormCard
19FormCard.AbstractFormDelegate {
22 required property string label
23 property bool showClearButton: true
24 property bool showCancelButton: true
25 property alias modifierOnlyAllowed: helper.modifierOnlyAllowed
26 property alias modifierlessAllowed: helper.modifierlessAllowed
27 property alias multiKeyShortcutsAllowed: helper.multiKeyShortcutsAllowed
28 property alias keySequence: helper.currentKeySequence
40 property alias checkForConflictsAgainst: helper.checkAgainstShortcutTypes
42 property string __previousSequence: ""
49 signal keySequenceModified()
51 signal errorOccurred(title: string, message: string)
53 signal showStealStandardShortcutDialog(title: string, message: string, sequence: var)
58 function startCapturing() {
59 mainButton.checked = true;
62 function stealStandardShortcut(sequence): void {
63 applyStealStandardShortcutTimer.sequence = sequence;
64 applyStealStandardShortcutTimer.start();
68 id: applyStealStandardShortcutTimer
74 helper.currentKeySequence = sequence;
75 root.keySequenceModified();
81 contentItem: ColumnLayout {
82 spacing: Kirigami.Units.smallSpacing
86 visible: text.length > 0
87 Layout.fillWidth:
true
91 Layout.fillWidth:
true
96 if (!isKeySequenceAvailable(keySequence)) {
97 currentKeySequence = root.__previousSequence;
99 mainButton.checked =
false;
100 root.keySequenceModified();
103 onErrorOccurred: (title, message) => {
104 root.errorOccurred(title, message);
107 onShowStealStandardShortcutDialog: (title, message, seq) => {
108 root.showStealStandardShortcutDialog(title, message, seq);
115 Layout.fillHeight:
true
116 Layout.fillWidth:
true
118 icon.name:
"configure"
127 const text = helper.keySequenceIsEmpty(keySequence)
128 ? (helper.isRecording
129 ?
i18ndc(
"kirigami-addons6",
"What the user inputs now will be taken as the new shortcut",
"Input")
130 :
i18ndc(
"kirigami-addons6",
"No shortcut defined",
"None"))
138 return " " + text + (helper.isRecording ?
" ... " :
" ");
141 Accessible.description:
i18nd(
"kirigami-addons6",
"Click on the button, then enter the shortcut like you would in the program.\nExample for Ctrl+A: hold the Ctrl key and press A.")
143 QQC2.ToolTip.visible: hovered
144 QQC2.ToolTip.text: Accessible.description
149 root.__previousSequence = helper.keySequenceNativeText(root.keySequence)
150 helper.window = helper.renderWindow(parent.Window.window)
151 mainButton.forceActiveFocus()
152 helper.startRecording()
153 }
else if (helper.isRecording) {
154 helper.cancelRecording()
160 mainButton.checked =
false
167 Layout.fillHeight:
true
168 Layout.preferredWidth: height
169 visible: root.showClearButton && !helper.isRecording
171 root.keySequence =
"";
172 root.keySequenceModified();
175 enabled: !helper.keySequenceIsEmpty(helper.currentKeySequence)
179 icon.name:
Qt.application.layoutDirection ===
Qt.LeftToRight ?
"edit-clear-locationbar-rtl" :
"edit-clear-locationbar-ltr"
181 display: QQC2.Button.IconOnly
182 text:
i18ndc(
"kirigami-addons6",
"@info:tooltip",
"Clear Key Sequence")
184 QQC2.ToolTip.visible: hovered
185 QQC2.ToolTip.text: text
190 Layout.fillHeight:
true
191 Layout.preferredWidth: height
192 onClicked: helper.cancelRecording()
193 visible: root.showCancelButton && helper.isRecording
195 icon.name:
"dialog-cancel"
197 display: QQC2.Button.IconOnly
198 text:
i18ndc(
"kirigami-addons6",
"@info:tooltip",
"Cancel Key Sequence Recording")
200 QQC2.ToolTip.visible: hovered
201 QQC2.ToolTip.text: Accessible.name
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
const QList< QKeySequence > & replace()
void keySequence(QWidget *widget, const QKeySequence &keySequence)