KDECore
KShortcut Class Reference
The KShortcut class is used to represent a keyboard shortcut to an action. More...
#include <kshortcut.h>
Public Types | |
enum | { MAX_SEQUENCES = 2 } |
Public Member Functions | |
bool | append (const KShortcut &cut) |
bool | append (const KKey &spec) |
bool | append (const KKeySequence &keySeq) |
void | clear () |
int | compare (const KShortcut &shortcut) const |
bool | contains (const KKeySequence &keySeq) const |
bool | contains (const KKeyNative &key) const |
bool | contains (const KKey &key) const |
uint | count () const |
bool | init (const QString &shortcut) |
bool | init (const KShortcut &shortcut) |
bool | init (const KKeySequence &keySeq) |
bool | init (const KKey &key) |
bool | init (const QKeySequence &keySeq) |
bool | init (int keyQt) |
bool | isNull () const |
int | keyCodeQt () const |
KShortcut (const QString &shortcut) | |
KShortcut (const char *shortcut) | |
KShortcut (const KShortcut &shortcut) | |
KShortcut (const KKeySequence &keySeq) | |
KShortcut (const KKey &key) | |
KShortcut (const QKeySequence &keySeq) | |
KShortcut (int keyQt) | |
KShortcut () | |
operator int () const | |
operator QKeySequence () const | |
bool | operator!= (const KShortcut &cut) const |
bool | operator< (const KShortcut &cut) const |
KShortcut & | operator= (const KShortcut &cut) |
bool | operator== (const KShortcut &cut) const |
void | remove (const KKeySequence &keySeq) |
const KKeySequence & | seq (uint i) const |
bool | setSeq (uint i, const KKeySequence &keySeq) |
QString | toString () const |
QString | toStringInternal (const KShortcut *pcutDefault=0) const |
~KShortcut () | |
Static Public Member Functions | |
static KShortcut & | null () |
Protected Attributes | |
uint | m_nSeqs |
KKeySequence | m_rgseq [MAX_SEQUENCES] |
Detailed Description
The KShortcut class is used to represent a keyboard shortcut to an action.A shortcut is normally a single key with modifiers, such as Ctrl+V. A KShortcut object may also contain an alternate key which will also activate the action it's associated to, as long as no other actions have defined that key as their primary key. Ex: Ctrl+V;Shift+Insert.
This can be used to add additional accelerators to a KAction. For example, the below code binds the escape key to the close action.
KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() ); KShortcut closeShortcut = closeAction->shortcut(); closeShortcut.append( KKey(Key_Escape)); closeAction->setShortcut(closeShortcut);
Note that a shortcut cannot have more than 2 key combinations associated with it, so the above code would not do anything (and append() would return false) if the closeAction already had an key and alternate key.
Definition at line 543 of file kshortcut.h.
Member Enumeration Documentation
anonymous enum |
The maximum number of key sequences that can be contained in a KShortcut.
Definition at line 550 of file kshortcut.h.
Constructor & Destructor Documentation
KShortcut::KShortcut | ( | ) |
KShortcut::KShortcut | ( | int | keyQt | ) |
Creates a new shortcut with the given Qt key code as the only key sequence.
- Parameters:
-
keyQt the qt keycode
- See also:
- Qt::Key
Definition at line 403 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const QKeySequence & | keySeq | ) |
Creates a new shortcut that contains only the given qt key sequence.
- Parameters:
-
keySeq the qt key sequence to add
Definition at line 404 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const KKey & | key | ) |
Creates a new shortcut that contains only the given key in its only sequence.
- Parameters:
-
key the key to add
Definition at line 405 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const KKeySequence & | keySeq | ) |
Creates a new shortcut that contains only the given key sequence.
- Parameters:
-
keySeq the key sequence to add
Definition at line 406 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const KShortcut & | shortcut | ) |
Copies the given shortcut.
- Parameters:
-
shortcut the shortcut to add
Definition at line 407 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const char * | shortcut | ) |
Creates a new key sequence that contains the given key sequence.
The description consists of semicolon-separated keys as used in KKeySequence::KKeySequence(const QString&).
- Parameters:
-
shortcut the description of the key
Definition at line 408 of file kshortcut.cpp.
KShortcut::KShortcut | ( | const QString & | shortcut | ) |
Creates a new key sequence that contains the given key sequence.
The description consists of semicolon-separated keys as used in KKeySequence::KKeySequence(const QString&).
- Parameters:
-
shortcut the description of the key
Definition at line 409 of file kshortcut.cpp.
KShortcut::~KShortcut | ( | ) |
Definition at line 411 of file kshortcut.cpp.
Member Function Documentation
Appends the sequences from the given shortcut.
- Parameters:
-
cut the shortcut to append
- Returns:
- true if successful, false otherwise
- See also:
- MAX_SEQUENCES
- Since:
- 3.2
Definition at line 606 of file kshortcut.cpp.
Appends the given key.
- Parameters:
-
spec the key to add
- Returns:
- true if successful, false otherwise
- See also:
- setSeq()
- Since:
- 3.2
Definition at line 596 of file kshortcut.cpp.
bool KShortcut::append | ( | const KKeySequence & | keySeq | ) |
Appends the given key sequence.
This sets it as either the keysequence or the alternate keysequence. If the shortcut already has MAX_SEQUENCES sequences then this call does nothing, and returns false.
- Parameters:
-
keySeq the key sequence to add
- Returns:
- true if successful, false otherwise
- See also:
- setSeq()
Definition at line 584 of file kshortcut.cpp.
void KShortcut::clear | ( | ) |
Clears the shortcut.
The shortcut is null after calling this function.
- See also:
- isNull()
Definition at line 415 of file kshortcut.cpp.
int KShortcut::compare | ( | const KShortcut & | shortcut | ) | const |
Compares this object with the given shortcut.
Returns a negative number if the given shortcut is larger, 0 if they are equal and a positive number this shortcut is larger. Shortcuts are compared by comparing the individual key sequences, starting from the beginning until an unequal key sequences has been found. If a shortcut contains more key sequences, it is considered larger.
- Parameters:
-
shortcut the shortcut to compare to
- Returns:
- a negative number if the given KShortcut is larger, 0 if they are equal and a positive number this KShortcut is larger
- See also:
- KKey::compare()
KKeyShortcut::compare()
Definition at line 519 of file kshortcut.cpp.
bool KShortcut::contains | ( | const KKeySequence & | keySeq | ) | const |
Checks whether this shortcut contains the given sequence.
- Parameters:
-
keySeq the key sequence to check
- Returns:
- true if the shortcut has the given key sequence
Definition at line 548 of file kshortcut.cpp.
bool KShortcut::contains | ( | const KKeyNative & | key | ) | const |
Checks whether this shortcut contains a sequence that starts with the given key.
- Parameters:
-
key the key to check
- Returns:
- true if a key sequence starts with the key
Definition at line 534 of file kshortcut.cpp.
Checks whether this shortcut contains a sequence that starts with the given key.
- Parameters:
-
key the key to check
- Returns:
- true if a key sequence starts with the key
Definition at line 529 of file kshortcut.cpp.
uint KShortcut::count | ( | ) | const |
Returns the number of sequences that are in this shortcut.
- Returns:
- the number of sequences MAX_SEQUENCES
Definition at line 497 of file kshortcut.cpp.
Initializes the key sequence with the given key sequence.
The description consists of semicolon-separated keys as used in KKeySequence::KKeySequence(const QString&).
- Parameters:
-
shortcut the description of the key
Definition at line 459 of file kshortcut.cpp.
Copies the given shortcut.
- Parameters:
-
shortcut the shortcut to add
Definition at line 451 of file kshortcut.cpp.
bool KShortcut::init | ( | const KKeySequence & | keySeq | ) |
Initializes the shortcut with the given qt key sequence.
- Parameters:
-
keySeq the qt key sequence to add
Definition at line 444 of file kshortcut.cpp.
Initializes the shortcut with the given key as its only sequence.
- Parameters:
-
key the key to add
Definition at line 437 of file kshortcut.cpp.
bool KShortcut::init | ( | const QKeySequence & | keySeq | ) |
Initializes the shortcut with the given qt key sequence.
- Parameters:
-
keySeq the qt key sequence to add
Definition at line 430 of file kshortcut.cpp.
bool KShortcut::init | ( | int | keyQt | ) |
Initializes the shortcut with the given Qt key code as the only key sequence.
- Parameters:
-
keyQt the qt keycode
- See also:
- Qt::Key
Definition at line 420 of file kshortcut.cpp.
bool KShortcut::isNull | ( | ) | const |
Returns true if the shortcut is null (after clear() or empty constructor).
- Returns:
- true if the shortcut is null
Definition at line 514 of file kshortcut.cpp.
int KShortcut::keyCodeQt | ( | ) | const |
Returns the key code of the first key sequence, or null if there is no first key sequence.
- Returns:
- the key code of the first sequence's first key
- See also:
- Qt::Key
Definition at line 507 of file kshortcut.cpp.
KShortcut & KShortcut::null | ( | ) | [static] |
KShortcut::operator int | ( | ) | const [inline] |
Definition at line 847 of file kshortcut.h.
KShortcut::operator QKeySequence | ( | ) | const |
Converts this shortcut to a key sequence.
The first key sequence will be taken.
Definition at line 624 of file kshortcut.cpp.
Compares the sequences of both shortcuts.
- See also:
- compare()
Definition at line 729 of file kshortcut.h.
Compares the sequences of both shortcuts.
- See also:
- compare()
Definition at line 736 of file kshortcut.h.
Compares the sequences of both shortcuts.
- See also:
- compare()
Definition at line 722 of file kshortcut.h.
void KShortcut::remove | ( | const KKeySequence & | keySeq | ) |
Removes the given key sequence from this shortcut.
- Parameters:
-
keySeq the key sequence to remove
- Since:
- 3.3
Definition at line 569 of file kshortcut.cpp.
const KKeySequence & KShortcut::seq | ( | uint | i | ) | const |
Returns the i'th
key sequence of this shortcut.
- Parameters:
-
i the number of the key sequence to retrieve
- Returns:
- the
i'th
sequence or KKeySequence::null() if there are less thani
key sequences MAX_SEQUENCES
Definition at line 502 of file kshortcut.cpp.
bool KShortcut::setSeq | ( | uint | i, | |
const KKeySequence & | keySeq | |||
) |
Sets the i
'th key sequence of the shortcut.
You can not introduce gaps in the list of sequences, so you must use an i
<= count(). Also note that the maximum number of key sequences is MAX_SEQUENCES.
- Parameters:
-
i the position of the new key sequence(0 <= i <= count(), 0 <= i < MAX_SEQUENCES) keySeq the key sequence to set
- Returns:
- true if successful, false otherwise
Definition at line 557 of file kshortcut.cpp.
QString KShortcut::toString | ( | ) | const |
Returns a description of the shortcut as semicolon-separated ket sequences, as returned by KKeySequence::toString().
- Returns:
- the string represenation of this shortcut
- See also:
- KKey::toString()
Definition at line 632 of file kshortcut.cpp.
Member Data Documentation
uint KShortcut::m_nSeqs [protected] |
Definition at line 838 of file kshortcut.h.
KKeySequence KShortcut::m_rgseq[MAX_SEQUENCES] [protected] |
Definition at line 839 of file kshortcut.h.
The documentation for this class was generated from the following files: