From f9faedb2091f2e4e53a103a2ab7b98450b0cdeb8 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Mon, 19 Jan 2009 11:48:27 +0000 Subject: [PATCH] added an OptionsInterface and added functionality to show optionWidgets for each plugin in the Options Dialog git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4362 383ad7c9-94d9-4d36-a494-682f7c89f535 --- BasePlugin/OptionsInterface.hh | 85 ++++++++++++++++++++++++++ Core/PluginInfo.hh | 5 ++ Core/PluginLoader.cc | 18 +++++- widgets/coreWidget/keyHandling.cc | 1 + widgets/optionsWidget/optionsWidget.cc | 51 ++++++++++++++++ widgets/optionsWidget/optionsWidget.hh | 11 +++- widgets/optionsWidget/optionsWidget.ui | 49 +++++++++++++-- 7 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 BasePlugin/OptionsInterface.hh diff --git a/BasePlugin/OptionsInterface.hh b/BasePlugin/OptionsInterface.hh new file mode 100644 index 00000000..ee89c708 --- /dev/null +++ b/BasePlugin/OptionsInterface.hh @@ -0,0 +1,85 @@ +//============================================================================= +// +// OpenFlipper +// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen +// www.openflipper.org +// +//----------------------------------------------------------------------------- +// +// License +// +// OpenFlipper is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// OpenFlipper is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with OpenFlipper. If not, see . +// +//----------------------------------------------------------------------------- +// +// $Revision: 3265 $ +// $Author: wilden $ +// $Date: 2008-09-30 18:08:19 +0200 (Tue, 30 Sep 2008) $ +// +//============================================================================= + + +#ifndef OPTIONSINTERFACE_HH +#define OPTIONSINTERFACE_HH + +#include + + /** + * This Interface should be used by plugins which will provide a their own options. + * For your options to show up in OpenFlippers Options window implement the initializeOptionsWidget() slot. + * The widget you return with this slot will be integrated into the options window and when + * the user hits the apply- or ok-button in the options window the slot applyOptions() is called and + * thus enables you to store the changes in your options. + */ +class OptionsInterface { + + private slots : + + public : + + /// Destructor + virtual ~OptionsInterface() {}; + + /** \brief Initialize the Options Widget + * + * Initialize the options widget (create a widget and return a pointer to it ) \n + * \n + * Example : \n + * _widget = new QWidget(); \n + * \n + * In the widget you can add anything you want.\n + * \n + * use the slot applyOptions() to save the values of options currently entered + * in your widget. + * \n + * @param _widget Pointer to the new Widget + * @return Return true if a widget has been created + */ + virtual bool initializeOptionsWidget(QWidget*& /*_widget*/) = 0; + + /** \brief Apply changes to options + * + * Called, when the user hits the apply/ok button in the options window + * of Openflipper.\n + * + * use this slot to save the values of options currently entered + * in your options widget. + */ + virtual void applyOptions() = 0; + +}; + +Q_DECLARE_INTERFACE(OptionsInterface,"OpenFlipper.OptionsInterface/1.0") + +#endif // OPTIONSINTERFACE_HH diff --git a/Core/PluginInfo.hh b/Core/PluginInfo.hh index 341a4963..20b95640 100644 --- a/Core/PluginInfo.hh +++ b/Core/PluginInfo.hh @@ -39,6 +39,7 @@ class PluginInfo{ slotInfos.clear(); keys.clear(); widget = 0; + optionsWidget = 0; } @@ -54,6 +55,7 @@ class PluginInfo{ slotInfos = _i.slotInfos; keys = _i.keys; widget = _i.widget; + optionsWidget = _i.optionsWidget; } /// Pointer to the loaded plugin (Already casted when loading it) @@ -85,6 +87,9 @@ class PluginInfo{ /// Pointer to plugins toolbar widget (if available) QDockWidget* widget; + + /// Pointer to plugins options widget (if available) + QWidget* optionsWidget; }; #endif //PLUGININFO_HH diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index 3a821d06..709c622f 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -57,6 +57,7 @@ #include "OpenFlipper/BasePlugin/MouseInterface.hh" #include "OpenFlipper/BasePlugin/PickingInterface.hh" #include "OpenFlipper/BasePlugin/ToolboxInterface.hh" +#include "OpenFlipper/BasePlugin/OptionsInterface.hh" #include "OpenFlipper/BasePlugin/ToolbarInterface.hh" #include "OpenFlipper/BasePlugin/TextureInterface.hh" #include "OpenFlipper/BasePlugin/MenuInterface.hh" @@ -618,7 +619,22 @@ void Core::loadPlugin(QString filename, bool silent){ } - //Check if the plugin supports Toolbox-Interface + //Check if the plugin supports Options-Interface + OptionsInterface* optionsPlugin = qobject_cast< OptionsInterface * >(plugin); + if ( optionsPlugin && OpenFlipper::Options::gui() ) { + supported = supported + "Options "; + + QWidget* widget = 0; + if ( optionsPlugin->initializeOptionsWidget( widget ) ) { + info.optionsWidget = widget; + + if ( checkSlot(plugin,"applyOptions()") ) + connect(coreWidget_ , SIGNAL( applyOptions() ), + plugin , SLOT( applyOptions() ),Qt::DirectConnection); + } + } + + //Check if the plugin supports Toolbar-Interface ToolbarInterface* toolbarPlugin = qobject_cast< ToolbarInterface * >(plugin); if ( toolbarPlugin && OpenFlipper::Options::gui() ) { supported = supported + "Toolbars "; diff --git a/widgets/coreWidget/keyHandling.cc b/widgets/coreWidget/keyHandling.cc index 269b3bc9..7ef07a2b 100644 --- a/widgets/coreWidget/keyHandling.cc +++ b/widgets/coreWidget/keyHandling.cc @@ -212,6 +212,7 @@ void CoreWidget::slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, Q replace = true; oldCombi = (*it).first; oldTarget = (*it).second; +std::cerr << "replacing \n"; continue; } diff --git a/widgets/optionsWidget/optionsWidget.cc b/widgets/optionsWidget/optionsWidget.cc index 141034d4..cd7a7f1a 100644 --- a/widgets/optionsWidget/optionsWidget.cc +++ b/widgets/optionsWidget/optionsWidget.cc @@ -50,6 +50,7 @@ OptionsWidget::OptionsWidget(std::vector& _plugins, std::vector& _plugins, std::vectorsetLayout( pluginOptionsLayout ); + http = new QHttp(this); // http specific connections @@ -131,6 +135,9 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) { color.fill( OpenFlipper::Options::defaultBackgroundColor() ); backgroundButton->setIcon( QIcon(color) ); + // plugin options + initPluginOptions(); + // updates updateUser->setText( OpenFlipper::Options::updateUsername() ); updatePass->setText( OpenFlipper::Options::updatePassword() ); @@ -291,6 +298,47 @@ void OptionsWidget::updateVersionsTable() { } +void OptionsWidget::initPluginOptions(){ + + pluginList->disconnect(); + + connect(pluginList, SIGNAL( currentTextChanged(const QString&) ), this, SLOT( slotShowPluginOptions(const QString&) ) ); + + //init list of plugins + pluginList->clear(); + + for ( uint i = 0 ; i < plugins_.size(); ++i ) + if (plugins_[i].optionsWidget != 0){ + + pluginList->addItem( plugins_[i].name ); + } + + if ( pluginList->count() > 0) + pluginList->setCurrentRow(0); +} + +void OptionsWidget::slotShowPluginOptions(const QString& _pluginName ){ + + //remove old children + for (int i = 0; i < pluginOptionsLayout->count(); ++i){ + QWidget* w = pluginOptionsLayout->itemAt(i)->widget(); + + if (w != 0) + w->setParent(0); + + pluginOptionsLayout->removeItem( pluginOptionsLayout->itemAt(i) ); + } + + //find the new optionsWidget + for ( uint i = 0 ; i < plugins_.size(); ++i ) + if (plugins_[i].optionsWidget != 0 && plugins_[i].name == _pluginName){ + + pluginOptionsLayout->addWidget( plugins_[i].optionsWidget ); + pluginOptionsLayout->addStretch(); + return; + } +} + void OptionsWidget::slotApply() { //general @@ -336,7 +384,10 @@ void OptionsWidget::slotApply() { emit applyOptions(); emit saveOptions(); +} +void OptionsWidget::slotOk(){ + slotApply(); hide(); } diff --git a/widgets/optionsWidget/optionsWidget.hh b/widgets/optionsWidget/optionsWidget.hh index bb259fc3..89c5ea68 100644 --- a/widgets/optionsWidget/optionsWidget.hh +++ b/widgets/optionsWidget/optionsWidget.hh @@ -61,7 +61,9 @@ signals: void addKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID); private slots: - /// Hide widget, Update Options and tell others about changed Options + /// call slotApply and hide widget + void slotOk(); + /// Update Options and tell others about changed Options void slotApply(); /// Only hide widget @@ -83,11 +85,18 @@ private slots: void updateShortcut(); + void slotShowPluginOptions(const QString& _pluginName ); + protected: void showEvent ( QShowEvent * event ); private: + // plugin Options + void initPluginOptions(); + + QVBoxLayout* pluginOptionsLayout; + //key-bindings std::vector& plugins_; std::vector& coreKeys_; diff --git a/widgets/optionsWidget/optionsWidget.ui b/widgets/optionsWidget/optionsWidget.ui index 1234f99f..fcb4e406 100644 --- a/widgets/optionsWidget/optionsWidget.ui +++ b/widgets/optionsWidget/optionsWidget.ui @@ -5,7 +5,7 @@ 0 0 - 472 + 541 763 @@ -382,6 +382,36 @@ You can select multiple modes at the same time. + + + Plugins + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + + + + Options + + + + + Key Bindings @@ -677,6 +707,13 @@ p, li { white-space: pre-wrap; } + + + + &Apply + + + @@ -684,23 +721,23 @@ p, li { white-space: pre-wrap; } - 40 - 20 + 188 + 23 - + - Apply + &Ok - Cancel + &Cancel -- GitLab