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

KDEUI

Public Types | Public Member Functions | List of all members
KShortcut Class Reference

#include <kshortcut.h>

Public Types

enum  EmptyHandling { KeepEmpty = 0, RemoveEmpty }
 

Public Member Functions

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

Mutator methods

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

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.

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
primaryQt 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
primaryQt keycode of primary shortcut
alternateQt 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
keyQtPriQt keycode of primary shortcut
keyQtAltQt 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
descriptionthe 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
seqsList of key sequeces.

Definition at line 80 of file kshortcut.cpp.

KShortcut::~KShortcut ( )

Destructor.

Definition at line 129 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 139 of file kshortcut.cpp.

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

Returns whether at least one of the key sequences conflicts witho needle.

Returns
whether this shortcut conflicts with needle

Definition at line 156 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 149 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 144 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 228 of file kshortcut.cpp.

KShortcut::operator QVariant ( ) const

Returns shortcut as QVariant.

Definition at line 265 of file kshortcut.cpp.

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

Definition at line 223 of file kshortcut.cpp.

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

Assignment operator.

Definition at line 211 of file kshortcut.cpp.

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

Definition at line 218 of file kshortcut.cpp.

QKeySequence KShortcut::primary ( ) const

Returns the primary key sequence of this shortcut.

Returns
primary key sequence

Definition at line 134 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
keySeqremove this key sequence from the shortcut

Definition at line 194 of file kshortcut.cpp.

void KShortcut::setAlternate ( const QKeySequence &  keySeq)

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

Parameters
keySeqset alternate key sequence to this

Definition at line 189 of file kshortcut.cpp.

void KShortcut::setPrimary ( const QKeySequence &  keySeq)

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

Parameters
keySeqset primary key sequence to this

Definition at line 184 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 233 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 249 of file kshortcut.cpp.

QString KShortcut::toString ( QKeySequence::SequenceFormat  format) 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)
Since
KDE 4.2

Definition at line 254 of file kshortcut.cpp.


The documentation for this class was generated from the following files:
  • kshortcut.h
  • kshortcut.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal