Radium Engine  1.5.0
Ra::Gui::KeyMappingManager Class Reference

An utility class used to map a (combination of) key / modifiers / mouse buttons to a specific action. Configuration can be loaded/saved to files, or use dynamic binding management. See KeyMapping API documentation for detailed concept and usage description. More...

#include <Gui/Utils/KeyMappingManager.hpp>

Inherits Ra::Core::Utils::ObservableVoid.

+ Collaboration diagram for Ra::Gui::KeyMappingManager:

Classes

class  EventBinding
 Inner class to store event binding. More...
 

Public Types

using KeyMappingAction = Ra::Core::Utils::Index
 handle to an action
 
using Context = Ra::Core::Utils::Index
 handle to a Context
 

Public Member Functions

void loadConfiguration (const std::string &filename={})
 
bool saveConfiguration (const std::string &filename={})
 
void reloadConfiguration ()
 reload last open file.
 
std::string getLoadedFilename ()
 
KeyMappingAction getAction (const Context &context, const Qt::MouseButtons &buttons, const Qt::KeyboardModifiers &modifiers, int key, bool wheel=false)
 
KeyMappingAction getAction (const Context &context, const QEvent *event, int key, bool wheel=false)
 
KeyMappingAction getAction (const Context &context, const EventBinding &binding)
 
std::optional< EventBindinggetBinding (const Context &context, KeyMappingAction action)
 
KeyMappingAction addAction (const Context &context, const std::string &actionName)
 
KeyMappingAction addAction (const Context &context, const EventBinding &binding, const std::string &actionName)
 
void setActionBinding (const Context &context, const EventBinding &binding, const KeyMappingAction &action)
 Bind binding to action, in context. More...
 
Context addContext (const std::string &contextName)
 Creates the context index for the given context name. More...
 
Context getContext (const std::string &contextName)
 
KeyMappingAction getAction (const Context &context, const std::string &actionName)
 
std::string getActionName (const Context &context, const KeyMappingAction &action)
 
std::string getContextName (const Context &context)
 
int addListener (Observable::Observer callback)
 Add a callback, triggered when configuration is load or reloaded.
 
void removeListener (int callbackId)
 
std::string getHelpText ()
 Return a string corresponding to the current dom document.
 

Static Public Member Functions

static std::string enumNamesFromMouseButtons (const Qt::MouseButtons &buttons)
 
static std::string enumNamesFromKeyboardModifiers (const Qt::KeyboardModifiers &modifiers)
 
static EventBinding createEventBindingFromStrings (const std::string &buttonsString="", const std::string &modifiersString="", const std::string &keyString="", const std::string &wheelString="")
 

Detailed Description

An utility class used to map a (combination of) key / modifiers / mouse buttons to a specific action. Configuration can be loaded/saved to files, or use dynamic binding management. See KeyMapping API documentation for detailed concept and usage description.

Definition at line 22 of file KeyMappingManager.hpp.

Member Function Documentation

◆ addAction() [1/2]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::addAction ( const Context context,
const EventBinding binding,
const std::string &  actionName 
)

Add an action from its name, with the given binding. If the actionName was already present, the privously added action is returned.

Definition at line 410 of file KeyMappingManager.cpp.

◆ addAction() [2/2]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::addAction ( const Context context,
const std::string &  actionName 
)

Add an action from its name. If the actionName was already present, the privously added action is returned.

Definition at line 397 of file KeyMappingManager.cpp.

◆ addContext()

KeyMappingManager::Context Ra::Gui::KeyMappingManager::addContext ( const std::string &  contextName)

Creates the context index for the given context name.

If the context already exist, return the existing index. If not, the context is created and its index is returned.

Parameters
contextNamethe name of the context
Returns
a valid context index for the given context name.

Definition at line 86 of file KeyMappingManager.cpp.

◆ createEventBindingFromStrings()

KeyMappingManager::EventBinding Ra::Gui::KeyMappingManager::createEventBindingFromStrings ( const std::string &  buttonsString = "",
const std::string &  modifiersString = "",
const std::string &  keyString = "",
const std::string &  wheelString = "" 
)
static

EventBinding factory from string description of buttons, modifiers, key and wheel.

Definition at line 592 of file KeyMappingManager.cpp.

◆ enumNamesFromKeyboardModifiers()

std::string Ra::Gui::KeyMappingManager::enumNamesFromKeyboardModifiers ( const Qt::KeyboardModifiers &  modifiers)
static

return a string of enum names from keyboard modifiers, comma separated, without space.

Definition at line 573 of file KeyMappingManager.cpp.

◆ enumNamesFromMouseButtons()

std::string Ra::Gui::KeyMappingManager::enumNamesFromMouseButtons ( const Qt::MouseButtons &  buttons)
static

return a string of enum names from mouse buttons, comma separated, without space.

Definition at line 535 of file KeyMappingManager.cpp.

◆ getAction() [1/2]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::getAction ( const Context context,
const Qt::MouseButtons &  buttons,
const Qt::KeyboardModifiers &  modifiers,
int  key,
bool  wheel = false 
)

Return the action associated to the binding buttons + modifiers + key

Parameters
contextis the context to get action from (e.g. camera or gizmo)
buttonsare the mouse buttons pressed, could be NoButton
modifiersare the keyboard modifiers, could be NoModifier
keyis the key pressed, could be -1
wheelspecifies if we consider a wheel event

Definition at line 50 of file KeyMappingManager.cpp.

◆ getAction() [2/2]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::getAction ( const Context context,
const std::string &  actionName 
)

Return the action index corresponding to a context index and actionName

Parameters
contextthe index of the context
actionNamethe name of the action
Returns
an invalid action if context is not valid, or if actionName has not been created. (i,e action.isInvalid())

Definition at line 113 of file KeyMappingManager.cpp.

◆ getActionName()

std::string Ra::Gui::KeyMappingManager::getActionName ( const Context context,
const KeyMappingAction action 
)
Returns
Action name if context index and action index are valid, "Invalid" otherwise

Definition at line 133 of file KeyMappingManager.cpp.

◆ getBinding()

std::optional< KeyMappingManager::EventBinding > Ra::Gui::KeyMappingManager::getBinding ( const Context context,
KeyMappingAction  action 
)

Return, if exists, the event binding associated with a context/action. if such binding doesn't exists, the optional does not contain a value.

Definition at line 79 of file KeyMappingManager.cpp.

◆ getContext()

KeyMappingManager::Context Ra::Gui::KeyMappingManager::getContext ( const std::string &  contextName)

Return the context index corresponding to contextName

Parameters
contextNamethe name of the context
Returns
an invalid context if contextName has not been created

Definition at line 106 of file KeyMappingManager.cpp.

◆ getContextName()

std::string Ra::Gui::KeyMappingManager::getContextName ( const Context context)
Returns
Context name if context index is valid, "Invalid" otherwise

Definition at line 150 of file KeyMappingManager.cpp.

◆ loadConfiguration()

void Ra::Gui::KeyMappingManager::loadConfiguration ( const std::string &  filename = {})

load configuration from filename, or default configration filename. It calls listeners callbacks then.

Definition at line 231 of file KeyMappingManager.cpp.

◆ removeListener()

void Ra::Gui::KeyMappingManager::removeListener ( int  callbackId)

Remove a callback. To be called when the related Context/Actions are no more needed.

Parameters
callbackIdthe Id, returned by addListener, of the Observer to be removed.

Definition at line 168 of file KeyMappingManager.cpp.

◆ saveConfiguration()

bool Ra::Gui::KeyMappingManager::saveConfiguration ( const std::string &  filename = {})

Save the configuration

Parameters
filenamethe file to write to. It will be replaced
Returns
true if file was correctly saved

Definition at line 274 of file KeyMappingManager.cpp.

◆ setActionBinding()

void Ra::Gui::KeyMappingManager::setActionBinding ( const Context context,
const EventBinding binding,
const KeyMappingAction action 
)

Bind binding to action, in context.

It replaces previously binded action, with a warning if binding was already present.

Definition at line 172 of file KeyMappingManager.cpp.


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