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 @@
#include "SideArea.hh"
#include "SideElement.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#include <iostream>
//== IMPLEMENTATION ==========================================================
SideArea::SideArea (QWidget *_parent) :
QWidget (_parent)
QWidget (_parent),
lastPos_(0)
{
layout_ = new QVBoxLayout;
......@@ -67,51 +69,50 @@ 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;
QVector<SideElement*>::iterator it = items_.begin();
for(; it != items_.end(); ++it) {
if ((*it)->widget() == _w) {
contains = true;
break;
}
}
if (contains) {
return;
} else {
SideElement *e = new SideElement (this, _w, _name, _icon);
layout_->addWidget (e);
items_.push_back (e);
}
plugins_.push_back(_plugin);
itemNames_.push_back(_name);
}
//-----------------------------------------------------------------------------
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);
layout_->addWidget (e);
items_.push_back (e);
plugins_.push_back(_plugin);
itemNames_.push_back(_name);
}
//-----------------------------------------------------------------------------
void SideArea::moveItemToPosition(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();
for(; it != items_.end(); ++it) {
if ((*it)->widget() == _w) {
contains = true;
if( (*it)->name() == _name )
break;
}
}
if (contains) {
return;
} else {
SideElement *e = new SideElement (this, _w, _name);
layout_->addWidget (e);
items_.push_back (e);
if(it != items_.end()) {
layout_->removeWidget(*it);
layout_->insertWidget(_position, (*it));
}
}
//-----------------------------------------------------------------------------
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())
......@@ -119,14 +120,20 @@ void SideArea::moveItemToPosition(const QString& _name, int _position) {
// Search item
QVector<SideElement*>::iterator it = items_.begin();
for(; it != items_.end(); ++it) {
if((*it)->name() == _name)
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();
}
}
......@@ -146,6 +153,9 @@ void SideArea::clear ()
delete e;
}
items_.clear ();
plugins_.clear();
itemNames_.clear();
lastPos_ = 0;
}
//-----------------------------------------------------------------------------
......@@ -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 {
SideArea (QWidget *_parent = 0);
/** Adds a plugin tool widget
\param _plugin plugin corresponding to the widget
\param _w Plugin widget
\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
\param _plugin plugin corresponding to the widget
\param _w Plugin widget
\param _name Plugin name
\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
void clear ();
......@@ -109,13 +111,31 @@ class SideArea : public QWidget {
/// Move a toolbox widget to a given 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
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:
// elements
QVector<SideElement *> items_;
// plugins in side area
QList<const QObject *> plugins_;
// item names
QStringList itemNames_;
// main layout
QVBoxLayout *layout_;
};
......
......@@ -57,6 +57,7 @@
#include <OpenFlipper/common/GlobalOptions.hh>
#include "SideElement.hh"
#include <iostream>
//== IMPLEMENTATION ==========================================================
......@@ -243,7 +244,7 @@ void SideElement::dialogClosed ()
void SideElement::saveState (QSettings &_settings)
{
_settings.beginGroup (name_);
_settings.setValue ("Active", active_);
_settings.setValue ("Active", active());
_settings.setValue ("Detached", (dialog_ != 0));
_settings.setValue ("DialogGeometry", (dialog_) ? dialog_->saveGeometry (): QByteArray());
_settings.endGroup ();
......@@ -282,6 +283,12 @@ const QString& SideElement::name(){
//-----------------------------------------------------------------------------
bool SideElement::active(){
return widget_->isVisible();
}
//-----------------------------------------------------------------------------
QWidget const * SideElement::widget() {
return widget_;
}
......
......@@ -104,6 +104,9 @@ class SideElement : public QWidget
/// return the name
const QString& name();
/// returns if the SideElement is active
bool active();
/// returns the pointer to the plugin tool widget
QWidget const * widget();
......
......@@ -366,11 +366,52 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
toolBox_->clear();
//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 j = 0 ; j < plugins_[p].toolboxWidgets.size(); ++j )
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);
}
}
}
}
}
}
......
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