KGlobalAccel
#include <kglobalaccel.h>

Public Types | |
enum | actionIdFields { ComponentUnique = 0, ActionUnique = 1, ComponentFriendly = 2, ActionFriendly = 3 } |
enum | GlobalShortcutLoading { Autoloading = 0x0, NoAutoloading = 0x4 } |
enum | MatchType { Equal, Shadows, Shadowed } |
Signals | |
void | globalShortcutActiveChanged (QAction *action, bool active) |
void | globalShortcutChanged (QAction *action, const QKeySequence &seq) |
Public Member Functions | |
QList< QStringList > | allActionsForComponent (const QStringList &actionId) |
QList< QStringList > | allMainComponents () |
QList< QKeySequence > | defaultShortcut (const QAction *action) const |
bool | eventFilter (QObject *watched, QEvent *event) override |
QList< QKeySequence > | globalShortcut (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< QKeySequence > | shortcut (const QAction *action) const |
![]() | |
QObject (QObject *parent) | |
bool | blockSignals (bool block) |
const QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, 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 QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () 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 | |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
T | qobject_cast (const QObject *object) |
T | qobject_cast (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) |
QThread * | thread () 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< KGlobalShortcutInfo > | getGlobalShortcutsByKey (const QKeySequence &seq) |
static QList< KGlobalShortcutInfo > | globalShortcutsByKey (const QKeySequence &seq, MatchType type=Equal) |
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 KGlobalAccel * | self () |
static bool | setGlobalShortcut (QAction *action, const QKeySequence &shortcut) |
static bool | setGlobalShortcut (QAction *action, const QList< QKeySequence > &shortcut) |
static void | stealShortcutSystemwide (const QKeySequence &seq) |
![]() | |
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 *context, Functor functor, 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) |
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, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
Additional Inherited Members | |
![]() | |
objectName | |
![]() | |
typedef | QObjectList |
![]() | |
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 |
QObject * | sender () 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
◆ actionIdFields
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.
◆ GlobalShortcutLoading
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.
|
NoAutoloading | Prevent autoloading of saved global shortcut for action. |
Definition at line 41 of file kglobalaccel.h.
◆ MatchType
Keysequence match semantics.
Assuming we have an Emacs-style shortcut, for example (Alt+B, Alt+F, Alt+G) already assigned, how a new shortcut is compared depends on which value of the enum is used: Equal
: Exact matching: (Alt+B, Alt+F, Alt+G) Shadows
: Sequence shadowing: (Alt+B, Alt+F), (Alt+F, Alt+G) Shadowed
: Sequence being shadowed: (Alt+B, Alt+F, Alt+G, <any key>), (<any key>, Alt+B, Alt+F, Alt+G)
- Since
- 5.90
Definition at line 71 of file kglobalaccel.h.
Member Function Documentation
◆ activateGlobalShortcutContext()
|
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
-
context the name of the context.
- Since
- 4.2
- Deprecated:
- since 5.102. Shortcut contexts are deprecated. No known users.
Definition at line 159 of file kglobalaccel.cpp.
◆ allActionsForComponent()
QList< QStringList > KGlobalAccel::allActionsForComponent | ( | const QStringList & | actionId | ) |
◆ allMainComponents()
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 569 of file kglobalaccel.cpp.
◆ cleanComponent()
|
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 168 of file kglobalaccel.cpp.
◆ defaultShortcut()
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 730 of file kglobalaccel.cpp.
◆ eventFilter()
Override no longer needed, left for BIC
Reimplemented from QObject.
Definition at line 763 of file kglobalaccel.cpp.
◆ findActionNameSystemwide()
|
static |
Definition at line 584 of file kglobalaccel.cpp.
◆ getGlobalShortcutsByKey()
|
static |
Returns a list of global shortcuts registered for the shortcut seq
.
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
- Deprecated:
- Since 5.90, use globalShortcutsByKey(const QKeySequence&, int) instead.
Definition at line 591 of file kglobalaccel.cpp.
◆ globalShortcut()
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 740 of file kglobalaccel.cpp.
◆ globalShortcutChanged
|
signal |
Emitted when the global shortcut is changed.
A global shortcut is subject to be changed by the global shortcuts kcm.
- Parameters
-
action pointer to the action for which the changed shortcut was registered seq the key sequence that corresponds to the changed shortcut
- See also
- setGlobalShortcut
- setDefaultShortcut
- Since
- 5.0
◆ globalShortcutsByKey()
|
static |
Returns a list of global shortcuts registered for the shortcut seq
.
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.
- Parameters
-
type a value from the KGlobalAccel::MatchType enum
- Since
- 5.90
Definition at line 597 of file kglobalaccel.cpp.
◆ hasShortcut()
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 757 of file kglobalaccel.cpp.
◆ isComponentActive()
|
static |
Check if component is active.
- Parameters
-
componentUnique the components unique identifier
- Returns
true
if active, @false if not
Definition at line 179 of file kglobalaccel.cpp.
◆ isEnabled()
bool KGlobalAccel::isEnabled | ( | ) | const |
◆ isGlobalShortcutAvailable()
|
static |
Check if the shortcut @seq 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 602 of file kglobalaccel.cpp.
◆ promptStealShortcutSystemwide() [1/2]
|
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 631 of file kglobalaccel.cpp.
◆ promptStealShortcutSystemwide() [2/2]
|
static |
- Deprecated:
- Since 4.2, use KGlobalAccel::promptStealShortcutSystemwide(QWidget *, const QList<KGlobalShortcutInfo> &, const QKeySequence &)
Definition at line 609 of file kglobalaccel.cpp.
◆ removeAllShortcuts()
void KGlobalAccel::removeAllShortcuts | ( | QAction * | action | ) |
Unregister and remove all defined global shortcuts for the given action.
- Since
- 5.0
Definition at line 752 of file kglobalaccel.cpp.
◆ self()
|
static |
Returns (and creates if necessary) the singleton instance.
Definition at line 225 of file kglobalaccel.cpp.
◆ setDefaultShortcut()
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 700 of file kglobalaccel.cpp.
◆ setEnabled()
void KGlobalAccel::setEnabled | ( | bool | enabled | ) |
◆ setGlobalShortcut() [1/2]
|
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 775 of file kglobalaccel.cpp.
◆ setGlobalShortcut() [2/2]
|
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 769 of file kglobalaccel.cpp.
◆ setShortcut()
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
-
action the action for which the shortcut will be assigned shortcut global 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).loadFlag if 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 715 of file kglobalaccel.cpp.
◆ shortcut()
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 735 of file kglobalaccel.cpp.
◆ stealShortcutSystemwide()
|
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 663 of file kglobalaccel.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 03:50:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.