Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qkeysequence.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qkeysequence.h"
7#include <qpa/qplatformtheme.h>
8#include "private/qguiapplication_p.h"
9
10#include "qdebug.h"
11#include <QtCore/qhashfunctions.h>
12#ifndef QT_NO_DATASTREAM
13# include "qdatastream.h"
14#endif
15#include "qvariant.h"
16
17#if defined(Q_OS_APPLE)
18#include <QtCore/private/qcore_mac_p.h>
19#endif
20
21#include <algorithm>
22#include <optional>
23#include <q20algorithm.h>
24
26
27using namespace Qt::StringLiterals;
28
29#if defined(Q_OS_APPLE) || defined(Q_QDOC)
30struct AppleSpecialKey {
31 int key;
32 ushort appleSymbol;
33};
34
35// Unicode code points for the glyphs associated with these keys
36// Defined by Carbon headers but not anywhere in Cocoa
37static constexpr int kShiftUnicode = 0x21E7;
38static constexpr int kControlUnicode = 0x2303;
39static constexpr int kOptionUnicode = 0x2325;
40static constexpr int kCommandUnicode = 0x2318;
41
42static constexpr AppleSpecialKey entries[] = {
43 { Qt::Key_Escape, 0x238B },
44 { Qt::Key_Tab, 0x21E5 },
45 { Qt::Key_Backtab, 0x21E4 },
46 { Qt::Key_Backspace, 0x232B },
47 { Qt::Key_Return, 0x21B5 },
48 { Qt::Key_Enter, 0x2324 },
49 { Qt::Key_Delete, 0x2326 },
50 { Qt::Key_Clear, 0x2327 },
51 { Qt::Key_Home, 0x2196 },
52 { Qt::Key_End, 0x2198 },
53 { Qt::Key_Left, 0x2190 },
54 { Qt::Key_Up, 0x2191 },
55 { Qt::Key_Right, 0x2192 },
56 { Qt::Key_Down, 0x2193 },
57 { Qt::Key_PageUp, 0x21DE },
58 { Qt::Key_PageDown, 0x21DF },
59 { Qt::Key_Shift, kShiftUnicode },
60 { Qt::Key_Control, kCommandUnicode },
61 { Qt::Key_Meta, kControlUnicode },
62 { Qt::Key_Alt, kOptionUnicode },
63 { Qt::Key_CapsLock, 0x21EA },
64 { Qt::Key_Eject, 0x23CF },
65};
66
67static constexpr bool operator<(const AppleSpecialKey &lhs, const AppleSpecialKey &rhs)
68{
69 return lhs.key < rhs.key;
70}
71
72static constexpr bool operator<(const AppleSpecialKey &lhs, int rhs)
73{
74 return lhs.key < rhs;
75}
76
77static constexpr bool operator<(int lhs, const AppleSpecialKey &rhs)
78{
79 return lhs < rhs.key;
80}
81
82static_assert(q20::is_sorted(std::begin(entries), std::end(entries)));
83
84static QChar appleSymbolForQtKey(int key)
85{
86 const auto i = std::lower_bound(std::begin(entries), std::end(entries), key);
87 if (i == std::end(entries) || key < *i)
88 return QChar();
89 ushort appleSymbol = i->appleSymbol;
90 if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
91 && (appleSymbol == kControlUnicode || appleSymbol == kCommandUnicode)) {
92 if (appleSymbol == kControlUnicode)
93 appleSymbol = kCommandUnicode;
94 else
95 appleSymbol = kControlUnicode;
96 }
97
98 return QChar(appleSymbol);
99}
100
101static int qtkeyForAppleSymbol(const QChar ch)
102{
103 const ushort unicode = ch.unicode();
104 for (const AppleSpecialKey &entry : entries) {
105 if (entry.appleSymbol == unicode) {
106 int key = entry.key;
107 if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
108 && (unicode == kControlUnicode || unicode == kCommandUnicode)) {
109 if (unicode == kControlUnicode)
110 key = Qt::Key_Control;
111 else
112 key = Qt::Key_Meta;
113 }
114 return key;
115 }
116 }
117 return -1;
118}
119
120#endif
121
122// Explicit override set via qt_set_sequence_auto_mnemonic(), taking precedence
123// over QPlatformTheme::MnemonicsEnabled when set.
124// ### Qt 7: remove in favor of theme hint.
125Q_CONSTINIT static std::optional<bool> qt_sequence_auto_mnemonic_override;
126
127/*!
128 \fn void qt_set_sequence_auto_mnemonic(bool b)
129 \relates QKeySequence
130
131 Specifies whether mnemonics for menu items, labels, etc., should
132 be honored or not. On Windows and X11, this feature is
133 on by default; on \macos, it is off. When this feature is off
134 (that is, when \a b is false), QKeySequence::mnemonic() always
135 returns an empty string.
136
137 \note This function is not declared in any of Qt's header files.
138 To use it in your application, declare the function prototype
139 before calling it.
140
141 \sa QShortcut
142*/
143void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_auto_mnemonic_override = b; }
144
145/*!
146 \class QKeySequence
147 \brief The QKeySequence class encapsulates a key sequence as used
148 by shortcuts.
149
150 \ingroup shared
151 \inmodule QtGui
152
153
154 In its most common form, a key sequence describes a combination of
155 keys that must be used together to perform some action. Key sequences
156 are used with QAction objects to specify which keyboard shortcuts can
157 be used to trigger actions.
158
159 Key sequences can be constructed for use as keyboard shortcuts in
160 three different ways:
161
162 \list
163 \li For standard shortcuts, a \l{QKeySequence::StandardKey}{standard key}
164 can be used to request the platform-specific key sequence associated
165 with each shortcut.
166 \li For custom shortcuts, human-readable strings such as "Ctrl+X" can
167 be used, and these can be translated into the appropriate shortcuts
168 for users of different languages. Translations are made in the
169 "QShortcut" context.
170 \li For hard-coded shortcuts, integer key codes can be specified with
171 a combination of values defined by the Qt::Key and Qt::KeyboardModifier
172 enum values. Each key code consists of a single Qt::Key value and zero
173 or more modifiers, such as Qt::ShiftModifier, Qt::ControlModifier,
174 Qt::AltModifier and Qt::MetaModifier.
175 \endlist
176
177 For example, \uicontrol{Ctrl P} might be a sequence used as a shortcut for
178 printing a document, and can be specified in any of the following
179 ways:
180
181 \snippet code/src_gui_kernel_qkeysequence.cpp 0
182
183 Note that, for letters, the case used in the specification string
184 does not matter. In the above examples, the user does not need to
185 hold down the \uicontrol{Shift} key to activate a shortcut specified
186 with "Ctrl+P". However, for other keys, the use of \uicontrol{Shift} as
187 an unspecified extra modifier key can lead to confusion for users
188 of an application whose keyboards have different layouts to those
189 used by the developers. See the \l{Keyboard Layout Issues} section
190 below for more details.
191
192 It is preferable to use standard shortcuts where possible.
193 When creating key sequences for non-standard shortcuts, you should use
194 human-readable strings in preference to hard-coded integer values.
195
196 QKeySequence object can be serialized to human-readable strings with the
197 toString() function.
198
199 An alternative way to specify hard-coded key codes is to use the Unicode
200 code point of the character; for example, 'A' gives the same key sequence
201 as Qt::Key_A.
202
203 \note On Apple platforms, references to "Ctrl", Qt::CTRL, Qt::Key_Control
204 and Qt::ControlModifier correspond to the \uicontrol Command keys on the
205 Macintosh keyboard, and references to "Meta", Qt::META, Qt::Key_Meta and
206 Qt::MetaModifier correspond to the \uicontrol Control keys. In effect,
207 developers can use the same shortcut descriptions across all platforms,
208 and their applications will automatically work as expected on Apple platforms.
209
210 \section1 Standard Shortcuts
211
212 QKeySequence defines many \l{QKeySequence::StandardKey} {standard
213 keyboard shortcuts} to reduce the amount of effort required when
214 setting up actions in a typical application. The table below shows
215 some common key sequences that are often used for these standard
216 shortcuts by applications on four widely-used platforms. Note
217 that on Apple platforms, the \uicontrol Ctrl value corresponds to the \uicontrol
218 Command keys on the Macintosh keyboard, and the \uicontrol Meta value
219 corresponds to the \uicontrol Control keys.
220
221 \table
222 \header \li StandardKey \li Windows \li Apple platforms \li KDE Plasma \li GNOME
223 \row \li HelpContents \li F1 \li Ctrl+? \li F1 \li F1
224 \row \li WhatsThis \li Shift+F1 \li Shift+F1 \li Shift+F1 \li Shift+F1
225 \row \li Open \li Ctrl+O \li Ctrl+O \li Ctrl+O \li Ctrl+O
226 \row \li Close \li Ctrl+F4, Ctrl+W \li Ctrl+W, Ctrl+F4 \li Ctrl+W \li Ctrl+W
227 \row \li Save \li Ctrl+S \li Ctrl+S \li Ctrl+S \li Ctrl+S
228 \row \li Quit \li \li Ctrl+Q \li Ctrl+Q \li Ctrl+Q
229 \row \li SaveAs \li Ctrl+Shift+S \li Ctrl+Shift+S \li Ctrl+Shift+S \li Ctrl+Shift+S
230 \row \li New \li Ctrl+N \li Ctrl+N \li Ctrl+N \li Ctrl+N
231 \row \li Delete \li Del \li Forward Delete, Meta+D \li Del, Ctrl+D \li Del, Ctrl+D
232 \row \li Cut \li Ctrl+X, Shift+Del \li Ctrl+X, Meta+K \li Ctrl+X, F20, Shift+Del \li Ctrl+X, F20, Shift+Del
233 \row \li Copy \li Ctrl+C, Ctrl+Ins \li Ctrl+C \li Ctrl+C, F16, Ctrl+Ins \li Ctrl+C, F16, Ctrl+Ins
234 \row \li Paste \li Ctrl+V, Shift+Ins \li Ctrl+V, Meta+Y \li Ctrl+V, F18, Shift+Ins \li Ctrl+V, F18, Shift+Ins
235 \row \li Preferences \li \li Ctrl+, \li Ctrl+Shift+, \li
236 \row \li Undo \li Ctrl+Z, Alt+Backspace \li Ctrl+Z \li Ctrl+Z, F14 \li Ctrl+Z, F14
237 \row \li Redo \li Ctrl+Y, Shift+Ctrl+Z, Alt+Shift+Backspace \li Ctrl+Shift+Z \li Ctrl+Shift+Z \li Ctrl+Shift+Z
238 \row \li Back \li Alt+Left, Backspace \li Ctrl+[ \li Alt+Left \li Alt+Left
239 \row \li Forward \li Alt+Right, Shift+Backspace \li Ctrl+] \li Alt+Right \li Alt+Right
240 \row \li Refresh \li F5 \li F5 \li F5 \li Ctrl+R, F5
241 \row \li ZoomIn \li Ctrl+Plus \li Ctrl+Plus \li Ctrl+Plus \li Ctrl+Plus
242 \row \li ZoomOut \li Ctrl+Minus \li Ctrl+Minus \li Ctrl+Minus \li Ctrl+Minus
243 \row \li FullScreen \li F11, Alt+Enter \li Ctrl+Meta+F \li F11, Ctrl+Shift+F \li Ctrl+F11
244 \row \li Print \li Ctrl+P \li Ctrl+P \li Ctrl+P \li Ctrl+P
245 \row \li AddTab \li Ctrl+T \li Ctrl+T \li Ctrl+Shift+N, Ctrl+T \li Ctrl+T
246 \row \li NextChild \li Ctrl+Tab, Forward, Ctrl+F6 \li Ctrl+}, Forward, Ctrl+Tab \li Ctrl+Tab, Forward, Ctrl+Comma \li Ctrl+Tab, Forward
247 \row \li PreviousChild \li Ctrl+Shift+Tab, Back, Ctrl+Shift+F6 \li Ctrl+{, Back, Ctrl+Shift+Tab \li Ctrl+Shift+Tab, Back, Ctrl+Period \li Ctrl+Shift+Tab, Back
248 \row \li Find \li Ctrl+F \li Ctrl+F \li Ctrl+F \li Ctrl+F
249 \row \li FindNext \li F3, Ctrl+G \li Ctrl+G \li F3 \li Ctrl+G, F3
250 \row \li FindPrevious \li Shift+F3, Ctrl+Shift+G \li Ctrl+Shift+G \li Shift+F3 \li Ctrl+Shift+G, Shift+F3
251 \row \li Replace \li Ctrl+H \li (none) \li Ctrl+R \li Ctrl+H
252 \row \li SelectAll \li Ctrl+A \li Ctrl+A \li Ctrl+A \li Ctrl+A
253 \row \li Deselect \li \li \li Ctrl+Shift+A \li Ctrl+Shift+A
254 \row \li Bold \li Ctrl+B \li Ctrl+B \li Ctrl+B \li Ctrl+B
255 \row \li Italic \li Ctrl+I \li Ctrl+I \li Ctrl+I \li Ctrl+I
256 \row \li Underline \li Ctrl+U \li Ctrl+U \li Ctrl+U \li Ctrl+U
257 \row \li MoveToNextChar \li Right \li Right, Meta+F \li Right \li Right
258 \row \li MoveToPreviousChar \li Left \li Left, Meta+B \li Left \li Left
259 \row \li MoveToNextWord \li Ctrl+Right \li Alt+Right \li Ctrl+Right \li Ctrl+Right
260 \row \li MoveToPreviousWord \li Ctrl+Left \li Alt+Left \li Ctrl+Left \li Ctrl+Left
261 \row \li MoveToNextLine \li Down \li Down, Meta+N \li Down \li Down
262 \row \li MoveToPreviousLine \li Up \li Up, Meta+P \li Up \li Up
263 \row \li MoveToNextPage \li PgDown \li PgDown, Alt+PgDown, Meta+Down, Meta+PgDown, Meta+V \li PgDown \li PgDown
264 \row \li MoveToPreviousPage \li PgUp \li PgUp, Alt+PgUp, Meta+Up, Meta+PgUp \li PgUp \li PgUp
265 \row \li MoveToStartOfLine \li Home \li Ctrl+Left, Meta+Left \li Home \li Home
266 \row \li MoveToEndOfLine \li End \li Ctrl+Right, Meta+Right \li End, Ctrl+E \li End, Ctrl+E
267 \row \li MoveToStartOfBlock \li (none) \li Alt+Up, Meta+A \li (none) \li (none)
268 \row \li MoveToEndOfBlock \li (none) \li Alt+Down, Meta+E \li (none) \li (none)
269 \row \li MoveToStartOfDocument\li Ctrl+Home \li Ctrl+Up, Home \li Ctrl+Home \li Ctrl+Home
270 \row \li MoveToEndOfDocument \li Ctrl+End \li Ctrl+Down, End \li Ctrl+End \li Ctrl+End
271 \row \li SelectNextChar \li Shift+Right \li Shift+Right \li Shift+Right \li Shift+Right
272 \row \li SelectPreviousChar \li Shift+Left \li Shift+Left \li Shift+Left \li Shift+Left
273 \row \li SelectNextWord \li Ctrl+Shift+Right \li Alt+Shift+Right \li Ctrl+Shift+Right \li Ctrl+Shift+Right
274 \row \li SelectPreviousWord \li Ctrl+Shift+Left \li Alt+Shift+Left \li Ctrl+Shift+Left \li Ctrl+Shift+Left
275 \row \li SelectNextLine \li Shift+Down \li Shift+Down \li Shift+Down \li Shift+Down
276 \row \li SelectPreviousLine \li Shift+Up \li Shift+Up \li Shift+Up \li Shift+Up
277 \row \li SelectNextPage \li Shift+PgDown \li Shift+PgDown \li Shift+PgDown \li Shift+PgDown
278 \row \li SelectPreviousPage \li Shift+PgUp \li Shift+PgUp \li Shift+PgUp \li Shift+PgUp
279 \row \li SelectStartOfLine \li Shift+Home \li Ctrl+Shift+Left \li Shift+Home \li Shift+Home
280 \row \li SelectEndOfLine \li Shift+End \li Ctrl+Shift+Right \li Shift+End \li Shift+End
281 \row \li SelectStartOfBlock \li (none) \li Alt+Shift+Up, Meta+Shift+A \li (none) \li (none)
282 \row \li SelectEndOfBlock \li (none) \li Alt+Shift+Down, Meta+Shift+E \li (none) \li (none)
283 \row \li SelectStartOfDocument\li Ctrl+Shift+Home \li Ctrl+Shift+Up, Shift+Home \li Ctrl+Shift+Home\li Ctrl+Shift+Home
284 \row \li SelectEndOfDocument \li Ctrl+Shift+End \li Ctrl+Shift+Down, Shift+End \li Ctrl+Shift+End \li Ctrl+Shift+End
285 \row \li DeleteStartOfWord \li Ctrl+Backspace \li Alt+Backspace \li Ctrl+Backspace \li Ctrl+Backspace
286 \row \li DeleteEndOfWord \li Ctrl+Del \li (none) \li Ctrl+Del \li Ctrl+Del
287 \row \li DeleteEndOfLine \li (none) \li (none) \li Ctrl+K \li Ctrl+K
288 \row \li DeleteCompleteLine \li (none) \li (none) \li Ctrl+U \li Ctrl+U
289 \row \li InsertParagraphSeparator \li Enter \li Enter \li Enter \li Enter
290 \row \li InsertLineSeparator \li Shift+Enter \li Meta+Enter, Meta+O \li Shift+Enter \li Shift+Enter
291 \row \li Backspace \li (none) \li Delete, Meta+H \li (none) \li (none)
292 \row \li Cancel \li Escape \li Escape, Ctrl+. \li Escape \li Escape
293 \endtable
294
295 Note that, since the key sequences used for the standard shortcuts differ
296 between platforms, you still need to test your shortcuts on each platform
297 to ensure that you do not unintentionally assign the same key sequence to
298 many actions.
299
300 \section1 Keyboard Layout Issues
301
302 Many key sequence specifications are chosen by developers based on the
303 layout of certain types of keyboard, rather than choosing keys that
304 represent the first letter of an action's name, such as \uicontrol{Ctrl S}
305 ("Ctrl+S") or \uicontrol{Ctrl C} ("Ctrl+C").
306 Additionally, because certain symbols can only be entered with the
307 help of modifier keys on certain keyboard layouts, key sequences intended
308 for use with one keyboard layout may map to a different key, map to no
309 keys at all, or require an additional modifier key to be used on
310 different keyboard layouts.
311
312 For example, the shortcuts, \uicontrol{Ctrl plus} and \uicontrol{Ctrl minus}, are often
313 used as shortcuts for zoom operations in graphics applications, and these
314 may be specified as "Ctrl++" and "Ctrl+-" respectively. However, the way
315 these shortcuts are specified and interpreted depends on the keyboard layout.
316 Users of Norwegian keyboards will note that the \uicontrol{+} and \uicontrol{-} keys
317 are not adjacent on the keyboard, but will still be able to activate both
318 shortcuts without needing to press the \uicontrol{Shift} key. However, users
319 with British keyboards will need to hold down the \uicontrol{Shift} key
320 to enter the \uicontrol{+} symbol, making the shortcut effectively the same as
321 "Ctrl+Shift+=".
322
323 Although some developers might resort to fully specifying all the modifiers
324 they use on their keyboards to activate a shortcut, this will also result
325 in unexpected behavior for users of different keyboard layouts.
326
327 For example, a developer using a British keyboard may decide to specify
328 "Ctrl+Shift+=" as the key sequence in order to create a shortcut that
329 coincidentally behaves in the same way as \uicontrol{Ctrl plus}. However, the
330 \uicontrol{=} key needs to be accessed using the \uicontrol{Shift} key on Norwegian
331 keyboard, making the required shortcut effectively \uicontrol{Ctrl Shift Shift =}
332 (an impossible key combination).
333
334 As a result, both human-readable strings and hard-coded key codes
335 can both be problematic to use when specifying a key sequence that
336 can be used on a variety of different keyboard layouts. Only the
337 use of \l{QKeySequence::StandardKey} {standard shortcuts}
338 guarantees that the user will be able to use the shortcuts that
339 the developer intended.
340
341 Despite this, we can address this issue by ensuring that human-readable
342 strings are used, making it possible for translations of key sequences to
343 be made for users of different languages. This approach will be successful
344 for users whose keyboards have the most typical layout for the language
345 they are using.
346
347 \section1 GNU Emacs Style Key Sequences
348
349 Key sequences similar to those used in \l{http://www.gnu.org/software/emacs/}{GNU Emacs}, allowing up to four
350 key codes, can be created by using the multiple argument constructor,
351 or by passing a human-readable string of comma-separated key sequences.
352
353 For example, the key sequence, \uicontrol{Ctrl X} followed by \uicontrol{Ctrl C}, can
354 be specified using either of the following ways:
355
356 \snippet code/src_gui_kernel_qkeysequence.cpp 1
357
358 \warning A QApplication instance must have been constructed before a
359 QKeySequence is created; otherwise, your application may crash.
360
361 \sa QShortcut
362*/
363
364/*!
365 \enum QKeySequence::SequenceMatch
366
367 \value NoMatch The key sequences are different; not even partially
368 matching.
369 \value PartialMatch The key sequences match partially, but are not
370 the same.
371 \value ExactMatch The key sequences are the same.
372*/
373
374/*!
375 \enum QKeySequence::SequenceFormat
376
377 \value NativeText The key sequence as a platform specific string.
378 This means that it will be shown translated and on Apple platforms it will
379 resemble a key sequence from the menu bar. This enum is best used when you
380 want to display the string to the user.
381
382 \value PortableText The key sequence is given in a "portable" format,
383 suitable for reading and writing to a file. In many cases, it will look
384 similar to the native text on Windows and X11.
385*/
386
387static constexpr struct {
388 int key;
389 const char name[25];
390} keyname[] = {
391 //: This and all following "incomprehensible" strings in QShortcut context
392 //: are key names. Please use the localized names appearing on actual
393 //: keyboards or whatever is commonly used.
394 { Qt::Key_Space, QT_TRANSLATE_NOOP("QShortcut", "Space") },
395 { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Esc") },
396 { Qt::Key_Tab, QT_TRANSLATE_NOOP("QShortcut", "Tab") },
397 { Qt::Key_Backtab, QT_TRANSLATE_NOOP("QShortcut", "Backtab") },
398 { Qt::Key_Backspace, QT_TRANSLATE_NOOP("QShortcut", "Backspace") },
399 { Qt::Key_Return, QT_TRANSLATE_NOOP("QShortcut", "Return") },
400 { Qt::Key_Enter, QT_TRANSLATE_NOOP("QShortcut", "Enter") },
401 { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Ins") },
402 { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Del") },
403 { Qt::Key_Pause, QT_TRANSLATE_NOOP("QShortcut", "Pause") },
404 { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print") },
405 { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "SysReq") },
406 { Qt::Key_Home, QT_TRANSLATE_NOOP("QShortcut", "Home") },
407 { Qt::Key_End, QT_TRANSLATE_NOOP("QShortcut", "End") },
408 { Qt::Key_Left, QT_TRANSLATE_NOOP("QShortcut", "Left") },
409 { Qt::Key_Up, QT_TRANSLATE_NOOP("QShortcut", "Up") },
410 { Qt::Key_Right, QT_TRANSLATE_NOOP("QShortcut", "Right") },
411 { Qt::Key_Down, QT_TRANSLATE_NOOP("QShortcut", "Down") },
412 { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "PgUp") },
413 { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "PgDown") },
414 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "CapsLock") },
415 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "NumLock") },
416 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "ScrollLock") },
417 { Qt::Key_Menu, QT_TRANSLATE_NOOP("QShortcut", "Menu") },
418 { Qt::Key_Help, QT_TRANSLATE_NOOP("QShortcut", "Help") },
419
420 // Special keys
421 // Includes multimedia, launcher, lan keys ( bluetooth, wireless )
422 // window navigation
423 { Qt::Key_Back, QT_TRANSLATE_NOOP("QShortcut", "Back") },
424 { Qt::Key_Forward, QT_TRANSLATE_NOOP("QShortcut", "Forward") },
425 { Qt::Key_Stop, QT_TRANSLATE_NOOP("QShortcut", "Stop") },
426 { Qt::Key_Refresh, QT_TRANSLATE_NOOP("QShortcut", "Refresh") },
427 { Qt::Key_VolumeDown, QT_TRANSLATE_NOOP("QShortcut", "Volume Down") },
428 { Qt::Key_VolumeMute, QT_TRANSLATE_NOOP("QShortcut", "Volume Mute") },
429 { Qt::Key_VolumeUp, QT_TRANSLATE_NOOP("QShortcut", "Volume Up") },
430 { Qt::Key_BassBoost, QT_TRANSLATE_NOOP("QShortcut", "Bass Boost") },
431 { Qt::Key_BassUp, QT_TRANSLATE_NOOP("QShortcut", "Bass Up") },
432 { Qt::Key_BassDown, QT_TRANSLATE_NOOP("QShortcut", "Bass Down") },
433 { Qt::Key_TrebleUp, QT_TRANSLATE_NOOP("QShortcut", "Treble Up") },
434 { Qt::Key_TrebleDown, QT_TRANSLATE_NOOP("QShortcut", "Treble Down") },
435 { Qt::Key_MediaPlay, QT_TRANSLATE_NOOP("QShortcut", "Media Play") },
436 { Qt::Key_MediaStop, QT_TRANSLATE_NOOP("QShortcut", "Media Stop") },
437 { Qt::Key_MediaPrevious, QT_TRANSLATE_NOOP("QShortcut", "Media Previous") },
438 { Qt::Key_MediaNext, QT_TRANSLATE_NOOP("QShortcut", "Media Next") },
439 { Qt::Key_MediaRecord, QT_TRANSLATE_NOOP("QShortcut", "Media Record") },
440 //: Media player pause button
441 { Qt::Key_MediaPause, QT_TRANSLATE_NOOP("QShortcut", "Media Pause") },
442 //: Media player button to toggle between playing and paused
443 { Qt::Key_MediaTogglePlayPause, QT_TRANSLATE_NOOP("QShortcut", "Toggle Media Play/Pause") },
444 { Qt::Key_HomePage, QT_TRANSLATE_NOOP("QShortcut", "Home Page") },
445 { Qt::Key_Favorites, QT_TRANSLATE_NOOP("QShortcut", "Favorites") },
446 { Qt::Key_Search, QT_TRANSLATE_NOOP("QShortcut", "Search") },
447 { Qt::Key_Standby, QT_TRANSLATE_NOOP("QShortcut", "Standby") },
448 { Qt::Key_OpenUrl, QT_TRANSLATE_NOOP("QShortcut", "Open URL") },
449 { Qt::Key_LaunchMail, QT_TRANSLATE_NOOP("QShortcut", "Launch Mail") },
450 { Qt::Key_LaunchMedia, QT_TRANSLATE_NOOP("QShortcut", "Launch Media") },
451 { Qt::Key_Launch0, QT_TRANSLATE_NOOP("QShortcut", "Launch (0)") },
452 { Qt::Key_Launch1, QT_TRANSLATE_NOOP("QShortcut", "Launch (1)") },
453 { Qt::Key_Launch2, QT_TRANSLATE_NOOP("QShortcut", "Launch (2)") },
454 { Qt::Key_Launch3, QT_TRANSLATE_NOOP("QShortcut", "Launch (3)") },
455 { Qt::Key_Launch4, QT_TRANSLATE_NOOP("QShortcut", "Launch (4)") },
456 { Qt::Key_Launch5, QT_TRANSLATE_NOOP("QShortcut", "Launch (5)") },
457 { Qt::Key_Launch6, QT_TRANSLATE_NOOP("QShortcut", "Launch (6)") },
458 { Qt::Key_Launch7, QT_TRANSLATE_NOOP("QShortcut", "Launch (7)") },
459 { Qt::Key_Launch8, QT_TRANSLATE_NOOP("QShortcut", "Launch (8)") },
460 { Qt::Key_Launch9, QT_TRANSLATE_NOOP("QShortcut", "Launch (9)") },
461 { Qt::Key_LaunchA, QT_TRANSLATE_NOOP("QShortcut", "Launch (A)") },
462 { Qt::Key_LaunchB, QT_TRANSLATE_NOOP("QShortcut", "Launch (B)") },
463 { Qt::Key_LaunchC, QT_TRANSLATE_NOOP("QShortcut", "Launch (C)") },
464 { Qt::Key_LaunchD, QT_TRANSLATE_NOOP("QShortcut", "Launch (D)") },
465 { Qt::Key_LaunchE, QT_TRANSLATE_NOOP("QShortcut", "Launch (E)") },
466 { Qt::Key_LaunchF, QT_TRANSLATE_NOOP("QShortcut", "Launch (F)") },
467 { Qt::Key_LaunchG, QT_TRANSLATE_NOOP("QShortcut", "Launch (G)") },
468 { Qt::Key_LaunchH, QT_TRANSLATE_NOOP("QShortcut", "Launch (H)") },
469 { Qt::Key_MonBrightnessUp, QT_TRANSLATE_NOOP("QShortcut", "Monitor Brightness Up") },
470 { Qt::Key_MonBrightnessDown, QT_TRANSLATE_NOOP("QShortcut", "Monitor Brightness Down") },
471 { Qt::Key_KeyboardLightOnOff, QT_TRANSLATE_NOOP("QShortcut", "Keyboard Light On/Off") },
472 { Qt::Key_KeyboardBrightnessUp, QT_TRANSLATE_NOOP("QShortcut", "Keyboard Brightness Up") },
473 { Qt::Key_KeyboardBrightnessDown, QT_TRANSLATE_NOOP("QShortcut", "Keyboard Brightness Down") },
474 { Qt::Key_PowerOff, QT_TRANSLATE_NOOP("QShortcut", "Power Off") },
475 { Qt::Key_WakeUp, QT_TRANSLATE_NOOP("QShortcut", "Wake Up") },
476 { Qt::Key_Eject, QT_TRANSLATE_NOOP("QShortcut", "Eject") },
477 { Qt::Key_ScreenSaver, QT_TRANSLATE_NOOP("QShortcut", "Screensaver") },
478 { Qt::Key_WWW, QT_TRANSLATE_NOOP("QShortcut", "WWW") },
479 { Qt::Key_Sleep, QT_TRANSLATE_NOOP("QShortcut", "Sleep") },
480 { Qt::Key_LightBulb, QT_TRANSLATE_NOOP("QShortcut", "LightBulb") },
481 { Qt::Key_Shop, QT_TRANSLATE_NOOP("QShortcut", "Shop") },
482 { Qt::Key_History, QT_TRANSLATE_NOOP("QShortcut", "History") },
483 { Qt::Key_AddFavorite, QT_TRANSLATE_NOOP("QShortcut", "Add Favorite") },
484 { Qt::Key_HotLinks, QT_TRANSLATE_NOOP("QShortcut", "Hot Links") },
485 { Qt::Key_BrightnessAdjust, QT_TRANSLATE_NOOP("QShortcut", "Adjust Brightness") },
486 { Qt::Key_Finance, QT_TRANSLATE_NOOP("QShortcut", "Finance") },
487 { Qt::Key_Community, QT_TRANSLATE_NOOP("QShortcut", "Community") },
488 { Qt::Key_AudioRewind, QT_TRANSLATE_NOOP("QShortcut", "Media Rewind") },
489 { Qt::Key_BackForward, QT_TRANSLATE_NOOP("QShortcut", "Back Forward") },
490 { Qt::Key_ApplicationLeft, QT_TRANSLATE_NOOP("QShortcut", "Application Left") },
491 { Qt::Key_ApplicationRight, QT_TRANSLATE_NOOP("QShortcut", "Application Right") },
492 { Qt::Key_Book, QT_TRANSLATE_NOOP("QShortcut", "Book") },
493 { Qt::Key_CD, QT_TRANSLATE_NOOP("QShortcut", "CD") },
494 { Qt::Key_Calculator, QT_TRANSLATE_NOOP("QShortcut", "Calculator") },
495 { Qt::Key_Calendar, QT_TRANSLATE_NOOP("QShortcut", "Calendar") },
496 { Qt::Key_Clear, QT_TRANSLATE_NOOP("QShortcut", "Clear") },
497 { Qt::Key_ClearGrab, QT_TRANSLATE_NOOP("QShortcut", "Clear Grab") },
498 { Qt::Key_Close, QT_TRANSLATE_NOOP("QShortcut", "Close") },
499 { Qt::Key_ContrastAdjust, QT_TRANSLATE_NOOP("QShortcut", "Adjust contrast") },
500 { Qt::Key_Copy, QT_TRANSLATE_NOOP("QShortcut", "Copy") },
501 { Qt::Key_Cut, QT_TRANSLATE_NOOP("QShortcut", "Cut") },
502 { Qt::Key_Display, QT_TRANSLATE_NOOP("QShortcut", "Display") },
503 { Qt::Key_DOS, QT_TRANSLATE_NOOP("QShortcut", "DOS") },
504 { Qt::Key_Documents, QT_TRANSLATE_NOOP("QShortcut", "Documents") },
505 { Qt::Key_Excel, QT_TRANSLATE_NOOP("QShortcut", "Spreadsheet") },
506 { Qt::Key_Explorer, QT_TRANSLATE_NOOP("QShortcut", "Browser") },
507 { Qt::Key_Game, QT_TRANSLATE_NOOP("QShortcut", "Game") },
508 { Qt::Key_Go, QT_TRANSLATE_NOOP("QShortcut", "Go") },
509 { Qt::Key_iTouch, QT_TRANSLATE_NOOP("QShortcut", "iTouch") },
510 { Qt::Key_LogOff, QT_TRANSLATE_NOOP("QShortcut", "Logoff") },
511 { Qt::Key_Market, QT_TRANSLATE_NOOP("QShortcut", "Market") },
512 { Qt::Key_Meeting, QT_TRANSLATE_NOOP("QShortcut", "Meeting") },
513 { Qt::Key_Memo, QT_TRANSLATE_NOOP("QShortcut", "Memo") },
514 { Qt::Key_MenuKB, QT_TRANSLATE_NOOP("QShortcut", "Keyboard Menu") },
515 { Qt::Key_MenuPB, QT_TRANSLATE_NOOP("QShortcut", "Menu PB") },
516 { Qt::Key_MySites, QT_TRANSLATE_NOOP("QShortcut", "My Sites") },
517 { Qt::Key_News, QT_TRANSLATE_NOOP("QShortcut", "News") },
518 { Qt::Key_OfficeHome, QT_TRANSLATE_NOOP("QShortcut", "Home Office") },
519 { Qt::Key_Option, QT_TRANSLATE_NOOP("QShortcut", "Option") },
520 { Qt::Key_Paste, QT_TRANSLATE_NOOP("QShortcut", "Paste") },
521 { Qt::Key_Phone, QT_TRANSLATE_NOOP("QShortcut", "Phone") },
522 { Qt::Key_Reply, QT_TRANSLATE_NOOP("QShortcut", "Reply") },
523 { Qt::Key_Reload, QT_TRANSLATE_NOOP("QShortcut", "Reload") },
524 { Qt::Key_RotateWindows, QT_TRANSLATE_NOOP("QShortcut", "Rotate Windows") },
525 { Qt::Key_RotationPB, QT_TRANSLATE_NOOP("QShortcut", "Rotation PB") },
526 { Qt::Key_RotationKB, QT_TRANSLATE_NOOP("QShortcut", "Rotation KB") },
527 { Qt::Key_Save, QT_TRANSLATE_NOOP("QShortcut", "Save") },
528 { Qt::Key_Send, QT_TRANSLATE_NOOP("QShortcut", "Send") },
529 { Qt::Key_Spell, QT_TRANSLATE_NOOP("QShortcut", "Spellchecker") },
530 { Qt::Key_SplitScreen, QT_TRANSLATE_NOOP("QShortcut", "Split Screen") },
531 { Qt::Key_Support, QT_TRANSLATE_NOOP("QShortcut", "Support") },
532 { Qt::Key_TaskPane, QT_TRANSLATE_NOOP("QShortcut", "Task Panel") },
533 { Qt::Key_Terminal, QT_TRANSLATE_NOOP("QShortcut", "Terminal") },
534 { Qt::Key_ToDoList, QT_TRANSLATE_NOOP("QShortcut", "To-do list") },
535 { Qt::Key_Tools, QT_TRANSLATE_NOOP("QShortcut", "Tools") },
536 { Qt::Key_Travel, QT_TRANSLATE_NOOP("QShortcut", "Travel") },
537 { Qt::Key_Video, QT_TRANSLATE_NOOP("QShortcut", "Video") },
538 { Qt::Key_Word, QT_TRANSLATE_NOOP("QShortcut", "Word Processor") },
539 { Qt::Key_Xfer, QT_TRANSLATE_NOOP("QShortcut", "XFer") },
540 { Qt::Key_ZoomIn, QT_TRANSLATE_NOOP("QShortcut", "Zoom In") },
541 { Qt::Key_ZoomOut, QT_TRANSLATE_NOOP("QShortcut", "Zoom Out") },
542 { Qt::Key_Away, QT_TRANSLATE_NOOP("QShortcut", "Away") },
543 { Qt::Key_Messenger, QT_TRANSLATE_NOOP("QShortcut", "Messenger") },
544 { Qt::Key_WebCam, QT_TRANSLATE_NOOP("QShortcut", "WebCam") },
545 { Qt::Key_MailForward, QT_TRANSLATE_NOOP("QShortcut", "Mail Forward") },
546 { Qt::Key_Pictures, QT_TRANSLATE_NOOP("QShortcut", "Pictures") },
547 { Qt::Key_Music, QT_TRANSLATE_NOOP("QShortcut", "Music") },
548 { Qt::Key_Battery, QT_TRANSLATE_NOOP("QShortcut", "Battery") },
549 { Qt::Key_Bluetooth, QT_TRANSLATE_NOOP("QShortcut", "Bluetooth") },
550 { Qt::Key_WLAN, QT_TRANSLATE_NOOP("QShortcut", "Wireless") },
551 { Qt::Key_UWB, QT_TRANSLATE_NOOP("QShortcut", "Ultra Wide Band") },
552 { Qt::Key_AudioForward, QT_TRANSLATE_NOOP("QShortcut", "Media Fast Forward") },
553 { Qt::Key_AudioRepeat, QT_TRANSLATE_NOOP("QShortcut", "Audio Repeat") },
554 { Qt::Key_AudioRandomPlay, QT_TRANSLATE_NOOP("QShortcut", "Audio Random Play") },
555 { Qt::Key_Subtitle, QT_TRANSLATE_NOOP("QShortcut", "Subtitle") },
556 { Qt::Key_AudioCycleTrack, QT_TRANSLATE_NOOP("QShortcut", "Audio Cycle Track") },
557 { Qt::Key_Time, QT_TRANSLATE_NOOP("QShortcut", "Time") },
558 { Qt::Key_Hibernate, QT_TRANSLATE_NOOP("QShortcut", "Hibernate") },
559 { Qt::Key_View, QT_TRANSLATE_NOOP("QShortcut", "View") },
560 { Qt::Key_TopMenu, QT_TRANSLATE_NOOP("QShortcut", "Top Menu") },
561 { Qt::Key_PowerDown, QT_TRANSLATE_NOOP("QShortcut", "Power Down") },
562 { Qt::Key_Suspend, QT_TRANSLATE_NOOP("QShortcut", "Suspend") },
563
564 { Qt::Key_MicMute, QT_TRANSLATE_NOOP("QShortcut", "Microphone Mute") },
565
566 { Qt::Key_Red, QT_TRANSLATE_NOOP("QShortcut", "Red") },
567 { Qt::Key_Green, QT_TRANSLATE_NOOP("QShortcut", "Green") },
568 { Qt::Key_Yellow, QT_TRANSLATE_NOOP("QShortcut", "Yellow") },
569 { Qt::Key_Blue, QT_TRANSLATE_NOOP("QShortcut", "Blue") },
570
571 { Qt::Key_ChannelUp, QT_TRANSLATE_NOOP("QShortcut", "Channel Up") },
572 { Qt::Key_ChannelDown, QT_TRANSLATE_NOOP("QShortcut", "Channel Down") },
573
574 { Qt::Key_Guide, QT_TRANSLATE_NOOP("QShortcut", "Guide") },
575 { Qt::Key_Info, QT_TRANSLATE_NOOP("QShortcut", "Info") },
576 { Qt::Key_Settings, QT_TRANSLATE_NOOP("QShortcut", "Settings") },
577
578 { Qt::Key_MicVolumeUp, QT_TRANSLATE_NOOP("QShortcut", "Microphone Volume Up") },
579 { Qt::Key_MicVolumeDown, QT_TRANSLATE_NOOP("QShortcut", "Microphone Volume Down") },
580
581 { Qt::Key_Keyboard, QT_TRANSLATE_NOOP("QShortcut", "Keyboard") },
582
583 { Qt::Key_New, QT_TRANSLATE_NOOP("QShortcut", "New") },
584 { Qt::Key_Open, QT_TRANSLATE_NOOP("QShortcut", "Open") },
585 { Qt::Key_Find, QT_TRANSLATE_NOOP("QShortcut", "Find") },
586 { Qt::Key_Undo, QT_TRANSLATE_NOOP("QShortcut", "Undo") },
587 { Qt::Key_Redo, QT_TRANSLATE_NOOP("QShortcut", "Redo") },
588
589 // --------------------------------------------------------------
590 // More consistent namings
591 { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print Screen") },
592 { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "Page Up") },
593 { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "Page Down") },
594 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "Caps Lock") },
595 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Num Lock") },
596 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Number Lock") },
597 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "Scroll Lock") },
598 { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Insert") },
599 { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Delete") },
600 { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Escape") },
601 { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "System Request") },
602
603 // --------------------------------------------------------------
604 // Keypad navigation keys
605 { Qt::Key_Select, QT_TRANSLATE_NOOP("QShortcut", "Select") },
606 { Qt::Key_Yes, QT_TRANSLATE_NOOP("QShortcut", "Yes") },
607 { Qt::Key_No, QT_TRANSLATE_NOOP("QShortcut", "No") },
608
609 // --------------------------------------------------------------
610 // Device keys
611 { Qt::Key_Context1, QT_TRANSLATE_NOOP("QShortcut", "Context1") },
612 { Qt::Key_Context2, QT_TRANSLATE_NOOP("QShortcut", "Context2") },
613 { Qt::Key_Context3, QT_TRANSLATE_NOOP("QShortcut", "Context3") },
614 { Qt::Key_Context4, QT_TRANSLATE_NOOP("QShortcut", "Context4") },
615 //: Button to start a call (note: a separate button is used to end the call)
616 { Qt::Key_Call, QT_TRANSLATE_NOOP("QShortcut", "Call") },
617 //: Button to end a call (note: a separate button is used to start the call)
618 { Qt::Key_Hangup, QT_TRANSLATE_NOOP("QShortcut", "Hangup") },
619 //: Button that will hang up if we're in call, or make a call if we're not.
620 { Qt::Key_ToggleCallHangup, QT_TRANSLATE_NOOP("QShortcut", "Toggle Call/Hangup") },
621 { Qt::Key_Flip, QT_TRANSLATE_NOOP("QShortcut", "Flip") },
622 //: Button to trigger voice dialing
623 { Qt::Key_VoiceDial, QT_TRANSLATE_NOOP("QShortcut", "Voice Dial") },
624 //: Button to redial the last number called
625 { Qt::Key_LastNumberRedial, QT_TRANSLATE_NOOP("QShortcut", "Last Number Redial") },
626 //: Button to trigger the camera shutter (take a picture)
627 { Qt::Key_Camera, QT_TRANSLATE_NOOP("QShortcut", "Camera Shutter") },
628 //: Button to focus the camera
629 { Qt::Key_CameraFocus, QT_TRANSLATE_NOOP("QShortcut", "Camera Focus") },
630
631 // --------------------------------------------------------------
632 // Japanese keyboard support
633 { Qt::Key_Kanji, QT_TRANSLATE_NOOP("QShortcut", "Kanji") },
634 { Qt::Key_Muhenkan, QT_TRANSLATE_NOOP("QShortcut", "Muhenkan") },
635 { Qt::Key_Henkan, QT_TRANSLATE_NOOP("QShortcut", "Henkan") },
636 { Qt::Key_Romaji, QT_TRANSLATE_NOOP("QShortcut", "Romaji") },
637 { Qt::Key_Hiragana, QT_TRANSLATE_NOOP("QShortcut", "Hiragana") },
638 { Qt::Key_Katakana, QT_TRANSLATE_NOOP("QShortcut", "Katakana") },
639 { Qt::Key_Hiragana_Katakana,QT_TRANSLATE_NOOP("QShortcut", "Hiragana Katakana") },
640 { Qt::Key_Zenkaku, QT_TRANSLATE_NOOP("QShortcut", "Zenkaku") },
641 { Qt::Key_Hankaku, QT_TRANSLATE_NOOP("QShortcut", "Hankaku") },
642 { Qt::Key_Zenkaku_Hankaku, QT_TRANSLATE_NOOP("QShortcut", "Zenkaku Hankaku") },
643 { Qt::Key_Touroku, QT_TRANSLATE_NOOP("QShortcut", "Touroku") },
644 { Qt::Key_Massyo, QT_TRANSLATE_NOOP("QShortcut", "Massyo") },
645 { Qt::Key_Kana_Lock, QT_TRANSLATE_NOOP("QShortcut", "Kana Lock") },
646 { Qt::Key_Kana_Shift, QT_TRANSLATE_NOOP("QShortcut", "Kana Shift") },
647 { Qt::Key_Eisu_Shift, QT_TRANSLATE_NOOP("QShortcut", "Eisu Shift") },
648 { Qt::Key_Eisu_toggle, QT_TRANSLATE_NOOP("QShortcut", "Eisu toggle") },
649 { Qt::Key_Codeinput, QT_TRANSLATE_NOOP("QShortcut", "Code input") },
650 { Qt::Key_MultipleCandidate,QT_TRANSLATE_NOOP("QShortcut", "Multiple Candidate") },
651 { Qt::Key_PreviousCandidate,QT_TRANSLATE_NOOP("QShortcut", "Previous Candidate") },
652
653 // --------------------------------------------------------------
654 // Korean keyboard support
655 { Qt::Key_Hangul, QT_TRANSLATE_NOOP("QShortcut", "Hangul") },
656 { Qt::Key_Hangul_Start, QT_TRANSLATE_NOOP("QShortcut", "Hangul Start") },
657 { Qt::Key_Hangul_End, QT_TRANSLATE_NOOP("QShortcut", "Hangul End") },
658 { Qt::Key_Hangul_Hanja, QT_TRANSLATE_NOOP("QShortcut", "Hangul Hanja") },
659 { Qt::Key_Hangul_Jamo, QT_TRANSLATE_NOOP("QShortcut", "Hangul Jamo") },
660 { Qt::Key_Hangul_Romaja, QT_TRANSLATE_NOOP("QShortcut", "Hangul Romaja") },
661 { Qt::Key_Hangul_Jeonja, QT_TRANSLATE_NOOP("QShortcut", "Hangul Jeonja") },
662 { Qt::Key_Hangul_Banja, QT_TRANSLATE_NOOP("QShortcut", "Hangul Banja") },
663 { Qt::Key_Hangul_PreHanja, QT_TRANSLATE_NOOP("QShortcut", "Hangul PreHanja") },
664 { Qt::Key_Hangul_PostHanja,QT_TRANSLATE_NOOP("QShortcut", "Hangul PostHanja") },
665 { Qt::Key_Hangul_Special, QT_TRANSLATE_NOOP("QShortcut", "Hangul Special") },
666
667 // --------------------------------------------------------------
668 // Miscellaneous keys
669 { Qt::Key_Cancel, QT_TRANSLATE_NOOP("QShortcut", "Cancel") },
670 { Qt::Key_Printer, QT_TRANSLATE_NOOP("QShortcut", "Printer") },
671 { Qt::Key_Execute, QT_TRANSLATE_NOOP("QShortcut", "Execute") },
672 { Qt::Key_Play, QT_TRANSLATE_NOOP("QShortcut", "Play") },
673 { Qt::Key_Zoom, QT_TRANSLATE_NOOP("QShortcut", "Zoom") },
674 { Qt::Key_Exit, QT_TRANSLATE_NOOP("QShortcut", "Exit") },
675 { Qt::Key_TouchpadToggle, QT_TRANSLATE_NOOP("QShortcut", "Touchpad Toggle") },
676 { Qt::Key_TouchpadOn, QT_TRANSLATE_NOOP("QShortcut", "Touchpad On") },
677 { Qt::Key_TouchpadOff, QT_TRANSLATE_NOOP("QShortcut", "Touchpad Off") },
678 { Qt::Key_Shift, QT_TRANSLATE_NOOP("QShortcut", "Shift") },
679 { Qt::Key_Control, QT_TRANSLATE_NOOP("QShortcut", "Control") },
680 { Qt::Key_Alt, QT_TRANSLATE_NOOP("QShortcut", "Alt") },
681 { Qt::Key_Meta, QT_TRANSLATE_NOOP("QShortcut", "Meta") },
682
684static constexpr int numKeyNames = sizeof keyname / sizeof *keyname;
685
686/*!
687 \enum QKeySequence::StandardKey
688 \since 4.2
689
690 This enum represent standard key bindings. They can be used to
691 assign platform dependent keyboard shortcuts to a QAction.
692
693 Note that the key bindings are platform dependent. The currently
694 bound shortcuts can be queried using keyBindings().
695
696 \value AddTab Add new tab.
697 \value Back Navigate back.
698 \value Backspace Delete previous character.
699 \value Bold Bold text.
700 \value Close Close document/tab.
701 \value Copy Copy.
702 \value Cut Cut.
703 \value Delete Delete.
704 \value DeleteEndOfLine Delete end of line.
705 \value DeleteEndOfWord Delete word from the end of the cursor.
706 \value DeleteStartOfWord Delete the beginning of a word up to the cursor.
707 \value DeleteCompleteLine Delete the entire line.
708 \value Find Find in document.
709 \value FindNext Find next result.
710 \value FindPrevious Find previous result.
711 \value Forward Navigate forward.
712 \value HelpContents Open help contents.
713 \value InsertLineSeparator Insert a new line.
714 \value InsertParagraphSeparator Insert a new paragraph.
715 \value Italic Italic text.
716 \value MoveToEndOfBlock Move cursor to end of block. This shortcut is only used on Apple platforms.
717 \value MoveToEndOfDocument Move cursor to end of document.
718 \value MoveToEndOfLine Move cursor to end of line.
719 \value MoveToNextChar Move cursor to next character.
720 \value MoveToNextLine Move cursor to next line.
721 \value MoveToNextPage Move cursor to next page.
722 \value MoveToNextWord Move cursor to next word.
723 \value MoveToPreviousChar Move cursor to previous character.
724 \value MoveToPreviousLine Move cursor to previous line.
725 \value MoveToPreviousPage Move cursor to previous page.
726 \value MoveToPreviousWord Move cursor to previous word.
727 \value MoveToStartOfBlock Move cursor to start of a block. This shortcut is only used on Apple platforms.
728 \value MoveToStartOfDocument Move cursor to start of document.
729 \value MoveToStartOfLine Move cursor to start of line.
730 \value New Create new document.
731 \value NextChild Navigate to next tab or child window.
732 \value Open Open document.
733 \value Paste Paste.
734 \value Preferences Open the preferences dialog.
735 \value PreviousChild Navigate to previous tab or child window.
736 \value Print Print document.
737 \value Quit Quit the application.
738 \value Redo Redo.
739 \value Refresh Refresh or reload current document.
740 \value Replace Find and replace.
741 \value SaveAs Save document after prompting the user for a file name.
742 \value Save Save document.
743 \value SelectAll Select all text.
744 \value Deselect Deselect text. Since 5.1
745 \value SelectEndOfBlock Extend selection to the end of a text block. This shortcut is only used on Apple platforms.
746 \value SelectEndOfDocument Extend selection to end of document.
747 \value SelectEndOfLine Extend selection to end of line.
748 \value SelectNextChar Extend selection to next character.
749 \value SelectNextLine Extend selection to next line.
750 \value SelectNextPage Extend selection to next page.
751 \value SelectNextWord Extend selection to next word.
752 \value SelectPreviousChar Extend selection to previous character.
753 \value SelectPreviousLine Extend selection to previous line.
754 \value SelectPreviousPage Extend selection to previous page.
755 \value SelectPreviousWord Extend selection to previous word.
756 \value SelectStartOfBlock Extend selection to the start of a text block. This shortcut is only used on Apple platforms.
757 \value SelectStartOfDocument Extend selection to start of document.
758 \value SelectStartOfLine Extend selection to start of line.
759 \value Underline Underline text.
760 \value Undo Undo.
761 \value UnknownKey Unbound key.
762 \value WhatsThis Activate "what's this".
763 \value ZoomIn Zoom in.
764 \value ZoomOut Zoom out.
765 \value FullScreen Toggle the window state to/from full screen.
766 \value Cancel Cancel the current operation.
767*/
768
769/*!
770 \fn QKeySequence &QKeySequence::operator=(QKeySequence &&other)
771
772 Move-assigns \a other to this QKeySequence instance.
773
774 \since 5.2
775*/
776
777/*!
778 \since 4.2
779
780 Constructs a QKeySequence object for the given \a key.
781 The result will depend on the currently running platform.
782
783 The resulting object will be based on the first element in the
784 list of key bindings for the \a key.
785*/
786QKeySequence::QKeySequence(StandardKey key)
787{
788 const QList <QKeySequence> bindings = keyBindings(key);
789 //pick only the first/primary shortcut from current bindings
790 if (!bindings.isEmpty()) {
791 d = bindings.constFirst().d;
792 d->ref.ref();
793 }
794 else
795 d = new QKeySequencePrivate();
796}
797
798
799/*!
800 Constructs an empty key sequence.
801*/
802QKeySequence::QKeySequence()
803{
804 Q_CONSTINIT static QKeySequencePrivate shared_empty;
805 d = &shared_empty;
806 d->ref.ref();
807}
808
809/*!
810 Creates a key sequence from the \a key string, based on \a format.
811
812 For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl",
813 "Shift", "Alt" and "Meta" are recognized, as well as their
814 translated equivalents in the "QShortcut" context (using
815 QObject::tr()).
816
817 Up to four key codes may be entered by separating them with
818 commas, e.g. "Alt+X,Ctrl+S,Q".
819
820 This constructor is typically used with \l{QObject::tr()}{tr}(), so
821 that shortcut keys can be replaced in translations:
822
823 \snippet code/src_gui_kernel_qkeysequence.cpp 2
824
825 Note the "File|Open" translator comment. It is by no means
826 necessary, but it provides some context for the human translator.
827*/
828QKeySequence::QKeySequence(const QString &key, QKeySequence::SequenceFormat format)
829{
830 d = new QKeySequencePrivate();
831 assign(key, format);
832}
833
834static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Change docs and ctor impl below");
835/*!
836 Constructs a key sequence with up to 4 keys \a k1, \a k2,
837 \a k3 and \a k4.
838
839 The key codes are listed in Qt::Key and can be combined with
840 modifiers (see Qt::KeyboardModifier) such as Qt::ShiftModifier,
841 Qt::ControlModifier, Qt::AltModifier, or Qt::MetaModifier.
842*/
843QKeySequence::QKeySequence(int k1, int k2, int k3, int k4)
844{
845 d = new QKeySequencePrivate();
846 d->key[0] = k1;
847 d->key[1] = k2;
848 d->key[2] = k3;
849 d->key[3] = k4;
850}
851
852/*!
853 Constructs a key sequence with up to 4 keys \a k1, \a k2,
854 \a k3 and \a k4.
855
856 \sa QKeyCombination
857*/
858QKeySequence::QKeySequence(QKeyCombination k1, QKeyCombination k2, QKeyCombination k3, QKeyCombination k4)
859 : QKeySequence(k1.toCombined(), k2.toCombined(), k3.toCombined(), k4.toCombined())
860{
861}
862
863/*!
864 Copy constructor. Makes a copy of \a keysequence.
865 */
866QKeySequence::QKeySequence(const QKeySequence& keysequence)
867 : d(keysequence.d)
868{
869 d->ref.ref();
870}
871
872/*!
873 \since 4.2
874
875 Returns a list of key bindings for the given \a key.
876 The result of calling this function will vary based on the target platform.
877 The first element of the list indicates the primary shortcut for the given platform.
878 If the result contains more than one result, these can
879 be considered alternative shortcuts on the same platform for the given \a key.
880*/
881QList<QKeySequence> QKeySequence::keyBindings(StandardKey key)
882{
883 return QGuiApplicationPrivate::platformTheme()->keyBindings(key);
884}
885
886/*!
887 Destroys the key sequence.
888 */
889QKeySequence::~QKeySequence()
890{
891 if (!d->ref.deref())
892 delete d;
893}
894
895/*!
896 \internal
897 KeySequences should never be modified, but rather just created.
898 Internally though we do need to modify to keep pace in event
899 delivery.
900*/
901
902void QKeySequence::setKey(QKeyCombination key, int index)
903{
904 Q_ASSERT_X(index >= 0 && index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::setKey", "index out of range");
905 qAtomicDetach(d);
906 d->key[index] = key.toCombined();
907}
908
909static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Change docs below");
910/*!
911 Returns the number of keys in the key sequence.
912 The maximum is 4.
913 */
914int QKeySequence::count() const
915{
916 return int(std::distance(d->key, std::find(d->key, d->key + QKeySequencePrivate::MaxKeyCount, 0)));
917}
918
919
920/*!
921 Returns \c true if the key sequence is empty; otherwise returns
922 false.
923*/
924bool QKeySequence::isEmpty() const
925{
926 return !d->key[0];
927}
928
929
930/*!
931 Returns the shortcut key sequence for the mnemonic in \a text,
932 or an empty key sequence if no mnemonics are found.
933
934 For example, mnemonic("E&xit") returns \c{Qt::ALT+Qt::Key_X},
935 mnemonic("&Quit") returns \c{ALT+Key_Q}, and mnemonic("Quit")
936 returns an empty QKeySequence.
937*/
938QKeySequence QKeySequence::mnemonic(const QString &text)
939{
940 QKeySequence ret;
941
942 const bool mnemonicsEnabled = qt_sequence_auto_mnemonic_override.value_or(
943 QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MnemonicsEnabled).toBool());
944 if (!mnemonicsEnabled)
945 return ret;
946
947 bool found = false;
948 qsizetype p = 0;
949 while (p >= 0) {
950 p = text.indexOf(u'&', p) + 1;
951 if (p <= 0 || p >= (int)text.size())
952 break;
953 if (text.at(p) != u'&') {
954 QChar c = text.at(p);
955 if (c.isPrint()) {
956 if (!found) {
957 c = c.toUpper();
958 ret = QKeySequence(QKeyCombination(Qt::ALT, Qt::Key(c.unicode())));
959#ifdef QT_NO_DEBUG
960 return ret;
961#else
962 found = true;
963 } else {
964 qWarning("QKeySequence::mnemonic: \"%s\" contains multiple occurrences of '&'", qPrintable(text));
965#endif
966 }
967 }
968 }
969 p++;
970 }
971 return ret;
972}
973
974/*!
975 \fn int QKeySequence::assign(const QString &keys)
976
977 Adds the given \a keys to the key sequence. \a keys may
978 contain up to four key codes, provided they are separated by a
979 comma; for example, "Alt+X,Ctrl+S,Z". The return value is the
980 number of key codes added.
981 \a keys should be in NativeText format.
982*/
983int QKeySequence::assign(const QString &ks)
984{
985 return assign(ks, NativeText);
986}
987
988/*!
989 \fn int QKeySequence::assign(const QString &keys, QKeySequence::SequenceFormat format)
990 \since 4.7
991
992 Adds the given \a keys to the key sequence (based on \a format).
993 \a keys may contain up to four key codes, provided they are
994 separated by a comma; for example, "Alt+X,Ctrl+S,Z". The return
995 value is the number of key codes added.
996*/
997int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
998{
999 QString keyseq = ks;
1000 int n = 0;
1001 qsizetype p = 0, diff = 0;
1002
1003 // Run through the whole string, but stop
1004 // if we have MaxKeyCount keys before the end.
1005 while (keyseq.size() && n < QKeySequencePrivate::MaxKeyCount) {
1006 // We MUST use something to separate each sequence, and space
1007 // does not cut it, since some of the key names have space
1008 // in them.. (Let's hope no one translate with a comma in it:)
1009 p = keyseq.indexOf(u',');
1010 if (-1 != p) {
1011 if (p == keyseq.size() - 1) { // Last comma 'Ctrl+,'
1012 p = -1;
1013 } else {
1014 if (u',' == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'
1015 p++;
1016 if (u' ' == keyseq.at(p+1)) { // Space after comma
1017 diff = 1;
1018 p++;
1019 } else {
1020 diff = 0;
1021 }
1022 }
1023 }
1024 QString part = keyseq.left(-1 == p ? keyseq.size() : p - diff);
1025 keyseq = keyseq.right(-1 == p ? 0 : keyseq.size() - (p + 1));
1026 d->key[n] = QKeySequencePrivate::decodeString(std::move(part), format).toCombined();
1027 ++n;
1028 }
1029 return n;
1030}
1031
1034 QModifKeyName(int q, QChar n) : qt_key(q), name(n) { }
1035 QModifKeyName(int q, const QString &n) : qt_key(q), name(n) { }
1037 QString name;
1038};
1040
1041Q_GLOBAL_STATIC(QList<QModifKeyName>, globalModifs)
1042Q_GLOBAL_STATIC(QList<QModifKeyName>, globalPortableModifs)
1043
1044QKeyCombination QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceFormat format)
1045{
1046 Q_ASSERT(!accel.isEmpty());
1047
1048 int ret = 0;
1049 accel = std::move(accel).toLower();
1050 bool nativeText = (format == QKeySequence::NativeText);
1051
1052 QList<QModifKeyName> *gmodifs;
1053 if (nativeText) {
1054 gmodifs = globalModifs();
1055 if (gmodifs->isEmpty()) {
1056#if defined(Q_OS_APPLE)
1057 const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
1058 if (dontSwap)
1059 *gmodifs << QModifKeyName(Qt::META, QChar(kCommandUnicode));
1060 else
1061 *gmodifs << QModifKeyName(Qt::CTRL, QChar(kCommandUnicode));
1062 *gmodifs << QModifKeyName(Qt::ALT, QChar(kOptionUnicode));
1063 if (dontSwap)
1064 *gmodifs << QModifKeyName(Qt::CTRL, QChar(kControlUnicode));
1065 else
1066 *gmodifs << QModifKeyName(Qt::META, QChar(kControlUnicode));
1067 *gmodifs << QModifKeyName(Qt::SHIFT, QChar(kShiftUnicode));
1068#endif
1069 *gmodifs << QModifKeyName(Qt::CTRL, u"ctrl+"_s)
1070 << QModifKeyName(Qt::SHIFT, u"shift+"_s)
1071 << QModifKeyName(Qt::ALT, u"alt+"_s)
1072 << QModifKeyName(Qt::META, u"meta+"_s)
1073 << QModifKeyName(Qt::KeypadModifier, u"num+"_s);
1074 }
1075 } else {
1076 gmodifs = globalPortableModifs();
1077 if (gmodifs->isEmpty()) {
1078 *gmodifs << QModifKeyName(Qt::CTRL, u"ctrl+"_s)
1079 << QModifKeyName(Qt::SHIFT, u"shift+"_s)
1080 << QModifKeyName(Qt::ALT, u"alt+"_s)
1081 << QModifKeyName(Qt::META, u"meta+"_s)
1082 << QModifKeyName(Qt::KeypadModifier, u"num+"_s);
1083 }
1084 }
1085
1086
1087 QList<QModifKeyName> modifs;
1088 if (nativeText) {
1089 modifs << QModifKeyName(Qt::CTRL, QCoreApplication::translate("QShortcut", "Ctrl").toLower().append(u'+'))
1090 << QModifKeyName(Qt::SHIFT, QCoreApplication::translate("QShortcut", "Shift").toLower().append(u'+'))
1091 << QModifKeyName(Qt::ALT, QCoreApplication::translate("QShortcut", "Alt").toLower().append(u'+'))
1092 << QModifKeyName(Qt::META, QCoreApplication::translate("QShortcut", "Meta").toLower().append(u'+'))
1093 << QModifKeyName(Qt::KeypadModifier, QCoreApplication::translate("QShortcut", "Num").toLower().append(u'+'));
1094 }
1095 modifs += *gmodifs; // Test non-translated ones last
1096
1097 QString sl = accel;
1098#if defined(Q_OS_APPLE)
1099 for (int i = 0; i < modifs.size(); ++i) {
1100 const QModifKeyName &mkf = modifs.at(i);
1101 if (sl.contains(mkf.name)) {
1102 ret |= mkf.qt_key;
1103 accel.remove(mkf.name);
1104 sl = accel;
1105 }
1106 }
1107 if (accel.isEmpty()) // Incomplete, like for "Meta+Shift+"
1108 return Qt::Key_unknown;
1109#endif
1110
1111 int singlePlus = -1;
1112 qsizetype i = 0;
1113 qsizetype lastI = 0;
1114 while ((i = sl.indexOf(u'+', i + 1)) != -1) {
1115 QStringView sub = QStringView{ sl }.mid(lastI, i - lastI + 1);
1116 while (sub.size() > 1 && sub.at(0) == u' ') {
1117 sub = sub.mid(1);
1118 ++lastI;
1119 }
1120
1121 // If we get here the shortcuts contains at least one '+'. We break up
1122 // along the following strategy:
1123 // Meta+Ctrl++ ( "Meta+", "Ctrl+", "+" )
1124 // Super+Shift+A ( "Super+", "Shift+" )
1125 // 4+3+2=1 ( "4+", "3+" )
1126 // In other words, everything we try to handle HAS to be a modifier
1127 // except for a single '+' at the end of the string.
1128
1129 // Only '+' can have length 1.
1130 if (sub.size() == 1) {
1131 // Make sure we only encounter a single '+' at the end of the accel
1132 if (singlePlus >= 0)
1133 return Qt::Key_unknown;
1134 singlePlus = lastI;
1135 } else {
1136
1137 const auto identifyModifier = [&](QStringView sub) {
1138 for (int j = 0; j < modifs.size(); ++j) {
1139 const QModifKeyName &mkf = modifs.at(j);
1140 if (sub == mkf.name) {
1141 ret |= mkf.qt_key;
1142 return true; // Shortcut, since if we find another it would/should just be a dup
1143 }
1144 }
1145 return false;
1146 };
1147
1148 bool validModifier = identifyModifier(sub);
1149
1150 if (!validModifier) {
1151 // Try harder with slower code that trims spaces
1152 const QString cleanedSub = sub.toString().remove(u' ');
1153 validModifier = identifyModifier(cleanedSub);
1154 }
1155 if (!validModifier)
1156 return Qt::Key_unknown;
1157 }
1158 lastI = i + 1;
1159 }
1160
1161 qsizetype p = accel.lastIndexOf(u'+', singlePlus > 0 ? singlePlus - 1 : accel.size() - 1);
1162 QStringView accelRef(accel);
1163 if (p > 0)
1164 accelRef = accelRef.mid(p + 1);
1165
1166 while (accelRef.size() > 1 && accelRef.at(0) == u' ')
1167 accelRef = accelRef.mid(1);
1168 while (accelRef.size() > 1 && accelRef.endsWith(u' '))
1169 accelRef.chop(1);
1170
1171 int fnum = 0;
1172 if (accelRef.isEmpty())
1173 return Qt::Key_unknown;
1174 else if (accelRef.size() == 1) {
1175#if defined(Q_OS_APPLE)
1176 int qtKey = qtkeyForAppleSymbol(accelRef.at(0));
1177 if (qtKey != -1) {
1178 ret |= qtKey;
1179 } else
1180#endif
1181 {
1182 ret |= accelRef.at(0).toUpper().unicode();
1183 }
1184 } else if (accelRef.at(0) == u'f' && (fnum = accelRef.mid(1).toInt()) >= 1 && fnum <= 35) {
1185 ret |= Qt::Key_F1 + fnum - 1;
1186 } else {
1187 // For NativeText, check the translation table first,
1188 // if we don't find anything then try it out with just the untranlated stuff.
1189 // PortableText will only try the untranlated table.
1190 bool found = false;
1191 for (int tran = 0; tran < 2; ++tran) {
1192 if (!nativeText)
1193 ++tran;
1194 for (int i = 0; i < numKeyNames; ++i) {
1195 QString keyName(tran == 0
1196 ? QCoreApplication::translate("QShortcut", keyname[i].name)
1197 : QString::fromLatin1(keyname[i].name));
1198 if (accelRef == std::move(keyName).toLower()) {
1199 ret |= keyname[i].key;
1200 found = true;
1201 break;
1202 }
1203 }
1204 if (found)
1205 break;
1206 }
1207 // We couldn't translate the key.
1208 if (!found)
1209 return Qt::Key_unknown;
1210 }
1211 return QKeyCombination::fromCombined(ret);
1212}
1213
1214static inline void addKey(QString &str, const QString &theKey, QKeySequence::SequenceFormat format)
1215{
1216 if (!str.isEmpty()) {
1217 if (format == QKeySequence::NativeText) {
1218 //: Key separator in shortcut string
1219 str += QCoreApplication::translate("QShortcut", "+");
1220 } else {
1221 str += u'+';
1222 }
1223 }
1224
1225 str += theKey;
1226}
1227
1228QString QKeySequencePrivate::encodeString(QKeyCombination keyCombination, QKeySequence::SequenceFormat format)
1229{
1230 bool nativeText = (format == QKeySequence::NativeText);
1231 QString s;
1232
1233 const auto key = keyCombination.key();
1234
1235 // Handle -1 (Invalid Key) and Qt::Key_unknown gracefully
1236 if (keyCombination.toCombined() == -1 || key == Qt::Key_unknown)
1237 return s;
1238
1239 const auto modifiers = keyCombination.keyboardModifiers();
1240
1241#if defined(Q_OS_APPLE)
1242 if (nativeText) {
1243 // On Apple platforms the order (by default) is Meta, Alt, Shift, Control.
1244 // If the AA_MacDontSwapCtrlAndMeta is enabled, then the order
1245 // is Ctrl, Alt, Shift, Meta. The appleSymbolForQtKey helper does this swap
1246 // for us, which means that we have to adjust our order here.
1247 // The upshot is a lot more infrastructure to keep the number of
1248 // if tests down and the code relatively clean.
1249 static constexpr int ModifierOrder[] = { Qt::META, Qt::ALT, Qt::SHIFT, Qt::CTRL, 0 };
1250 static constexpr int QtKeyOrder[] = { Qt::Key_Meta, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Control, 0 };
1251 static constexpr int DontSwapModifierOrder[] = { Qt::CTRL, Qt::ALT, Qt::SHIFT, Qt::META, 0 };
1252 static constexpr int DontSwapQtKeyOrder[] = { Qt::Key_Control, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Meta, 0 };
1253 const int *modifierOrder;
1254 const int *qtkeyOrder;
1255 if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
1256 modifierOrder = DontSwapModifierOrder;
1257 qtkeyOrder = DontSwapQtKeyOrder;
1258 } else {
1259 modifierOrder = ModifierOrder;
1260 qtkeyOrder = QtKeyOrder;
1261 }
1262
1263 for (int i = 0; modifierOrder[i] != 0; ++i) {
1264 if (modifiers & modifierOrder[i])
1265 s += appleSymbolForQtKey(qtkeyOrder[i]);
1266 }
1267 } else
1268#endif
1269 {
1270 // On other systems the order is Meta, Control, Alt, Shift
1271 if (modifiers & Qt::MetaModifier)
1272 s = nativeText ? QCoreApplication::translate("QShortcut", "Meta") : QString::fromLatin1("Meta");
1273 if (modifiers & Qt::ControlModifier)
1274 addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Ctrl") : QString::fromLatin1("Ctrl"), format);
1275 if (modifiers & Qt::AltModifier)
1276 addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Alt") : QString::fromLatin1("Alt"), format);
1277 if (modifiers & Qt::ShiftModifier)
1278 addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Shift") : QString::fromLatin1("Shift"), format);
1279 }
1280 if (modifiers & Qt::KeypadModifier)
1281 addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Num") : QString::fromLatin1("Num"), format);
1282
1283 QString keyName = QKeySequencePrivate::keyName(key, format);
1284
1285#if defined(Q_OS_APPLE)
1286 if (nativeText)
1287 s += keyName;
1288 else
1289#endif
1290 addKey(s, keyName, format);
1291 return s;
1292}
1293
1294/*!
1295 \internal
1296 Returns the text representation of the key \a key, which can be used i.e.
1297 when the sequence is serialized. This does not take modifiers into account
1298 (see encodeString() for a version that does).
1299
1300 This static method is used by encodeString() and by the D-Bus menu exporter.
1301*/
1302QString QKeySequencePrivate::keyName(Qt::Key key, QKeySequence::SequenceFormat format)
1303{
1304 bool nativeText = (format == QKeySequence::NativeText);
1305 QString p;
1306
1307 if (nativeText && (key > 0x00 && key <= 0x1f)) {
1308 // Map C0 control codes to the corresponding Control Pictures
1309 p = QChar::fromUcs2(0x2400 + key);
1310 } else if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
1311 if (!QChar::requiresSurrogates(key)) {
1312 p = QChar::fromUcs2(key).toUpper();
1313 } else {
1314 p += QChar(QChar::highSurrogate(key));
1315 p += QChar(QChar::lowSurrogate(key));
1316 }
1317 } else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
1318 p = nativeText ? QCoreApplication::translate("QShortcut", "F%1").arg(key - Qt::Key_F1 + 1)
1319 : QString::fromLatin1("F%1").arg(key - Qt::Key_F1 + 1);
1320 } else if (key) {
1321 int i=0;
1322#if defined(Q_OS_APPLE)
1323 if (nativeText) {
1324 QChar ch = appleSymbolForQtKey(key);
1325 if (!ch.isNull())
1326 p = ch;
1327 else
1328 goto NonSymbol;
1329 } else
1330#endif
1331 {
1332#if defined(Q_OS_APPLE)
1333NonSymbol:
1334#endif
1335 while (i < numKeyNames) {
1336 if (key == keyname[i].key) {
1337 p = nativeText ? QCoreApplication::translate("QShortcut", keyname[i].name)
1338 : QString::fromLatin1(keyname[i].name);
1339 break;
1340 }
1341 ++i;
1342 }
1343 // If we can't find the actual translatable keyname,
1344 // fall back on the unicode representation of it...
1345 // Or else characters like Qt::Key_aring may not get displayed
1346 // (Really depends on you locale)
1347 if (i >= numKeyNames) {
1348 if (!QChar::requiresSurrogates(key)) {
1349 p = QChar::fromUcs2(key).toUpper();
1350 } else {
1351 p += QChar(QChar::highSurrogate(key));
1352 p += QChar(QChar::lowSurrogate(key));
1353 }
1354 }
1355 }
1356 }
1357 return p;
1358}
1359/*!
1360 Matches the sequence with \a seq. Returns ExactMatch if
1361 successful, PartialMatch if \a seq matches incompletely,
1362 and NoMatch if the sequences have nothing in common.
1363 Returns NoMatch if \a seq is shorter.
1364*/
1365QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
1366{
1367 uint userN = count(),
1368 seqN = seq.count();
1369
1370 if (userN > seqN)
1371 return NoMatch;
1372
1373 // If equal in length, we have a potential ExactMatch sequence,
1374 // else we already know it can only be partial.
1375 SequenceMatch match = (userN == seqN ? ExactMatch : PartialMatch);
1376
1377 for (uint i = 0; i < userN; ++i) {
1378 QKeyCombination userKey = (*this)[i],
1379 sequenceKey = seq[i];
1380 if (userKey != sequenceKey)
1381 return NoMatch;
1382 }
1383 return match;
1384}
1385
1386/*!
1387 Returns the key sequence as a QVariant
1388*/
1389QKeySequence::operator QVariant() const
1390{
1391 return QVariant::fromValue(*this);
1392}
1393
1394/*!
1395 Returns a reference to the element at position \a index in the key
1396 sequence. This can only be used to read an element.
1397 */
1398QKeyCombination QKeySequence::operator[](uint index) const
1399{
1400 Q_ASSERT_X(index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::operator[]", "index out of range");
1401 return QKeyCombination::fromCombined(d->key[index]);
1402}
1403
1404
1405/*!
1406 Assignment operator. Assigns the \a other key sequence to this
1407 object.
1408 */
1409QKeySequence &QKeySequence::operator=(const QKeySequence &other)
1410{
1411 qAtomicAssign(d, other.d);
1412 return *this;
1413}
1414
1415/*!
1416 \fn void QKeySequence::swap(QKeySequence &other)
1417 \since 4.8
1418 \memberswap{key sequence}
1419*/
1420
1421/*!
1422 \fn bool QKeySequence::operator!=(const QKeySequence &other) const
1423
1424 Returns \c true if this key sequence is not equal to the \a other
1425 key sequence; otherwise returns \c false.
1426*/
1427
1428
1429/*!
1430 Returns \c true if this key sequence is equal to the \a other
1431 key sequence; otherwise returns \c false.
1432 */
1433bool QKeySequence::operator==(const QKeySequence &other) const
1434{
1435 return (d->key[0] == other.d->key[0] &&
1436 d->key[1] == other.d->key[1] &&
1437 d->key[2] == other.d->key[2] &&
1438 d->key[3] == other.d->key[3]);
1439}
1440
1441/*!
1442 \since 5.6
1443 \qhashold{QKeySequence}
1444*/
1445size_t qHash(const QKeySequence &key, size_t seed) noexcept
1446{
1447 return qHashRange(key.d->key, key.d->key + QKeySequencePrivate::MaxKeyCount, seed);
1448}
1449
1450/*!
1451 Provides an arbitrary comparison of this key sequence and
1452 \a other key sequence. All that is guaranteed is that the
1453 operator returns \c false if both key sequences are equal and
1454 that (ks1 < ks2) == !( ks2 < ks1) if the key sequences
1455 are not equal.
1456
1457 This function is useful in some circumstances, for example
1458 if you want to use QKeySequence objects as keys in a QMap.
1459
1460 \sa operator==(), operator!=(), operator>(), operator<=(), operator>=()
1461*/
1462bool QKeySequence::operator< (const QKeySequence &other) const
1463{
1464 return std::lexicographical_compare(d->key, d->key + QKeySequencePrivate::MaxKeyCount,
1465 other.d->key, other.d->key + QKeySequencePrivate::MaxKeyCount);
1466}
1467
1468/*!
1469 \fn bool QKeySequence::operator> (const QKeySequence &other) const
1470
1471 Returns \c true if this key sequence is larger than the \a other key
1472 sequence; otherwise returns \c false.
1473
1474 \sa operator==(), operator!=(), operator<(), operator<=(), operator>=()
1475*/
1476
1477/*!
1478 \fn bool QKeySequence::operator<= (const QKeySequence &other) const
1479
1480 Returns \c true if this key sequence is smaller or equal to the
1481 \a other key sequence; otherwise returns \c false.
1482
1483 \sa operator==(), operator!=(), operator<(), operator>(), operator>=()
1484*/
1485
1486/*!
1487 \fn bool QKeySequence::operator>= (const QKeySequence &other) const
1488
1489 Returns \c true if this key sequence is larger or equal to the
1490 \a other key sequence; otherwise returns \c false.
1491
1492 \sa operator==(), operator!=(), operator<(), operator>(), operator<=()
1493*/
1494
1495/*!
1496 \internal
1497*/
1498bool QKeySequence::isDetached() const
1499{
1500 return d->ref.loadRelaxed() == 1;
1501}
1502
1503/*!
1504 \since 4.1
1505
1506 Return a string representation of the key sequence,
1507 based on \a format.
1508
1509 For example, the value Qt::CTRL+Qt::Key_O results in "Ctrl+O".
1510 If the key sequence has multiple key codes, each is separated
1511 by commas in the string returned, such as "Alt+X, Ctrl+Y, Z".
1512 The strings, "Ctrl", "Shift", etc. are translated using
1513 QObject::tr() in the "QShortcut" context.
1514
1515 If the key sequence has no keys, an empty string is returned.
1516
1517 On Apple platforms, the string returned resembles the sequence that is
1518 shown in the menu bar if \a format is
1519 QKeySequence::NativeText; otherwise, the string uses the
1520 "portable" format, suitable for writing to a file.
1521
1522 \sa fromString()
1523*/
1524QString QKeySequence::toString(SequenceFormat format) const
1525{
1526 QString finalString;
1527 // A standard string, with no translation or anything like that. In some ways it will
1528 // look like our latin case on Windows and X11
1529 int end = count();
1530 for (int i = 0; i < end; ++i) {
1531 finalString += d->encodeString(QKeyCombination::fromCombined(d->key[i]), format);
1532 finalString += ", "_L1;
1533 }
1534 finalString.truncate(finalString.size() - 2);
1535 return finalString;
1536}
1537
1538/*!
1539 \since 4.1
1540
1541 Return a QKeySequence from the string \a str based on \a format.
1542
1543 \sa toString()
1544*/
1545QKeySequence QKeySequence::fromString(const QString &str, SequenceFormat format)
1546{
1547 return QKeySequence(str, format);
1548}
1549
1550/*!
1551 \since 5.1
1552
1553 Return a list of QKeySequence from the string \a str based on \a format.
1554
1555 \sa fromString()
1556 \sa listToString()
1557*/
1558QList<QKeySequence> QKeySequence::listFromString(const QString &str, SequenceFormat format)
1559{
1560 QList<QKeySequence> result;
1561
1562 const QStringList strings = str.split("; "_L1);
1563 result.reserve(strings.size());
1564 for (const QString &string : strings) {
1565 result << fromString(string, format);
1566 }
1567
1568 return result;
1569}
1570
1571/*!
1572 \since 5.1
1573
1574 Return a string representation of \a list based on \a format.
1575
1576 \sa toString()
1577 \sa listFromString()
1578*/
1579QString QKeySequence::listToString(const QList<QKeySequence> &list, SequenceFormat format)
1580{
1581 QString result;
1582
1583 for (const QKeySequence &sequence : list) {
1584 result += sequence.toString(format);
1585 result += "; "_L1;
1586 }
1587 result.truncate(result.size() - 2);
1588
1589 return result;
1590}
1591
1592/*****************************************************************************
1593 QKeySequence stream functions
1594 *****************************************************************************/
1595#if !defined(QT_NO_DATASTREAM)
1596/*!
1597 \fn QDataStream &operator<<(QDataStream &stream, const QKeySequence &sequence)
1598 \relates QKeySequence
1599
1600 Writes the key \a sequence to the \a stream.
1601
1602 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1603*/
1604QDataStream &operator<<(QDataStream &s, const QKeySequence &keysequence)
1605{
1606 static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Forgot to adapt QDataStream &operator<<(QDataStream &s, const QKeySequence &keysequence) to new QKeySequence::MaxKeyCount");
1607 const bool extended = s.version() >= 5 && keysequence.count() > 1;
1608 s << quint32(extended ? 4 : 1) << quint32(keysequence.d->key[0]);
1609 if (extended) {
1610 s << quint32(keysequence.d->key[1])
1611 << quint32(keysequence.d->key[2])
1612 << quint32(keysequence.d->key[3]);
1613 }
1614 return s;
1615}
1616
1617
1618/*!
1619 \fn QDataStream &operator>>(QDataStream &stream, QKeySequence &sequence)
1620 \relates QKeySequence
1621
1622 Reads a key sequence from the \a stream into the key \a sequence.
1623
1624 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1625*/
1626QDataStream &operator>>(QDataStream &s, QKeySequence &keysequence)
1627{
1628 const quint32 MaxKeys = QKeySequencePrivate::MaxKeyCount;
1629 quint32 c;
1630 s >> c;
1631 quint32 keys[MaxKeys] = {0};
1632 for (uint i = 0; i < qMin(c, MaxKeys); ++i) {
1633 if (s.atEnd()) {
1634 qWarning("Premature EOF while reading QKeySequence");
1635 return s;
1636 }
1637 s >> keys[i];
1638 }
1639 qAtomicDetach(keysequence.d);
1640 std::copy(keys, keys + MaxKeys, QT_MAKE_CHECKED_ARRAY_ITERATOR(keysequence.d->key, MaxKeys));
1641 return s;
1642}
1643
1644#endif //QT_NO_DATASTREAM
1645
1646#ifndef QT_NO_DEBUG_STREAM
1647QDebug operator<<(QDebug dbg, const QKeySequence &p)
1648{
1649 QDebugStateSaver saver(dbg);
1650 dbg.nospace() << "QKeySequence(" << p.toString() << ')';
1651 return dbg;
1652}
1653#endif
1654
1655/*!
1656 \typedef QKeySequence::DataPtr
1657 \internal
1658*/
1659
1660 /*!
1661 \fn DataPtr &QKeySequence::data_ptr()
1662 \internal
1663*/
1664
1665QT_END_NAMESPACE
1666
1667#include "moc_qkeysequence.cpp"
static constexpr int MaxKeyCount
Combined button and popup list for selecting options.
int key
Q_DECLARE_TYPEINFO(QModifKeyName, Q_RELOCATABLE_TYPE)
static constexpr int numKeyNames
const char name[25]
QDebug Q_GUI_EXPORT & operator<<(QDebug &s, const QVectorPath &path)
QModifKeyName(int q, QChar n)
QModifKeyName(int q, const QString &n)