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