KGlobalAccel

#include <kglobalaccel.h>

Inheritance diagram for KGlobalAccel:

Public Types

enum  actionIdFields { ComponentUnique = 0, ActionUnique = 1, ComponentFriendly = 2, ActionFriendly = 3 }
 
enum  GlobalShortcutLoading { Autoloading = 0x0, NoAutoloading = 0x4 }
 

Signals

void globalShortcutChanged (QAction *action, const QKeySequence &seq)
 

Public Member Functions

QList< QStringListallActionsForComponent (const QStringList &actionId)
 
QList< QStringListallMainComponents ()
 
QList< QKeySequencedefaultShortcut (const QAction *action) const
 
bool eventFilter (QObject *watched, QEvent *event) override
 
QList< QKeySequenceglobalShortcut (const QString &componentName, const QString &actionId) const
 
bool hasShortcut (const QAction *action) const
 
bool isEnabled () const
 
void removeAllShortcuts (QAction *action)
 
bool setDefaultShortcut (QAction *action, const QList< QKeySequence > &shortcut, GlobalShortcutLoading loadFlag=Autoloading)
 
void setEnabled (bool enabled)
 
bool setShortcut (QAction *action, const QList< QKeySequence > &shortcut, GlobalShortcutLoading loadFlag=Autoloading)
 
QList< QKeySequenceshortcut (const QAction *action) const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static void activateGlobalShortcutContext (const QString &contextUnique, const QString &contextFriendly, const QString &programName)
 
static bool cleanComponent (const QString &componentUnique)
 
static QStringList findActionNameSystemwide (const QKeySequence &seq)
 
static QList< KGlobalShortcutInfogetGlobalShortcutsByKey (const QKeySequence &seq)
 
static bool isComponentActive (const QString &componentName)
 
static bool isGlobalShortcutAvailable (const QKeySequence &seq, const QString &component=QString())
 
static bool promptStealShortcutSystemwide (QWidget *parent, const QList< KGlobalShortcutInfo > &shortcuts, const QKeySequence &seq)
 
static bool promptStealShortcutSystemwide (QWidget *parent, const QStringList &actionIdentifier, const QKeySequence &seq)
 
static KGlobalAccelself ()
 
static bool setGlobalShortcut (QAction *action, const QList< QKeySequence > &shortcut)
 
static bool setGlobalShortcut (QAction *action, const QKeySequence &shortcut)
 
static void stealShortcutSystemwide (const QKeySequence &seq)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

Configurable global shortcut support.

KGlobalAccel allows you to have global accelerators that are independent of the focused window. Unlike regular shortcuts, the application's window does not need focus for them to be activated.

See also
KKeyChooser
KKeyDialog

Definition at line 33 of file kglobalaccel.h.

Member Enumeration Documentation

Index for actionId QStringLists.

Enumerator
ComponentUnique 

Components Unique Name (ID)

ActionUnique 

Actions Unique Name(ID)

ComponentFriendly 

Components Friendly Translated Name.

ActionFriendly 

Actions Friendly Translated Name.

Definition at line 53 of file kglobalaccel.h.

An enum about global shortcut setter semantics.

Enumerator
Autoloading 

Look up the action in global settings (using its main component's name and text()) and set the shortcut as saved there.

See also
setGlobalShortcut()
NoAutoloading 

Prevent autoloading of saved global shortcut for action.

Definition at line 41 of file kglobalaccel.h.

Member Function Documentation

void KGlobalAccel::activateGlobalShortcutContext ( const QString contextUnique,
const QString contextFriendly,
const QString programName 
)
static

Set global shortcut context.

A global shortcut context allows an application to have different sets of global shortcuts and to switch between them. This is used by plasma to switch the active global shortcuts when switching between activities.

Parameters
contextthe name of the context.
Since
4.2

Definition at line 151 of file kglobalaccel.cpp.

QList< QStringList > KGlobalAccel::allActionsForComponent ( const QStringList actionId)
Deprecated:
Since 4.2.

Do not use

Definition at line 510 of file kglobalaccel.cpp.

QList< QStringList > KGlobalAccel::allMainComponents ( )

Return the unique and common names of all main components that have global shortcuts.

The action strings of the returned actionId stringlists will be empty.

Deprecated:
Since 4.2. Do not use.

Definition at line 503 of file kglobalaccel.cpp.

bool KGlobalAccel::cleanComponent ( const QString componentUnique)
static

Clean the shortcuts for component componentUnique.

If the component is not active all global shortcut registrations are purged and the component is removed completely.

If the component is active all global shortcut registrations not in use will be purged. If there is no shortcut registration left the component is purged too.

If a purged component or shortcut is activated the next time it will reregister itself. All you probably will lose on wrong usage are the user's set shortcuts.

If you make sure your component is running and all global shortcuts it has are active this function can be used to clean up the registry.

Handle with care!

If the method return true at least one shortcut was purged so handle all previously acquired information with care.

Definition at line 162 of file kglobalaccel.cpp.

QList< QKeySequence > KGlobalAccel::defaultShortcut ( const QAction action) const

Get the global default shortcut for this action, if one exists.

Global shortcuts allow your actions to respond to accellerators independently of the focused window. Unlike regular shortcuts, the application's window does not need focus for them to be activated.

See also
setDefaultShortcut()
Since
5.0

Definition at line 661 of file kglobalaccel.cpp.

bool KGlobalAccel::eventFilter ( QObject watched,
QEvent event 
)
overridevirtual

Override no longer needed, left for BIC

Reimplemented from QObject.

Definition at line 695 of file kglobalaccel.cpp.

QStringList KGlobalAccel::findActionNameSystemwide ( const QKeySequence seq)
static
QList< KGlobalShortcutInfo > KGlobalAccel::getGlobalShortcutsByKey ( const QKeySequence seq)
static

Returns a list of global shortcuts registered for the shortcut .

If the list contains more that one entry it means the component that registered the shortcuts uses global shortcut contexts. All returned shortcuts belong to the same component.

Since
4.2

Definition at line 524 of file kglobalaccel.cpp.

QList< QKeySequence > KGlobalAccel::globalShortcut ( const QString componentName,
const QString actionId 
) const

Retrieves the shortcut as defined in global settings by componentName (e.g.

"kwin") and actionId (e.g. "Kill Window").

Since
5.10

Definition at line 671 of file kglobalaccel.cpp.

void KGlobalAccel::globalShortcutChanged ( QAction action,
const QKeySequence seq 
)
signal

Emitted when the global shortcut is changed.

A global shortcut is subject to be changed by the global shortcuts kcm.

Parameters
actionpointer to the action for which the changed shortcut was registered
seqthe key sequence that corresponds to the changed shortcut
See also
setGlobalShortcut
setDefaultShortcut
Since
5.0
Todo:
KF6: add const to the QAction parameter
bool KGlobalAccel::hasShortcut ( const QAction action) const

Returns true if a shortcut or a default shortcut has been registered for the given action.

Since
5.0

Definition at line 689 of file kglobalaccel.cpp.

bool KGlobalAccel::isComponentActive ( const QString componentName)
static

Check if component is active.

Parameters
componentUniquethe components unique identifier
Returns
true if active, if not

Definition at line 173 of file kglobalaccel.cpp.

bool KGlobalAccel::isEnabled ( ) const

No effect.

Deprecated:
Since 4.4.

Definition at line 184 of file kglobalaccel.cpp.

bool KGlobalAccel::isGlobalShortcutAvailable ( const QKeySequence seq,
const QString component = QString() 
)
static

Check if the shortcut is available for the component.

The component is only of interest if the current application uses global shortcut contexts. In that case a global shortcut by component in an inactive global shortcut contexts does not block the seq for us.

Since
4.2

Definition at line 529 of file kglobalaccel.cpp.

bool KGlobalAccel::promptStealShortcutSystemwide ( QWidget parent,
const QList< KGlobalShortcutInfo > &  shortcuts,
const QKeySequence seq 
)
static

Show a messagebox to inform the user that a global shortcut is already occupied, and ask to take it away from its current action(s).

This is GUI only, so nothing will be actually changed.

See also
stealShortcutSystemwide()
Since
4.2

Definition at line 561 of file kglobalaccel.cpp.

bool KGlobalAccel::promptStealShortcutSystemwide ( QWidget parent,
const QStringList actionIdentifier,
const QKeySequence seq 
)
static
void KGlobalAccel::removeAllShortcuts ( QAction action)

Unregister and remove all defined global shortcuts for the given action.

Since
5.0

Definition at line 684 of file kglobalaccel.cpp.

KGlobalAccel * KGlobalAccel::self ( )
static

Returns (and creates if necessary) the singleton instance.

Definition at line 219 of file kglobalaccel.cpp.

bool KGlobalAccel::setDefaultShortcut ( QAction action,
const QList< QKeySequence > &  shortcut,
GlobalShortcutLoading  loadFlag = Autoloading 
)

Assign a default global shortcut for a given QAction.

For more information about global shortcuts

See also
setShortcut Upon shortcut change the globalShortcutChanged will be triggered so other applications get notified
globalShortcutChanged
Since
5.0

Definition at line 631 of file kglobalaccel.cpp.

void KGlobalAccel::setEnabled ( bool  enabled)

No effect.

Deprecated:
Since 4.4.

Definition at line 196 of file kglobalaccel.cpp.

bool KGlobalAccel::setGlobalShortcut ( QAction action,
const QList< QKeySequence > &  shortcut 
)
static

Convenient method to set both active and default shortcut.

If more control for loading the shortcuts is needed use the variants offering more control.

See also
setShortcut
setDefaultShortcut
Since
5.0

Definition at line 701 of file kglobalaccel.cpp.

bool KGlobalAccel::setGlobalShortcut ( QAction action,
const QKeySequence shortcut 
)
static

Convenient method to set both active and default shortcut.

This method is suited for the case that only one shortcut is to be configured.

If more control for loading the shortcuts is needed use the variants offering more control.

See also
setShortcut
setDefaultShortcut
Since
5.0

Definition at line 707 of file kglobalaccel.cpp.

bool KGlobalAccel::setShortcut ( QAction action,
const QList< QKeySequence > &  shortcut,
GlobalShortcutLoading  loadFlag = Autoloading 
)

Assign a global shortcut for the given action.

Global shortcuts allow an action to respond to key shortcuts independently of the focused window, i.e. the action will trigger if the keys were pressed no matter where in the X session.

The action must have a per main component unique action->objectName() to enable cross-application bookkeeping. If the action->objectName() is empty this method will do nothing and will return false.

It is mandatory that the action->objectName() doesn't change once the shortcut has been successfully registered.

Note
KActionCollection::insert(name, action) will set action's objectName to name so you often don't have to set an objectName explicitly.

When an action, identified by main component name and objectName(), is assigned a global shortcut for the first time on a KDE installation the assignment will be saved. The shortcut will then be restored every time setGlobalShortcut() is called with loading == Autoloading.

If you actually want to change the global shortcut you have to set loading to NoAutoloading. The new shortcut will be automatically saved again.

Parameters
actionthe action for which the shortcut will be assigned
shortcutglobal shortcut(s) to assign. Will be ignored unless loading is set to NoAutoloading or this is the first time ever you call this method (see above).
loadFlagif Autoloading, assign the global shortcut this action has previously had if any. That way user preferences and changes made to avoid clashes will be conserved. if NoAutoloading the given shortcut will be assigned without looking up old values. You should only do this if the user wants to change the shortcut or if you have another very good reason. Key combinations that clash with other shortcuts will be dropped.
Note
the default shortcut will never be influenced by autoloading - it will be set as given.
See also
shortcut()
globalShortcutChanged
Since
5.0

Definition at line 646 of file kglobalaccel.cpp.

QList< QKeySequence > KGlobalAccel::shortcut ( const QAction action) const

Get the global shortcut for this action, if one exists.

Global shortcuts allow your actions to respond to accellerators independently of the focused window. Unlike regular shortcuts, the application's window does not need focus for them to be activated.

Note
that this method only works together with setShortcut() because the action pointer is used to retrieve the result. If you would like to retrieve the shortcut as stored in the global settings, use the globalShortcut(componentName, actionId) instead.
See also
setShortcut()
Since
5.0

Definition at line 666 of file kglobalaccel.cpp.

void KGlobalAccel::stealShortcutSystemwide ( const QKeySequence seq)
static

Take away the given shortcut from the named action it belongs to.

This applies to all actions with global shortcuts in any KDE application.

See also
promptStealShortcutSystemwide()

Definition at line 599 of file kglobalaccel.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Sep 21 2020 22:54:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.