00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qkeysequence.h"
00025 #include "qkeysequence_p.h"
00026 #include "private/qapplication_p.h"
00027
00028 #ifndef QT_NO_SHORTCUT
00029
00030 #include "qshortcut.h"
00031 #include "qdebug.h"
00032 #ifndef QT_NO_REGEXP
00033 # include "qregexp.h"
00034 #endif
00035 #ifndef QT_NO_DATASTREAM
00036 # include "qdatastream.h"
00037 #endif
00038 #include "qvariant.h"
00039
00040 #ifdef Q_WS_MAC
00041 # include <private/qt_mac_p.h>
00042 # define QMAC_CTRL QChar(kCommandUnicode)
00043 # define QMAC_META QChar(kControlUnicode)
00044 # define QMAC_ALT QChar(kOptionUnicode)
00045 # define QMAC_SHIFT QChar(kShiftUnicode)
00046 #endif
00047
00048 #ifdef Q_WS_MAC
00049 static bool qt_sequence_no_mnemonics = true;
00050 #else
00051 static bool qt_sequence_no_mnemonics = false;
00052 #endif
00053 void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemonics = !b; }
00054
00196 static const struct {
00197 int key;
00198 const char* name;
00199 } keyname[] = {
00200 { Qt::Key_Space, QT_TRANSLATE_NOOP("QShortcut", "Space") },
00201 { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Esc") },
00202 { Qt::Key_Tab, QT_TRANSLATE_NOOP("QShortcut", "Tab") },
00203 { Qt::Key_Backtab, QT_TRANSLATE_NOOP("QShortcut", "Backtab") },
00204 { Qt::Key_Backspace, QT_TRANSLATE_NOOP("QShortcut", "Backspace") },
00205 { Qt::Key_Return, QT_TRANSLATE_NOOP("QShortcut", "Return") },
00206 { Qt::Key_Enter, QT_TRANSLATE_NOOP("QShortcut", "Enter") },
00207 { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Ins") },
00208 { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Del") },
00209 { Qt::Key_Pause, QT_TRANSLATE_NOOP("QShortcut", "Pause") },
00210 { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print") },
00211 { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "SysReq") },
00212 { Qt::Key_Home, QT_TRANSLATE_NOOP("QShortcut", "Home") },
00213 { Qt::Key_End, QT_TRANSLATE_NOOP("QShortcut", "End") },
00214 { Qt::Key_Left, QT_TRANSLATE_NOOP("QShortcut", "Left") },
00215 { Qt::Key_Up, QT_TRANSLATE_NOOP("QShortcut", "Up") },
00216 { Qt::Key_Right, QT_TRANSLATE_NOOP("QShortcut", "Right") },
00217 { Qt::Key_Down, QT_TRANSLATE_NOOP("QShortcut", "Down") },
00218 { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "PgUp") },
00219 { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "PgDown") },
00220 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "CapsLock") },
00221 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "NumLock") },
00222 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "ScrollLock") },
00223 { Qt::Key_Menu, QT_TRANSLATE_NOOP("QShortcut", "Menu") },
00224 { Qt::Key_Help, QT_TRANSLATE_NOOP("QShortcut", "Help") },
00225
00226
00227 { Qt::Key_Back, QT_TRANSLATE_NOOP("QShortcut", "Back") },
00228 { Qt::Key_Forward, QT_TRANSLATE_NOOP("QShortcut", "Forward") },
00229 { Qt::Key_Stop, QT_TRANSLATE_NOOP("QShortcut", "Stop") },
00230 { Qt::Key_Refresh, QT_TRANSLATE_NOOP("QShortcut", "Refresh") },
00231 { Qt::Key_VolumeDown, QT_TRANSLATE_NOOP("QShortcut", "Volume Down") },
00232 { Qt::Key_VolumeMute, QT_TRANSLATE_NOOP("QShortcut", "Volume Mute") },
00233 { Qt::Key_VolumeUp, QT_TRANSLATE_NOOP("QShortcut", "Volume Up") },
00234 { Qt::Key_BassBoost, QT_TRANSLATE_NOOP("QShortcut", "Bass Boost") },
00235 { Qt::Key_BassUp, QT_TRANSLATE_NOOP("QShortcut", "Bass Up") },
00236 { Qt::Key_BassDown, QT_TRANSLATE_NOOP("QShortcut", "Bass Down") },
00237 { Qt::Key_TrebleUp, QT_TRANSLATE_NOOP("QShortcut", "Treble Up") },
00238 { Qt::Key_TrebleDown, QT_TRANSLATE_NOOP("QShortcut", "Treble Down") },
00239 { Qt::Key_MediaPlay, QT_TRANSLATE_NOOP("QShortcut", "Media Play") },
00240 { Qt::Key_MediaStop, QT_TRANSLATE_NOOP("QShortcut", "Media Stop") },
00241 { Qt::Key_MediaPrevious,QT_TRANSLATE_NOOP("QShortcut", "Media Previous") },
00242 { Qt::Key_MediaNext, QT_TRANSLATE_NOOP("QShortcut", "Media Next") },
00243 { Qt::Key_MediaRecord, QT_TRANSLATE_NOOP("QShortcut", "Media Record") },
00244 { Qt::Key_HomePage, QT_TRANSLATE_NOOP("QShortcut", "Home Page") },
00245 { Qt::Key_Favorites, QT_TRANSLATE_NOOP("QShortcut", "Favorites") },
00246 { Qt::Key_Search, QT_TRANSLATE_NOOP("QShortcut", "Search") },
00247 { Qt::Key_Standby, QT_TRANSLATE_NOOP("QShortcut", "Standby") },
00248 { Qt::Key_OpenUrl, QT_TRANSLATE_NOOP("QShortcut", "Open URL") },
00249 { Qt::Key_LaunchMail, QT_TRANSLATE_NOOP("QShortcut", "Launch Mail") },
00250 { Qt::Key_LaunchMedia, QT_TRANSLATE_NOOP("QShortcut", "Launch Media") },
00251 { Qt::Key_Launch0, QT_TRANSLATE_NOOP("QShortcut", "Launch (0)") },
00252 { Qt::Key_Launch1, QT_TRANSLATE_NOOP("QShortcut", "Launch (1)") },
00253 { Qt::Key_Launch2, QT_TRANSLATE_NOOP("QShortcut", "Launch (2)") },
00254 { Qt::Key_Launch3, QT_TRANSLATE_NOOP("QShortcut", "Launch (3)") },
00255 { Qt::Key_Launch4, QT_TRANSLATE_NOOP("QShortcut", "Launch (4)") },
00256 { Qt::Key_Launch5, QT_TRANSLATE_NOOP("QShortcut", "Launch (5)") },
00257 { Qt::Key_Launch6, QT_TRANSLATE_NOOP("QShortcut", "Launch (6)") },
00258 { Qt::Key_Launch7, QT_TRANSLATE_NOOP("QShortcut", "Launch (7)") },
00259 { Qt::Key_Launch8, QT_TRANSLATE_NOOP("QShortcut", "Launch (8)") },
00260 { Qt::Key_Launch9, QT_TRANSLATE_NOOP("QShortcut", "Launch (9)") },
00261 { Qt::Key_LaunchA, QT_TRANSLATE_NOOP("QShortcut", "Launch (A)") },
00262 { Qt::Key_LaunchB, QT_TRANSLATE_NOOP("QShortcut", "Launch (B)") },
00263 { Qt::Key_LaunchC, QT_TRANSLATE_NOOP("QShortcut", "Launch (C)") },
00264 { Qt::Key_LaunchD, QT_TRANSLATE_NOOP("QShortcut", "Launch (D)") },
00265 { Qt::Key_LaunchE, QT_TRANSLATE_NOOP("QShortcut", "Launch (E)") },
00266 { Qt::Key_LaunchF, QT_TRANSLATE_NOOP("QShortcut", "Launch (F)") },
00267
00268
00269
00270 { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print Screen") },
00271 { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "Page Up") },
00272 { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "Page Down") },
00273 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "Caps Lock") },
00274 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Num Lock") },
00275 { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Number Lock") },
00276 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "Scroll Lock") },
00277 { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Insert") },
00278 { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Delete") },
00279 { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Escape") },
00280 { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "System Request") },
00281
00282
00283
00284 { Qt::Key_Select, QT_TRANSLATE_NOOP("QShortcut", "Select") },
00285 { Qt::Key_Yes, QT_TRANSLATE_NOOP("QShortcut", "Yes") },
00286 { Qt::Key_No, QT_TRANSLATE_NOOP("QShortcut", "No") },
00287
00288
00289
00290 { Qt::Key_Context1, QT_TRANSLATE_NOOP("QShortcut", "Context1") },
00291 { Qt::Key_Context2, QT_TRANSLATE_NOOP("QShortcut", "Context2") },
00292 { Qt::Key_Context3, QT_TRANSLATE_NOOP("QShortcut", "Context3") },
00293 { Qt::Key_Context4, QT_TRANSLATE_NOOP("QShortcut", "Context4") },
00294 { Qt::Key_Call, QT_TRANSLATE_NOOP("QShortcut", "Call") },
00295 { Qt::Key_Hangup, QT_TRANSLATE_NOOP("QShortcut", "Hangup") },
00296 { Qt::Key_Flip, QT_TRANSLATE_NOOP("QShortcut", "Flip") },
00297
00298
00299 { 0, 0 }
00300 };
00301
00302
00303
00304
00305 const QKeyBinding QKeySequencePrivate::keyBindings[] = {
00306
00307 {QKeySequence::Back, 0, Qt::Key_Backspace, QApplicationPrivate::KB_Win},
00308 {QKeySequence::Delete, 1, Qt::Key_Delete, QApplicationPrivate::KB_All},
00309 {QKeySequence::MoveToStartOfLine, 0, Qt::Key_Home, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00310 {QKeySequence::MoveToStartOfDocument, 0, Qt::Key_Home, QApplicationPrivate::KB_Mac},
00311 {QKeySequence::MoveToEndOfLine, 0, Qt::Key_End, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00312 {QKeySequence::MoveToEndOfDocument, 0, Qt::Key_End, QApplicationPrivate::KB_Mac},
00313 {QKeySequence::MoveToPreviousChar, 0, Qt::Key_Left, QApplicationPrivate::KB_All},
00314 {QKeySequence::MoveToPreviousLine, 0, Qt::Key_Up, QApplicationPrivate::KB_All},
00315 {QKeySequence::MoveToNextChar, 0, Qt::Key_Right, QApplicationPrivate::KB_All},
00316 {QKeySequence::MoveToNextLine, 0, Qt::Key_Down, QApplicationPrivate::KB_All},
00317 {QKeySequence::MoveToPreviousPage, 1, Qt::Key_PageUp, QApplicationPrivate::KB_All},
00318 {QKeySequence::MoveToNextPage, 1, Qt::Key_PageDown, QApplicationPrivate::KB_All},
00319 {QKeySequence::HelpContents, 0, Qt::Key_F1, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00320 {QKeySequence::FindNext, 0, Qt::Key_F3, QApplicationPrivate::KB_X11},
00321 {QKeySequence::FindNext, 1, Qt::Key_F3, QApplicationPrivate::KB_Win},
00322 {QKeySequence::Refresh, 0, Qt::Key_F5, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00323 {QKeySequence::Undo, 0, Qt::Key_F14, QApplicationPrivate::KB_X11},
00324 {QKeySequence::Copy, 0, Qt::Key_F16, QApplicationPrivate::KB_X11},
00325 {QKeySequence::Paste, 0, Qt::Key_F18, QApplicationPrivate::KB_X11},
00326 {QKeySequence::Cut, 0, Qt::Key_F20, QApplicationPrivate::KB_X11},
00327 {QKeySequence::PreviousChild, 0, Qt::Key_Back, QApplicationPrivate::KB_All},
00328 {QKeySequence::NextChild, 0, Qt::Key_Forward, QApplicationPrivate::KB_All},
00329 {QKeySequence::Forward, 0, Qt::SHIFT | Qt::Key_Backspace, QApplicationPrivate::KB_Win},
00330 {QKeySequence::Paste, 0, Qt::SHIFT | Qt::Key_Insert, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00331 {QKeySequence::Cut, 0, Qt::SHIFT | Qt::Key_Delete, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00332 {QKeySequence::SelectStartOfLine, 0, Qt::SHIFT | Qt::Key_Home, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00333 {QKeySequence::SelectStartOfDocument, 0, Qt::SHIFT | Qt::Key_Home, QApplicationPrivate::KB_Mac},
00334 {QKeySequence::SelectEndOfLine, 0, Qt::SHIFT | Qt::Key_End, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00335 {QKeySequence::SelectEndOfDocument, 0, Qt::SHIFT | Qt::Key_End, QApplicationPrivate::KB_Mac},
00336 {QKeySequence::SelectPreviousChar, 0, Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_All},
00337 {QKeySequence::SelectPreviousLine, 0, Qt::SHIFT | Qt::Key_Up, QApplicationPrivate::KB_All},
00338 {QKeySequence::SelectNextChar, 0, Qt::SHIFT | Qt::Key_Right, QApplicationPrivate::KB_All},
00339 {QKeySequence::SelectNextLine, 0, Qt::SHIFT | Qt::Key_Down, QApplicationPrivate::KB_All},
00340 {QKeySequence::SelectPreviousPage, 0, Qt::SHIFT | Qt::Key_PageUp, QApplicationPrivate::KB_All},
00341 {QKeySequence::SelectNextPage, 0, Qt::SHIFT | Qt::Key_PageDown, QApplicationPrivate::KB_All},
00342 {QKeySequence::WhatsThis, 1, Qt::SHIFT | Qt::Key_F1, QApplicationPrivate::KB_All},
00343 {QKeySequence::FindPrevious, 0, Qt::SHIFT | Qt::Key_F3, QApplicationPrivate::KB_X11},
00344 {QKeySequence::FindPrevious, 1, Qt::SHIFT | Qt::Key_F3, QApplicationPrivate::KB_Win},
00345 {QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, QApplicationPrivate::KB_All},
00346 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Comma, QApplicationPrivate::KB_KDE},
00347 {QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, QApplicationPrivate::KB_All},
00348 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, QApplicationPrivate::KB_KDE},
00349 {QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, QApplicationPrivate::KB_Mac},
00350 {QKeySequence::SelectAll, 1, Qt::CTRL | Qt::Key_A, QApplicationPrivate::KB_All},
00351 {QKeySequence::Bold, 1, Qt::CTRL | Qt::Key_B, QApplicationPrivate::KB_All},
00352 {QKeySequence::Copy, 1, Qt::CTRL | Qt::Key_C, QApplicationPrivate::KB_All},
00353 {QKeySequence::Delete, 0, Qt::CTRL | Qt::Key_D, QApplicationPrivate::KB_X11},
00354 {QKeySequence::Find, 0, Qt::CTRL | Qt::Key_F, QApplicationPrivate::KB_All},
00355 {QKeySequence::FindNext, 1, Qt::CTRL | Qt::Key_G, QApplicationPrivate::KB_Gnome | QApplicationPrivate::KB_Mac},
00356 {QKeySequence::FindNext, 0, Qt::CTRL | Qt::Key_G, QApplicationPrivate::KB_Win},
00357 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, QApplicationPrivate::KB_Win},
00358 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, QApplicationPrivate::KB_Gnome},
00359 {QKeySequence::Italic, 0, Qt::CTRL | Qt::Key_I, QApplicationPrivate::KB_All},
00360 {QKeySequence::DeleteEndOfLine, 0, Qt::CTRL | Qt::Key_K, QApplicationPrivate::KB_X11},
00361 {QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, QApplicationPrivate::KB_All},
00362 {QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, QApplicationPrivate::KB_All},
00363 {QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, QApplicationPrivate::KB_All},
00364 {QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, QApplicationPrivate::KB_Gnome | QApplicationPrivate::KB_Mac},
00365 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_R, QApplicationPrivate::KB_KDE},
00366 {QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, QApplicationPrivate::KB_All},
00367 {QKeySequence::AddTab, 0, Qt::CTRL | Qt::Key_T, QApplicationPrivate::KB_All},
00368 {QKeySequence::Underline, 1, Qt::CTRL | Qt::Key_U, QApplicationPrivate::KB_All},
00369 {QKeySequence::Paste, 1, Qt::CTRL | Qt::Key_V, QApplicationPrivate::KB_All},
00370 {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_W, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00371 {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_W, QApplicationPrivate::KB_Mac},
00372 {QKeySequence::Cut, 1, Qt::CTRL | Qt::Key_X, QApplicationPrivate::KB_All},
00373 {QKeySequence::Redo, 1, Qt::CTRL | Qt::Key_Y, QApplicationPrivate::KB_Win},
00374 {QKeySequence::Redo, 0, Qt::CTRL | Qt::Key_Y, QApplicationPrivate::KB_Mac},
00375 {QKeySequence::Undo, 1, Qt::CTRL | Qt::Key_Z, QApplicationPrivate::KB_All},
00376 {QKeySequence::Back, 1, Qt::CTRL | Qt::Key_BracketLeft, QApplicationPrivate::KB_Mac},
00377 {QKeySequence::Forward, 1, Qt::CTRL | Qt::Key_BracketRight, QApplicationPrivate::KB_Mac},
00378 {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::Key_BraceLeft, QApplicationPrivate::KB_Mac},
00379 {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_BraceRight, QApplicationPrivate::KB_Mac},
00380 {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_Tab, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00381 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Tab, QApplicationPrivate::KB_Mac},
00382 {QKeySequence::DeleteStartOfWord, 0, Qt::CTRL | Qt::Key_Backspace, QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_Win},
00383 {QKeySequence::Copy, 0, Qt::CTRL | Qt::Key_Insert, QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_Win},
00384 {QKeySequence::DeleteEndOfWord, 0, Qt::CTRL | Qt::Key_Delete, QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_Win},
00385 {QKeySequence::MoveToStartOfDocument, 0, Qt::CTRL | Qt::Key_Home, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00386 {QKeySequence::MoveToEndOfDocument, 0, Qt::CTRL | Qt::Key_End, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00387 {QKeySequence::Back, 0, Qt::CTRL | Qt::Key_Left, QApplicationPrivate::KB_Mac},
00388 {QKeySequence::MoveToPreviousWord, 0, Qt::CTRL | Qt::Key_Left, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00389 {QKeySequence::MoveToStartOfLine, 0, Qt::CTRL | Qt::Key_Left, QApplicationPrivate::KB_Mac },
00390 {QKeySequence::MoveToStartOfDocument, 1, Qt::CTRL | Qt::Key_Up, QApplicationPrivate::KB_Mac},
00391 {QKeySequence::Forward, 0, Qt::CTRL | Qt::Key_Right, QApplicationPrivate::KB_Mac},
00392 {QKeySequence::MoveToEndOfLine, 0, Qt::CTRL | Qt::Key_Right, QApplicationPrivate::KB_Mac },
00393 {QKeySequence::MoveToNextWord, 0, Qt::CTRL | Qt::Key_Right, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00394 {QKeySequence::MoveToEndOfDocument, 1, Qt::CTRL | Qt::Key_Down, QApplicationPrivate::KB_Mac},
00395 {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_F4, QApplicationPrivate::KB_Win},
00396 {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_F4, QApplicationPrivate::KB_Mac},
00397 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_F6, QApplicationPrivate::KB_Win},
00398 {QKeySequence::FindPrevious, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_G, QApplicationPrivate::KB_Gnome | QApplicationPrivate::KB_Mac},
00399 {QKeySequence::FindPrevious, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_G, QApplicationPrivate::KB_Win},
00400 {QKeySequence::AddTab, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_N, QApplicationPrivate::KB_KDE},
00401 {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00402 {QKeySequence::Redo, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, QApplicationPrivate::KB_Mac},
00403 {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Tab, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00404 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Tab, QApplicationPrivate::KB_Mac },
00405 {QKeySequence::SelectStartOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Home, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00406 {QKeySequence::SelectEndOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_End, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00407 {QKeySequence::SelectPreviousWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00408 {QKeySequence::SelectStartOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_Mac },
00409 {QKeySequence::SelectStartOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Up, QApplicationPrivate::KB_Mac},
00410 {QKeySequence::SelectNextWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00411 {QKeySequence::SelectEndOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, QApplicationPrivate::KB_Mac },
00412 {QKeySequence::SelectEndOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Down, QApplicationPrivate::KB_Mac},
00413 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F6, QApplicationPrivate::KB_Win},
00414 {QKeySequence::Undo, 0, Qt::ALT | Qt::Key_Backspace, QApplicationPrivate::KB_Win},
00415 {QKeySequence::DeleteStartOfWord, 0, Qt::ALT | Qt::Key_Backspace, QApplicationPrivate::KB_Mac},
00416 {QKeySequence::DeleteEndOfWord, 0, Qt::ALT | Qt::Key_Delete, QApplicationPrivate::KB_Mac},
00417 {QKeySequence::Back, 1, Qt::ALT | Qt::Key_Left, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00418 {QKeySequence::MoveToPreviousWord, 0, Qt::ALT | Qt::Key_Left, QApplicationPrivate::KB_Mac},
00419 {QKeySequence::MoveToStartOfBlock, 0, Qt::ALT | Qt::Key_Up, QApplicationPrivate::KB_Mac},
00420 {QKeySequence::MoveToNextWord, 0, Qt::ALT | Qt::Key_Right, QApplicationPrivate::KB_Mac},
00421 {QKeySequence::Forward, 1, Qt::ALT | Qt::Key_Right, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11},
00422 {QKeySequence::MoveToEndOfBlock, 0, Qt::ALT | Qt::Key_Down, QApplicationPrivate::KB_Mac},
00423 {QKeySequence::MoveToPreviousPage, 0, Qt::ALT | Qt::Key_PageUp, QApplicationPrivate::KB_Mac },
00424 {QKeySequence::MoveToNextPage, 0, Qt::ALT | Qt::Key_PageDown, QApplicationPrivate::KB_Mac },
00425 {QKeySequence::Redo, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,QApplicationPrivate::KB_Win},
00426 {QKeySequence::SelectPreviousWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_Mac},
00427 {QKeySequence::SelectStartOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Up, QApplicationPrivate::KB_Mac},
00428 {QKeySequence::SelectNextWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Right, QApplicationPrivate::KB_Mac},
00429 {QKeySequence::SelectEndOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Down, QApplicationPrivate::KB_Mac},
00430 {QKeySequence::MoveToStartOfBlock, 0, Qt::META | Qt::Key_A, QApplicationPrivate::KB_Mac},
00431 {QKeySequence::Delete, 0, Qt::META | Qt::Key_D, QApplicationPrivate::KB_Mac},
00432 {QKeySequence::MoveToEndOfBlock, 0, Qt::META | Qt::Key_E, QApplicationPrivate::KB_Mac},
00433 {QKeySequence::MoveToStartOfLine, 0, Qt::META | Qt::Key_Left, QApplicationPrivate::KB_Mac},
00434 {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_Up, QApplicationPrivate::KB_Mac},
00435 {QKeySequence::MoveToEndOfLine, 0, Qt::META | Qt::Key_Right, QApplicationPrivate::KB_Mac},
00436 {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_Down, QApplicationPrivate::KB_Mac},
00437 {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_PageUp, QApplicationPrivate::KB_Mac},
00438 {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_PageDown, QApplicationPrivate::KB_Mac},
00439 {QKeySequence::SelectStartOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_Mac},
00440 {QKeySequence::SelectEndOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Right, QApplicationPrivate::KB_Mac}
00441 };
00442
00443 const uint QKeySequencePrivate::numberOfKeyBindings = sizeof(QKeySequencePrivate::keyBindings)/(sizeof(QKeyBinding));
00444
00445
00530 QKeySequence::QKeySequence(StandardKey key)
00531 {
00532 const QList <QKeySequence> bindings = keyBindings(key);
00533
00534 if (bindings.size() > 0) {
00535 d = bindings.first().d;
00536 d->ref.ref();
00537 }
00538 else
00539 d = new QKeySequencePrivate();
00540 }
00541
00542
00546 QKeySequence::QKeySequence()
00547 {
00548 d = new QKeySequencePrivate();
00549 }
00550
00574 QKeySequence::QKeySequence(const QString &key)
00575 {
00576 d = new QKeySequencePrivate();
00577 assign(key);
00578 }
00579
00588 QKeySequence::QKeySequence(int k1, int k2, int k3, int k4)
00589 {
00590 d = new QKeySequencePrivate();
00591 d->key[0] = k1;
00592 d->key[1] = k2;
00593 d->key[2] = k3;
00594 d->key[3] = k4;
00595 }
00596
00600 QKeySequence::QKeySequence(const QKeySequence& keysequence)
00601 : d(keysequence.d)
00602 {
00603 d->ref.ref();
00604 }
00605
00615 QList<QKeySequence> QKeySequence::keyBindings(StandardKey key)
00616 {
00617 uint platform = QApplicationPrivate::currentPlatform();
00618 QList <QKeySequence> list;
00619 for (uint i = 0; i < QKeySequencePrivate::numberOfKeyBindings ; ++i) {
00620 QKeyBinding keyBinding = QKeySequencePrivate::keyBindings[i];
00621 if (keyBinding.standardKey == key && (keyBinding.platform & platform))
00622 if (keyBinding.priority > 0)
00623 list.prepend(QKeySequence(QKeySequencePrivate::keyBindings[i].shortcut));
00624 else
00625 list.append(QKeySequence(QKeySequencePrivate::keyBindings[i].shortcut));
00626 }
00627 return list;
00628 }
00629
00633 QKeySequence::~QKeySequence()
00634 {
00635 if (!d->ref.deref())
00636 delete d;
00637 }
00638
00646 void QKeySequence::setKey(int key, int index)
00647 {
00648 Q_ASSERT_X(index >= 0 && index < 4, "QKeySequence::setKey", "index out of range");
00649 qAtomicDetach(d);
00650 d->key[index] = key;
00651 }
00652
00657 uint QKeySequence::count() const
00658 {
00659 if (!d->key[0])
00660 return 0;
00661 if (!d->key[1])
00662 return 1;
00663 if (!d->key[2])
00664 return 2;
00665 if (!d->key[3])
00666 return 3;
00667 return 4;
00668 }
00669
00670
00675 bool QKeySequence::isEmpty() const
00676 {
00677 return !d->key[0];
00678 }
00679
00680
00694 QKeySequence QKeySequence::mnemonic(const QString &text)
00695 {
00696 if(qt_sequence_no_mnemonics)
00697 return QKeySequence();
00698
00699 int p = 0;
00700 while (p >= 0) {
00701 p = text.indexOf(QLatin1Char('&'), p) + 1;
00702 if (p <= 0 || p >= (int)text.length())
00703 break;
00704 if (text.at(p) != QLatin1Char('&')) {
00705 QChar c = text.at(p);
00706 if (c.isPrint()) {
00707 c = c.toUpper();
00708 return QKeySequence(c.unicode() + Qt::ALT);
00709 }
00710 }
00711 p++;
00712 }
00713 return QKeySequence();
00714 }
00715
00724 int QKeySequence::assign(const QString &ks)
00725 {
00726 QString keyseq = ks;
00727 QString part;
00728 int n = 0;
00729 int p = 0, diff = 0;
00730
00731
00732
00733 while (keyseq.length() && n < 4) {
00734
00735
00736
00737 p = keyseq.indexOf(QLatin1Char(','));
00738 if (-1 != p) {
00739 if (p == keyseq.count() - 1) {
00740 p = -1;
00741 } else {
00742 if (QLatin1Char(',') == keyseq.at(p+1))
00743 p++;
00744 if (QLatin1Char(' ') == keyseq.at(p+1)) {
00745 diff = 1;
00746 p++;
00747 } else {
00748 diff = 0;
00749 }
00750 }
00751 }
00752 part = keyseq.left(-1 == p ? keyseq.length() : p - diff);
00753 keyseq = keyseq.right(-1 == p ? 0 : keyseq.length() - (p + 1));
00754 d->key[n] = decodeString(part);
00755 ++n;
00756 }
00757 return n;
00758 }
00759
00760 struct QModifKeyName {
00761 QModifKeyName() { }
00762 QModifKeyName(int q, QChar n) : qt_key(q), name(n) { }
00763 QModifKeyName(int q, const QString &n) : qt_key(q), name(n) { }
00764 int qt_key;
00765 QString name;
00766 };
00767
00768 Q_GLOBAL_STATIC(QList<QModifKeyName>, globalModifs)
00769 Q_GLOBAL_STATIC(QList<QModifKeyName>, globalPortableModifs)
00770
00774 int QKeySequence::decodeString(const QString &str)
00775 {
00776 return QKeySequencePrivate::decodeString(str, NativeText);
00777 }
00778
00779 int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::SequenceFormat format)
00780 {
00781 int ret = 0;
00782 QString accel = str.toLower();
00783 bool nativeText = (format == QKeySequence::NativeText);
00784
00785 QList<QModifKeyName> *gmodifs;
00786 if (nativeText) {
00787 gmodifs = globalModifs();
00788 if (gmodifs->isEmpty()) {
00789 #ifdef QMAC_CTRL
00790 *gmodifs << QModifKeyName(Qt::CTRL, QMAC_CTRL);
00791 #endif
00792 #ifdef QMAC_ALT
00793 *gmodifs << QModifKeyName(Qt::ALT, QMAC_ALT);
00794 #endif
00795 #ifdef QMAC_META
00796 *gmodifs << QModifKeyName(Qt::META, QMAC_META);
00797 #endif
00798 #ifdef QMAC_SHIFT
00799 *gmodifs << QModifKeyName(Qt::SHIFT, QMAC_SHIFT);
00800 #endif
00801 *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
00802 << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
00803 << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
00804 << QModifKeyName(Qt::META, QLatin1String("meta+"));
00805 }
00806 } else {
00807 gmodifs = globalPortableModifs();
00808 if (gmodifs->isEmpty()) {
00809 *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
00810 << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
00811 << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
00812 << QModifKeyName(Qt::META, QLatin1String("meta+"));
00813 }
00814 }
00815 if (!gmodifs) return ret;
00816
00817
00818 QList<QModifKeyName> modifs;
00819 if (nativeText) {
00820 modifs << QModifKeyName(Qt::CTRL, QShortcut::tr("Ctrl").toLower().append(QLatin1Char('+')))
00821 << QModifKeyName(Qt::SHIFT, QShortcut::tr("Shift").toLower().append(QLatin1Char('+')))
00822 << QModifKeyName(Qt::ALT, QShortcut::tr("Alt").toLower().append(QLatin1Char('+')))
00823 << QModifKeyName(Qt::META, QShortcut::tr("Meta").toLower().append(QLatin1Char('+')));
00824 }
00825 modifs += *gmodifs;
00826
00827 QString sl = accel;
00828 #ifdef Q_WS_MAC
00829 for (int i = 0; i < modifs.size(); ++i) {
00830 const QModifKeyName &mkf = modifs.at(i);
00831 if (sl.contains(mkf.name)) {
00832 ret |= mkf.qt_key;
00833 accel.remove(mkf.name);
00834 sl = accel;
00835 }
00836 }
00837 #else
00838 int i = 0;
00839 int lastI = 0;
00840 while ((i = sl.indexOf('+', i + 1)) != -1) {
00841 const QString sub = sl.mid(lastI, i - lastI + 1);
00842
00843
00844
00845 if (sub.length() > 1) {
00846 for (int j = 0; j < modifs.size(); ++j) {
00847 const QModifKeyName &mkf = modifs.at(j);
00848 if (sub == mkf.name) {
00849 ret |= mkf.qt_key;
00850 break;
00851 }
00852 }
00853 }
00854 lastI = i + 1;
00855 }
00856 #endif
00857
00858 int p = accel.lastIndexOf(QLatin1Char('+'), str.length() - 2);
00859 if(p > 0)
00860 accel = accel.mid(p + 1);
00861
00862 int fnum = 0;
00863 if (accel.length() == 1) {
00864 ret |= accel[0].toUpper().unicode();
00865 } else if (accel[0] == QLatin1Char('f') && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35)) {
00866 ret |= Qt::Key_F1 + fnum - 1;
00867 } else {
00868
00869
00870
00871 bool found = false;
00872 for (int tran = 0; tran < 2; ++tran) {
00873 if (!nativeText)
00874 ++tran;
00875 for (int i = 0; keyname[i].name; ++i) {
00876 QString keyName(tran == 0
00877 ? QShortcut::tr(keyname[i].name)
00878 : QString::fromLatin1(keyname[i].name));
00879 if (accel == keyName.toLower()) {
00880 ret |= keyname[i].key;
00881 found = true;
00882 break;
00883 }
00884 }
00885 if (found)
00886 break;
00887 }
00888 }
00889 return ret;
00890 }
00891
00897 QString QKeySequence::encodeString(int key)
00898 {
00899 return QKeySequencePrivate::encodeString(key, NativeText);
00900 }
00901
00902 static inline void addKey(QString &str, const QString &theKey, QKeySequence::SequenceFormat format)
00903 {
00904 if (!str.isEmpty())
00905 str += (format == QKeySequence::NativeText) ? QShortcut::tr("+")
00906 : QString(QLatin1String("+"));
00907 str += theKey;
00908 }
00909
00910 QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat format)
00911 {
00912 bool nativeText = (format == QKeySequence::NativeText);
00913 QString s;
00914 #if defined(Q_WS_MAC)
00915 if (nativeText) {
00916
00917 if ((key & Qt::META) == Qt::META)
00918 s += QMAC_META;
00919 if ((key & Qt::ALT) == Qt::ALT)
00920 s += QMAC_ALT;
00921 if ((key & Qt::SHIFT) == Qt::SHIFT)
00922 s += QMAC_SHIFT;
00923 if ((key & Qt::CTRL) == Qt::CTRL)
00924 s += QMAC_CTRL;
00925 } else
00926 #endif
00927 {
00928
00929 if ((key & Qt::META) == Qt::META)
00930 s = nativeText ? QShortcut::tr("Meta") : QString(QLatin1String("Meta"));
00931 if ((key & Qt::CTRL) == Qt::CTRL)
00932 addKey(s, nativeText ? QShortcut::tr("Ctrl") : QString(QLatin1String("Ctrl")), format);
00933 if ((key & Qt::ALT) == Qt::ALT)
00934 addKey(s, nativeText ? QShortcut::tr("Alt") : QString(QLatin1String("Alt")), format);
00935 if ((key & Qt::SHIFT) == Qt::SHIFT)
00936 addKey(s, nativeText ? QShortcut::tr("Shift") : QString(QLatin1String("Shift")), format);
00937 }
00938
00939
00940 key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier);
00941 QString p;
00942
00943 if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
00944 if (key < 0x10000) {
00945 p = QChar(key & 0xffff).toUpper();
00946 } else {
00947 p = QChar((key-0x10000)/0x400+0xd800);
00948 p += QChar((key-0x10000)%400+0xdc00);
00949 }
00950 } else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
00951 p = nativeText ? QShortcut::tr("F%1").arg(key - Qt::Key_F1 + 1)
00952 : QString(QLatin1String("F%1")).arg(key - Qt::Key_F1 + 1);
00953 } else if (key) {
00954 int i=0;
00955 while (keyname[i].name) {
00956 if (key == keyname[i].key) {
00957 p = nativeText ? QShortcut::tr(keyname[i].name)
00958 : QString(QLatin1String(keyname[i].name));
00959 break;
00960 }
00961 ++i;
00962 }
00963
00964
00965
00966
00967 if (!keyname[i].name) {
00968 if (key < 0x10000) {
00969 p = QChar(key & 0xffff).toUpper();
00970 } else {
00971 p = QChar((key-0x10000)/0x400+0xd800);
00972 p += QChar((key-0x10000)%400+0xdc00);
00973 }
00974 }
00975 }
00976
00977 #ifdef Q_WS_MAC
00978 if (nativeText)
00979 s += p;
00980 else
00981 #endif
00982 addKey(s, p, format);
00983 return s;
00984 }
00991 QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
00992 {
00993 uint userN = count(),
00994 seqN = seq.count();
00995
00996 if (userN > seqN)
00997 return NoMatch;
00998
00999
01000
01001 SequenceMatch match = (userN == seqN ? ExactMatch : PartialMatch);
01002
01003 for (uint i = 0; i < userN; ++i) {
01004 int userKey = (*this)[i],
01005 sequenceKey = seq[i];
01006 if (userKey != sequenceKey)
01007 return NoMatch;
01008 }
01009 return match;
01010 }
01011
01012
01018 QKeySequence::operator QString() const
01019 {
01020 return QKeySequence::toString(QKeySequence::NativeText);
01021 }
01022
01026 QKeySequence::operator QVariant() const
01027 {
01028 return QVariant(QVariant::KeySequence, this);
01029 }
01030
01036 QKeySequence::operator int () const
01037 {
01038 if (1 <= count())
01039 return d->key[0];
01040 return 0;
01041 }
01042
01043
01048 int QKeySequence::operator[](uint index) const
01049 {
01050 Q_ASSERT_X(index < 4, "QKeySequence::operator[]", "index out of range");
01051 return d->key[index];
01052 }
01053
01054
01059 QKeySequence &QKeySequence::operator=(const QKeySequence &other)
01060 {
01061 qAtomicAssign(d, other.d);
01062 return *this;
01063 }
01064
01077 bool QKeySequence::operator==(const QKeySequence &other) const
01078 {
01079 return (d->key[0] == other.d->key[0] &&
01080 d->key[1] == other.d->key[1] &&
01081 d->key[2] == other.d->key[2] &&
01082 d->key[3] == other.d->key[3]);
01083 }
01084
01085
01098 bool QKeySequence::operator< (const QKeySequence &other) const
01099 {
01100 for (int i = 0; i < 4; ++i)
01101 if (d->key[i] != other.d->key[i])
01102 return d->key[i] < other.d->key[i];
01103 return false;
01104 }
01105
01136 bool QKeySequence::isDetached() const
01137 {
01138 return d->ref == 1;
01139 }
01140
01160 QString QKeySequence::toString(SequenceFormat format) const
01161 {
01162 QString finalString;
01163
01164
01165 int end = count();
01166 for (int i = 0; i < end; ++i) {
01167 finalString += d->encodeString(d->key[i], format);
01168 finalString += QLatin1String(", ");
01169 }
01170 finalString.truncate(finalString.length() - 2);
01171 return finalString;
01172 }
01173
01181 QKeySequence QKeySequence::fromString(const QString &str, SequenceFormat format)
01182 {
01183 QStringList sl = str.split(QLatin1String(", "));
01184 int keys[4] = {0, 0, 0, 0};
01185 int total = qMin(sl.count(), 4);
01186 for (int i = 0; i < total; ++i)
01187 keys[i] = QKeySequencePrivate::decodeString(sl[i], format);
01188 return QKeySequence(keys[0], keys[1], keys[2], keys[3]);
01189 }
01190
01191
01192
01193
01194 #if !defined(QT_NO_DATASTREAM)
01195
01203 QDataStream &operator<<(QDataStream &s, const QKeySequence &keysequence)
01204 {
01205 QList<quint32> list;
01206 list << keysequence.d->key[0];
01207
01208 if (s.version() >= 5 && keysequence.count() > 1) {
01209 list << keysequence.d->key[1];
01210 list << keysequence.d->key[2];
01211 list << keysequence.d->key[3];
01212 }
01213 s << list;
01214 return s;
01215 }
01216
01217
01226 QDataStream &operator>>(QDataStream &s, QKeySequence &keysequence)
01227 {
01228 qAtomicDetach(keysequence.d);
01229 QList<quint32> list;
01230 s >> list;
01231 for (int i = 0; i < 4; ++i)
01232 keysequence.d->key[i] = list.value(i);
01233 return s;
01234 }
01235
01236 #endif //QT_NO_DATASTREAM
01237
01238 #ifndef QT_NO_DEBUG_STREAM
01239 QDebug operator<<(QDebug dbg, const QKeySequence &p)
01240 {
01241 #ifndef Q_BROKEN_DEBUG_STREAM
01242 dbg.nospace() << "QKeySequence(" << p.toString() << ')';
01243 return dbg.space();
01244 #else
01245 qWarning("This compiler doesn't support streaming QKeySequence to QDebug");
01246 return dbg;
01247 Q_UNUSED(p);
01248 #endif
01249 }
01250 #endif
01251
01252 #endif // QT_NO_SHORTCUT