• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

KShortcut Class Reference

#include <kshortcut.h>

List of all members.


Detailed Description

Represents a keyboard shortcut.

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 sequence which will also activate the action it's associated with, 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 = KStandardAction::close(this, SLOT( close() ), actionCollection());
  KShortcut closeShortcut = closeAction->shortcut();
  closeShortcut.setAlternate(Qt::Key_Escape);
  closeAction->setShortcut(closeShortcut);

Definition at line 57 of file kshortcut.h.


Mutator methods

KShortcut & operator= (const KShortcut &other)
void remove (const QKeySequence &keySeq, enum EmptyHandling handleEmpty=RemoveEmpty)
void setAlternate (const QKeySequence &keySeq)
void setPrimary (const QKeySequence &keySeq)

Public Types

enum  EmptyHandling { KeepEmpty = 0, RemoveEmpty }

Public Member Functions

 KShortcut (const QList< QKeySequence > &seqs)
 KShortcut (const QString &description)
 KShortcut (const KShortcut &other)
 KShortcut (int keyQtPri, int keyQtAlt=0)
 KShortcut (const QKeySequence &primary, const QKeySequence &alternate)
 KShortcut (const QKeySequence &primary)
 KShortcut ()
 ~KShortcut ()
Query methods
QKeySequence alternate () const
bool contains (const QKeySequence &needle) const
bool isEmpty () const
 operator QList< QKeySequence > () const
 operator QVariant () const
bool operator!= (const KShortcut &other) const
bool operator== (const KShortcut &other) const
QKeySequence primary () const
QList< QKeySequence > toList (enum EmptyHandling handleEmpty=RemoveEmpty) const
QString toString () const

Member Enumeration Documentation

enum KShortcut::EmptyHandling

An enum about the behavior of operations that treat a KShortcut like a list of QKeySequences.

Enumerator:
KeepEmpty  if a shortcut is or becomes empty, let it stay as a placeholder
RemoveEmpty  remove empty QKeySequences, possibly changing the positions of QKeySequences due to the ensuing reshuffling.

Definition at line 63 of file kshortcut.h.


Constructor & Destructor Documentation

KShortcut::KShortcut (  ) 

Creates a new empty shortcut.

See also:
isEmpty()

clear()

Definition at line 44 of file kshortcut.cpp.

KShortcut::KShortcut ( const QKeySequence &  primary  )  [explicit]

Creates a new shortcut that contains the given Qt key sequence as primary shortcut.

Parameters:
primary Qt key sequence to add

Definition at line 50 of file kshortcut.cpp.

KShortcut::KShortcut ( const QKeySequence &  primary,
const QKeySequence &  alternate 
)

Creates a new shortcut with the given Qt key sequences as primary and secondary shortcuts.

Parameters:
primary Qt keycode of primary shortcut
alternate Qt keycode of alternate shortcut
See also:
Qt::Key

Definition at line 57 of file kshortcut.cpp.

KShortcut::KShortcut ( int  keyQtPri,
int  keyQtAlt = 0 
) [explicit]

Creates a new shortcut with the given Qt key codes as primary and secondary shortcuts.

You can only assign single-key shortcuts this way.

Parameters:
keyQtPri Qt keycode of primary shortcut
keyQtAlt Qt keycode of alternate shortcut
See also:
Qt::Key

Definition at line 65 of file kshortcut.cpp.

KShortcut::KShortcut ( const KShortcut &  other  ) 

Copy constructor.

Definition at line 73 of file kshortcut.cpp.

KShortcut::KShortcut ( const QString &  description  )  [explicit]

Creates a new shortcut that contains the key sequences described in description.

The format of description is the same as used in QKeySequence::fromString(const QString&). Up to two key sequences separated by a semicolon followed by a space "; " may be given.

Parameters:
description the description of key sequence(s)
See also:
QKeySequence::fromString(const QString&, SequenceFormat)

Definition at line 90 of file kshortcut.cpp.

KShortcut::KShortcut ( const QList< QKeySequence > &  seqs  )  [explicit]

Creates a new shortcut with the given Qt key sequences.

The first sequence in the list is considered to be the primary sequence, the second one the alternate.

Parameters:
seqs List of key sequeces.

Definition at line 80 of file kshortcut.cpp.

KShortcut::~KShortcut (  ) 

Destructor.

Definition at line 125 of file kshortcut.cpp.


Member Function Documentation

QKeySequence KShortcut::alternate (  )  const

Returns the alternate key sequence of this shortcut.

Returns:
alternate key sequence

Definition at line 135 of file kshortcut.cpp.

bool KShortcut::contains ( const QKeySequence &  needle  )  const

Returns whether at least one of the key sequences is equal to needle.

Returns:
whether this shortcut contains needle

Definition at line 145 of file kshortcut.cpp.

bool KShortcut::isEmpty (  )  const

Returns whether this shortcut contains any nonempty key sequences.

Returns:
whether this shortcut is empty

Definition at line 140 of file kshortcut.cpp.

KShortcut::operator QList< QKeySequence > (  )  const

Returns shortcut as QList<QKeySequence>, and is equivalent to toList(RemoveEmpty).

Be aware that empty shortcuts will not be included in the list; due to this, conversion operations like KShortcut b = (QList<QKeySequence>)KShortcut a will not always result in b == a.

Returns:
the shortcut converted to a QList<QKeySequence>

Definition at line 196 of file kshortcut.cpp.

KShortcut::operator QVariant (  )  const

Returns shortcut as QVariant.

Definition at line 228 of file kshortcut.cpp.

bool KShortcut::operator!= ( const KShortcut &  other  )  const

Definition at line 191 of file kshortcut.cpp.

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

Assignment operator.

Definition at line 179 of file kshortcut.cpp.

bool KShortcut::operator== ( const KShortcut &  other  )  const

Definition at line 186 of file kshortcut.cpp.

QKeySequence KShortcut::primary (  )  const

Returns the primary key sequence of this shortcut.

Returns:
primary key sequence

Definition at line 130 of file kshortcut.cpp.

void KShortcut::remove ( const QKeySequence &  keySeq,
enum EmptyHandling  handleEmpty = RemoveEmpty 
)

Remove keySeq from this shortcut.

If handleEmpty equals RemoveEmpty, following key sequences will move up to take the place of keySeq. Otherwise, key sequences equal to keySeq will be set to empty.

Parameters:
keySeq remove this key sequence from the shortcut

Definition at line 162 of file kshortcut.cpp.

void KShortcut::setAlternate ( const QKeySequence &  keySeq  ) 

Set the alternate key sequence of this shortcut to the given key sequence.

Parameters:
keySeq set alternate key sequence to this

Definition at line 157 of file kshortcut.cpp.

void KShortcut::setPrimary ( const QKeySequence &  keySeq  ) 

Set the primary key sequence of this shortcut to the given key sequence.

Parameters:
keySeq set primary key sequence to this

Definition at line 152 of file kshortcut.cpp.

QList< QKeySequence > KShortcut::toList ( enum EmptyHandling  handleEmpty = RemoveEmpty  )  const

The same as operator QList<QKeySequence>() If handleEmpty equals RemoveEmpty, empty key sequences will be left out of the result.

Otherwise, empy key sequences will be included; you can be sure that shortcut.alternate() == shortcut.toList(KeepEmpty).at(1).

Returns:
the shortcut converted to a QList<QKeySequence>

Definition at line 201 of file kshortcut.cpp.

QString KShortcut::toString (  )  const

Returns a description of the shortcut as a semicolon-separated list of key sequences, as returned by QKeySequence::toString().

Returns:
the string represenation of this shortcut
See also:
QKeySequence::toString()

KShortcut(const QString &description)

Definition at line 217 of file kshortcut.cpp.


The documentation for this class was generated from the following files:
  • kshortcut.h
  • kshortcut.cpp

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal