60 for (uint i=0; i <
plugins_.size(); i++){
65 emit
log(
LOGERR,tr(
"ERROR: could not get KeyBinding"));
73 for (uint i=0; i <
plugins_.size(); i++){
78 emit
log(
LOGERR,tr(
"ERROR: could not get rpcname"));
85 std::pair< int,Qt::KeyboardModifiers > key = std::make_pair(_e->key(), _e->modifiers() );
91 for (it=range.first; it != range.second; ++it){
93 QObject* plugin = (*it).second.first;
102 emit
call(
"core." + binding.description, ok);
110 QKeyEvent mappedEvent (_e->type(),binding.key, binding.modifiers,
111 _e->text(), _e->isAutoRepeat(), _e->count() );
116 if (binding.multiUse)
140 QKeyEvent mappedEvent(_e->type(),binding.key, binding.modifiers,
141 _e->text(), _e->isAutoRepeat(), _e->count() );
147 if (!binding.multiUse)
157 if (_e->isAutoRepeat())
return;
159 std::pair< int,Qt::KeyboardModifiers > key = std::make_pair(_e->key(), _e->modifiers() );
165 for (it=range.first; it != range.second; ++it){
167 QObject* plugin = (*it).second.first;
176 QKeyEvent mappedEvent (_e->type(),binding.key, binding.modifiers,
177 _e->text(), _e->isAutoRepeat(), _e->count() );
181 if (binding.multiUse)
197 QKeyEvent mappedEvent (_e->type(),binding.key, binding.modifiers,
198 _e->text(), _e->isAutoRepeat(), _e->count() );
204 if (!binding.multiUse)
218 for (uint i=0; i <
coreKeys_.size(); i++)
228 for (uint i=0; i <
plugins_.size(); i++)
229 for (
int k=0; k <
plugins_[i].keys.count(); k++)
231 &&
plugins_[i].keys[k].modifiers == _modifiers){
233 multi =
plugins_[i].keys[k].multiUse;
239 emit
log(
LOGERR, tr(
"Key already registered by '%1'").arg( name ) );
242 if (sender() ==
this){
245 kb.modifiers = _modifiers;
246 kb.description = _description;
247 kb.multiUse = multi || _multiUse;
250 if (multi && !_multiUse)
251 emit
log(
LOGERR, tr(
"Key already registered by '%1'. Forced registration as multiUse key.").arg( name ));
255 keys_.insert( std::make_pair( std::make_pair(_key, _modifiers) , std::make_pair ((QObject*)0,
int(
coreKeys_.size()-1 ) ) )) ;
256 invKeys_.insert( std::make_pair( std::make_pair ((QObject*)0,
int(
coreKeys_.size()-1) ) , std::make_pair(_key, _modifiers) ) );
263 for (uint i=0; i <
plugins_.size(); i++)
267 if (pluginInfo == 0){
268 emit
log(
LOGERR, tr(
"Unable to register key. Plugin not found!"));
274 kb.modifiers = _modifiers;
275 kb.description = _description;
276 kb.multiUse = multi || _multiUse;
279 if (multi && !_multiUse)
280 emit
log(
LOGERR, tr(
"Key already registered by '%1'. Forced registration as multiUse key.").arg( name ));
282 pluginInfo->
keys.append( kb );
284 keys_.insert( std::make_pair( std::make_pair(_key, _modifiers) , std::make_pair(pluginInfo->
plugin, pluginInfo->
keys.size()-1) ) );
285 invKeys_.insert( std::make_pair( std::make_pair(pluginInfo->
plugin, pluginInfo->
keys.size()-1) , std::make_pair(_key, _modifiers) ) );
295 if ( !
coreSlots_.at(i).slotName.contains(
"()" ) )
307 keys_.insert( std::make_pair( std::make_pair(-1, (QFlags<Qt::KeyboardModifier>)0) , std::make_pair ((QObject*)0,
int(
coreKeys_.size()-1) ) )) ;
308 invKeys_.insert( std::make_pair( std::make_pair ((QObject*)0,
int(
coreKeys_.size()-1) ) , std::make_pair(-1, (QFlags<Qt::KeyboardModifier>)0) ) );
312 for (uint i=0; i <
plugins_.size(); i++)
314 for (
int j=0; j <
plugins_[i].rpcFunctions.count(); j++){
317 if ( !
plugins_[i].rpcFunctions[j].contains(
"()" )
318 ||
plugins_[i].rpcFunctions[j] ==
"version()")
324 kb.description =
plugins_[i].rpcFunctions[j];
330 keys_.insert( std::make_pair( std::make_pair(-1, (QFlags<Qt::KeyboardModifier>)0) , std::make_pair(
plugins_[i].plugin,
plugins_[i].keys.size()-1) ) );
331 invKeys_.insert( std::make_pair( std::make_pair(
plugins_[i].plugin,
plugins_[i].keys.size()-1) , std::make_pair(-1, (QFlags<Qt::KeyboardModifier>)0) ) );
338 std::pair< int,Qt::KeyboardModifiers > keyCombi = std::make_pair(_key, _modifiers );
339 std::pair< int,Qt::KeyboardModifiers > oldCombi;
340 std::pair< QObject*, int > oldTarget;
342 bool replace =
false;
346 for (it=
keys_.begin(); it !=
keys_.end(); ++it){
348 int key = (*it).first.first;
349 Qt::KeyboardModifiers modifiers = (*it).first.second;
350 QObject* plugin = (*it).second.first;
351 int bindingID = (*it).second.second;
355 if (plugin == _plugin && bindingID == _keyBindingID){
357 oldCombi = (*it).first;
358 oldTarget = (*it).second;
363 if (_key == key && _modifiers == modifiers ){
365 if (!binding.multiUse){
367 emit
log(
LOGERR, tr(
"Could not add key mapping. Key already assigned to the core."));
372 emit
log(
LOGERR, tr(
"Could not add key mapping. Key already assigned to %1").arg( basePlugin->
name() ) );
374 emit
log(
LOGERR, tr(
"Could not add key mapping. Key already assigned to an unknown plugin."));
384 if (!keyBinding.multiUse)
385 if ( (replace &&
keys_.count(keyCombi) > 1) || (!replace &&
keys_.count(keyCombi) > 0) ){
386 emit
log(
LOGERR, tr(
"Could not add (single usage) key mapping. Key already assigned."));
391 keys_.erase(oldCombi);
396 keys_.insert ( std::make_pair( keyCombi , std::make_pair(_plugin, _keyBindingID) ));
397 invKeys_.insert( std::make_pair( std::make_pair(_plugin, _keyBindingID), keyCombi ));
405 QVector< int > modifiers;
406 QStringList pluginNames;
407 QVector< int > bindingIDs;
414 if (_ini.
get_entry(keyCount,
"KeyBindings",
"KeyCount") ){
421 for (
int i=0; i < keyCount; i++){
423 if (!_ini.
get_entry(key,
"KeyBindings",
"Key" + QString::number(i) ) )
continue;
424 if (!_ini.
get_entry(mod,
"KeyBindings",
"KeyModifiers" + QString::number(i) ) )
continue;
425 if (!_ini.
get_entry(name,
"KeyBindings",
"KeyTarget" + QString::number(i) ) )
continue;
426 if (!_ini.
get_entry(binding,
"KeyBindings",
"KeyBinding" + QString::number(i) ) )
continue;
428 keys.push_back( key );
429 modifiers.push_back( mod );
430 pluginNames.push_back( name );
431 bindingIDs.push_back( binding );
436 for (
int i=0; i < keys.count(); i++){
441 if (pluginNames[i] !=
"Core" ){
443 for (uint i=0; i <
plugins_.size(); i++)
444 if (
plugins_[i].rpcName == pluginNames[i] ){
453 slotAddKeyMapping( keys[i], (Qt::KeyboardModifiers) modifiers[i], plugin, bindingIDs[i] );
462 QVector< int > modifiers;
463 QStringList pluginNames;
464 QVector< int > bindingIDs;
468 for (it=
keys_.begin(); it !=
keys_.end(); ++it){
470 int key = (*it).first.first;
471 Qt::KeyboardModifiers mod = (*it).first.second;
472 QObject* plugin = (*it).second.first;
473 int bindingID = (*it).second.second;
477 if (key != binding.key || mod != binding.modifiers){
488 keys.push_back( key );
489 modifiers.push_back( mod );
490 pluginNames.push_back( name );
491 bindingIDs.push_back( bindingID );
496 _ini.
add_entry(
"KeyBindings",
"KeyCount", keys.count());
498 for (
int i=0; i < keys.count(); i++){
500 _ini.
add_entry(
"KeyBindings",
"Key" + QString::number(i) , keys[i] );
501 _ini.
add_entry(
"KeyBindings",
"KeyModifiers" + QString::number(i), modifiers[i] );
502 _ini.
add_entry(
"KeyBindings",
"KeyTarget" + QString::number(i) , pluginNames[i] );
503 _ini.
add_entry(
"KeyBindings",
"KeyBinding" + QString::number(i) , bindingIDs[i] );
511 connect(
this , SIGNAL(
registerKey(
int, Qt::KeyboardModifiers, QString,
bool) ),
512 this , SLOT(
slotRegisterKey(
int, Qt::KeyboardModifiers, QString,
bool)) );
514 emit
registerKey(Qt::Key_Print , Qt::NoModifier,
"Create Snapshot");
515 emit
registerKey(Qt::Key_Escape , Qt::NoModifier,
"Switch to last action mode ( Move,Picking,Light or Info Mode)");
516 emit
registerKey(Qt::Key_Space , Qt::NoModifier,
"Toggle between multiview and single view");
518 emit
registerKey(Qt::Key_S , Qt::ControlModifier,
"Save Object");
519 emit
registerKey(Qt::Key_O , Qt::ControlModifier,
"Open Object");
520 emit
registerKey(Qt::Key_L , Qt::ControlModifier,
"Show/Hide Logger");
521 emit
registerKey(Qt::Key_T , Qt::ControlModifier,
"Show/Hide Toolbox");
522 emit
registerKey(Qt::Key_F , Qt::ControlModifier,
"Toggle Fullscreen");
523 emit
registerKey(Qt::Key_B , Qt::ControlModifier,
"Show/Hide StatusBar");
524 emit
registerKey(Qt::Key_N , Qt::ControlModifier,
"Show/Hide ToolBar");
525 emit
registerKey(Qt::Key_M , Qt::ControlModifier,
"Show/Hide MenuBar");
528 if ( OpenFlipper::Options::isLinux() ) {
529 emit
registerKey(Qt::Key_Meta , Qt::MetaModifier,
"Use Navigation mode while key is pressed");
530 emit
registerKey(Qt::Key_Meta , Qt::NoModifier,
"Use Navigation mode while key is pressed");
531 emit
registerKey(Qt::Key_Super_L , Qt::NoModifier,
"Use Navigation mode while key is pressed");
532 emit
registerKey(Qt::Key_Super_L , Qt::MetaModifier,
"Use Navigation mode while key is pressed");
533 emit
registerKey(Qt::Key_Super_R , Qt::NoModifier,
"Use Navigation mode while key is pressed");
534 emit
registerKey(Qt::Key_Super_R , Qt::MetaModifier,
"Use Navigation mode while key is pressed");
536 emit
registerKey(Qt::Key_Alt , Qt::AltModifier,
"Use Navigation mode while key is pressed");
537 emit
registerKey(Qt::Key_Alt , Qt::NoModifier,
"Use Navigation mode while key is pressed");
540 emit
registerKey(Qt::Key_Shift , Qt::ShiftModifier,
"Apply context menu action to all Viewers",
true);
541 emit
registerKey(Qt::Key_Shift , Qt::NoModifier,
"Apply context menu action to all Viewers",
true);
544 emit
registerKey(Qt::Key_A , Qt::NoModifier,
"First Person view strafe left");
545 emit
registerKey(Qt::Key_D , Qt::NoModifier,
"First Person view strafe right");
546 emit
registerKey(Qt::Key_W , Qt::NoModifier,
"First Person view move forward");
547 emit
registerKey(Qt::Key_S , Qt::NoModifier,
"First Person view move back");
554 if ( (( _e->key() == Qt::Key_Meta ) || (_e->key() == Qt::Key_Super_L) || (_e->key() == Qt::Key_Super_R))
555 && OpenFlipper::Options::isLinux() ) {
567 if ( ( _e->key() == Qt::Key_Alt ) && ! OpenFlipper::Options::isLinux() ) {
580 if (_e->modifiers() & Qt::ControlModifier ) {
624 std::cerr <<
"Todo : On Print Screen, create a snapshot for all viewers" << std::endl;
660 if ( (( _e->key() == Qt::Key_Meta ) || (_e->key() == Qt::Key_Super_L) || (_e->key() == Qt::Key_Super_R))
661 && OpenFlipper::Options::isLinux() ) {
667 if ( ( _e->key() == Qt::Key_Alt ) && !OpenFlipper::Options::isLinux() ) {
Interface class from which all plugins have to be created.
void registerCoreKeys()
Register all events related to the core.
Keyboard Event Interface.
void strafeLeft()
When using first person mode strafe to the left.
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse=false)
internal signal to register CoreWidget keys
void coreKeyReleaseEvent(QKeyEvent *_e)
if a keyReleaseEvent belongs to the core this functions is called
QObject * plugin
Pointer to the loaded plugin (Already casted when loading it)
void call(QString _expression, bool &_success)
call a scripting function
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void toggleLogger()
Hide or show logging area.
void toggleFullscreen()
Set application to Fullscreen and back.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Viewer::ActionMode lastActionMode()
void nextViewerLayout()
Switches over to the next view mode.
virtual void slotKeyEvent(QKeyEvent *_event)
Key Event from Main App.
void coreKeyPressEvent()
handle key events for the core
void slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse=false)
key registration
void slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject *_plugin, int _keyBindingID)
add a new key Mapping
void saveKeyBindings(INIFile &_ini)
Store current key assignments to a given INI file.
Class for the handling of simple configuration files.
virtual void keyReleaseEvent(QKeyEvent *_e)
passes keyReleaseEvents to either the Core or a Plugin depending on who has registered the key ...
std::vector< PluginInfo > plugins_
List of all loaded plugins_.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void setActionMode(const Viewer::ActionMode _am)
virtual QString name()=0
Return a name for the plugin.
void toggleStatusBar()
Change visibility of the Status Bar.
std::pair< KeyMap::iterator, KeyMap::iterator > KeyRange
typedefs
QList< SlotInfo > & coreSlots_
list of scripting slots from core
bool shiftPressed_
Store the state of the shift key.
QString getRPCName(QObject *_plugin)
typedefs
void slotRegisterSlotKeyBindings()
register scripting slots to allow keyBindings
void moveForward()
When using first person mode move forward.
KeyMap keys_
mapping of all keys to registered keys and the corresponding plugins
void toggleToolbox()
Hide or show toolbox area.
KeyBinding getKeyBinding(QObject *_plugin, int _keyIndex)
typedefs
void toggleToolBar()
Hide or show current toolbar.
virtual void slotKeyReleaseEvent(QKeyEvent *_event)
Key Release Event from Main App.
Viewer::ActionMode actionMode()
void moveBack()
When using first person mode move backward.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void strafeRight()
When using first person mode strafe to the right.
void loadKeyBindings(INIFile &_ini)
Load key assignments from a given INI file.
void toggleMenuBar()
Hide or show menu bar.
InverseKeyMap invKeys_
mapping of all registered keys and the corresponding plugins to currently assigned keys ...
virtual void keyPressEvent(QKeyEvent *_e)
Handle key events.
std::vector< KeyBinding > coreKeys_
vector of keys registered to the core
QList< KeyBinding > keys
List of registered keys with description.