Commit 1a8febc8 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

upgraded toolboxes

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10540 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fac59fd9
...@@ -83,13 +83,18 @@ class ToolboxInterface { ...@@ -83,13 +83,18 @@ class ToolboxInterface {
virtual ~ToolboxInterface() {}; virtual ~ToolboxInterface() {};
signals : signals :
/** \brief Add a toolbox widget to the gui with the given name /** \brief Add a toolbox widget to the gui with the given name
* *
* This signal adds a toolbox widget to the toolbar on the right. * This signal adds a toolbox widget to the toolbar on the right.
*/ */
virtual void addToolbox( QString /* _name */ , QWidget* /*_widget*/ ) {}; virtual void addToolbox( QString /* _name */ , QWidget* /*_widget*/ ) {};
/** \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*/, QIcon* /*_icon*/) {};
}; };
Q_DECLARE_INTERFACE(ToolboxInterface,"OpenFlipper.ToolboxInterface/1.1") Q_DECLARE_INTERFACE(ToolboxInterface,"OpenFlipper.ToolboxInterface/1.1")
......
...@@ -1446,6 +1446,10 @@ void Core::setDescriptions(){ ...@@ -1446,6 +1446,10 @@ void Core::setDescriptions(){
QString(tr("Toolbox Entry name,Widget")).split(","), QString(tr("Toolbox Entry name,Widget")).split(","),
QString(tr("Name of the new widget in the toolbox,Pointer to the new widget")).split(",")); QString(tr("Name of the new widget in the toolbox,Pointer to the new widget")).split(","));
emit setSlotDescription("addToolbox(QString,QWidget*,QIcon*)", tr("Add a widget as a toolbox"),
QString(tr("Toolbox Entry name,Widget,Icon")).split(","),
QString(tr("Name of the new widget in the toolbox,Pointer to the new widget,Pointer to icon")).split(","));
emit setSlotDescription("addViewModeToolboxes(QString,QString)", tr("Set toolboxes for a viewmode (This automatically adds the view mode if it does not exist)"), emit setSlotDescription("addViewModeToolboxes(QString,QString)", tr("Set toolboxes for a viewmode (This automatically adds the view mode if it does not exist)"),
QString(tr("Name,Toolbox List")).split(","), QString(tr("Name,Toolbox List")).split(","),
QString(tr("Name of the Viewmode,seperated list of toolboxes visible in this viewmode")).split(",")); QString(tr("Name of the Viewmode,seperated list of toolboxes visible in this viewmode")).split(","));
......
...@@ -566,6 +566,12 @@ public slots: ...@@ -566,6 +566,12 @@ public slots:
*/ */
void setToolBoxSide(QString _side); void setToolBoxSide(QString _side);
/** \brief Scripting function to set the side of the main window on which the toolbox should be displayed
@param _side The desired side (either "left" or "right")
*/
void setToolBoxActive(QString _toolBoxName, bool _active);
/** @} */ /** @} */
//=========================================================================== //===========================================================================
...@@ -765,6 +771,9 @@ private slots: ...@@ -765,6 +771,9 @@ private slots:
/// Add a Toolbox from a plugin or from scripting /// Add a Toolbox from a plugin or from scripting
void addToolbox(QString _name ,QWidget* _widget); void addToolbox(QString _name ,QWidget* _widget);
/// Add a Toolbox from a plugin or from scripting (with icon)
void addToolbox(QString _name ,QWidget* _widget, QIcon* _icon);
private : private :
//=========================================================================== //===========================================================================
......
...@@ -82,6 +82,7 @@ class PluginInfo{ ...@@ -82,6 +82,7 @@ class PluginInfo{
slotInfos.clear(); slotInfos.clear();
keys.clear(); keys.clear();
toolboxWidgets.clear(); toolboxWidgets.clear();
toolboxIcons.clear();
toolbars.clear(); toolbars.clear();
contextMenus.clear(); contextMenus.clear();
optionsWidget = 0; optionsWidget = 0;
...@@ -100,6 +101,7 @@ class PluginInfo{ ...@@ -100,6 +101,7 @@ class PluginInfo{
slotInfos = _i.slotInfos; slotInfos = _i.slotInfos;
keys = _i.keys; keys = _i.keys;
toolboxWidgets = _i.toolboxWidgets; toolboxWidgets = _i.toolboxWidgets;
toolboxIcons = _i.toolboxIcons;
toolbars = _i.toolbars; toolbars = _i.toolbars;
contextMenus = _i.contextMenus; contextMenus = _i.contextMenus;
optionsWidget = _i.optionsWidget; optionsWidget = _i.optionsWidget;
...@@ -134,6 +136,9 @@ class PluginInfo{ ...@@ -134,6 +136,9 @@ class PluginInfo{
/// Pointer to plugins toolbox widget (if available) /// Pointer to plugins toolbox widget (if available)
std::vector< std::pair< QString , QWidget* > > toolboxWidgets; std::vector< std::pair< QString , QWidget* > > toolboxWidgets;
/// Pointer to plugins toolbox widget icons (if available)
std::vector< QIcon* > toolboxIcons;
/// Pointer to plugins toolbars (if available) /// Pointer to plugins toolbars (if available)
std::vector< std::pair< QString , QToolBar* > > toolbars; std::vector< std::pair< QString , QToolBar* > > toolbars;
......
...@@ -488,6 +488,9 @@ void Core::unloadPlugin(QString name){ ...@@ -488,6 +488,9 @@ void Core::unloadPlugin(QString name){
if (plugins[i].toolboxWidgets[j].second ){ if (plugins[i].toolboxWidgets[j].second ){
plugins[i].toolboxWidgets[j].second->setVisible(false); plugins[i].toolboxWidgets[j].second->setVisible(false);
delete plugins[i].toolboxWidgets[j].second; delete plugins[i].toolboxWidgets[j].second;
if( plugins[i].toolboxIcons[j] != 0 )
delete plugins[i].toolboxIcons[j];
} }
plugins.erase(plugins.begin() + i); plugins.erase(plugins.begin() + i);
...@@ -826,8 +829,9 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO ...@@ -826,8 +829,9 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO
connect(plugin, SIGNAL( addToolbox(QString,QWidget*) ), connect(plugin, SIGNAL( addToolbox(QString,QWidget*) ),
this, SLOT( addToolbox(QString,QWidget*) ),Qt::DirectConnection ); this, SLOT( addToolbox(QString,QWidget*) ),Qt::DirectConnection );
if ( checkSignal(plugin, "addToolbox(QString,QWidget*,QIcon*)"))
connect(plugin, SIGNAL( addToolbox(QString,QWidget*,QIcon*) ),
this, SLOT( addToolbox(QString,QWidget*,QIcon*) ),Qt::DirectConnection );
} }
//Check if the plugin supports ViewMode-Interface //Check if the plugin supports ViewMode-Interface
......
...@@ -219,6 +219,7 @@ void Core::addToolbox(QString _name ,QWidget* _widget) { ...@@ -219,6 +219,7 @@ void Core::addToolbox(QString _name ,QWidget* _widget) {
} }
plugins[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) ); plugins[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
plugins[id].toolboxIcons.push_back( 0 );
// add widget name to viewMode 'all' // add widget name to viewMode 'all'
if ( !viewModes_[0]->visibleToolboxes.contains(_name) ){ if ( !viewModes_[0]->visibleToolboxes.contains(_name) ){
...@@ -229,6 +230,54 @@ void Core::addToolbox(QString _name ,QWidget* _widget) { ...@@ -229,6 +230,54 @@ void Core::addToolbox(QString _name ,QWidget* _widget) {
setViewMode( OpenFlipper::Options::currentViewMode() ); setViewMode( OpenFlipper::Options::currentViewMode() );
} }
//-----------------------------------------------------------------------------
void Core::addToolbox(QString _name ,QWidget* _widget, QIcon* _icon) {
int id = -1;
// Find the plugin which added this Toolbox
for ( uint i = 0 ; i < plugins.size(); ++i ) {
if ( plugins[i].plugin == sender() ) {
id = i;
break;
}
}
// Find the scripting plugin because we assign this toolBox to it as we did not find the original sender
if ( id == -1 ) {
for ( uint i = 0 ; i < plugins.size(); ++i ) {
if ( plugins[i].name == "Scripting" ) {
id = i;
break;
}
}
if ( id == -1 ) {
std::cerr << "Unknown sender plugin when adding Toolbox!" << std::endl;
return;
}
}
plugins[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
plugins[id].toolboxIcons.push_back( _icon );
// add widget name to viewMode 'all'
if ( !viewModes_[0]->visibleToolboxes.contains(_name) ){
viewModes_[0]->visibleToolboxes << _name;
viewModes_[0]->visibleToolboxes.sort();
}
setViewMode( OpenFlipper::Options::currentViewMode() );
}
void Core::setToolBoxActive(QString _toolBoxName, bool _active)
{
if ( OpenFlipper::Options::gui() ){
coreWidget_->toolBox_->setElementActive(_toolBoxName,_active);
}
}
//============================================================================= //=============================================================================
//== Script Special Functions ================================================= //== Script Special Functions =================================================
//============================================================================= //=============================================================================
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#include "SideArea.hh" #include "SideArea.hh"
#include "SideElement.hh" #include "SideElement.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
SideArea::SideArea (QWidget *_parent) : SideArea::SideArea (QWidget *_parent) :
...@@ -67,6 +67,16 @@ SideArea::SideArea (QWidget *_parent) : ...@@ -67,6 +67,16 @@ SideArea::SideArea (QWidget *_parent) :
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SideArea::addItem (QWidget *_w, QString _name, QIcon *_icon)
{
SideElement *e = new SideElement (this, _w, _name, _icon);
layout_->addWidget (e);
items_.push_back (e);
}
//-----------------------------------------------------------------------------
void SideArea::addItem (QWidget *_w, QString _name) void SideArea::addItem (QWidget *_w, QString _name)
{ {
SideElement *e = new SideElement (this, _w, _name); SideElement *e = new SideElement (this, _w, _name);
...@@ -109,6 +119,7 @@ void SideArea::saveState (QSettings &_settings) ...@@ -109,6 +119,7 @@ void SideArea::saveState (QSettings &_settings)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SideArea::restoreState (QSettings &_settings) void SideArea::restoreState (QSettings &_settings)
{ {
_settings.beginGroup ("SideArea"); _settings.beginGroup ("SideArea");
...@@ -119,5 +130,16 @@ void SideArea::restoreState (QSettings &_settings) ...@@ -119,5 +130,16 @@ void SideArea::restoreState (QSettings &_settings)
_settings.endGroup (); _settings.endGroup ();
} }
//-----------------------------------------------------------------------------
void SideArea::setElementActive(QString _name, bool _active)
{
for (int i=0; i < items_.count(); i++)
if ( items_[i]->name() == _name ){
items_[i]->setActive(_active);
return;
}
}
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
//== INCLUDES ================================================================= //== INCLUDES =================================================================
#include <QIcon>
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include <QSettings> #include <QSettings>
...@@ -83,6 +84,13 @@ class SideArea : public QWidget { ...@@ -83,6 +84,13 @@ class SideArea : public QWidget {
*/ */
void addItem (QWidget *_w, QString _name); void addItem (QWidget *_w, QString _name);
/** Adds a plugin tool widget
\param _w Plugin widget
\param _name Plugin name
\param _icon an icon
*/
void addItem (QWidget *_w, QString _name, QIcon* _icon);
/// clears the whole tool widget area /// clears the whole tool widget area
void clear (); void clear ();
...@@ -95,6 +103,9 @@ class SideArea : public QWidget { ...@@ -95,6 +103,9 @@ class SideArea : public QWidget {
/// restores the state /// restores the state
void restoreState (QSettings &_settings); void restoreState (QSettings &_settings);
/// set the active state of given element
void setElementActive(QString _name, bool _active);
private: private:
// elements // elements
QVector<SideElement *> items_; QVector<SideElement *> items_;
......
...@@ -60,10 +60,11 @@ ...@@ -60,10 +60,11 @@
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name) : SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name, QIcon* _icon) :
parent_ (_parent), parent_ (_parent),
widget_ (_w), widget_ (_w),
name_ (_name), name_ (_name),
icon_ (_icon),
active_ (0), active_ (0),
dialog_ (0) dialog_ (0)
{ {
...@@ -77,8 +78,20 @@ SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name) : ...@@ -77,8 +78,20 @@ SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name) :
label_ = new QLabel (_name); label_ = new QLabel (_name);
label_->setFont (font); label_->setFont (font);
iconHolder_ = new QLabel ();
if (icon_ != 0)
iconHolder_->setPixmap( icon_->pixmap(22,22) );
else{
QPixmap pic(QSize(22,22));
pic.fill( QColor(0,0,0,0) );
iconHolder_->setPixmap( pic );
}
detachButton_ = new QToolButton (); detachButton_ = new QToolButton ();
detachButton_->setAutoRaise(true); detachButton_->setAutoRaise(true);
hl->addWidget (iconHolder_);
hl->addWidget (label_); hl->addWidget (label_);
hl->addStretch (1); hl->addStretch (1);
hl->addWidget (detachButton_); hl->addWidget (detachButton_);
...@@ -263,6 +276,12 @@ void SideElement::restoreState (QSettings &_settings) ...@@ -263,6 +276,12 @@ void SideElement::restoreState (QSettings &_settings)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const QString& SideElement::name(){
return name_;
}
//-----------------------------------------------------------------------------
SideElement::TopArea::TopArea (SideElement *_e) : SideElement::TopArea::TopArea (SideElement *_e) :
e_ (_e) e_ (_e)
{ {
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
//== FORWARDDECLARATIONS ====================================================== //== FORWARDDECLARATIONS ======================================================
class QIcon;
class QLabel; class QLabel;
class QToolButton; class QToolButton;
class QAction; class QAction;
...@@ -84,7 +85,7 @@ class SideElement : public QWidget ...@@ -84,7 +85,7 @@ class SideElement : public QWidget
\param _w Plugin tool widget \param _w Plugin tool widget
\param _name Plugin name \param _name Plugin name
*/ */
SideElement (SideArea *_parent, QWidget *_w, QString _name); SideElement (SideArea *_parent, QWidget *_w, QString _name, QIcon* _icon = 0);
/// Destructor /// Destructor
~SideElement (); ~SideElement ();
...@@ -97,6 +98,9 @@ class SideElement : public QWidget ...@@ -97,6 +98,9 @@ class SideElement : public QWidget
/// restores the state /// restores the state
void restoreState (QSettings &_settings); void restoreState (QSettings &_settings);
/// return the name
const QString& name();
private: private:
...@@ -133,6 +137,9 @@ class SideElement : public QWidget ...@@ -133,6 +137,9 @@ class SideElement : public QWidget
// plugin name // plugin name
QString name_; QString name_;
// Icon
QIcon* icon_;
// main layout // main layout
QVBoxLayout *mainLayout_; QVBoxLayout *mainLayout_;
...@@ -141,6 +148,7 @@ class SideElement : public QWidget ...@@ -141,6 +148,7 @@ class SideElement : public QWidget
// label that display the plugin name // label that display the plugin name
QLabel *label_; QLabel *label_;
QLabel *iconHolder_;
// detach button & action // detach button & action
QToolButton *detachButton_; QToolButton *detachButton_;
......
...@@ -368,7 +368,7 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr ...@@ -368,7 +368,7 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
for (uint p=0; p < plugins_.size(); p++){ for (uint p=0; p < plugins_.size(); p++){
for ( uint j = 0 ; j < plugins_[p].toolboxWidgets.size(); ++j ) for ( uint j = 0 ; j < plugins_[p].toolboxWidgets.size(); ++j )
if (_toolboxWidgets[i] == plugins_[p].toolboxWidgets[j].first ) if (_toolboxWidgets[i] == plugins_[p].toolboxWidgets[j].first )
toolBox_->addItem (plugins_[p].toolboxWidgets[j].second, plugins_[p].toolboxWidgets[j].first); toolBox_->addItem (plugins_[p].toolboxWidgets[j].second, plugins_[p].toolboxWidgets[j].first, plugins_[p].toolboxIcons[j] );
} }
if (_expandAll) if (_expandAll)
......
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