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