LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LeechCraft::Util::ShortcutManager Class Reference

Aids in providing configurable shortcuts. More...

#include "shortcutmanager.h"

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

Public Types

typedef QPair< QString, QAction * > IDPair_t
 

Public Member Functions

UTIL_API ShortcutManager (ICoreProxy_ptr proxy, QObject *parent=0)
 Creates the shortcut manager. More...
 
UTIL_API void SetObject (QObject *pluginObj)
 Sets the plugin instance object of this manager. More...
 
UTIL_API void RegisterAction (const QString &id, QAction *action, bool update=false)
 Registers the given QAction by the given id. More...
 
UTIL_API void RegisterShortcut (const QString &id, const ActionInfo &info, QShortcut *shortcut, bool update=false)
 Registers the given QShortcut with the given id. More...
 
UTIL_API void RegisterActionInfo (const QString &id, const ActionInfo &info)
 Registers the given action info with the given id. More...
 
UTIL_API void SetShortcut (const QString &id, const QKeySequences_t &sequences) const
 Sets the key sequence for the given action. More...
 
UTIL_API QMap< QString,
ActionInfo
GetActionInfo () const
 Returns the map with information about actions. More...
 
UTIL_API 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().

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

See Also
IHaveShortcuts

Definition at line 67 of file shortcutmanager.h.

Member Typedef Documentation

typedef QPair<QString, QAction*> LeechCraft::Util::ShortcutManager::IDPair_t

Definition at line 186 of file shortcutmanager.h.

Constructor & Destructor Documentation

LeechCraft::Util::ShortcutManager::ShortcutManager ( ICoreProxy_ptr  proxy,
QObject *  parent = 0 
)

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 39 of file shortcutmanager.cpp.

Member Function Documentation

QMap< QString, ActionInfo > LeechCraft::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 100 of file shortcutmanager.cpp.

ShortcutManager & LeechCraft::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 105 of file shortcutmanager.cpp.

void LeechCraft::Util::ShortcutManager::RegisterAction ( const QString &  id,
QAction *  action,
bool  update = false 
)

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.

If update is set to true, the shortcut manager will request an actual and up-to-date shortcut from the LeechCraft core. There is no need to update an action registered during IInfo::Init() as the Core will update actions with custom shortcuts later on anyway.

Note
Updating the action (setting update to true) will trigger the Core to request the action map, and all new IDs past this point won't be known to LeechCraft core. Thus as a rule of thumb one should only set update to true only in calls happening after IInfo::Init().
Parameters
[in]idThe ID of action to register.
[in]actionThe action to register.
[in]updateWhether action shortcut should be updated immediately.
See Also
RegisterShortcut(), RegisterActionInfo()

Definition at line 51 of file shortcutmanager.cpp.

References RegisterActionInfo(), and SetShortcut().

+ Here is the call graph for this function:

void LeechCraft::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 85 of file shortcutmanager.cpp.

Referenced by RegisterAction(), and RegisterShortcut().

+ Here is the caller graph for this function:

void LeechCraft::Util::ShortcutManager::RegisterShortcut ( const QString &  id,
const ActionInfo info,
QShortcut *  shortcut,
bool  update = false 
)

Registers the given QShortcut with the given id.

If update is set to true, the shortcut manager will request an actual and up-to-date shortcut from the LeechCraft core. There is no need to update an action registered during IInfo::Init() as the Core will update actions with custom shortcuts later on anyway.

Note
Updating the action (setting update to true) will trigger the Core to request the action map, and all new IDs past this point won't be known to LeechCraft core. Thus as a rule of thumb one should only set update to true only in calls happening after IInfo::Init().
Parameters
[in]idThe ID of QShortcut to register.
[in]infoThe additional ActionInfo about this shortcut.
[in]shortcutThe QShortcut to register.
[in]updateWhether action shortcut should be updated immediately.
See Also
RegisterAction(), RegisterActionInfo()

Definition at line 70 of file shortcutmanager.cpp.

References RegisterActionInfo(), and SetShortcut().

+ Here is the call graph for this function:

void LeechCraft::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 46 of file shortcutmanager.cpp.

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

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 91 of file shortcutmanager.cpp.

Referenced by RegisterAction(), and RegisterShortcut().

+ Here is the caller graph for this function:


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