Commit f9faedb2 authored by Dirk Wilden's avatar Dirk Wilden

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
parent 9a968229
//=============================================================================
//
// 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 <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 3265 $
// $Author: wilden $
// $Date: 2008-09-30 18:08:19 +0200 (Tue, 30 Sep 2008) $
//
//=============================================================================
#ifndef OPTIONSINTERFACE_HH
#define OPTIONSINTERFACE_HH
#include <QtGui>
/**
* 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
......@@ -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
......@@ -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 ";
......
......@@ -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;
}
......
......@@ -50,6 +50,7 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
{
setupUi(this);
connect(okButton,SIGNAL(clicked()),this,SLOT(slotOk()));
connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));
......@@ -77,6 +78,9 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
}
pluginOptionsLayout = new QVBoxLayout;
pluginOptions->setLayout( 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();
}
......
......@@ -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<PluginInfo>& plugins_;
std::vector<KeyBinding>& coreKeys_;
......
......@@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<width>541</width>
<height>763</height>
</rect>
</property>
......@@ -382,6 +382,36 @@ You can select multiple modes at the same time.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>Plugins</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_11" >
<item>
<widget class="QListWidget" name="pluginList" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize" >
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="pluginOptions" >
<property name="title" >
<string>Options</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="key" >
<attribute name="title" >
<string>Key Bindings</string>
......@@ -677,6 +707,13 @@ p, li { white-space: pre-wrap; }
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QPushButton" name="applyButton" >
<property name="text" >
<string>&amp;Apply</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer" >
<property name="orientation" >
......@@ -684,23 +721,23 @@ p, li { white-space: pre-wrap; }
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
<width>188</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="applyButton" >
<widget class="QPushButton" name="okButton" >
<property name="text" >
<string>Apply</string>
<string>&amp;Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
<string>&amp;Cancel</string>
</property>
</widget>
</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