KDeclarative

KeySequenceItem.qml
1 import QtQuick 2.0
2 import QtQuick.Controls 2.12
3 import QtQuick.Layouts 1.1
4 import QtQuick.Window 2.15
5 
6 import org.kde.private.kquickcontrols 2.0 as KQuickControlsPrivate
7 
8 RowLayout {
9  id: root
10  property alias showClearButton: clearButton.visible
11  property alias modifierlessAllowed: _helper.modifierlessAllowed
12  property alias multiKeyShortcutsAllowed: _helper.multiKeyShortcutsAllowed
13  property var keySequence
14 
15  /**
16  * This property controls which types of shortcuts are checked for conflicts when the keySequence
17  * is set. If a conflict is detected, a messagebox will be shown asking the user to confirm their
18  * input. Valid values are combinations of the following flags:
19  * - @p ShortcutType.None Do not check for conflicts.
20  * - @p ShortcutType.StandardShortcuts Check against standard shortcuts. @see KStandardshortcut
21  * - @p ShortcutType.GlobalShortcuts Check against global shortcuts. @see KGlobalAccel
22  *
23  * The default is `ShortcutType.GlobalShortcuts | ShortcutType.StandardShortcut`
24  * @since 5.74
25  */
26  property alias checkForConflictsAgainst: _helper.checkAgainstShortcutTypes
27 
28  /**
29  * This signal is emitted after the user introduces a new key sequence
30  *
31  * @since 5.68
32  */
33  signal captureFinished()
34 
35  /**
36  * Start capturing a key sequence. This equivalent to the user clicking on the main button of the item
37  * @since 5.70
38  */
39  function startCapturing() {
40  mainButton.checked = true
41  }
42 
43  KQuickControlsPrivate.KeySequenceHelper {
44  id: _helper
45  window: renderWindow(parent.Window.window)
46  onGotKeySequence: {
47  if (isKeySequenceAvailable(keySequence)) {
48  root.keySequence = keySequence
49  }
50  mainButton.checked = false;
51  root.captureFinished();
52  }
53  }
54 
55  KQuickControlsPrivate.TranslationContext {
56  id: _tr
57  domain: "kdeclarative5"
58  }
59 
60  Button
61  {
62  id: mainButton
63 
64  icon.name: "configure"
65 
66  checkable: true
67  focus: checked
68 
69  hoverEnabled: true
70 
71  text: {
72  const keys = _helper.isRecording ? _helper.currentKeySequence : parent.keySequence
73  let text = " " // This space is intentional
74  if (keys == undefined || _helper.keySequenceIsEmpty(keys)) {
75  if (_helper.isRecording) {
76  text += _tr.i18nc("What the user inputs now will be taken as the new shortcut", "Input")
77  } else {
78  text += _tr.i18nc("No shortcut defined", "None");
79  }
80  } else {
81  text += _helper.keySequenceNativeText(keys)
82  }
83  return _helper.isRecording ? text.concat(" ... ") : text.concat(" ")
84  }
85 
86  ToolTip.visible: hovered
87  ToolTip.delay: 1000
88  ToolTip.text: _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.")
89  ToolTip.timeout: 5000
90 
91  onCheckedChanged: {
92  if (checked) {
93  mainButton.forceActiveFocus()
94  _helper.startRecording()
95  }
96  }
97 
98  onFocusChanged: {
99  if (!focus) {
100  mainButton.checked = false
101  }
102  }
103  }
104 
105  Button {
106  id: clearButton
107  Layout.fillHeight: true
108  Layout.preferredWidth: height
109  onClicked: root.keySequence = ""
110 
111  //icon name determines the direction of the arrow, NOT the direction of the app layout
112  icon.name: Qt.application.layoutDirection == Qt.LeftToRight ? "edit-clear-locationbar-rtl" : "edit-clear-locationbar-ltr"
113  }
114 }
int timeout
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed May 12 2021 22:38:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.