LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::ShortcutManager Class Reference

Aids in providing configurable shortcuts. More...

#include "shortcutmanager.h"

+ Inheritance diagram for LC::Util::ShortcutManager:
+ Collaboration diagram for LC::Util::ShortcutManager:

Public Types

using IDPair_t = QPair< QString, QAction * >
 

Public Member Functions

 ShortcutManager (const ICoreProxy_ptr &proxy, QObject *parent=nullptr)
 Creates the shortcut manager. More...
 
void SetObject (QObject *pluginObj)
 Sets the plugin instance object of this manager. More...
 
void RegisterAction (const QString &id, QAction *action)
 Registers the given QAction by the given id. More...
 
void RegisterActions (const std::initializer_list< IDPair_t > &actions)
 
void RegisterShortcut (const QString &id, const ActionInfo &info, QShortcut *shortcut)
 Registers the given QShortcut with the given id. More...
 
void RegisterActionInfo (const QString &id, const ActionInfo &info)
 Registers the given action info with the given id. More...
 
void RegisterGlobalShortcut (const QString &id, QObject *target, const QByteArray &method, const ActionInfo &info)
 Registers the given global shortcut with the given id. More...
 
void AnnounceGlobalShorcuts ()
 Announces the global shortcuts. More...
 
void SetShortcut (const QString &id, const QKeySequences_t &sequences)
 Sets the key sequence for the given action. More...
 
QMap< QString, ActionInfoGetActionInfo () const
 Returns the map with information about actions. More...
 
ShortcutManageroperator<< (const QPair< QString, QAction * > &pair)
 Utility function equivalent to RegisterAction(). More...
 

Detailed Description

Aids in providing configurable shortcuts.

This class serves as a "collector" for different QActions and QShortcuts. One typically instantiates an object of this class as a per-plugin global object (via a singleton, for example), registers all required actions via the RegisterShortcut(), RegisterAction() and RegisterActionInfo() functions and relays calls to the IHaveShortcuts::SetShortcut() and IHaveShortcuts::GetActionInfo() functions to this class.

Though one can register actions at arbitrary points of time, only those "kinds" of actions registered during the IInfo::Init() will be visible to the LeechCraft core. Actions added later will still have customized shortcuts (if any), but only if another action with the same ID has been added during IInfo::Init().

ShortcutManager also supports global shortcuts via the RegisterGlobalShortcut() and AnnounceGlobalShorcuts() methods.

See the documentation for IHaveShortcuts for more information about actions and their IDs.

See also
IHaveShortcuts

Definition at line 55 of file shortcutmanager.h.

Member Typedef Documentation

◆ IDPair_t

using LC::Util::ShortcutManager::IDPair_t = QPair<QString, QAction*>

Definition at line 100 of file shortcutmanager.h.

Constructor & Destructor Documentation

◆ ShortcutManager()

LC::Util::ShortcutManager::ShortcutManager ( const ICoreProxy_ptr proxy,
QObject *  parent = nullptr 
)
explicit

Creates the shortcut manager.

Parameters
[in]proxyThe proxy object passed to IInfo::Init() of your plugin.
[in]parentThe parent object of this object.

Definition at line 27 of file shortcutmanager.cpp.

Member Function Documentation

◆ AnnounceGlobalShorcuts()

void LC::Util::ShortcutManager::AnnounceGlobalShorcuts ( )

Announces the global shortcuts.

This function announces global shortcuts registered via RegisterGlobalShortcut() method. Because global shortcuts are handled by a special plugin like GActs, this function needs to be called in IInfo::SecondInit() of your plugin.

See also
RegisterGlobalShortcut()

Definition at line 125 of file shortcutmanager.cpp.

◆ GetActionInfo()

QMap< QString, ActionInfo > LC::Util::ShortcutManager::GetActionInfo ( ) const

Returns the map with information about actions.

The return result is suitable to be returned from IHaveShortcuts::GetActionInfo().

Returns
Action info map.

Definition at line 165 of file shortcutmanager.cpp.

References RegisterAction().

+ Here is the call graph for this function:

◆ operator<<()

ShortcutManager & LC::Util::ShortcutManager::operator<< ( const QPair< QString, QAction * > &  pair)

Utility function equivalent to RegisterAction().

This function is equivalent to calling RegisterAction (pair.first, pair.second);.

Parameters
[in]pairThe pair of action ID and the action itself.
Returns
The shortcut manager object.

Definition at line 170 of file shortcutmanager.cpp.

◆ RegisterAction()

void LC::Util::ShortcutManager::RegisterAction ( const QString &  id,
QAction *  action 
)

Registers the given QAction by the given id.

This function registers the given action at the given id and updates it if necessary. The ActionInfo structure is created automatically, and ActionIcon property of the action is used to fetch its icon.

Parameters
[in]idThe ID of action to register.
[in]actionThe action to register.
See also
RegisterShortcut(), RegisterActionInfo()

Definition at line 38 of file shortcutmanager.cpp.

Referenced by GetActionInfo().

+ Here is the caller graph for this function:

◆ RegisterActionInfo()

void LC::Util::ShortcutManager::RegisterActionInfo ( const QString &  id,
const ActionInfo info 
)

Registers the given action info with the given id.

This function can be used to register an action info with the given ID before any actions or shortcuts with this ID are really created. This function can be used, for example, to register shortcuts that will be available during some time after IInfo::Init(), like a reload action in a web page (as there are no web pages during plugin initialization).

Parameters
[in]idThe ID of an action or QShortcut to register.
[in]infoThe ActionInfo about this shortcut.
See also
RegisterAction(), RegisterShortcut()

Definition at line 104 of file shortcutmanager.cpp.

References LC::Entity::Additional_, and LC::Util::MakeEntity().

+ Here is the call graph for this function:

◆ RegisterActions()

void LC::Util::ShortcutManager::RegisterActions ( const std::initializer_list< IDPair_t > &  actions)

Definition at line 77 of file shortcutmanager.cpp.

◆ RegisterGlobalShortcut()

void LC::Util::ShortcutManager::RegisterGlobalShortcut ( const QString &  id,
QObject *  target,
const QByteArray &  method,
const ActionInfo info 
)

Registers the given global shortcut with the given id.

Registered global shortcuts need to be announced during SecondInit() of your plugin by calling the AnnounceGlobalShorcuts() method.

Parameters
[in]idThe ID of the global shortcut to register.
[in]targetThe object whose method will be invoked on shortcut activation.
[in]methodThe method of the object which will be invoked on shortcut activation.
[in]infoThe ActionInfo about this global shortcut.
See also
AnnounceGlobalShorcuts()

Definition at line 110 of file shortcutmanager.cpp.

◆ RegisterShortcut()

void LC::Util::ShortcutManager::RegisterShortcut ( const QString &  id,
const ActionInfo info,
QShortcut *  shortcut 
)

Registers the given QShortcut with the given id.

Parameters
[in]idThe ID of QShortcut to register.
[in]infoThe additional ActionInfo about this shortcut.
[in]shortcutThe QShortcut to register.
See also
RegisterAction(), RegisterActionInfo()

Definition at line 83 of file shortcutmanager.cpp.

◆ SetObject()

void LC::Util::ShortcutManager::SetObject ( QObject *  pluginObj)

Sets the plugin instance object of this manager.

The plugin instance object serves as a kind of "context" for the shortcut manager.

Parameters
[in]pluginObjThe plugin instance object.

Definition at line 33 of file shortcutmanager.cpp.

◆ SetShortcut()

void LC::Util::ShortcutManager::SetShortcut ( const QString &  id,
const QKeySequences_t sequences 
)

Sets the key sequence for the given action.

This function updates all the registered actions with the given ID. It is intended to be called only from IHaveShortcuts::SetShortcut(), user code should hardly ever need to call it elsewhere.

Parameters
[in]idThe ID of the action to update.
[in]sequencesThe list of sequences to for the action.

Definition at line 131 of file shortcutmanager.cpp.


The documentation for this class was generated from the following files: