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