Commit a0e673aa authored by Dirk Wilden's avatar Dirk Wilden

updated keyInterface

key registration added

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@2826 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a07d1616
...@@ -49,13 +49,25 @@ ...@@ -49,13 +49,25 @@
/** \brief Interface class for plugins which have to react on keyboard events /** \brief Interface class for plugins which have to react on keyboard events
* *
* Using this interface you can react on key events. The key events are emitted to all plugins * Using this interface you can react on key events. You first have to register
* implementing this interface. So a key event may be handled by multiple plugins. * a key (or key combination). For each registered key you will receive a keyEvent when
* Use keys with care!! * the key was pressed and a keyReleaseEvent when the key was released.
* @todo : implement core handling of key events and warn on multiple definitions for the same key. *
*/ */
class KeyInterface { class KeyInterface {
private slots : signals:
/** \brief Register a key-combination for your plugin
*
* To obtain key events from the viewer for a certain key-combination, you have
* to register that combination first
*
* @param _key the key that should be registered
* @param _modifiers the keyboard modifiers
* @param _description a short description about the functionality
*/
virtual void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description) {};
public slots :
/** \brief Key Event from Main App /** \brief Key Event from Main App
* *
...@@ -78,6 +90,6 @@ class KeyInterface { ...@@ -78,6 +90,6 @@ class KeyInterface {
}; };
Q_DECLARE_INTERFACE(KeyInterface,"OpenFlipper.KeyInterface/1.0") Q_DECLARE_INTERFACE(KeyInterface,"OpenFlipper.KeyInterface/1.1")
#endif // KEYINTERFACE_HH #endif // KEYINTERFACE_HH
...@@ -198,7 +198,23 @@ Core::init() { ...@@ -198,7 +198,23 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection); connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection); connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// ======================================================================
// Create a logger class for CoreWidget
// ======================================================================
if ( OpenFlipper::Options::gui() ){
PluginLogger* widgetlog = new PluginLogger("CoreWidget");
loggers_.push_back(widgetlog);
connect(coreWidget_,SIGNAL(log(Logtype, QString )),widgetlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(coreWidget_,SIGNAL(log(QString )),widgetlog,SLOT(slotLog(QString )),Qt::DirectConnection);
// Connect it to the Master logger
connect(widgetlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
}
// ====================================================================== // ======================================================================
// Catch OpenMesh Error logs with an own Logger // Catch OpenMesh Error logs with an own Logger
......
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/Core/PluginInfo.hh>
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
struct fileTypes { struct fileTypes {
...@@ -494,7 +496,7 @@ private: ...@@ -494,7 +496,7 @@ private:
private: private:
/// List of all loaded plugins /// List of all loaded plugins
std::vector<PluginInfoT> plugins; std::vector<PluginInfo> plugins;
/// List of Plugins that should not be loaded /// List of Plugins that should not be loaded
QStringList dontLoadPlugins_; QStringList dontLoadPlugins_;
......
#ifndef PLUGININFO_HH
#define PLUGININFO_HH
#include <Qt>
#include <QString>
#include <QObject>
#include <QStringList>
#include <QList>
#include <QDockWidget>
struct KeyBinding{
int key;
Qt::KeyboardModifiers modifiers;
QString description;
};
/** Type defining a currently loaded Plugin */
struct PluginInfo{
/// Pointer to the loaded plugin (Already casted when loading it)
QObject* plugin;
/// Name of the plugin ( requested from the plugin on load)
QString name;
/// Description of the plugin ( requested from the plugin on load)
QString description;
/// Path to the plugin ( set on load )
QString path;
/// Clean rpc name of the plugin
QString rpcName;
/// List of exported rpc slots
QStringList rpcFunctions;
/// List of registered keys with description
QList< KeyBinding > keys;
/// Pointer to plugins toolbar widget (if available)
QDockWidget* widget;
};
#endif //PLUGININFO_HH
...@@ -329,7 +329,7 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -329,7 +329,7 @@ void Core::loadPlugin(QString filename, bool silent){
// Check if a plugin has been loaded // Check if a plugin has been loaded
if (plugin) { if (plugin) {
PluginInfoT info; PluginInfo info;
QString supported; QString supported;
// Check if it is a BasePlugin // Check if it is a BasePlugin
...@@ -572,11 +572,16 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -572,11 +572,16 @@ void Core::loadPlugin(QString filename, bool silent){
KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugin); KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugin);
if ( keyPlugin && OpenFlipper::Options::gui() ) { if ( keyPlugin && OpenFlipper::Options::gui() ) {
supported = supported + "KeyboardEvents "; supported = supported + "KeyboardEvents ";
if ( checkSlot( plugin , "slotKeyEvent(QKeyEvent*)" ) )
connect(coreWidget_,SIGNAL(PluginKeyEvent(QKeyEvent* )), plugin,SLOT(slotKeyEvent(QKeyEvent*)));
if ( checkSlot( plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) ) if ( checkSignal(plugin,"registerKey(int,Qt::KeyboardModifiers,QString)") )
connect(coreWidget_,SIGNAL(PluginKeyReleaseEvent(QKeyEvent* )), plugin,SLOT(slotKeyReleaseEvent(QKeyEvent*))); connect(plugin,SIGNAL( registerKey(int, Qt::KeyboardModifiers, QString) ),
coreWidget_,SLOT(slotRegisterKey(int, Qt::KeyboardModifiers, QString)) );
// if ( checkSlot( plugin , "slotKeyEvent(QKeyEvent*)" ) )
// connect(coreWidget_,SIGNAL(PluginKeyEvent(QKeyEvent* )), plugin,SLOT(slotKeyEvent(QKeyEvent*)));
//
// if ( checkSlot( plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) )
// connect(coreWidget_,SIGNAL(PluginKeyReleaseEvent(QKeyEvent* )), plugin,SLOT(slotKeyReleaseEvent(QKeyEvent*)));
} }
//Check if the plugin supports Mouse-Interface //Check if the plugin supports Mouse-Interface
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/RecentFiles.hh> #include <OpenFlipper/common/RecentFiles.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#define WIDGET_HEIGHT 800 #define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800 #define WIDGET_WIDTH 800
...@@ -59,7 +61,7 @@ ...@@ -59,7 +61,7 @@
*/ */
CoreWidget:: CoreWidget::
CoreWidget( QVector<ViewMode*>& _viewModes, CoreWidget( QVector<ViewMode*>& _viewModes,
std::vector<PluginInfoT>& _plugins ) : std::vector<PluginInfo>& _plugins ) :
QMainWindow(), QMainWindow(),
viewModes_(_viewModes), viewModes_(_viewModes),
dockViewMode_(0), dockViewMode_(0),
...@@ -251,6 +253,13 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -251,6 +253,13 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
updateRecent(); updateRecent();
statusBar_->showMessage("Ready", 5000); statusBar_->showMessage("Ready", 5000);
//register keys for coreWidget
connect(this,SIGNAL( registerKey(int, Qt::KeyboardModifiers, QString) ),
this,SLOT(slotRegisterKey(int, Qt::KeyboardModifiers, QString)) );
emit registerKey(Qt::Key_S,Qt::ControlModifier, "Save Object");
emit registerKey(Qt::Key_O,Qt::ControlModifier, "Open Object");
} }
...@@ -356,7 +365,7 @@ CoreWidget::keyPressEvent(QKeyEvent* _e) ...@@ -356,7 +365,7 @@ CoreWidget::keyPressEvent(QKeyEvent* _e)
// Send remaining events to plugins // Send remaining events to plugins
default: default:
emit PluginKeyEvent(_e); mapKeyPressEvent(_e);
return; return;
} }
} }
...@@ -365,7 +374,7 @@ CoreWidget::keyPressEvent(QKeyEvent* _e) ...@@ -365,7 +374,7 @@ CoreWidget::keyPressEvent(QKeyEvent* _e)
{ {
// Send remaining events to plugins // Send remaining events to plugins
default: default:
emit PluginKeyEvent(_e); mapKeyPressEvent(_e);
break; break;
} }
} }
...@@ -375,7 +384,109 @@ CoreWidget::keyPressEvent(QKeyEvent* _e) ...@@ -375,7 +384,109 @@ CoreWidget::keyPressEvent(QKeyEvent* _e)
/** Handle Key Release Events */ /** Handle Key Release Events */
void void
CoreWidget::keyReleaseEvent(QKeyEvent* _e) { CoreWidget::keyReleaseEvent(QKeyEvent* _e) {
emit PluginKeyReleaseEvent(_e); mapKeyReleaseEvent(_e);
}
//-----------------------------------------------------------------------------
/** Map Key Press Events to Plugins */
void
CoreWidget::mapKeyPressEvent(QKeyEvent* _e){
//find the first plugin which wants to handle that key
for (uint i=0; i < plugins_.size(); i++)
for (int k=0; k < plugins_[i].keys.count(); k++)
if ( plugins_[i].keys[k].key == _e->key()
&& plugins_[i].keys[k].modifiers == _e->modifiers() ){
KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugins_[i].plugin);
if (keyPlugin){
// if ( checkSlot( plugins_[i].plugin , "slotKeyEvent(QKeyEvent*)" ) )
keyPlugin->slotKeyEvent(_e);
return;
}
}
}
//-----------------------------------------------------------------------------
/** Map Key Release Events to Plugins */
void
CoreWidget::mapKeyReleaseEvent(QKeyEvent* _e){
if (_e->isAutoRepeat()) return; //consider only "real" release events
//find the first plugin which wants to handle that key
for (uint i=0; i < plugins_.size(); i++)
for (int k=0; k < plugins_[i].keys.count(); k++)
if ( plugins_[i].keys[k].key == _e->key()
&& plugins_[i].keys[k].modifiers == _e->modifiers() ){
KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugins_[i].plugin);
if (keyPlugin){
// if ( checkSlot( plugins_[i].plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) )
keyPlugin->slotKeyReleaseEvent(_e);
return;
}
}
}
//-----------------------------------------------------------------------------
/** Register a key to a plugin */
void
CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description){
//first check if the key is already registered by the coreWidget
bool found = false;
for (uint i=0; i < coreKeys_.size(); i++)
if (coreKeys_[i].key == _key && coreKeys_[i].modifiers == _modifiers){
found = true;
break;
}
//then check if the key is already registered by a different plugin
if (!found)
for (uint i=0; i < plugins_.size(); i++)
for (int k=0; k < plugins_[i].keys.count(); k++)
if (plugins_[i].keys[k].key == _key
&& plugins_[i].keys[k].modifiers == _modifiers)
found = true;
if (found)
emit log(LOGERR, "Key already registered elsewhere.");
//check if its a key for the core
if (sender() == this){
KeyBinding kb;
kb.key = _key;
kb.modifiers = _modifiers;
kb.description = _description;
coreKeys_.push_back( kb );
return;
}
//find plugin
PluginInfo* pluginInfo = 0;
for (uint i=0; i < plugins_.size(); i++)
if (plugins_[i].plugin == sender())
pluginInfo = &plugins_[i];
if (pluginInfo == 0){
emit log(LOGERR, "Unable to register key. Plugin not found!");
return;
}
KeyBinding kb;
kb.key = _key;
kb.modifiers = _modifiers;
kb.description = _description;
pluginInfo->keys.append( kb );
} }
//============================================================================= //=============================================================================
...@@ -432,7 +543,7 @@ void CoreWidget::showOptionsWidget() { ...@@ -432,7 +543,7 @@ void CoreWidget::showOptionsWidget() {
return; return;
if ( optionsWidget_ == 0 ) { if ( optionsWidget_ == 0 ) {
optionsWidget_ = new OptionsWidget(0); optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, 0);
connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions())); connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions())); connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
} }
...@@ -442,7 +553,8 @@ void CoreWidget::showOptionsWidget() { ...@@ -442,7 +553,8 @@ void CoreWidget::showOptionsWidget() {
center.setX( x() + width() / 2 ); center.setX( x() + width() / 2 );
center.setY( y() + height() / 2 ); center.setY( y() + height() / 2 );
optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2, center.y() - optionsWidget_->height() / 2, optionsWidget_->width(), optionsWidget_->height()); optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
optionsWidget_->show(); optionsWidget_->show();
......
...@@ -70,30 +70,7 @@ ...@@ -70,30 +70,7 @@
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh> #include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
#include <OpenFlipper/widgets/helpBrowser/helpWidget.hh> #include <OpenFlipper/widgets/helpBrowser/helpWidget.hh>
/** Type defining a currently loaded Plugin */ #include <OpenFlipper/Core/PluginInfo.hh>
struct PluginInfoT{
/// Pointer to the loaded plugin (Already casted when loading it)
QObject* plugin;
/// Name of the plugin ( requested from the plugin on load)
QString name;
/// Description of the plugin ( requested from the plugin on load)
QString description;
/// Path to the plugin ( set on load )
QString path;
/// Clean rpc name of the plugin
QString rpcName;
/// List of exported rpc slots
QStringList rpcFunctions;
/// Pointer to plugins toolbar widget (if available)
QDockWidget* widget;
};
struct ViewMode{ struct ViewMode{
QString name; QString name;
...@@ -132,7 +109,7 @@ class CoreWidget : public QMainWindow ...@@ -132,7 +109,7 @@ class CoreWidget : public QMainWindow
public: public:
/// constructor /// constructor
CoreWidget( QVector<ViewMode*>& _viewModes, std::vector<PluginInfoT>& _plugins ); CoreWidget( QVector<ViewMode*>& _viewModes, std::vector<PluginInfo>& _plugins );
/// destructor /// destructor
~CoreWidget(); ~CoreWidget();
...@@ -156,6 +133,17 @@ public: ...@@ -156,6 +133,17 @@ public:
/// Called on applications close /// Called on applications close
void closeEvent ( QCloseEvent * event ); void closeEvent ( QCloseEvent * event );
//===========================================================================
/** @name Logger
* @{ */
//===========================================================================
signals :
void log(Logtype _type, QString _message);
void log(QString _message);
/** @} */
//=========================================================================== //===========================================================================
/** @name Keys /** @name Keys
* @{ */ * @{ */
...@@ -174,6 +162,18 @@ public: ...@@ -174,6 +162,18 @@ public:
/// When this Signal is emitted when a key release event event occures /// When this Signal is emitted when a key release event event occures
void PluginKeyReleaseEvent(QKeyEvent* ); void PluginKeyReleaseEvent(QKeyEvent* );
/// internal signal to register CoreWidget keys
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description);
private:
void mapKeyPressEvent(QKeyEvent* _e);
void mapKeyReleaseEvent(QKeyEvent* _e);
std::vector<KeyBinding> coreKeys_;
private slots:
void slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description);
/** @} */ /** @} */
//=========================================================================== //===========================================================================
...@@ -499,7 +499,7 @@ public: ...@@ -499,7 +499,7 @@ public:
private : private :
std::vector<PluginInfoT>& plugins_; std::vector<PluginInfo>& plugins_;
}; };
......
...@@ -36,10 +36,15 @@ ...@@ -36,10 +36,15 @@
#include <iostream> #include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
OptionsWidget::OptionsWidget( QWidget *parent)
: QWidget(parent)
OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent)
: plugins_(_plugins),
coreKeys_(_core),
QWidget(parent)
{ {
setupUi(this); setupUi(this);
connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply())); connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel())); connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
} }
...@@ -57,6 +62,50 @@ void OptionsWidget::showEvent ( QShowEvent * event ) { ...@@ -57,6 +62,50 @@ void OptionsWidget::showEvent ( QShowEvent * event ) {
wZoomFactor->setText( QString::number(OpenFlipper::Options::wheelZoomFactor(), 'f') ); wZoomFactor->setText( QString::number(OpenFlipper::Options::wheelZoomFactor(), 'f') );
wZoomFactorShift->setText( QString::number(OpenFlipper::Options::wheelZoomFactorShift(), 'f') ); wZoomFactorShift->setText( QString::number(OpenFlipper::Options::wheelZoomFactorShift(), 'f') );
//keyBindings
keyTree->setColumnCount ( 2 );
QStringList headerdata;
headerdata << "Action" << "Shortcut";
keyTree->setHeaderLabels(headerdata);
//add Core Keys
QTreeWidgetItem * core = new QTreeWidgetItem(keyTree, QStringList("CoreWidget"));
QList<QTreeWidgetItem *> keys;
for (uint i=0; i < coreKeys_.size(); i++){
QStringList row;
row << coreKeys_[i].description << QString::number(coreKeys_[i].key);
keys.append(new QTreeWidgetItem(core, row));
}
core->addChildren(keys);
keyTree->addTopLevelItem( core );
QList<QTreeWidgetItem *> plugins;
for (uint i=0; i < plugins_.size(); i++){
plugins.append(new QTreeWidgetItem(keyTree, QStringList( plugins_[i].name )));
QList<QTreeWidgetItem *> keys;
for (int k=0; k < plugins_[i].keys.count(); k++){
QStringList row;
row << plugins_[i].keys[k].description << QString::number(plugins_[i].keys[k].key);
keys.append(new QTreeWidgetItem(plugins[i], row));
}
plugins[i]->addChildren(keys);
}
keyTree->addTopLevelItems( plugins );
keyTree->resizeColumnToContents(0);
keyTree->resizeColumnToContents(1);
} }
void OptionsWidget::slotApply() { void OptionsWidget::slotApply() {
...@@ -80,4 +129,3 @@ void OptionsWidget::slotApply() { ...@@ -80,4 +129,3 @@ void OptionsWidget::slotApply() {
void OptionsWidget::slotCancel() { void OptionsWidget::slotCancel() {
hide(); hide();
} }
...@@ -39,12 +39,14 @@ ...@@ -39,12 +39,14 @@
#include <QtGui> #include <QtGui>
#include <QStringList> #include <QStringList>
#include <OpenFlipper/Core/PluginInfo.hh>
class OptionsWidget : public QWidget, public Ui::OptionsWidget class OptionsWidget : public QWidget, public Ui::OptionsWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
OptionsWidget(QWidget *parent = 0 ); OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent = 0 );
signals: signals:
void applyOptions(); void applyOptions();
...@@ -59,6 +61,11 @@ class OptionsWidget : public QWidget, public Ui::OptionsWidget ...@@ -59,6 +61,11 @@ class OptionsWidget : public QWidget, public Ui::OptionsWidget
protected: protected:
void showEvent ( QShowEvent * event ); void showEvent ( QShowEvent * event );
private:
//key-bindings
std::vector<PluginInfo>& plugins_;
std::vector<KeyBinding>& coreKeys_;
}; };
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<string/> <string/>
</property> </property>
<property name="currentIndex" > <property name="currentIndex" >
<number>1</number> <number>2</number>
</property> </property>
<property name="usesScrollButtons" > <property name="usesScrollButtons" >
<bool>true</bool> <bool>true</bool>
...@@ -187,6 +187,24 @@ ...@@ -187,6 +187,24 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="key" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>409</height>
</rect>
</property>
<attribute name="title" >
<string>Key Bindings</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QTreeWidget" name="keyTree" />
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item> <item>
......
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