Radium Engine  1.5.20
Loading...
Searching...
No Matches
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>

+ 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.
 
Context addContext (const std::string &contextName)
 Creates the context index for the given context name.
 
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 Typedef Documentation

◆ Context

using Ra::Gui::KeyMappingManager::Context = Ra::Core::Utils::Index

handle to a Context

Definition at line 79 of file KeyMappingManager.hpp.

◆ KeyMappingAction

using Ra::Gui::KeyMappingManager::KeyMappingAction = Ra::Core::Utils::Index

handle to an action

Definition at line 78 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 409 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 396 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 85 of file KeyMappingManager.cpp.

◆ addListener()

int Ra::Gui::KeyMappingManager::addListener ( Observable::Observer callback)

Add a callback, triggered when configuration is load or reloaded.

Definition at line 159 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 591 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ 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 572 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 534 of file KeyMappingManager.cpp.

◆ getAction() [1/4]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::getAction ( const Context & context,
const EventBinding & binding )

Definition at line 69 of file KeyMappingManager.cpp.

◆ getAction() [2/4]

KeyMappingManager::KeyMappingAction Ra::Gui::KeyMappingManager::getAction ( const Context & context,
const QEvent * event,
int key,
bool wheel = false )

Definition at line 33 of file KeyMappingManager.cpp.

◆ getAction() [3/4]

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 49 of file KeyMappingManager.cpp.

◆ getAction() [4/4]

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 112 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 132 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ 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 78 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 105 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 149 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ getHelpText()

std::string Ra::Gui::KeyMappingManager::getHelpText ( )

Return a string corresponding to the current dom document.

Definition at line 483 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ getLoadedFilename()

std::string Ra::Gui::KeyMappingManager::getLoadedFilename ( )
inline

Definition at line 93 of file KeyMappingManager.hpp.

◆ 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 230 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ reloadConfiguration()

void Ra::Gui::KeyMappingManager::reloadConfiguration ( )

reload last open file.

Definition at line 474 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 167 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 273 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

◆ 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 171 of file KeyMappingManager.cpp.

+ Here is the call graph for this function:

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