ImFusion SDK 4.3
KeyboardShortcutManager Class Reference

#include <ImFusion/GUI/KeyboardShortcutManager.h>

Singleton class to manage global keyboard shortcuts. More...

+ Inheritance diagram for KeyboardShortcutManager:

Detailed Description

Singleton class to manage global keyboard shortcuts.

Before this class can be used you must register the QMainWindow of the application using setParent() so that KeyboardShortcutManager can hook into its event loop to listen for keyboard user input.

Shortcut actions are identified using a unique ID. Register shortcuts using action() which returns an Action struct containing both an ImFusion signal and a QShortcut. You can connect to either of it in order to get notified when the shortcut has been triggered.

Example for registering an action an installing a handler for it:

KeyboardShortcutManager::instance().action("InteractionView3D::Reset",
"3D View: reset",
QKeySequence("Ctrl+R"))
.signalTriggered.connect(this, &InteractionView3D::reset);

Classes

struct  Action
 Small structure encapsulating a shortcut action. More...
 

Public Member Functions

void setParent (QMainWindow *mainWindow)
 Register the window for which keyboard events are received.
 
void setParent (QMainWindow &mainWindow)
 
const Actionaction (const std::string &uniqueId, const std::string &description, QKeySequence defaultSequence)
 Register a shortcut action and return the corresponding Action struct.
 
bool removeAction (const std::string &uniqueId)
 Remove a registered shortcut action with the given uniqueId. Returns false if no such action was registered.
 
void setKeySequence (const std::string &id, const QKeySequence &key)
 Sets an already registered action, identified by id string, to a Key sequence.
 
void saveMapping ()
 Saves the Action Shortcut mapping using QString.
 
const std::map< std::string, std::unique_ptr< Action > > & registeredActions () const
 Return a const reference of the map list.
 
void clearActions ()
 Clears all registered actions.
 

Static Public Member Functions

static KeyboardShortcutManagerinstance ()
 

Member Function Documentation

◆ action()

const Action & action ( const std::string & uniqueId,
const std::string & description,
QKeySequence defaultSequence )

Register a shortcut action and return the corresponding Action struct.

If a shortcut with the same unique ID is already registered, this function will return the old shortcut Action and not update description and/or default sequence.

Parameters
uniqueIdUnique identifier for the shortcut
descriptionHuman readable description of the shortcut to show in the settings UI.
defaultSequenceDefault keyboard sequence to trigger the shortcut.
Returns
The Action instance for the registered shortcut; connect to its ImFusion signal and/or its qtShortcut to react to the user pressing the shortcut.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close