?? qkeysequence.cpp
字號:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qkeysequence.h"#ifndef QT_NO_SHORTCUT#include "qshortcut.h"#include "qdebug.h"#ifndef QT_NO_REGEXP# include "qregexp.h"#endif#ifndef QT_NO_DATASTREAM# include "qdatastream.h"#endif#include "qvariant.h"#ifdef Q_WS_MAC# include <private/qt_mac_p.h># define QMAC_CTRL QChar(kCommandUnicode)# define QMAC_META QChar(kControlUnicode)# define QMAC_ALT QChar(kOptionUnicode)# define QMAC_SHIFT QChar(kShiftUnicode)#endif#ifdef Q_WS_MACstatic bool qt_sequence_no_mnemonics = true;#elsestatic bool qt_sequence_no_mnemonics = false;#endifvoid Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemonics = !b; }/*! \class QKeySequence \brief The QKeySequence class encapsulates a key sequence as used by shortcuts. \ingroup misc \mainclass A key sequence consists of up to four keyboard codes, each optionally combined with modifiers, such as Qt::SHIFT, Qt::CTRL, Qt::ALT or Qt::META. For example, Qt::CTRL + Qt::Key_P might be a sequence used as a shortcut for printing a document. Valid codes for keys and modifiers are listed in Qt::Key and Qt::Modifier. As an alternative, use the unicode code point of the character; for example, 'A' gives the same key sequence as Qt::Key_A. Key sequences can be constructed either from an integer key code, or from a human readable translatable string such as "Ctrl+X,Alt+Space". A key sequence can be cast to a QString to obtain a human readable translated version of the sequence. Translations are done in the "QShortcut" context. \bold{Note:} On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to the Control keys. Developers on Mac OS X can use the same shortcut descriptions across all platforms, and their applications will automatically work as expected on Mac OS X. The toString() function produces human-readable strings for use in menus. On Mac OS X, the appropriate symbols are used to describe keyboard shortcuts using special keys on the Macintosh keyboard. \sa QShortcut*//*! \enum QKeySequence::SequenceMatch \value NoMatch The key sequences are different; not even partially matching. \value PartialMatch The key sequences match partially, but are not the same. \value ExactMatch The key sequences are the same. \omitvalue Identical*//*! \enum QKeySequence::SequenceFormat \value NativeText The key sequence as a platform specific string. This means that it will be shown translated and on the Mac it will resemble a keysequence from the menu bar. This enum is best used when you want to display the string to the user. \value PortableText The key sequence is given in a "portable" format, suitable for reading and writing to a file. In many cases, it will look similar to the native text on Windows and X11.*/static struct { int key; const char* name;} keyname[] = { { Qt::Key_Space, QT_TRANSLATE_NOOP("QShortcut", "Space") }, { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Esc") }, { Qt::Key_Tab, QT_TRANSLATE_NOOP("QShortcut", "Tab") }, { Qt::Key_Backtab, QT_TRANSLATE_NOOP("QShortcut", "Backtab") }, { Qt::Key_Backspace, QT_TRANSLATE_NOOP("QShortcut", "Backspace") }, { Qt::Key_Return, QT_TRANSLATE_NOOP("QShortcut", "Return") }, { Qt::Key_Enter, QT_TRANSLATE_NOOP("QShortcut", "Enter") }, { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Ins") }, { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Del") }, { Qt::Key_Pause, QT_TRANSLATE_NOOP("QShortcut", "Pause") }, { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print") }, { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "SysReq") }, { Qt::Key_Home, QT_TRANSLATE_NOOP("QShortcut", "Home") }, { Qt::Key_End, QT_TRANSLATE_NOOP("QShortcut", "End") }, { Qt::Key_Left, QT_TRANSLATE_NOOP("QShortcut", "Left") }, { Qt::Key_Up, QT_TRANSLATE_NOOP("QShortcut", "Up") }, { Qt::Key_Right, QT_TRANSLATE_NOOP("QShortcut", "Right") }, { Qt::Key_Down, QT_TRANSLATE_NOOP("QShortcut", "Down") }, { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "PgUp") }, { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "PgDown") }, { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "CapsLock") }, { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "NumLock") }, { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "ScrollLock") }, { Qt::Key_Menu, QT_TRANSLATE_NOOP("QShortcut", "Menu") }, { Qt::Key_Help, QT_TRANSLATE_NOOP("QShortcut", "Help") }, // Multimedia keys { Qt::Key_Back, QT_TRANSLATE_NOOP("QShortcut", "Back") }, { Qt::Key_Forward, QT_TRANSLATE_NOOP("QShortcut", "Forward") }, { Qt::Key_Stop, QT_TRANSLATE_NOOP("QShortcut", "Stop") }, { Qt::Key_Refresh, QT_TRANSLATE_NOOP("QShortcut", "Refresh") }, { Qt::Key_VolumeDown, QT_TRANSLATE_NOOP("QShortcut", "Volume Down") }, { Qt::Key_VolumeMute, QT_TRANSLATE_NOOP("QShortcut", "Volume Mute") }, { Qt::Key_VolumeUp, QT_TRANSLATE_NOOP("QShortcut", "Volume Up") }, { Qt::Key_BassBoost, QT_TRANSLATE_NOOP("QShortcut", "Bass Boost") }, { Qt::Key_BassUp, QT_TRANSLATE_NOOP("QShortcut", "Bass Up") }, { Qt::Key_BassDown, QT_TRANSLATE_NOOP("QShortcut", "Bass Down") }, { Qt::Key_TrebleUp, QT_TRANSLATE_NOOP("QShortcut", "Treble Up") }, { Qt::Key_TrebleDown, QT_TRANSLATE_NOOP("QShortcut", "Treble Down") }, { Qt::Key_MediaPlay, QT_TRANSLATE_NOOP("QShortcut", "Media Play") }, { Qt::Key_MediaStop, QT_TRANSLATE_NOOP("QShortcut", "Media Stop") }, { Qt::Key_MediaPrevious,QT_TRANSLATE_NOOP("QShortcut", "Media Previous") }, { Qt::Key_MediaNext, QT_TRANSLATE_NOOP("QShortcut", "Media Next") }, { Qt::Key_MediaRecord, QT_TRANSLATE_NOOP("QShortcut", "Media Record") }, { Qt::Key_HomePage, QT_TRANSLATE_NOOP("QShortcut", "Home Page") }, { Qt::Key_Favorites, QT_TRANSLATE_NOOP("QShortcut", "Favorites") }, { Qt::Key_Search, QT_TRANSLATE_NOOP("QShortcut", "Search") }, { Qt::Key_Standby, QT_TRANSLATE_NOOP("QShortcut", "Standby") }, { Qt::Key_OpenUrl, QT_TRANSLATE_NOOP("QShortcut", "Open URL") }, { Qt::Key_LaunchMail, QT_TRANSLATE_NOOP("QShortcut", "Launch Mail") }, { Qt::Key_LaunchMedia, QT_TRANSLATE_NOOP("QShortcut", "Launch Media") }, { Qt::Key_Launch0, QT_TRANSLATE_NOOP("QShortcut", "Launch (0)") }, { Qt::Key_Launch1, QT_TRANSLATE_NOOP("QShortcut", "Launch (1)") }, { Qt::Key_Launch2, QT_TRANSLATE_NOOP("QShortcut", "Launch (2)") }, { Qt::Key_Launch3, QT_TRANSLATE_NOOP("QShortcut", "Launch (3)") }, { Qt::Key_Launch4, QT_TRANSLATE_NOOP("QShortcut", "Launch (4)") }, { Qt::Key_Launch5, QT_TRANSLATE_NOOP("QShortcut", "Launch (5)") }, { Qt::Key_Launch6, QT_TRANSLATE_NOOP("QShortcut", "Launch (6)") }, { Qt::Key_Launch7, QT_TRANSLATE_NOOP("QShortcut", "Launch (7)") }, { Qt::Key_Launch8, QT_TRANSLATE_NOOP("QShortcut", "Launch (8)") }, { Qt::Key_Launch9, QT_TRANSLATE_NOOP("QShortcut", "Launch (9)") }, { Qt::Key_LaunchA, QT_TRANSLATE_NOOP("QShortcut", "Launch (A)") }, { Qt::Key_LaunchB, QT_TRANSLATE_NOOP("QShortcut", "Launch (B)") }, { Qt::Key_LaunchC, QT_TRANSLATE_NOOP("QShortcut", "Launch (C)") }, { Qt::Key_LaunchD, QT_TRANSLATE_NOOP("QShortcut", "Launch (D)") }, { Qt::Key_LaunchE, QT_TRANSLATE_NOOP("QShortcut", "Launch (E)") }, { Qt::Key_LaunchF, QT_TRANSLATE_NOOP("QShortcut", "Launch (F)") }, // -------------------------------------------------------------- // More consistent namings { Qt::Key_Print, QT_TRANSLATE_NOOP("QShortcut", "Print Screen") }, { Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "Page Up") }, { Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "Page Down") }, { Qt::Key_CapsLock, QT_TRANSLATE_NOOP("QShortcut", "Caps Lock") }, { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Num Lock") }, { Qt::Key_NumLock, QT_TRANSLATE_NOOP("QShortcut", "Number Lock") }, { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP("QShortcut", "Scroll Lock") }, { Qt::Key_Insert, QT_TRANSLATE_NOOP("QShortcut", "Insert") }, { Qt::Key_Delete, QT_TRANSLATE_NOOP("QShortcut", "Delete") }, { Qt::Key_Escape, QT_TRANSLATE_NOOP("QShortcut", "Escape") }, { Qt::Key_SysReq, QT_TRANSLATE_NOOP("QShortcut", "System Request") }, // -------------------------------------------------------------- // Keypad navigation keys { Qt::Key_Select, QT_TRANSLATE_NOOP("QShortcut", "Select") }, { Qt::Key_Yes, QT_TRANSLATE_NOOP("QShortcut", "Yes") }, { Qt::Key_No, QT_TRANSLATE_NOOP("QShortcut", "No") }, // -------------------------------------------------------------- // Device keys { Qt::Key_Context1, QT_TRANSLATE_NOOP("QShortcut", "Context1") }, { Qt::Key_Context2, QT_TRANSLATE_NOOP("QShortcut", "Context2") }, { Qt::Key_Context3, QT_TRANSLATE_NOOP("QShortcut", "Context3") }, { Qt::Key_Context4, QT_TRANSLATE_NOOP("QShortcut", "Context4") }, { Qt::Key_Call, QT_TRANSLATE_NOOP("QShortcut", "Call") }, { Qt::Key_Hangup, QT_TRANSLATE_NOOP("QShortcut", "Hangup") }, { Qt::Key_Flip, QT_TRANSLATE_NOOP("QShortcut", "Flip") }, { 0, 0 }};class QKeySequencePrivate{public: inline QKeySequencePrivate() { ref = 1; key[0] = key[1] = key[2] = key[3] = 0; } inline QKeySequencePrivate(const QKeySequencePrivate ©) { ref = 1; key[0] = copy.key[0]; key[1] = copy.key[1]; key[2] = copy.key[2]; key[3] = copy.key[3]; } QAtomic ref; int key[4]; static QString encodeString(int key, QKeySequence::SequenceFormat format); static int decodeString(const QString &keyStr, QKeySequence::SequenceFormat format);};/*! Constructs an empty key sequence.*/QKeySequence::QKeySequence(){ d = new QKeySequencePrivate();}/*! Creates a key sequence from the \a key string. For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl", "Shift", "Alt" and "Meta" are recognized, as well as their translated equivalents in the "QShortcut" context (using QObject::tr()). Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q". This contructor is typically used with \link QObject::tr() tr \endlink(), so that shortcut keys can be replaced in translations: \code QMenu *file = new QMenu(this); file->addAction(tr("&Open..."), this, SLOT(open()), QKeySequence(tr("Ctrl+O", "File|Open"))); \endcode Note the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator.*/QKeySequence::QKeySequence(const QString &key){ d = new QKeySequencePrivate(); assign(key);}/*! Constructs a key sequence with up to 4 keys \a k1, \a k2, \a k3 and \a k4. The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.*/QKeySequence::QKeySequence(int k1, int k2, int k3, int k4){ d = new QKeySequencePrivate(); d->key[0] = k1; d->key[1] = k2; d->key[2] = k3; d->key[3] = k4;}/*! Copy constructor. Makes a copy of \a keysequence. */QKeySequence::QKeySequence(const QKeySequence& keysequence) : d(keysequence.d){ d->ref.ref();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -