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

now the sidearea is not cleared everytime a toolbox is added, thus preventing...

now the sidearea is not cleared everytime a toolbox is added, thus preventing the loss of active states

refs #1015

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15472 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fda65e17
......@@ -69,36 +69,61 @@ SideArea::SideArea (QWidget *_parent) :
void SideArea::addItem (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;
}
}
SideElement *e = new SideElement (this, _w, _name, _icon);
layout_->addWidget (e);
items_.push_back (e);
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)
{
SideElement *e = new SideElement (this, _w, _name);
layout_->addWidget (e);
items_.push_back (e);
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);
layout_->addWidget (e);
items_.push_back (e);
}
}
//-----------------------------------------------------------------------------
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)->name() == _name)
break;
}
if(it != items_.end()) {
layout_->removeWidget(*it);
layout_->insertWidget(_position, (*it));
......@@ -134,7 +159,7 @@ void SideArea::expandAll()
}
//-----------------------------------------------------------------------------
void SideArea::saveState (QSettings &_settings)
{
_settings.beginGroup ("SideArea");
......@@ -164,9 +189,11 @@ 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;
}
}
//=============================================================================
//=============================================================================
......@@ -93,7 +93,7 @@ class SideArea : public QWidget {
/// clears the whole tool widget area
void clear ();
//expand all elements
void expandAll();
......@@ -105,10 +105,10 @@ class SideArea : public QWidget {
/// set the active state of given element
void setElementActive(QString _name, bool _active);
/// Move a toolbox widget to a given position
void moveItemToPosition(const QString& _name, int _position);
/// Get number of widgets
int getNumberOfWidgets() const;
......
......@@ -96,16 +96,16 @@ SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name, QIcon*
hl->addStretch (1);
hl->addWidget (detachButton_);
QIcon detachIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"button-detach.png");
detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"button-detach_over.png"), QIcon::Active);
detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"button-detach_over.png"), QIcon::Selected);
detachAction_ = new QAction ( detachIcon, "", this);
detachAction_->setToolTip( tr("Show as separate window") );
detachAction_->setCheckable (true);
detachButton_->setDefaultAction (detachAction_);
connect (detachAction_, SIGNAL (triggered (bool)), this, SLOT (detachPressed (bool)));
tra->setLayout (hl);
......@@ -281,7 +281,13 @@ const QString& SideElement::name(){
}
//-----------------------------------------------------------------------------
QWidget const * SideElement::widget() {
return widget_;
}
//-----------------------------------------------------------------------------
SideElement::TopArea::TopArea (SideElement *_e) :
e_ (_e)
{
......
......@@ -94,16 +94,19 @@ class SideElement : public QWidget
/// Set the element as active
void setActive(bool _active);
/// saves the current state
void saveState (QSettings &_settings);
/// restores the state
void restoreState (QSettings &_settings);
/// return the name
const QString& name();
/// returns the pointer to the plugin tool widget
QWidget const * widget();
private:
/// Clickable area inside of the side element.
......@@ -119,7 +122,7 @@ class SideElement : public QWidget
/// Called on mouse press
void labelPress ();
private slots:
/// Called if the detach button was pressed
......@@ -155,7 +158,7 @@ class SideElement : public QWidget
// detach button & action
QToolButton *detachButton_;
QAction *detachAction_;
// dialog for detached widget
QDialog *dialog_;
};
......
......@@ -111,7 +111,7 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi
vm->visibleToolbars = QString("Main Toolbar;Viewer Toolbar").split(";");
vm->visibleContextMenus = QString("ALL_THAT_EXIST").split(" ");
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -157,7 +157,7 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
vm->icon = "Unknown.png";
vm->visibleContextMenus = QString("ALL_THAT_EXIST").split(" ");
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -173,15 +173,15 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
} else {
vm = viewModes_[id];
}
// Always add the viewer Toolbar
if ( ! _usedToolbars.contains("Viewer Toolbar") )
_usedToolbars.prepend("Viewer Toolbar");
// Always add the main Toolbar
if ( ! _usedToolbars.contains("Main Toolbar") )
_usedToolbars.prepend("Main Toolbar");
vm->visibleToolbars = _usedToolbars;
initViewModes();
......@@ -211,7 +211,7 @@ void CoreWidget::slotAddViewModeContextMenus(QString _mode, bool _custom, QStrin
vm->icon = "Unknown.png";
vm->visibleToolbars = QString("Main Toolbar;Viewer Toolbar").split(";");
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -228,7 +228,7 @@ void CoreWidget::slotAddViewModeContextMenus(QString _mode, bool _custom, QStrin
} else {
vm = viewModes_[id];
}
vm->visibleContextMenus = _usedContextMenus;
initViewModes();
......@@ -359,18 +359,22 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
_toolbars = viewModes_[i]->visibleToolbars;
_contextmenus = viewModes_[i]->visibleContextMenus;
}
// Remove all toolbox entries
toolBox_->clear ();
// Remove all toolbox entries if the view has changed
if (_mode != OpenFlipper::Options::currentViewMode())
toolBox_->clear();
//find all widgets that should be visible
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 )
if (_toolboxWidgets[i] == plugins_[p].toolboxWidgets[j].first ) {
toolBox_->addItem (plugins_[p].toolboxWidgets[j].second, plugins_[p].toolboxWidgets[j].first, plugins_[p].toolboxIcons[j] );
}
}
if (_expandAll)
toolBox_->expandAll();
......@@ -402,7 +406,7 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
}
void CoreWidget::moveToolBoxToTop(QString _name) {
toolBox_->moveItemToPosition(_name, 0);
}
......
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