Commit f06a7cda authored by Isaak Lim's avatar Isaak Lim
Browse files

- toolboxes should be sorted according to the given order now

- state of toolboxes added via script is restored

TODO: 
- fix flickering? 
- remember state of toolboxes when changing views correctly

refs #1015

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15475 383ad7c9-94d9-4d36-a494-682f7c89f535
parent de667b3e
...@@ -49,10 +49,12 @@ ...@@ -49,10 +49,12 @@
#include "SideArea.hh" #include "SideArea.hh"
#include "SideElement.hh" #include "SideElement.hh"
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <iostream>
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
SideArea::SideArea (QWidget *_parent) : SideArea::SideArea (QWidget *_parent) :
QWidget (_parent) QWidget (_parent),
lastPos_(0)
{ {
layout_ = new QVBoxLayout; layout_ = new QVBoxLayout;
...@@ -67,46 +69,24 @@ SideArea::SideArea (QWidget *_parent) : ...@@ -67,46 +69,24 @@ SideArea::SideArea (QWidget *_parent) :
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SideArea::addItem (QWidget *_w, QString _name, QIcon *_icon) void SideArea::addItem (QObject const * const _plugin, QWidget *_w, QString _name, QIcon *_icon)
{ {
bool contains = false; SideElement *e = new SideElement (this, _w, _name, _icon);
QVector<SideElement*>::iterator it = items_.begin(); layout_->addWidget (e);
for(; it != items_.end(); ++it) { items_.push_back (e);
if ((*it)->widget() == _w) { plugins_.push_back(_plugin);
contains = true; itemNames_.push_back(_name);
break;
}
}
if (contains) {
return;
} else {
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 (QObject const * const _plugin, QWidget *_w, QString _name)
{ {
bool contains = false; SideElement *e = new SideElement (this, _w, _name);
QVector<SideElement*>::iterator it = items_.begin(); layout_->addWidget (e);
for(; it != items_.end(); ++it) { items_.push_back (e);
if ((*it)->widget() == _w) { plugins_.push_back(_plugin);
contains = true; itemNames_.push_back(_name);
break;
}
}
if (contains) {
return;
} else {
SideElement *e = new SideElement (this, _w, _name);
layout_->addWidget (e);
items_.push_back (e);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -120,7 +100,7 @@ void SideArea::moveItemToPosition(const QString& _name, int _position) { ...@@ -120,7 +100,7 @@ void SideArea::moveItemToPosition(const QString& _name, int _position) {
// Search item // Search item
QVector<SideElement*>::iterator it = items_.begin(); QVector<SideElement*>::iterator it = items_.begin();
for(; it != items_.end(); ++it) { for(; it != items_.end(); ++it) {
if((*it)->name() == _name) if( (*it)->name() == _name )
break; break;
} }
...@@ -132,6 +112,33 @@ void SideArea::moveItemToPosition(const QString& _name, int _position) { ...@@ -132,6 +112,33 @@ void SideArea::moveItemToPosition(const QString& _name, int _position) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SideArea::moveItemToPosition(QObject const * const _plugin, const QString& _name, int _position) {
// Position is in valid range
if(_position < 0 || _position >= items_.size())
return;
// Search item
QVector<SideElement*>::iterator it = items_.begin();
int i = 0;
for(; it != items_.end(); ++it, ++i) {
if( ((*it)->name() == _name)
&& (plugins_[i] == _plugin) )
break;
}
bool active = (*it)->active();
if(it != items_.end()) {
layout_->removeWidget(*it);
layout_->insertWidget(_position, (*it));
if (active)
(*it)->show();
}
}
//-----------------------------------------------------------------------------
int SideArea::getNumberOfWidgets() const { int SideArea::getNumberOfWidgets() const {
return items_.size(); return items_.size();
} }
...@@ -146,6 +153,9 @@ void SideArea::clear () ...@@ -146,6 +153,9 @@ void SideArea::clear ()
delete e; delete e;
} }
items_.clear (); items_.clear ();
plugins_.clear();
itemNames_.clear();
lastPos_ = 0;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -194,6 +204,18 @@ void SideArea::setElementActive(QString _name, bool _active) ...@@ -194,6 +204,18 @@ void SideArea::setElementActive(QString _name, bool _active)
} }
} }
//-----------------------------------------------------------------------------
const QList<const QObject *>& SideArea::plugins() {
return plugins_;
}
//-----------------------------------------------------------------------------
const QStringList& SideArea::names() {
return itemNames_;
}
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
...@@ -79,17 +79,19 @@ class SideArea : public QWidget { ...@@ -79,17 +79,19 @@ class SideArea : public QWidget {
SideArea (QWidget *_parent = 0); SideArea (QWidget *_parent = 0);
/** Adds a plugin tool widget /** Adds a plugin tool widget
\param _plugin plugin corresponding to the widget
\param _w Plugin widget \param _w Plugin widget
\param _name Plugin name \param _name Plugin name
*/ */
void addItem (QWidget *_w, QString _name); void addItem (QObject const * const _plugin, QWidget *_w, QString _name);
/** Adds a plugin tool widget /** Adds a plugin tool widget
\param _plugin plugin corresponding to the widget
\param _w Plugin widget \param _w Plugin widget
\param _name Plugin name \param _name Plugin name
\param _icon an icon \param _icon an icon
*/ */
void addItem (QWidget *_w, QString _name, QIcon* _icon); void addItem (QObject const * const _plugin, QWidget *_w, QString _name, QIcon* _icon);
/// clears the whole tool widget area /// clears the whole tool widget area
void clear (); void clear ();
...@@ -109,13 +111,31 @@ class SideArea : public QWidget { ...@@ -109,13 +111,31 @@ class SideArea : public QWidget {
/// Move a toolbox widget to a given position /// Move a toolbox widget to a given position
void moveItemToPosition(const QString& _name, int _position); void moveItemToPosition(const QString& _name, int _position);
/// Move a toolbox widget to a given position
void moveItemToPosition(QObject const * const _plugin, const QString& _name, int _position);
/// Get number of widgets /// Get number of widgets
int getNumberOfWidgets() const; int getNumberOfWidgets() const;
/// Get plugins in side area
const QList<const QObject *>& plugins();
/// Get item names
const QStringList& names();
// position of the last added item
int lastPos_;
private: private:
// elements // elements
QVector<SideElement *> items_; QVector<SideElement *> items_;
// plugins in side area
QList<const QObject *> plugins_;
// item names
QStringList itemNames_;
// main layout // main layout
QVBoxLayout *layout_; QVBoxLayout *layout_;
}; };
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include "SideElement.hh" #include "SideElement.hh"
#include <iostream>
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
...@@ -243,7 +244,7 @@ void SideElement::dialogClosed () ...@@ -243,7 +244,7 @@ void SideElement::dialogClosed ()
void SideElement::saveState (QSettings &_settings) void SideElement::saveState (QSettings &_settings)
{ {
_settings.beginGroup (name_); _settings.beginGroup (name_);
_settings.setValue ("Active", active_); _settings.setValue ("Active", active());
_settings.setValue ("Detached", (dialog_ != 0)); _settings.setValue ("Detached", (dialog_ != 0));
_settings.setValue ("DialogGeometry", (dialog_) ? dialog_->saveGeometry (): QByteArray()); _settings.setValue ("DialogGeometry", (dialog_) ? dialog_->saveGeometry (): QByteArray());
_settings.endGroup (); _settings.endGroup ();
...@@ -282,6 +283,12 @@ const QString& SideElement::name(){ ...@@ -282,6 +283,12 @@ const QString& SideElement::name(){
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool SideElement::active(){
return widget_->isVisible();
}
//-----------------------------------------------------------------------------
QWidget const * SideElement::widget() { QWidget const * SideElement::widget() {
return widget_; return widget_;
} }
......
...@@ -104,6 +104,9 @@ class SideElement : public QWidget ...@@ -104,6 +104,9 @@ class SideElement : public QWidget
/// return the name /// return the name
const QString& name(); const QString& name();
/// returns if the SideElement is active
bool active();
/// returns the pointer to the plugin tool widget /// returns the pointer to the plugin tool widget
QWidget const * widget(); QWidget const * widget();
......
...@@ -366,13 +366,54 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr ...@@ -366,13 +366,54 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
toolBox_->clear(); toolBox_->clear();
//find all widgets that should be visible //find all widgets that should be visible
for (int i=0; i < _toolboxWidgets.size(); i++) for (int i=0; i < _toolboxWidgets.size(); i++) {
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, plugins_[p].toolboxIcons[j] );
bool skip = false;
if (toolBox_->plugins().contains(plugins_[p].plugin)) {
// account for the case, where a plugin can have several
// toolboxes, for example 'Scripting'
if (toolBox_->names().contains(_toolboxWidgets[i]))
skip = true;
}
// only add items that have not been added yet
if (!skip) {
toolBox_->addItem (plugins_[p].plugin, plugins_[p].toolboxWidgets[j].second, plugins_[p].toolboxWidgets[j].first, plugins_[p].toolboxIcons[j] );
// move item to the correct position
if (i < toolBox_->lastPos_) {
toolBox_->moveItemToPosition(plugins_[p].plugin, _toolboxWidgets[i], i);
} else
toolBox_->lastPos_ = i;
// check if we have to restore the state
// of toolboxes added via scripts
if (plugins_[p].name == "Scripting") {
QFile statesFile(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "WindowStates.dat");
if (statesFile.exists() ) {
QSettings windowStates(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "WindowStates.dat", QSettings::IniFormat);
windowStates.beginGroup ("Core");
windowStates.beginGroup("SideArea");
windowStates.beginGroup(_toolboxWidgets[i]);
bool active = windowStates.value ("Active", false).toBool();
windowStates.endGroup();
windowStates.endGroup();
windowStates.endGroup();
toolBox_->setElementActive(_toolboxWidgets[i], active);
}
}
}
} }
} }
}
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