org.kde.koala
Class KShortcut

java.lang.Object
  extended by org.kde.koala.KShortcut
All Implemented Interfaces:
org.kde.qt.QtSupport

public class KShortcut
extends java.lang.Object
implements org.kde.qt.QtSupport

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.


Field Summary
static int MAX_SEQUENCES
          The maximum number of key sequences that can be contained in a KShortcut.
 
Constructor Summary
  KShortcut()
          Creates a new null shortcut.
protected KShortcut(java.lang.Class dummy)
           
  KShortcut(int keyQt)
          Creates a new shortcut with the given Qt key code as the only key sequence.
  KShortcut(KKey key)
          Creates a new shortcut that contains only the given key in its only sequence.
  KShortcut(KKeySequence keySeq)
          Creates a new shortcut that contains only the given key sequence.
  KShortcut(KShortcut shortcut)
          Copies the given shortcut.
  KShortcut(org.kde.qt.QKeySequence keySeq)
          Creates a new shortcut that contains only the given qt key sequence.
  KShortcut(java.lang.String shortcut)
          Creates a new key sequence that contains the given key sequence.
 
Method Summary
 boolean append(KKey spec)
          Appends the given key
 boolean append(KKeySequence keySeq)
          Appends the given key sequence.
 boolean append(KShortcut cut)
          Appends the sequences from the given shortcut.
 void clear()
          Clears the shortcut.
 int compare(KShortcut shortcut)
          Compares this object with the given shortcut.
 boolean contains(KKey key)
          Checks whether this shortcut contains a sequence that starts with the given key.
 boolean contains(KKeySequence keySeq)
          Checks whether this shortcut contains the given sequence.
 int count()
          Returns the number of sequences that are in this shortcut.
 void dispose()
          Delete the wrapped C++ instance ahead of finalize()
protected  void finalize()
          Deletes the wrapped C++ instance
 boolean init(int keyQt)
          Initializes the shortcut with the given Qt key code as the only key sequence.
 boolean init(KKey key)
          Initializes the shortcut with the given key as its only sequence.
 boolean init(KKeySequence keySeq)
          Initializes the shortcut with the given qt key sequence.
 boolean init(KShortcut shortcut)
          Copies the given shortcut.
 boolean init(org.kde.qt.QKeySequence keySeq)
          Initializes the shortcut with the given qt key sequence.
 boolean init(java.lang.String shortcut)
          Initializes the key sequence with the given key sequence.
 boolean isDisposed()
          Has the wrapped C++ instance been deleted?
 boolean isNull()
          Returns true if the shortcut is null (after clear() or empty constructor).
 int keyCodeQt()
          Returns the key code of the first key sequence, or null if there is no first key sequence.
static KShortcut nil()
          Returns a null shortcut.
 boolean op_equals(KShortcut cut)
          Compares the sequences of both shortcuts.
 boolean op_lt(KShortcut cut)
          Compares the sequences of both shortcuts.
 boolean op_not_equals(KShortcut cut)
          Compares the sequences of both shortcuts.
 void remove(KKeySequence keySeq)
          Removes the given key sequence from this shortcut
 KKeySequence seq(int i)
          Returns the i'th key sequence of this shortcut.
 boolean setSeq(int i, KKeySequence keySeq)
          Sets the i 'th key sequence of the shortcut.
 java.lang.String toString()
          Returns a description of the shortcut as semicolon-separated ket sequences, as returned by KKeySequence.toString().
 java.lang.String toStringInternal()
           
 java.lang.String toStringInternal(KShortcut pcutDefault)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SEQUENCES

public static final int MAX_SEQUENCES
The maximum number of key sequences that can be contained in a KShortcut.

See Also:
Constant Field Values
Constructor Detail

KShortcut

protected KShortcut(java.lang.Class dummy)

KShortcut

public KShortcut()
Creates a new null shortcut.

See Also:
#null, isNull(), clear()

KShortcut

public 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:
org.kde.qt.Qt#Key

KShortcut

public KShortcut(org.kde.qt.QKeySequence keySeq)
Creates a new shortcut that contains only the given qt key sequence.

Parameters:
keySeq - the qt key sequence to add

KShortcut

public KShortcut(KKey key)
Creates a new shortcut that contains only the given key in its only sequence.

Parameters:
key - the key to add

KShortcut

public KShortcut(KKeySequence keySeq)
Creates a new shortcut that contains only the given key sequence.

Parameters:
keySeq - the key sequence to add

KShortcut

public KShortcut(KShortcut shortcut)
Copies the given shortcut.

Parameters:
shortcut - the shortcut to add

KShortcut

public KShortcut(java.lang.String shortcut)
Creates a new key sequence that contains the given key sequence. The description consists of semicolon-separated keys as used in KKeySequence.KKeySequence(String).

Parameters:
shortcut - the description of the key
See Also:
KKeySequence#KKeySequence(const
Method Detail

clear

public void clear()
Clears the shortcut. The shortcut is null after calling this function.

See Also:
isNull()

init

public boolean init(int keyQt)
Initializes the shortcut with the given Qt key code as the only key sequence.

Parameters:
keyQt - the qt keycode
See Also:
org.kde.qt.Qt#Key

init

public boolean init(org.kde.qt.QKeySequence keySeq)
Initializes the shortcut with the given qt key sequence.

Parameters:
keySeq - the qt key sequence to add

init

public boolean init(KKey key)
Initializes the shortcut with the given key as its only sequence.

Parameters:
key - the key to add

init

public boolean init(KKeySequence keySeq)
Initializes the shortcut with the given qt key sequence.

Parameters:
keySeq - the qt key sequence to add

init

public boolean init(KShortcut shortcut)
Copies the given shortcut.

Parameters:
shortcut - the shortcut to add

init

public boolean init(java.lang.String shortcut)
Initializes the key sequence with the given key sequence. The description consists of semicolon-separated keys as used in KKeySequence.KKeySequence(String).

Parameters:
shortcut - the description of the key
See Also:
KKeySequence#KKeySequence(const

count

public int count()
Returns the number of sequences that are in this shortcut.

Returns:
the number of sequences MAX_SEQUENCES

seq

public KKeySequence seq(int i)
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 than i key sequences MAX_SEQUENCES

keyCodeQt

public int keyCodeQt()
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:
org.kde.qt.Qt#Key, KKeySequence.keyCodeQt()

isNull

public boolean isNull()
Returns true if the shortcut is null (after clear() or empty constructor).

Returns:
true if the shortcut is null
See Also:
clear(), #null

compare

public int compare(KShortcut shortcut)
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(org.kde.koala.KKey), KKeyShortcut#compare

op_equals

public boolean op_equals(KShortcut cut)
Compares the sequences of both shortcuts.

See Also:
compare(org.kde.koala.KShortcut)

op_not_equals

public boolean op_not_equals(KShortcut cut)
Compares the sequences of both shortcuts.

See Also:
compare(org.kde.koala.KShortcut)

op_lt

public boolean op_lt(KShortcut cut)
Compares the sequences of both shortcuts.

See Also:
compare(org.kde.koala.KShortcut)

contains

public boolean contains(KKey key)
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

contains

public boolean contains(KKeySequence keySeq)
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

setSeq

public boolean setSeq(int i,
                      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

append

public boolean append(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(int, org.kde.koala.KKeySequence)

remove

public void remove(KKeySequence keySeq)
Removes the given key sequence from this shortcut

Parameters:
keySeq - the key sequence to remove

append

public boolean append(KKey spec)
Appends the given key

Parameters:
spec - the key to add
Returns:
true if successful, false otherwise
See Also:
setSeq(int, org.kde.koala.KKeySequence), MAX_SEQUENCES

append

public boolean append(KShortcut cut)
Appends the sequences from the given shortcut.

Parameters:
cut - the shortcut to append
Returns:
true if successful, false otherwise
See Also:
MAX_SEQUENCES

toString

public java.lang.String toString()
Returns a description of the shortcut as semicolon-separated ket sequences, as returned by KKeySequence.toString().

Overrides:
toString in class java.lang.Object
Returns:
the string represenation of this shortcut
See Also:
KKey.toString(), KKeySequence.toString()

toStringInternal

public java.lang.String toStringInternal(KShortcut pcutDefault)

toStringInternal

public java.lang.String toStringInternal()

nil

public static KShortcut nil()
Returns a null shortcut.

Returns:
the null shortcut
See Also:
isNull(), clear()

finalize

protected void finalize()
                 throws java.lang.InternalError
Deletes the wrapped C++ instance

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.InternalError

dispose

public void dispose()
Delete the wrapped C++ instance ahead of finalize()


isDisposed

public boolean isDisposed()
Has the wrapped C++ instance been deleted?