QKeySequence Class Reference

#include <qkeysequence.h>

Collaboration diagram for QKeySequence:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QKeySequence class encapsulates a key sequence as used by shortcuts.

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.

{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.

QKeySequence defines many \l{StandardKey} standard keyboard shortcuts to reduce the amount of effort required when setting up actions in a typical application. The table below shows some common key sequences that are often used for these standard shortcuts by applications on four widely-used platforms. Note that on Mac OS X, the \key Ctrl value corresponds to the \key Command keys on the Macintosh keyboard, and the \key Meta value corresponds to the \key Control keys. \table \header \i StandardKey \i Windows \i Mac OS X \i KDE \i GNOME \row \i HelpContents \i F1 \i Ctrl+? \i F1 \i F1 \row \i WhatsThis \i Shift+F1 \i Shift+F1 \i Shift+F1 \i Shift+F1 \row \i Open \i Ctrl+O \i Ctrl+O \i Ctrl+O \i Ctrl+O \row \i Close \i Ctrl+F4, Ctrl+W \i Ctrl+W, Ctrl+F4 \i Ctrl+W \i Ctrl+W \row \i Save \i Ctrl+S \i Ctrl+S \i Ctrl+S \i Ctrl+S \row \i New \i Ctrl+N \i Ctrl+N \i Ctrl+N \i Ctrl+N \row \i Delete \i Del \i Del, Meta+D \i Del, Ctrl+D \i Del, Ctrl+D \row \i Cut \i Ctrl+X, Shift+Del \i Ctrl+X \i Ctrl+X, F20, Shift+Del \i Ctrl+X, F20, Shift+Del \row \i Copy \i Ctrl+C, Ctrl+Ins \i Ctrl+C \i Ctrl+C, F16, Ctrl+Ins \i Ctrl+C, F16, Ctrl+Ins \row \i Paste \i Ctrl+V, Shift+Ins \i Ctrl+V \i Ctrl+V, F18, Shift+Ins \i Ctrl+V, F18, Shift+Ins \row \i Undo \i Ctrl+Z, Alt+Backspace \i Ctrl+Z \i Ctrl+Z, F14 \i Ctrl+Z, F14 \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 \row \i Back \i Alt+Left, Backspace \i Ctrl+[ \i Alt+Left \i Alt+Left \row \i Forward \i Alt+Right, Shift+Backspace \i Ctrl+] \i Alt+Right \i Alt+Right \row \i Refresh \i F5 \i F5 \i F5 \i Ctrl+R, F5 \row \i ZoomIn \i Ctrl+Plus \i Ctrl+Plus \i Ctrl+Plus \i Ctrl+Plus \row \i ZoomOut \i Ctrl+Minus \i Ctrl+Minus \i Ctrl+Minus \i Ctrl+Minus \row \i Print \i Ctrl+P \i Ctrl+P \i Ctrl+P \i Ctrl+P \row \i AddTab \i Ctrl+T \i Ctrl+T \i Ctrl+Shift+N, Ctrl+T \i Ctrl+T \row \i NextChild \i Ctrl+Tab, Forward, Ctrl+F6 \i Ctrl+}, Forward, Ctrl+Tab \i Ctrl+Tab, Forward, Ctrl+Comma \i Ctrl+Tab, Forward \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 \row \i Find \i Ctrl+F \i Ctrl+F \i Ctrl+F \i Ctrl+F \row \i FindNext \i F3, Ctrl+G \i Ctrl+G \i F3 \i Ctrl+G, F3 \row \i FindPrevious \i Shift+F3, Ctrl+Shift+G \i Ctrl+Shift+G \i Shift+F3 \i Ctrl+Shift+G, F3 \row \i Replace \i Ctrl+H \i (none) \i Ctrl+R \i Ctrl+H \row \i SelectAll \i Ctrl+A \i Ctrl+A \i Ctrl+A \i Ctrl+A \row \i Bold \i Ctrl+B \i Ctrl+B \i Ctrl+B \i Ctrl+B \row \i Italic \i Ctrl+I \i Ctrl+I \i Ctrl+I \i Ctrl+I \row \i Underline \i Ctrl+U \i Ctrl+U \i Ctrl+U \i Ctrl+U \row \i MoveToNextChar \i Right \i Right \i Right \i Right \row \i MoveToPreviousChar \i Left \i Left \i Left \i Left \row \i MoveToNextWord \i Ctrl+Right \i Alt+Right \i Ctrl+Right \i Ctrl+Right \row \i MoveToPreviousWord \i Ctrl+Left \i Alt+Left \i Ctrl+Left \i Ctrl+Left \row \i MoveToNextLine \i Down \i Down \i Down \i Down \row \i MoveToPreviousLine \i Up \i Up \i Up \i Up \row \i MoveToNextPage \i PgDown \i PgDown, Alt+PgDown, Meta+Down, Meta+PgDown\i PgDown \i PgDown \row \i MoveToPreviousPage \i PgUp \i PgUp, Alt+PgUp, Meta+Up, Meta+PgUp \i PgUp \i PgUp \row \i MoveToStartOfLine \i Home \i Ctrl+Left, Meta+Left \i Home \i Home \row \i MoveToEndOfLine \i End \i Ctrl+Right, Meta+Right \i End \i End \row \i MoveToStartOfBlock \i (none) \i Alt+Up, Meta+A \i (none) \i (none) \row \i MoveToEndOfBlock \i (none) \i Alt+Down, Meta+E \i (none) \i (none) \row \i MoveToStartOfDocument\i Ctrl+Home \i Ctrl+Up, Home \i Ctrl+Home \i Ctrl+Home \row \i MoveToEndOfDocument \i Ctrl+End \i Ctrl+Down, End \i Ctrl+End \i Ctrl+End \row \i SelectNextChar \i Shift+Right \i Shift+Right \i Shift+Right \i Shift+Right \row \i SelectPreviousChar \i Shift+Left \i Shift+Left \i Shift+Left \i Shift?left \row \i SelectNextWord \i Ctrl+Shift+Right \i Alt+Shift+Right \i Ctrl+Shift+Right \i Ctrl+Shift+Definition at line 52 of file qkeysequence.h.

Public Types

enum  StandardKey
enum  SequenceMatch
enum  SequenceFormat

Public Member Functions

 QKeySequence ()
 QKeySequence (const QString &key)
 QKeySequence (int k1, int k2=0, int k3=0, int k4=0)
 QKeySequence (const QKeySequence &ks)
 QKeySequence (StandardKey key)
 ~QKeySequence ()
uint count () const
bool isEmpty () const
QString toString (SequenceFormat format=PortableText) const
SequenceMatch matches (const QKeySequence &seq) const
 operator QString () const
 operator QVariant () const
 operator int () const
int operator[] (uint i) const
QKeySequenceoperator= (const QKeySequence &other)
bool operator== (const QKeySequence &other) const
bool operator!= (const QKeySequence &other) const
bool operator< (const QKeySequence &ks) const
bool operator> (const QKeySequence &other) const
bool operator<= (const QKeySequence &other) const
bool operator>= (const QKeySequence &other) const
bool isDetached () const

Static Public Member Functions

static QKeySequence fromString (const QString &str, SequenceFormat format=PortableText)
static QKeySequence mnemonic (const QString &text)
static QList< QKeySequencekeyBindings (StandardKey key)

Private Member Functions

int assign (const QString &str)
void setKey (int key, int index)

Static Private Member Functions

static int decodeString (const QString &ks)
static QString encodeString (int key)

Private Attributes

QKeySequencePrivated

Friends

class Q3AccelManager
class QShortcutMap
class QShortcut
Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &in, const QKeySequence &ks)
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &in, QKeySequence &ks)


Member Enumeration Documentation

enum QKeySequence::StandardKey

Since:
4.2
This enum represent standard key bindings. They can be used to assign platform dependent keyboard shortcuts to a QAction. QKeyEvent also provides the function QKeyEvent::standardKey() to query if it matches an existing key binding.

Note that the key bindings are platform dependent. The currently bound shortcuts can be queried using keyBindings().

UnknownKey Unbound key. HelpContents Open help contents. WhatsThis Activate whats this. Open Open Document. Close Close Document/Tab. Save Save Document. New Create new Document. Delete Delete. Cut Cut. Copy Copy. Paste Paste. Undo Undo. Redo Redo. Back Navigate back. Forward Navigate forward. Refresh Refresh or reload current document. ZoomIn Zoom in. ZoomOut Zoom out. Print Print document. AddTab Add new tab. NextChild Navigate to next tab or child window. PreviousChild Navigate to previous tab or child window. Find Find in document. FindNext Find next result. FindPrevious Find previous result. Replace Find and replace. SelectAll Select all text. Bold Bold text. Italic Italic text. Underline Underline text. MoveToNextChar Move cursor to next character. MoveToPreviousChar Move cursor to previous character. MoveToNextWord Move cursor to next word. MoveToPreviousWord Move cursor to previous word. MoveToNextLine Move cursor to next line. MoveToPreviousLine Move cursor to previous line. MoveToNextPage Move cursor to next page. MoveToPreviousPage Move cursor to previous page. MoveToStartOfLine Move cursor to start of line. MoveToEndOfLine Move cursor to end of line. MoveToStartOfBlock Move cursor to start of a block. This shortcut is only used on OS X. MoveToEndOfBlock Move cursor to end of block. This shortcut is only used on the OS X. MoveToStartOfDocument Move cursor to start of document. MoveToEndOfDocument Move cursor to end of document. SelectNextChar Extend selection to next character. SelectPreviousChar Extend selection to previous character. SelectNextWord Extend selection to next word. SelectPreviousWord Extend selection to previous word. SelectNextLine Extend selection to next line. SelectPreviousLine Extend selection to previous line. SelectNextPage Extend selection to next page. SelectPreviousPage Extend selection to previous page. SelectStartOfLine Extend selection to start of line. SelectEndOfLine Extend selection to end of line. SelectStartOfBlock Extend selection to the start of a text block. This shortcut is only used on OS X. SelectEndOfBlock Extend selection to the end of a text block. This shortcut is only used on OS X. SelectStartOfDocument Extend selection to start of document. SelectEndOfDocument Extend selection to end of document. DeleteStartOfWord Delete the beginning of a word up to the cursor. DeleteEndOfWord Delete word from the end of the cursor. DeleteEndOfLine Delete end of line.

Definition at line 55 of file qkeysequence.h.

00055                      {
00056         UnknownKey,
00057         HelpContents,
00058         WhatsThis,
00059         Open,
00060         Close,
00061         Save,
00062         New,
00063         Delete,
00064         Cut,
00065         Copy,
00066         Paste,
00067         Undo,
00068         Redo,
00069         Back,
00070         Forward,
00071         Refresh,
00072         ZoomIn,
00073         ZoomOut,
00074         Print,
00075         AddTab,
00076         NextChild,
00077         PreviousChild,
00078         Find,
00079         FindNext,
00080         FindPrevious,
00081         Replace,
00082         SelectAll,
00083         Bold,
00084         Italic,
00085         Underline,
00086         MoveToNextChar,
00087         MoveToPreviousChar,
00088         MoveToNextWord,
00089         MoveToPreviousWord,
00090         MoveToNextLine,
00091         MoveToPreviousLine,
00092         MoveToNextPage,
00093         MoveToPreviousPage,
00094         MoveToStartOfLine,
00095         MoveToEndOfLine,
00096         MoveToStartOfBlock,
00097         MoveToEndOfBlock,
00098         MoveToStartOfDocument,
00099         MoveToEndOfDocument,
00100         SelectNextChar,
00101         SelectPreviousChar,
00102         SelectNextWord,
00103         SelectPreviousWord,
00104         SelectNextLine,
00105         SelectPreviousLine,
00106         SelectNextPage,
00107         SelectPreviousPage,
00108         SelectStartOfLine,
00109         SelectEndOfLine,
00110         SelectStartOfBlock,
00111         SelectEndOfBlock,
00112         SelectStartOfDocument,
00113         SelectEndOfDocument,
00114         DeleteStartOfWord,
00115         DeleteEndOfWord,
00116         DeleteEndOfLine
00117      };

enum QKeySequence::SequenceMatch

NoMatch The key sequences are different; not even partially matching. PartialMatch The key sequences match partially, but are not the same. ExactMatch The key sequences are the same. Identical

Definition at line 129 of file qkeysequence.h.

00129                        {
00130         NoMatch,
00131         PartialMatch,
00132         ExactMatch
00133 #ifdef QT3_SUPPORT
00134         , Identical = ExactMatch
00135 #endif
00136     };

enum QKeySequence::SequenceFormat

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.

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.

Definition at line 138 of file qkeysequence.h.

00138                         {
00139         NativeText,
00140         PortableText
00141     };


Constructor & Destructor Documentation

QKeySequence::QKeySequence (  ) 

Constructs an empty key sequence.

Definition at line 546 of file qkeysequence.cpp.

References d.

Referenced by fromString(), keyBindings(), and mnemonic().

00547 {
00548     d = new QKeySequencePrivate();
00549 }

QKeySequence::QKeySequence ( const QString key  ) 

Creates a key sequence from the 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 constructor is typically used with tr (), so that shortcut keys can be replaced in translations:

        QMenu *file = new QMenu(this);
        file->addAction(tr("&Open..."), this, SLOT(open()),
                          QKeySequence(tr("Ctrl+O", "File|Open")));

Note the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator.

Definition at line 574 of file qkeysequence.cpp.

References assign(), d, and key.

00575 {
00576     d = new QKeySequencePrivate();
00577     assign(key);
00578 }

Here is the call graph for this function:

QKeySequence::QKeySequence ( int  k1,
int  k2 = 0,
int  k3 = 0,
int  k4 = 0 
)

Constructs a key sequence with up to 4 keys k1, k2, k3 and 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.

Definition at line 588 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::key.

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 }

QKeySequence::QKeySequence ( const QKeySequence keysequence  ) 

Copy constructor. Makes a copy of keysequence.

Definition at line 600 of file qkeysequence.cpp.

References d, QKeySequencePrivate::ref, and QBasicAtomic::ref().

00601     : d(keysequence.d)
00602 {
00603     d->ref.ref();
00604 }

Here is the call graph for this function:

QKeySequence::QKeySequence ( StandardKey  key  ) 

Since:
4.2
Constructs a QKeySequence object for the given key. The result will depend on the currently running platform.

The resulting object will be based on the first element in the list of key bindings for the key.

Definition at line 530 of file qkeysequence.cpp.

References d, QList< T >::first(), keyBindings(), QKeySequencePrivate::ref, QBasicAtomic::ref(), and QList< T >::size().

00531 {
00532     const QList <QKeySequence> bindings = keyBindings(key);
00533     //pick only the first/primary shortcut from current bindings
00534     if (bindings.size() > 0) {
00535         d = bindings.first().d; 
00536         d->ref.ref();
00537     }
00538     else
00539         d = new QKeySequencePrivate();
00540 }

Here is the call graph for this function:

QKeySequence::~QKeySequence (  ) 

Destroys the key sequence.

Definition at line 633 of file qkeysequence.cpp.

References d, QBasicAtomic::deref(), and QKeySequencePrivate::ref.

00634 {
00635     if (!d->ref.deref())
00636         delete d;
00637 }

Here is the call graph for this function:


Member Function Documentation

uint QKeySequence::count (  )  const

Returns the number of keys in the key sequence. The maximum is 4.

Definition at line 657 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::key.

Referenced by Q3AccelManager::dispatchAccelEvent(), Q3AccelManager::match(), QShortcutMap::matches(), matches(), operator int(), operator<<(), and toString().

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 }

bool QKeySequence::isEmpty (  )  const

Returns true if the key sequence is empty; otherwise returns false.

Definition at line 675 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::key.

Referenced by QMenuPrivate::calcActionRects(), QActionPrivate::redoGrab(), QShortcutPrivate::redoGrab(), and QAbstractButton::setText().

00676 {
00677     return !d->key[0];
00678 }

QString QKeySequence::toString ( SequenceFormat  format = PortableText  )  const

Since:
4.1
Return a string representation of the key sequence, based on format.

For example, the value Qt::CTRL+QtKey_O results in "Ctrl+O". If the key sequence has multiple key codes, each is separated by commas in the string returned, such as "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are translated using QObject::tr() in the "QShortcut" context.

If the key sequence has no keys, an empty string is returned.

On Mac OS X, the string returned resembles the sequence that is shown in the menubar.

See also:
fromString()

Definition at line 1160 of file qkeysequence.cpp.

References count(), d, QKeySequencePrivate::encodeString(), i, QKeySequencePrivate::key, QString::length(), and QString::truncate().

Referenced by operator QString().

01161 {
01162     QString finalString;
01163     // A standard string, with no translation or anything like that. In some ways it will
01164     // look like our latin case on Windows and X11
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 }

Here is the call graph for this function:

QKeySequence QKeySequence::fromString ( const QString str,
SequenceFormat  format = PortableText 
) [static]

Since:
4.1
Return a QKeySequence from the string str based on format.

See also:
toString()

Definition at line 1181 of file qkeysequence.cpp.

References QList< T >::count(), QKeySequencePrivate::decodeString(), i, QKeySequence(), qMin(), and QString::split().

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 }

Here is the call graph for this function:

QKeySequence::SequenceMatch QKeySequence::matches ( const QKeySequence seq  )  const

Matches the sequence with seq. Returns ExactMatch if successful, PartialMatch if seq matches incompletely, and NoMatch if the sequences have nothing in common. Returns NoMatch if seq is shorter.

Definition at line 991 of file qkeysequence.cpp.

References count(), ExactMatch, i, match(), NoMatch, and PartialMatch.

Referenced by Q3AccelManager::match().

00992 {
00993     uint userN = count(),
00994           seqN = seq.count();
00995 
00996     if (userN > seqN)
00997         return NoMatch;
00998 
00999     // If equal in length, we have a potential ExactMatch sequence,
01000     // else we already know it can only be partial.
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 }

Here is the call graph for this function:

QKeySequence QKeySequence::mnemonic ( const QString text  )  [static]

Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics are found.

For example, mnemonic("E&xit") returns {Qt::ALT+QtKey_X}, mnemonic("&Quit") returns {ALT+Key_Q}, and mnemonic("Quit") returns an empty QKeySequence.

We provide a {accelerators.html}{list of common mnemonics} in English. At the time of writing, Microsoft and Open Group do not appear to have issued equivalent recommendations for other languages.

Definition at line 694 of file qkeysequence.cpp.

References Qt::ALT, QString::at(), c, QString::indexOf(), QString::length(), p, QKeySequence(), and qt_sequence_no_mnemonics.

Referenced by QTabBar::insertTab(), QMenu::keyPressEvent(), QTabBar::setTabText(), QAbstractButton::setText(), QGroupBox::setTitle(), QMenuBarPrivate::updateGeometries(), and QLabelPrivate::updateShortcut().

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 }

Here is the call graph for this function:

QList< QKeySequence > QKeySequence::keyBindings ( StandardKey  key  )  [static]

Since:
4.2
Returns a list of key bindings for the given key. The result of calling this function will vary based on the target platform. The first element of the list indicates the primary shortcut for the given platform. If the result contains more than one result, these can be considered alternative shortcuts on the same platform for the given key.

Definition at line 615 of file qkeysequence.cpp.

References QList< T >::append(), QApplicationPrivate::currentPlatform(), i, QKeySequencePrivate::keyBindings, QKeySequencePrivate::numberOfKeyBindings, QList< T >::prepend(), and QKeySequence().

Referenced by QWorkspacePrivate::init(), QKeySequence(), and QAction::setShortcuts().

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 }

Here is the call graph for this function:

QKeySequence::operator QString (  )  const

Use toString() instead.

Definition at line 1018 of file qkeysequence.cpp.

References NativeText, and toString().

01019 {
01020     return QKeySequence::toString(QKeySequence::NativeText);
01021 }

Here is the call graph for this function:

QKeySequence::operator QVariant (  )  const

Returns the key sequence as a QVariant

Definition at line 1026 of file qkeysequence.cpp.

References QVariant::KeySequence.

01027 {
01028     return QVariant(QVariant::KeySequence, this);
01029 }

QKeySequence::operator int (  )  const

For backward compatibility: returns the first keycode as integer. If the key sequence is empty, 0 is returned.

Definition at line 1036 of file qkeysequence.cpp.

References count(), d, and QKeySequencePrivate::key.

01037 {
01038     if (1 <= count())
01039         return d->key[0];
01040     return 0;
01041 }

Here is the call graph for this function:

int QKeySequence::operator[] ( uint  index  )  const

Returns a reference to the element at position index in the key sequence. This can only be used to read an element.

Definition at line 1048 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::key.

01049 {
01050     Q_ASSERT_X(index < 4, "QKeySequence::operator[]", "index out of range");
01051     return d->key[index];
01052 }

QKeySequence & QKeySequence::operator= ( const QKeySequence other  ) 

Assignment operator. Assigns the other key sequence to this object.

Definition at line 1059 of file qkeysequence.cpp.

References d, and qAtomicAssign().

01060 {
01061     qAtomicAssign(d, other.d);
01062     return *this;
01063 }

Here is the call graph for this function:

bool QKeySequence::operator== ( const QKeySequence other  )  const

Returns true if this key sequence is equal to the other key sequence; otherwise returns false.

Definition at line 1077 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::key.

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 }

bool QKeySequence::operator!= ( const QKeySequence other  )  const [inline]

Returns true if this key sequence is not equal to the other key sequence; otherwise returns false.

Definition at line 157 of file qkeysequence.h.

00158     { return !(*this == other); }

bool QKeySequence::operator< ( const QKeySequence other  )  const

Provides an arbitrary comparison of this key sequence and other key sequence. All that is guaranteed is that the operator returns false if both key sequences are equal and that (ks1 < ks2) == !( ks2 < ks1) if the key sequences are not equal.

This function is useful in some circumstances, for example if you want to use QKeySequence objects as keys in a QMap.

See also:
operator==() operator!=() operator>() operator<=() operator>=()

Definition at line 1098 of file qkeysequence.cpp.

References d, i, and QKeySequencePrivate::key.

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 }

bool QKeySequence::operator> ( const QKeySequence other  )  const [inline]

Returns true if this key sequence is larger than the other key sequence; otherwise returns false.

See also:
operator==() operator!=() operator<() operator<=() operator>=()

Definition at line 160 of file qkeysequence.h.

00161     { return other < *this; }

bool QKeySequence::operator<= ( const QKeySequence other  )  const [inline]

Returns true if this key sequence is smaller or equal to the other key sequence; otherwise returns false.

See also:
operator==() operator!=() operator<() operator>() operator>=()

Definition at line 162 of file qkeysequence.h.

00163     { return !(other < *this); }

bool QKeySequence::operator>= ( const QKeySequence other  )  const [inline]

Returns true if this key sequence is larger or equal to the other key sequence; otherwise returns false.

See also:
operator==() operator!=() operator<() operator>() operator<=()

Definition at line 164 of file qkeysequence.h.

00165     { return !(*this < other); }

bool QKeySequence::isDetached (  )  const

Definition at line 1136 of file qkeysequence.cpp.

References d, and QKeySequencePrivate::ref.

01137 {
01138     return d->ref == 1;
01139 }

int QKeySequence::decodeString ( const QString str  )  [static, private]

Constructs a single key from the string str.

Definition at line 774 of file qkeysequence.cpp.

References QKeySequencePrivate::decodeString().

Referenced by assign().

00775 {
00776     return QKeySequencePrivate::decodeString(str, NativeText);
00777 }

Here is the call graph for this function:

QString QKeySequence::encodeString ( int  key  )  [static, private]

Creates a shortcut string for key. For example, Qt::CTRL+QtKey_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are translated (using QObject::tr()) in the "QShortcut" context.

Definition at line 897 of file qkeysequence.cpp.

References QKeySequencePrivate::encodeString(), and NativeText.

Referenced by Q3AccelManager::dispatchAccelEvent().

00898 {
00899     return QKeySequencePrivate::encodeString(key, NativeText);
00900 }

Here is the call graph for this function:

int QKeySequence::assign ( const QString keys  )  [private]

Adds the given keys to the key sequence. keys may contain up to four key codes, provided they are separated by a comma; for example, "Alt+X,Ctrl+S,Z". The return value is the number of key codes added.

Definition at line 724 of file qkeysequence.cpp.

References QString::at(), QString::count(), d, decodeString(), diff(), QString::indexOf(), QKeySequencePrivate::key, QString::left(), QString::length(), n, p, and QString::right().

Referenced by QKeySequence().

00725 {
00726     QString keyseq = ks;
00727     QString part;
00728     int n = 0;
00729     int p = 0, diff = 0;
00730 
00731     // Run through the whole string, but stop
00732     // if we have 4 keys before the end.
00733     while (keyseq.length() && n < 4) {
00734         // We MUST use something to separate each sequence, and space
00735         // does not cut it, since some of the key names have space
00736         // in them.. (Let's hope no one translate with a comma in it:)
00737         p = keyseq.indexOf(QLatin1Char(','));
00738         if (-1 != p) {
00739             if (p == keyseq.count() - 1) { // Last comma 'Ctrl+,'
00740                 p = -1;
00741             } else {
00742                 if (QLatin1Char(',') == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'
00743                     p++;
00744                 if (QLatin1Char(' ') == keyseq.at(p+1)) { // Space after comma
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 }

Here is the call graph for this function:

void QKeySequence::setKey ( int  key,
int  index 
) [private]

Definition at line 646 of file qkeysequence.cpp.

References d, QKeySequencePrivate::key, and qAtomicDetach().

Referenced by QShortcutMap::createNewSequences(), and Q3AccelManager::match().

00647 {
00648     Q_ASSERT_X(index >= 0 && index < 4, "QKeySequence::setKey", "index out of range");
00649     qAtomicDetach(d);
00650     d->key[index] = key;
00651 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Q3AccelManager [friend]

Definition at line 178 of file qkeysequence.h.

friend class QShortcutMap [friend]

Definition at line 179 of file qkeysequence.h.

friend class QShortcut [friend]

Definition at line 180 of file qkeysequence.h.

QDataStream & operator<< ( QDataStream stream,
const QKeySequence sequence 
) [friend]

Writes the key sequence to the stream.

See also:
Format of the QDataStream operators

Definition at line 1203 of file qkeysequence.cpp.

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 }

QDataStream & operator>> ( QDataStream stream,
QKeySequence sequence 
) [friend]

Reads a key sequence from the stream into the key sequence.

See also:
Format of the QDataStream operators

Definition at line 1226 of file qkeysequence.cpp.

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 }


Member Data Documentation

QKeySequencePrivate* QKeySequence::d [private]

Definition at line 174 of file qkeysequence.h.

Referenced by assign(), count(), isDetached(), isEmpty(), operator int(), operator<(), operator<<(), operator=(), operator==(), operator>>(), operator[](), QKeySequence(), setKey(), toString(), and ~QKeySequence().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:07:29 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1