Commit 1a43a60c authored by Jan Möbius's avatar Jan Möbius
Browse files

Allow adding multiple toolboxes per plugin via signal

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5216 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3799bf7c
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
/** /**
* \brief Plugins can add its own toolbox to the main widget's toolbox area by using this interface. * \brief Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
* *
* This Interface should be used by plugins which will provide a toolbox widget. * This Interface should be used by plugins which will provide a toolbox widget.
* Each Plugin can create own Widgets in the Toolbox area as long as they use the returned widget as their parent. * Each Plugin can create own Widgets in the Toolbox area as long as they use the returned widget as their parent.
* ToolboxInterface::initializeToolbox(QWidget*& _widget). You can create extra Signals and slots in your Plugin. * ToolboxInterface::initializeToolbox(QWidget*& _widget). You can create extra Signals and slots in your Plugin.
...@@ -92,6 +92,13 @@ class ToolboxInterface { ...@@ -92,6 +92,13 @@ class ToolboxInterface {
virtual void defineViewMode(QString& /*_mode*/, QStringList& /*_usedWidgets*/){}; virtual void defineViewMode(QString& /*_mode*/, QStringList& /*_usedWidgets*/){};
/** \brief Add a toolbox widget to the gui with the given name
*
* This signal adds a toolbox widget to the toolbar on the right.
*/
virtual void addToolbox( QString /* _name */ , QWidget*& /*_widget*/ ) {};
}; };
Q_DECLARE_INTERFACE(ToolboxInterface,"OpenFlipper.ToolboxInterface/1.1") Q_DECLARE_INTERFACE(ToolboxInterface,"OpenFlipper.ToolboxInterface/1.1")
......
...@@ -750,7 +750,7 @@ void Core::fullscreen( bool _state ) { ...@@ -750,7 +750,7 @@ void Core::fullscreen( bool _state ) {
void Core::loggerState(int _state) { void Core::loggerState(int _state) {
OpenFlipper::Options::LoggerState state = static_cast<OpenFlipper::Options::LoggerState> (_state); OpenFlipper::Options::LoggerState state = static_cast<OpenFlipper::Options::LoggerState> (_state);
if ( OpenFlipper::Options::gui() && if ( OpenFlipper::Options::gui() &&
(state == OpenFlipper::Options::Hidden || (state == OpenFlipper::Options::Hidden ||
state == OpenFlipper::Options::InScene || state == OpenFlipper::Options::InScene ||
state == OpenFlipper::Options::Normal)) state == OpenFlipper::Options::Normal))
...@@ -1116,6 +1116,33 @@ void Core::setDescriptions(){ ...@@ -1116,6 +1116,33 @@ void Core::setDescriptions(){
} }
void Core::slotAddToolbox(QString _name ,QWidget* _widget) {
int id = -1;
for ( uint i = 0 ; i < plugins.size(); ++i ) {
if ( plugins[i].plugin == sender() ) {
id = i;
std::cerr << "Found" << std::endl;
break;
}
}
if ( id == -1 ) {
std::cerr << "Unknown sender plugin when adding Toolbox!" << std::endl;
return;
}
plugins[id].widgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
// add widget name to viewMode 'all'
if ( !viewModes_[0]->visibleWidgets.contains(_name) ){
viewModes_[0]->visibleWidgets << _name;
viewModes_[0]->visibleWidgets.sort();
}
}
// //----------------------------------------------------------------------------- // //-----------------------------------------------------------------------------
// //
// void Core::slotGetPlugin(QString _name, QObject* & _plugin ){ // void Core::slotGetPlugin(QString _name, QObject* & _plugin ){
......
...@@ -393,6 +393,9 @@ private: ...@@ -393,6 +393,9 @@ private:
/// The current Toolbox item has changed /// The current Toolbox item has changed
// void slotToolboxSwitched(int _index); // void slotToolboxSwitched(int _index);
/// Add a Toolbox from a plugin
void slotAddToolbox(QString _name ,QWidget* _widget);
/// Slot adding empty object from Menu /// Slot adding empty object from Menu
void slotAddEmptyObjectMenu(); void slotAddEmptyObjectMenu();
......
...@@ -39,7 +39,7 @@ class PluginInfo{ ...@@ -39,7 +39,7 @@ class PluginInfo{
rpcFunctions.clear(); rpcFunctions.clear();
slotInfos.clear(); slotInfos.clear();
keys.clear(); keys.clear();
widget = 0; widgets.clear();
optionsWidget = 0; optionsWidget = 0;
} }
...@@ -55,7 +55,7 @@ class PluginInfo{ ...@@ -55,7 +55,7 @@ class PluginInfo{
rpcFunctions = _i.rpcFunctions; rpcFunctions = _i.rpcFunctions;
slotInfos = _i.slotInfos; slotInfos = _i.slotInfos;
keys = _i.keys; keys = _i.keys;
widget = _i.widget; widgets = _i.widgets;
optionsWidget = _i.optionsWidget; optionsWidget = _i.optionsWidget;
} }
...@@ -87,7 +87,7 @@ class PluginInfo{ ...@@ -87,7 +87,7 @@ class PluginInfo{
QList< KeyBinding > keys; QList< KeyBinding > keys;
/// Pointer to plugins toolbar widget (if available) /// Pointer to plugins toolbar widget (if available)
QWidget* widget; std::vector< std::pair< QString , QWidget* > > widgets;
/// Pointer to plugins options widget (if available) /// Pointer to plugins options widget (if available)
QWidget* optionsWidget; QWidget* optionsWidget;
......
...@@ -329,10 +329,11 @@ void Core::unloadPlugin(QString name){ ...@@ -329,10 +329,11 @@ void Core::unloadPlugin(QString name){
name_nospace.remove(" "); name_nospace.remove(" ");
if ( coreWidget_->viewModes_[0]->visibleWidgets.contains(name_nospace) ) if ( coreWidget_->viewModes_[0]->visibleWidgets.contains(name_nospace) )
coreWidget_->viewModes_[0]->visibleWidgets.removeAt(coreWidget_->viewModes_[0]->visibleWidgets.indexOf(name_nospace)); coreWidget_->viewModes_[0]->visibleWidgets.removeAt(coreWidget_->viewModes_[0]->visibleWidgets.indexOf(name_nospace));
if (plugins[i].widget){ for ( uint j = 0 ; j < plugins[i].widgets.size() ; ++j )
plugins[i].widget->setVisible(false); if (plugins[i].widgets[j].second ){
delete plugins[i].widget; plugins[i].widgets[j].second->setVisible(false);
} delete plugins[i].widgets[j].second;
}
plugins.erase(plugins.begin() + i); plugins.erase(plugins.begin() + i);
...@@ -436,7 +437,6 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -436,7 +437,6 @@ void Core::loadPlugin(QString filename, bool silent){
info.description = basePlugin->description(); info.description = basePlugin->description();
info.plugin = plugin; info.plugin = plugin;
info.path = filename; info.path = filename;
info.widget = 0;
if ( checkSlot(plugin,"version()") ) if ( checkSlot(plugin,"version()") )
info.version = basePlugin->version(); info.version = basePlugin->version();
...@@ -583,13 +583,11 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -583,13 +583,11 @@ void Core::loadPlugin(QString filename, bool silent){
QWidget* widget = 0; QWidget* widget = 0;
if ( toolboxPlugin->initializeToolbox( widget ) ) { if ( toolboxPlugin->initializeToolbox( widget ) ) {
info.widget = widget; info.widgets.push_back( std::pair< QString,QWidget* >( info.name , widget) );
// add widget name to viewMode 'all' // add widget name to viewMode 'all'
QString name_nospace = info.name; if ( !viewModes_[0]->visibleWidgets.contains(info.name) ){
name_nospace.remove(" "); viewModes_[0]->visibleWidgets << info.name;
if ( !viewModes_[0]->visibleWidgets.contains(name_nospace) ){
viewModes_[0]->visibleWidgets << name_nospace;
viewModes_[0]->visibleWidgets.sort(); viewModes_[0]->visibleWidgets.sort();
} }
} }
...@@ -598,6 +596,12 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -598,6 +596,12 @@ void Core::loadPlugin(QString filename, bool silent){
connect(plugin, SIGNAL( defineViewMode(QString, QStringList) ), connect(plugin, SIGNAL( defineViewMode(QString, QStringList) ),
coreWidget_, SLOT( slotAddViewMode(QString, QStringList) ),Qt::DirectConnection ); coreWidget_, SLOT( slotAddViewMode(QString, QStringList) ),Qt::DirectConnection );
if ( checkSignal(plugin, "addToolbox(QString,QWidget*)"))
connect(plugin, SIGNAL( addToolbox(QString,QWidget*) ),
this, SLOT( slotAddToolbox(QString,QWidget*) ),Qt::DirectConnection );
} }
//Check if the plugin supports Options-Interface //Check if the plugin supports Options-Interface
......
...@@ -160,12 +160,9 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolWidgets){ ...@@ -160,12 +160,9 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolWidgets){
//find all widgets that should be visible //find all widgets that should be visible
for (int i=0; i < _toolWidgets.size(); i++) for (int i=0; i < _toolWidgets.size(); i++)
for (uint p=0; p < plugins_.size(); p++){ for (uint p=0; p < plugins_.size(); p++){
if (plugins_[p].widget == 0) continue; for ( uint j = 0 ; j < plugins_[p].widgets.size(); ++j )
QString name_nospace = plugins_[p].name; if (_toolWidgets[i] == plugins_[p].widgets[j].first )
name_nospace.remove(" "); toolBox_->addItem (plugins_[p].widgets[j].second, plugins_[p].widgets[j].first);
if (_toolWidgets[i] == name_nospace ){
toolBox_->addItem (plugins_[p].widget, plugins_[p].name);
}
} }
if (_mode != "") if (_mode != "")
......
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