Commit 6a453497 authored by Jan Möbius's avatar Jan Möbius

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 e1f67bf3
......@@ -51,7 +51,7 @@
/**
* \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.
* 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.
......@@ -92,6 +92,13 @@ class ToolboxInterface {
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")
......
......@@ -750,7 +750,7 @@ void Core::fullscreen( bool _state ) {
void Core::loggerState(int _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::InScene ||
state == OpenFlipper::Options::Normal))
......@@ -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 ){
......
......@@ -393,6 +393,9 @@ private:
/// The current Toolbox item has changed
// void slotToolboxSwitched(int _index);
/// Add a Toolbox from a plugin
void slotAddToolbox(QString _name ,QWidget* _widget);
/// Slot adding empty object from Menu
void slotAddEmptyObjectMenu();
......
......@@ -39,7 +39,7 @@ class PluginInfo{
rpcFunctions.clear();
slotInfos.clear();
keys.clear();
widget = 0;
widgets.clear();
optionsWidget = 0;
}
......@@ -55,7 +55,7 @@ class PluginInfo{
rpcFunctions = _i.rpcFunctions;
slotInfos = _i.slotInfos;
keys = _i.keys;
widget = _i.widget;
widgets = _i.widgets;
optionsWidget = _i.optionsWidget;
}
......@@ -87,7 +87,7 @@ class PluginInfo{
QList< KeyBinding > keys;
/// Pointer to plugins toolbar widget (if available)
QWidget* widget;
std::vector< std::pair< QString , QWidget* > > widgets;
/// Pointer to plugins options widget (if available)
QWidget* optionsWidget;
......
......@@ -329,10 +329,11 @@ void Core::unloadPlugin(QString name){
name_nospace.remove(" ");
if ( coreWidget_->viewModes_[0]->visibleWidgets.contains(name_nospace) )
coreWidget_->viewModes_[0]->visibleWidgets.removeAt(coreWidget_->viewModes_[0]->visibleWidgets.indexOf(name_nospace));
if (plugins[i].widget){
plugins[i].widget->setVisible(false);
delete plugins[i].widget;
}
for ( uint j = 0 ; j < plugins[i].widgets.size() ; ++j )
if (plugins[i].widgets[j].second ){
plugins[i].widgets[j].second->setVisible(false);
delete plugins[i].widgets[j].second;
}
plugins.erase(plugins.begin() + i);
......@@ -436,7 +437,6 @@ void Core::loadPlugin(QString filename, bool silent){
info.description = basePlugin->description();
info.plugin = plugin;
info.path = filename;
info.widget = 0;
if ( checkSlot(plugin,"version()") )
info.version = basePlugin->version();
......@@ -583,13 +583,11 @@ void Core::loadPlugin(QString filename, bool silent){
QWidget* widget = 0;
if ( toolboxPlugin->initializeToolbox( widget ) ) {
info.widget = widget;
info.widgets.push_back( std::pair< QString,QWidget* >( info.name , widget) );
// add widget name to viewMode 'all'
QString name_nospace = info.name;
name_nospace.remove(" ");
if ( !viewModes_[0]->visibleWidgets.contains(name_nospace) ){
viewModes_[0]->visibleWidgets << name_nospace;
if ( !viewModes_[0]->visibleWidgets.contains(info.name) ){
viewModes_[0]->visibleWidgets << info.name;
viewModes_[0]->visibleWidgets.sort();
}
}
......@@ -598,6 +596,12 @@ void Core::loadPlugin(QString filename, bool silent){
connect(plugin, SIGNAL( defineViewMode(QString, QStringList) ),
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
......
......@@ -160,12 +160,9 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolWidgets){
//find all widgets that should be visible
for (int i=0; i < _toolWidgets.size(); i++)
for (uint p=0; p < plugins_.size(); p++){
if (plugins_[p].widget == 0) continue;
QString name_nospace = plugins_[p].name;
name_nospace.remove(" ");
if (_toolWidgets[i] == name_nospace ){
toolBox_->addItem (plugins_[p].widget, plugins_[p].name);
}
for ( uint j = 0 ; j < plugins_[p].widgets.size(); ++j )
if (_toolWidgets[i] == plugins_[p].widgets[j].first )
toolBox_->addItem (plugins_[p].widgets[j].second, plugins_[p].widgets[j].first);
}
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