Commit 31cb136e authored by Dirk Wilden's avatar Dirk Wilden

shortcuts for scripting slots ;)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4369 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 75dbf467
......@@ -177,7 +177,7 @@ Core::init() {
QApplication::processEvents();
}
coreWidget_ = new CoreWidget(viewModes_ , plugins);
coreWidget_ = new CoreWidget(viewModes_ , plugins, coreSlots_);
connect(coreWidget_, SIGNAL(clearAll()) , this, SLOT(clearAll()));
connect(coreWidget_, SIGNAL(loadMenu()) , this, SLOT(loadObject()));
......@@ -194,6 +194,8 @@ Core::init() {
connect(coreWidget_, SIGNAL(loadPlugin()) , this, SLOT(slotLoadPlugin()));
connect(coreWidget_, SIGNAL(unloadPlugin()) , this, SLOT(slotUnloadPlugin()));
connect(coreWidget_, SIGNAL(call(QString,bool&)), this, SLOT(slotCall(QString,bool&)));
coreWidget_->resize(1000,1000);
coreWidget_->setWindowTitle( OpenFlipper::Options::windowTitle() );
......@@ -391,6 +393,9 @@ Core::init() {
if ( OpenFlipper::Options::gui() ) {
//register keyBinding for all scripting slots
coreWidget_->slotRegisterSlotKeyBindings();
if ( OpenFlipper::Options::defaultToolboxMode( ) != "" )
coreWidget_->setViewMode( OpenFlipper::Options::defaultToolboxMode() );
else
......
......@@ -14,6 +14,7 @@ struct KeyBinding{
Qt::KeyboardModifiers modifiers;
QString description;
bool multiUse;
bool slot;
};
struct SlotInfo{
......
......@@ -1010,7 +1010,6 @@ void Core::loadPlugin(QString filename, bool silent){
plugins.push_back(info);
//tab all dockwidgets together
if (OpenFlipper::Options::gui())
coreWidget_->tabDockWidgets( QVector< QDockWidget* >() );
......
......@@ -61,8 +61,10 @@
*/
CoreWidget::
CoreWidget( QVector<ViewMode*>& _viewModes,
std::vector<PluginInfo>& _plugins ) :
std::vector<PluginInfo>& _plugins,
QList< SlotInfo >& _coreSlots ) :
QMainWindow(),
coreSlots_(_coreSlots),
viewModes_(_viewModes),
dockViewMode_(0),
viewModeButton_(0),
......
......@@ -112,7 +112,7 @@ class CoreWidget : public QMainWindow
public:
/// constructor
CoreWidget( QVector<ViewMode*>& _viewModes, std::vector<PluginInfo>& _plugins );
CoreWidget( QVector<ViewMode*>& _viewModes, std::vector<PluginInfo>& _plugins, QList< SlotInfo >& _coreSlots );
/// destructor
~CoreWidget();
......@@ -174,6 +174,8 @@ public:
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description,
bool _multiUse = false);
///call a scripting function
void call( QString _expression , bool& _success );
private:
///typedefs
......@@ -198,6 +200,7 @@ public:
void coreKeyReleaseEvent(QKeyEvent* _e);
KeyBinding getKeyBinding(QObject* _plugin, int _keyIndex );
QString getRPCName(QObject* _plugin );
///vector of keys registered to the core
std::vector<KeyBinding> coreKeys_;
......@@ -208,6 +211,9 @@ public:
///mapping of all registered keys and the corresponding plugins to currently assigned keys
InverseKeyMap invKeys_;
///list of scripting slots from core
QList< SlotInfo >& coreSlots_;
private slots:
void slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description,
bool _multiUse = false);
......@@ -215,6 +221,8 @@ public:
public slots:
void slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID);
void slotRegisterSlotKeyBindings();
/** @} */
//===========================================================================
......
......@@ -20,6 +20,19 @@ KeyBinding CoreWidget::getKeyBinding(QObject* _plugin, int _keyIndex ){
return KeyBinding();
}
QString CoreWidget::getRPCName(QObject* _plugin ){
if (_plugin == 0)
return "";
for (uint i=0; i < plugins_.size(); i++){
if (plugins_[i].plugin == _plugin)
return plugins_[i].rpcName;
}
std::cerr << "ERROR: could not get rpcName\n";
return "";
}
/// passes keyPressEvents to either the Core or a Plugin depending on who has registered the key
void CoreWidget::keyPressEvent(QKeyEvent* _e)
{
......@@ -36,6 +49,15 @@ void CoreWidget::keyPressEvent(QKeyEvent* _e)
//check if its a core Key
if (plugin == 0){
//the key belongs to a slot
if (binding.slot){
bool ok;
emit call("core." + binding.description, ok);
return;
}
//the key was specified through keyInterface
QKeyEvent* mappedEvent = new QKeyEvent(_e->type(),binding.key, binding.modifiers,
_e->text(), _e->isAutoRepeat(), _e->count() );
......@@ -51,6 +73,15 @@ void CoreWidget::keyPressEvent(QKeyEvent* _e)
}
//it's a plugin key
//the key belongs to a slot
if (binding.slot){
bool ok;
emit call(getRPCName(plugin) +"."+ binding.description, ok);
return;
}
//the key was specified through keyInterface
KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugin);
if (keyPlugin){
......@@ -150,6 +181,7 @@ void CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QSt
kb.modifiers = _modifiers;
kb.description = _description;
kb.multiUse = multi || _multiUse;
kb.slot = false;
if (multi && !_multiUse)
log(LOGWARN, "Key registered as multiUse key.");
......@@ -178,6 +210,7 @@ void CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QSt
kb.modifiers = _modifiers;
kb.description = _description;
kb.multiUse = multi || _multiUse;
kb.slot = false;
if (multi && !_multiUse)
log(LOGWARN, "Key registered as multiUse key.");
......@@ -188,6 +221,53 @@ void CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QSt
invKeys_.insert( std::make_pair( std::make_pair(pluginInfo->plugin, pluginInfo->keys.size()-1) , std::make_pair(_key, _modifiers) ) );
}
///scripting slots will automatically registered to be assigned to an invalid key(-1)
void CoreWidget::slotRegisterSlotKeyBindings(){
//check the core slots
for (int i=0; i < coreSlots_.count(); i++){
//only consider functions without arguments
if ( !coreSlots_.at(i).slotName.contains( "()" ) )
continue;
KeyBinding kb;
kb.key = -1;
kb.modifiers = 0;
kb.description = coreSlots_.at(i).slotName;
kb.multiUse = true;
kb.slot = true;
coreKeys_.push_back( kb );
keys_.insert( std::make_pair( std::make_pair(-1, 0) , std::make_pair ((QObject*)0, coreKeys_.size()-1 ) )) ;
invKeys_.insert( std::make_pair( std::make_pair ((QObject*)0, coreKeys_.size()-1 ) , std::make_pair(-1, 0) ) );
}
//check all plugins
for (uint i=0; i < plugins_.size(); i++)
for (int j=0; j < plugins_[i].rpcFunctions.count(); j++){
//only consider functions without arguments
if ( !plugins_[i].rpcFunctions[j].contains( "()" )
|| plugins_[i].rpcFunctions[j] == "version()")
continue;
KeyBinding kb;
kb.key = -1;
kb.modifiers = 0;
kb.description = plugins_[i].rpcFunctions[j];
kb.multiUse = true;
kb.slot = true;
plugins_[i].keys.append( kb );
keys_.insert( std::make_pair( std::make_pair(-1, 0) , std::make_pair(plugins_[i].plugin, plugins_[i].keys.size()-1) ) );
invKeys_.insert( std::make_pair( std::make_pair(plugins_[i].plugin, plugins_[i].keys.size()-1) , std::make_pair(-1, 0) ) );
}
}
/// add a new keyMapping (keyBindingID is the id of the keyBinding in the pluginInfo of _plugin :)
void CoreWidget::slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID){
......@@ -212,7 +292,6 @@ void CoreWidget::slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, Q
replace = true;
oldCombi = (*it).first;
oldTarget = (*it).second;
std::cerr << "replacing \n";
continue;
}
......
......@@ -59,7 +59,9 @@ void ShortcutButton::showCurrentShortcut()
QString keyString;
if (key_ == Qt::Key_AltGr || key_ == Qt::Key_Alt || key_ == Qt::Key_Control || key_ == Qt::Key_Shift || key_ == Qt::Key_Meta){
if (key_ == -1){
keyString = "unassigned";
}else if (key_ == Qt::Key_AltGr || key_ == Qt::Key_Alt || key_ == Qt::Key_Control || key_ == Qt::Key_Shift || key_ == Qt::Key_Meta){
keyString = QKeySequence( modifiers_ ).toString();
keyString = keyString.left(keyString.size()-1);
}else
......
......@@ -180,6 +180,7 @@ void OptionsWidget::initKeyTree(){
//get the default settings
QString description;
bool multiUse;
bool slot;
int defKey;
Qt::KeyboardModifiers defModi;
......@@ -187,6 +188,7 @@ void OptionsWidget::initKeyTree(){
description = coreKeys_[bindingID].description;
multiUse = coreKeys_[bindingID].multiUse;
slot = coreKeys_[bindingID].slot;
defKey = coreKeys_[bindingID].key;
defModi = coreKeys_[bindingID].modifiers;
......@@ -194,6 +196,7 @@ void OptionsWidget::initKeyTree(){
description = plugins_[i].keys[bindingID].description;
multiUse = plugins_[i].keys[bindingID].multiUse;
slot = plugins_[i].keys[bindingID].slot;
defKey = plugins_[i].keys[bindingID].key;
defModi = plugins_[i].keys[bindingID].modifiers;
}
......@@ -203,7 +206,9 @@ void OptionsWidget::initKeyTree(){
//setup the strings for the shortcuts
QString keyString;
if (key == Qt::Key_AltGr || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta){
if (key == -1 && modifiers == 0){
keyString = "unassigned";
}else if (key == Qt::Key_AltGr || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta){
keyString = QKeySequence( modifiers ).toString();
keyString = keyString.left(keyString.size()-1);
}else
......@@ -211,7 +216,10 @@ void OptionsWidget::initKeyTree(){
QString defaultStr;
if (defKey == Qt::Key_AltGr || defKey == Qt::Key_Alt || defKey == Qt::Key_Control || defKey == Qt::Key_Shift || defKey == Qt::Key_Meta){
if (defKey == -1 && defModi == 0){
defaultStr = "unassigned";
}else if (defKey == Qt::Key_AltGr || defKey == Qt::Key_Alt || defKey == Qt::Key_Control
|| defKey == Qt::Key_Shift || defKey == Qt::Key_Meta){
defaultStr = QKeySequence( defModi ).toString();
defaultStr = defaultStr.left(defaultStr.size()-1);
}else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment