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

KDEUI

Public Types | Public Member Functions | Properties | List of all members
KKeySequenceWidget Class Reference

#include <kkeysequencewidget.h>

Inheritance diagram for KKeySequenceWidget:
QWidget

Public Types

enum  Validation { Validate = 0 , NoValidate = 1 }
 

Public Member Functions

 KKeySequenceWidget (QWidget *parent=0)
 
virtual ~KKeySequenceWidget ()
 

Properties

ShortcutTypes checkForConflictsAgainst
 
bool modifierlessAllowed
 
bool multiKeyShortcutsAllowed
 

Configuration

Configuration options for the widget.

enum  ShortcutType { None = 0x00 , LocalShortcuts = 0x01 , StandardShortcuts = 0x02 , GlobalShortcuts = 0x03 }
 
void setCheckForConflictsAgainst (ShortcutTypes types)
 
ShortcutTypes checkForConflictsAgainst () const
 
void setMultiKeyShortcutsAllowed (bool)
 
bool multiKeyShortcutsAllowed () const
 
void setModifierlessAllowed (bool allow)
 
bool isModifierlessAllowed ()
 
void setClearButtonShown (bool show)
 
bool isKeySequenceAvailable (const QKeySequence &seq) const
 
QKeySequence keySequence () const
 
void setCheckActionCollections (const QList< KActionCollection * > &actionCollections)
 
void setCheckActionList (const QList< QAction * > &checkList)
 
void setComponentName (const QString &componentName)
 
void keySequenceChanged (const QKeySequence &seq)
 
void stealShortcut (const QKeySequence &seq, KAction *action)
 
void captureKeySequence ()
 
void setKeySequence (const QKeySequence &seq, Validation val=NoValidate)
 
void clearKeySequence ()
 
void applyStealShortcut ()
 

Detailed Description

A widget to input a QKeySequence.

This widget lets the user choose a QKeySequence, which is usually used as a shortcut key. The recording is initiated by calling captureKeySequence() or the user clicking into the widget.

The widgets provides support for conflict handling. See setCheckForConflictsAgainst() for more information.

KDE Key Sequence Widget
Author
Mark Donohoe donoh.nosp@m.oe@k.nosp@m.de.or.nosp@m.g

Definition at line 51 of file kkeysequencewidget.h.

Member Enumeration Documentation

◆ ShortcutType

enum KKeySequenceWidget::ShortcutType
Enumerator
None 

No checking for conflicts.

LocalShortcuts 

Check with local shortcuts.

See also
setCheckActionCollections()
StandardShortcuts 

Check against standard shortcuts.

See also
KStandardShortcut
GlobalShortcuts 

Check against global shortcuts.

See also
KGlobalAccel

Definition at line 99 of file kkeysequencewidget.h.

◆ Validation

enum KKeySequenceWidget::Validation

An enum about validation when setting a key sequence.

See also
setKeySequence()
Enumerator
Validate 

Validate key sequence.

NoValidate 

Use key sequence without validation.

Definition at line 75 of file kkeysequencewidget.h.

Constructor & Destructor Documentation

◆ KKeySequenceWidget()

KKeySequenceWidget::KKeySequenceWidget ( QWidget *  parent = 0)
explicit

Constructor.

Definition at line 251 of file kkeysequencewidget.cpp.

◆ ~KKeySequenceWidget()

KKeySequenceWidget::~KKeySequenceWidget ( )
virtual

Destructs the widget.

Definition at line 289 of file kkeysequencewidget.cpp.

Member Function Documentation

◆ applyStealShortcut

void KKeySequenceWidget::applyStealShortcut ( )
slot

Actually remove the shortcut that the user wanted to steal, from the action that was using it.

This only applies to actions provided to us by setCheckActionCollections() and setCheckActionList().

Global and Standard Shortcuts have to be stolen immediately when the user gives his consent (technical reasons). That means those changes will be active even if you never call applyStealShortcut().

To be called before you apply your changes. No local shortcuts are stolen until this function is called.

Definition at line 398 of file kkeysequencewidget.cpp.

◆ captureKeySequence

void KKeySequenceWidget::captureKeySequence ( )
slot

Capture a shortcut from the keyboard.

This call will only return once a key sequence has been captured or input was aborted. If a key sequence was input, keySequenceChanged() will be emitted.

See also
setModifierlessAllowed()

Definition at line 364 of file kkeysequencewidget.cpp.

◆ checkForConflictsAgainst()

KKeySequenceWidget::ShortcutTypes KKeySequenceWidget::checkForConflictsAgainst ( ) const

The shortcut types we check for conflicts.

See also
setCheckForConflictsAgainst()
Since
4.2

Definition at line 295 of file kkeysequencewidget.cpp.

◆ clearKeySequence

void KKeySequenceWidget::clearKeySequence ( )
slot

Clear the key sequence.

Definition at line 392 of file kkeysequencewidget.cpp.

◆ isKeySequenceAvailable()

bool KKeySequenceWidget::isKeySequenceAvailable ( const QKeySequence &  seq) const

Checks whether the key sequence seq is available to grab.

The sequence is checked under the same rules as if it has been typed by the user. This method is useful if you get key sequences from another input source and want to check if it is save to set them.

Since
4.2

Definition at line 329 of file kkeysequencewidget.cpp.

◆ isModifierlessAllowed()

bool KKeySequenceWidget::isModifierlessAllowed ( )
See also
setModifierlessAllowed()

Definition at line 339 of file kkeysequencewidget.cpp.

◆ keySequence()

QKeySequence KKeySequenceWidget::keySequence ( ) const

Return the currently selected key sequence.

Definition at line 370 of file kkeysequencewidget.cpp.

◆ keySequenceChanged

void KKeySequenceWidget::keySequenceChanged ( const QKeySequence &  seq)
signal

This signal is emitted when the current key sequence has changed, be it by user input or programmatically.

◆ multiKeyShortcutsAllowed()

bool KKeySequenceWidget::multiKeyShortcutsAllowed ( ) const

Definition at line 306 of file kkeysequencewidget.cpp.

◆ setCheckActionCollections()

void KKeySequenceWidget::setCheckActionCollections ( const QList< KActionCollection * > &  actionCollections)

Set a list of action collections to check against for conflictuous shortcut.

See also
setCheckForConflictsAgainst()

If a KAction with a conflicting shortcut is found inside this list and its shortcut can be configured (KAction::isShortcutConfigurable() returns true) the user will be prompted whether to steal the shortcut from this action.

Since
4.1

Definition at line 358 of file kkeysequencewidget.cpp.

◆ setCheckActionList()

void KKeySequenceWidget::setCheckActionList ( const QList< QAction * > &  checkList)
Deprecated:
since 4.1 use setCheckActionCollections so that KKeySequenceWidget knows in which action collection to call the writeSettings method after stealing a shortcut from an action.

Definition at line 351 of file kkeysequencewidget.cpp.

◆ setCheckForConflictsAgainst()

void KKeySequenceWidget::setCheckForConflictsAgainst ( ShortcutTypes  types)

Configure if the widget should check for conflicts with existing shortcuts.

When capturing a key sequence for local shortcuts you should check against GlobalShortcuts and your other local shortcuts. This is the default.

You have to provide the local actions to check against with setCheckActionCollections().

When capturing a key sequence for a global shortcut you should check against StandardShortcuts, GlobalShortcuts and your local shortcuts.

There are two ways to react to a user agreeing to steal a shortcut:

  1. Listen to the stealShortcut() signal and steal the shortcuts manually. It's your responsibility to save that change later when you think it is appropriate.
  2. Call applyStealShortcut and KKeySequenceWidget will steal the shortcut. This will save the actionCollections the shortcut is part of so make sure it doesn't inadvertly save some unwanted changes too. Read its documentation for some limitation when handling global shortcuts.

If you want to do the conflict checking yourself here are some code snippets for global ...

QStringList conflicting = KGlobalAccel::findActionNameSystemwide(keySequence);
if (!conflicting.isEmpty()) {
// Inform and ask the user about the conflict and reassigning
// the keys sequence
if (!KGlobalAccel::promptStealShortcutSystemwide(q, conflicting, keySequence)) {
return true;
}
KGlobalAccel::stealShortcutSystemwide(keySequence);
}
KGlobalAccel::findActionNameSystemwide
static QStringList findActionNameSystemwide(const QKeySequence &seq)
Definition: kglobalaccel.cpp:513
KGlobalAccel::promptStealShortcutSystemwide
static bool promptStealShortcutSystemwide(QWidget *parent, const QList< KGlobalShortcutInfo > &shortcuts, const QKeySequence &seq)
Show a messagebox to inform the user that a global shorcut is already occupied, and ask to take it aw...
Definition: kglobalaccel.cpp:554
KGlobalAccel::stealShortcutSystemwide
static void stealShortcutSystemwide(const QKeySequence &seq)
Take away the given shortcut from the named action it belongs to.
Definition: kglobalaccel.cpp:593

... and standard shortcuts

KStandardShortcut::StandardShortcut ssc = KStandardShortcut::find(keySequence);
if (ssc != KStandardShortcut::AccelNone) {
// We have a conflict
}
KStandardShortcut::find
const KShortcut & find()
Find, search.
Definition: kstandardshortcut.cpp:342
KStandardShortcut::StandardShortcut
StandardShortcut
Defines the identifier of all standard accelerators.
Definition: kstandardshortcut.h:55
KStandardShortcut::AccelNone
@ AccelNone
Definition: kstandardshortcut.h:58
Since
4.2

Definition at line 318 of file kkeysequencewidget.cpp.

◆ setClearButtonShown()

void KKeySequenceWidget::setClearButtonShown ( bool  show)

Set whether a small button to set an empty key sequence should be displayed next to the main input widget.

The default is to show the clear button.

Definition at line 345 of file kkeysequencewidget.cpp.

◆ setComponentName()

void KKeySequenceWidget::setComponentName ( const QString &  componentName)

If the component using this widget supports shortcuts contexts, it has to set its component name so we can check conflicts correctly.

Definition at line 301 of file kkeysequencewidget.cpp.

◆ setKeySequence

void KKeySequenceWidget::setKeySequence ( const QKeySequence &  seq,
Validation  val = NoValidate 
)
slot

Set the key sequence.

If val == Validate, and the call is actually changing the key sequence, conflictuous shortcut will be checked.

Definition at line 377 of file kkeysequencewidget.cpp.

◆ setModifierlessAllowed()

void KKeySequenceWidget::setModifierlessAllowed ( bool  allow)

This only applies to user input, not to setShortcut().

Set whether to accept "plain" keys without modifiers (like Ctrl, Alt, Meta). Plain keys by our definition include letter and symbol keys and text editing keys (Return, Space, Tab, Backspace, Delete). "Special" keys like F1, Cursor keys, Insert, PageDown will always work.

Definition at line 323 of file kkeysequencewidget.cpp.

◆ setMultiKeyShortcutsAllowed()

void KKeySequenceWidget::setMultiKeyShortcutsAllowed ( bool  allowed)

Allow multikey shortcuts?

Definition at line 312 of file kkeysequencewidget.cpp.

◆ stealShortcut

void KKeySequenceWidget::stealShortcut ( const QKeySequence &  seq,
KAction *  action 
)
signal

This signal is emitted after the user agreed to steal a shortcut from an action.

This is only done for local shortcuts. So you can be sure action is one of the actions you provided with setCheckActionList() or setCheckActionCollections().

If you listen to that signal and don't call applyStealShortcut() you are supposed to steal the shortcut and save this change.

Property Documentation

◆ checkForConflictsAgainst

ShortcutTypes KKeySequenceWidget::checkForConflictsAgainst
readwrite

Definition at line 1 of file kkeysequencewidget.h.

◆ modifierlessAllowed

bool KKeySequenceWidget::modifierlessAllowed
readwrite

Definition at line 1 of file kkeysequencewidget.h.

◆ multiKeyShortcutsAllowed

bool KKeySequenceWidget::multiKeyShortcutsAllowed
readwrite

Definition at line 1 of file kkeysequencewidget.h.


The documentation for this class was generated from the following files:
  • kkeysequencewidget.h
  • kkeysequencewidget.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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