8import QtQuick.Controls as QQC2
11import org.kde.private.kquickcontrols as KQuickControlsPrivate
16 property bool showClearButton: true
17 property bool showCancelButton: false
18 property alias modifierOnlyAllowed: helper.modifierOnlyAllowed
19 property alias modifierlessAllowed: helper.modifierlessAllowed
20 property alias multiKeyShortcutsAllowed: helper.multiKeyShortcutsAllowed
21 property alias keySequence: helper.currentKeySequence
34 property alias checkForConflictsAgainst: helper.checkAgainstShortcutTypes
42 signal captureFinished()
51 signal keySequenceModified()
57 function startCapturing() {
58 mainButton.checked = true;
65 Layout.fillHeight:
false
67 KQuickControlsPrivate.KeySequenceHelper {
70 onGotKeySequence: keySequence => {
71 validator.validateSequence(keySequence)
74 onQuestionDialogAccepted: validator.accept()
75 onQuestionDialogRejected: validator.reject()
78 KQuickControlsPrivate.KeySequenceValidator {
81 validateTypes: helper.checkAgainstShortcutTypes
83 onError: (title, message) => {
84 helper.showErrorDialog(title, message)
87 onQuestion: (title, message) => {
88 helper.showQuestionDialog(title, message)
92 helper.updateKeySequence(keySequence)
93 mainButton.checked =
false
94 root.captureFinished()
95 root.keySequenceModified()
99 KQuickControlsPrivate.TranslationContext {
101 domain:
"kdeclarative6"
107 Layout.fillHeight:
true
109 icon.name:
"configure"
118 const text = helper.keySequenceIsEmpty(keySequence)
119 ? (helper.isRecording
120 ? _tr.i18nc(
"What the user inputs now will be taken as the new shortcut",
"Input")
121 : _tr.i18nc(
"No shortcut defined",
"None"))
127 : helper.keySequenceNativeText(keySequence).replace(
'&',
'&&');
129 return " " + text + (helper.isRecording ?
" ... " :
" ");
132 Accessible.description: _tr.i18n(
"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.")
133 Accessible.role: Accessible.Button
136 visible: mainButton.hovered
137 text: mainButton.Accessible.description
142 validator.currentKeySequence = root.keySequence
143 helper.window = helper.renderWindow(parent.Window.window)
144 mainButton.forceActiveFocus()
145 helper.startRecording()
146 }
else if (helper.isRecording) {
147 helper.cancelRecording()
153 mainButton.checked =
false
160 Layout.fillHeight:
true
161 Layout.preferredWidth: height
162 visible: root.showClearButton && !helper.isRecording
164 root.keySequence =
"";
165 root.keySequenceModified();
166 root.captureFinished();
169 enabled: !helper.keySequenceIsEmpty(helper.currentKeySequence)
173 icon.name:
Qt.application.layoutDirection ===
Qt.LeftToRight ?
"edit-clear-locationbar-rtl" :
"edit-clear-locationbar-ltr"
175 Accessible.name: _tr.i18nc(
"@info:tooltip",
"Clear Key Sequence")
178 visible: clearButton.hovered
179 text: clearButton.Accessible.name
184 Layout.fillHeight:
true
185 Layout.preferredWidth: height
186 onClicked: helper.cancelRecording()
187 visible: root.showCancelButton && helper.isRecording
189 icon.name:
"dialog-cancel"
191 Accessible.name: _tr.i18nc(
"@info:tooltip",
"Cancel Key Sequence Recording")
194 visible: parent.hovered
195 text: parent.Accessible.name
void keySequence(QWidget *widget, const QKeySequence &keySequence)