![]() |
LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
|
Aids in providing configurable shortcuts. More...
#include "shortcutmanager.h"
Public Types | |
using | IDPair_t = QPair<QByteArray, QAction*> |
Public Member Functions | |
ShortcutManager (const ICoreProxy_ptr &proxy, QObject *parent) | |
Creates the shortcut manager. | |
void | RegisterAction (const QByteArray &id, QAction *action) |
Registers the given QAction by the given id. | |
void | RegisterActions (const std::initializer_list< IDPair_t > &actions) |
void | RegisterShortcut (const QByteArray &id, const ActionInfo &info, QShortcut *shortcut) |
Registers the given QShortcut with the given id. | |
void | RegisterActionInfo (const QByteArray &id, const ActionInfo &info) |
Registers the given action info with the given id. | |
void | RegisterGlobalShortcut (const QByteArray &id, QObject *target, const QByteArray &method, const ActionInfo &info) |
Registers the given global shortcut with the given id. | |
void | AnnounceGlobalShorcuts () |
Announces the global shortcuts. | |
void | SetShortcut (const QByteArray &id, const QKeySequences_t &sequences) |
Sets the key sequence for the given action. | |
QMap< QByteArray, ActionInfo > | GetActionInfo () const |
Returns the map with information about actions. | |
ShortcutManager & | operator<< (const QPair< QByteArray, QAction * > &pair) |
Utility function equivalent to RegisterAction(). | |
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.
Definition at line 55 of file shortcutmanager.h.
using LC::Util::ShortcutManager::IDPair_t = QPair<QByteArray, QAction*> |
Definition at line 92 of file shortcutmanager.h.
|
explicit |
Creates the shortcut manager.
[in] | proxy | The proxy object passed to IInfo::Init() of your plugin. |
[in] | parent | The parent object of this object, which also serves as the context object. |
Definition at line 22 of file shortcutmanager.cpp.
Referenced by operator<<().
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.
Definition at line 124 of file shortcutmanager.cpp.
QMap< QByteArray, ActionInfo > LC::Util::ShortcutManager::GetActionInfo | ( | ) | const |
Returns the map with information about actions.
The return result is suitable to be returned from IHaveShortcuts::GetActionInfo().
Definition at line 164 of file shortcutmanager.cpp.
ShortcutManager & LC::Util::ShortcutManager::operator<< | ( | const QPair< QByteArray, QAction * > & | pair | ) |
Utility function equivalent to RegisterAction().
This function is equivalent to calling RegisterAction (pair.first, pair.second);
.
[in] | pair | The pair of action ID and the action itself. |
Definition at line 169 of file shortcutmanager.cpp.
References ShortcutManager(), and RegisterAction().
void LC::Util::ShortcutManager::RegisterAction | ( | const QByteArray & | 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.
[in] | id | The ID of action to register. |
[in] | action | The action to register. |
Definition at line 29 of file shortcutmanager.cpp.
References RegisterActionInfo(), SetShortcut(), and LC::Util::Visit().
Referenced by operator<<(), and RegisterActions().
void LC::Util::ShortcutManager::RegisterActionInfo | ( | const QByteArray & | 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).
[in] | id | The ID of an action or QShortcut to register. |
[in] | info | The ActionInfo about this shortcut. |
Definition at line 103 of file shortcutmanager.cpp.
Referenced by RegisterAction(), and RegisterShortcut().
void LC::Util::ShortcutManager::RegisterActions | ( | const std::initializer_list< IDPair_t > & | actions | ) |
Definition at line 76 of file shortcutmanager.cpp.
References RegisterAction().
void LC::Util::ShortcutManager::RegisterGlobalShortcut | ( | const QByteArray & | 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.
[in] | id | The ID of the global shortcut to register. |
[in] | target | The object whose method will be invoked on shortcut activation. |
[in] | method | The method of the object which will be invoked on shortcut activation. |
[in] | info | The ActionInfo about this global shortcut. |
Definition at line 109 of file shortcutmanager.cpp.
References LC::Entity::Additional_, LC::ActionInfo::AdditionalSeqs_, LC::Mimes::GlobalActionRegister, LC::Util::MakeEntity(), LC::Util::Map(), and LC::ActionInfo::Seq_.
void LC::Util::ShortcutManager::RegisterShortcut | ( | const QByteArray & | id, |
const ActionInfo & | info, | ||
QShortcut * | shortcut ) |
Registers the given QShortcut with the given id.
[in] | id | The ID of QShortcut to register. |
[in] | info | The additional ActionInfo about this shortcut. |
[in] | shortcut | The QShortcut to register. |
Definition at line 82 of file shortcutmanager.cpp.
References RegisterActionInfo(), and SetShortcut().
void LC::Util::ShortcutManager::SetShortcut | ( | const QByteArray & | 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.
[in] | id | The ID of the action to update. |
[in] | sequences | The list of sequences to for the action. |
Definition at line 130 of file shortcutmanager.cpp.
References LC::Util::Map().
Referenced by RegisterAction(), and RegisterShortcut().