Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SideArea.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 //== INCLUDES =================================================================
53 
54 #include <QVBoxLayout>
55 
56 #include "SideArea.hh"
57 #include "SideElement.hh"
58 //== IMPLEMENTATION ==========================================================
59 
60 SideArea::SideArea (QWidget *_parent) :
61  QWidget (_parent),
62  lastPos_(0)
63 {
64 
65  layout_ = new QVBoxLayout;
66  layout_->setSpacing (0);
67 
68  QVBoxLayout *l = new QVBoxLayout;
69  l->addLayout (layout_);
70  l->addStretch(1);
71  l->setContentsMargins(2, 2, 2, 2);
72 
73  setLayout (l);
74 }
75 
76 //-----------------------------------------------------------------------------
77 
78 void SideArea::addItem (QObject const * const _plugin, QWidget *_w, QString _name,
79  QIcon *_icon, QWidget *_headerAreaWidget)
80 {
81  SideElement *e = new SideElement (this, _w, _name, _icon, _headerAreaWidget);
82  layout_->addWidget (e);
83  items_.push_back (e);
84  plugins_.push_back(_plugin);
85  itemNames_.push_back(_name);
86 }
87 
88 //-----------------------------------------------------------------------------
89 
90 void SideArea::moveItemToPosition(const QString& _name, int _position) {
91 
92  // Position is in valid range
93  if(_position < 0 || _position >= items_.size())
94  return;
95 
96  // Search item
97  QVector<SideElement*>::iterator it = items_.begin();
98  for(; it != items_.end(); ++it) {
99  if( (*it)->name() == _name )
100  break;
101  }
102 
103  if(it != items_.end()) {
104  layout_->removeWidget(*it);
105  layout_->insertWidget(_position, (*it));
106  }
107 }
108 
109 //-----------------------------------------------------------------------------
110 
111 void SideArea::moveItemToPosition(QObject const * const _plugin, const QString& _name, int _position) {
112 
113  // Position is in valid range
114  if(_position < 0 || _position >= items_.size())
115  return;
116 
117  // Search item
118  QVector<SideElement*>::iterator it = items_.begin();
119  int i = 0;
120  for(; it != items_.end(); ++it, ++i) {
121  if( ((*it)->name() == _name)
122  && (plugins_[i] == _plugin) )
123  break;
124  }
125 
126  bool active = (*it)->active();
127 
128  if(it != items_.end()) {
129  layout_->removeWidget(*it);
130  layout_->insertWidget(_position, (*it));
131  if (active)
132  (*it)->show();
133  }
134 }
135 
136 //-----------------------------------------------------------------------------
137 
139  return items_.size();
140 }
141 
142 //-----------------------------------------------------------------------------
143 
145 {
146  foreach (SideElement *e, items_)
147  {
148  layout_->removeWidget (e);
149  delete e;
150  }
151  items_.clear ();
152  plugins_.clear();
153  itemNames_.clear();
154  lastPos_ = 0;
155 }
156 
157 //-----------------------------------------------------------------------------
158 
159 void SideArea::expandAll()
160 {
161  foreach (SideElement *e, items_)
162  {
163  e->setActive(true);
164  }
165 }
166 
167 void SideArea::expand(QWidget *sideElementWidget, bool expand)
168 {
169  foreach (SideElement *e, items_)
170  {
171  if (e->widget() == sideElementWidget)
172  e->setActive(expand);
173  }
174 }
175 
176 //-----------------------------------------------------------------------------
177 
178 void SideArea::saveState (QSettings &_settings)
179 {
180  _settings.beginGroup ("SideArea");
181  foreach (SideElement *e, items_)
182  {
183  e->saveState (_settings);
184  }
185  _settings.endGroup ();
186 }
187 
188 //-----------------------------------------------------------------------------
189 
190 void SideArea::restoreState (QSettings &_settings)
191 {
192  _settings.beginGroup ("SideArea");
193  foreach (SideElement *e, items_)
194  {
195  e->restoreState (_settings);
196  }
197  _settings.endGroup ();
198 }
199 
200 //-----------------------------------------------------------------------------
201 
202 void SideArea::saveViewModeState(const QString& _viewMode) {
203  foreach (SideElement *e, items_) {
204  sideElementState_[_viewMode + e->name()] = e->active();
205  }
206 }
207 
208 //-----------------------------------------------------------------------------
209 
210 void SideArea::restoreViewModeState(const QString& _viewMode) {
211  foreach (SideElement *e, items_) {
212  e->setActive(sideElementState_[_viewMode + e->name()]);
213  }
214 }
215 
216 //-----------------------------------------------------------------------------
217 
218 void SideArea::setElementActive(QString _name, bool _active)
219 {
220  for (int i=0; i < items_.count(); i++)
221  if ( items_[i]->name() == _name ){
222  items_[i]->setActive(_active);
223 
224  return;
225  }
226 }
227 
228 //-----------------------------------------------------------------------------
229 
230 const QList<const QObject *>& SideArea::plugins() {
231  return plugins_;
232 }
233 
234 //-----------------------------------------------------------------------------
235 
236 const QStringList& SideArea::names() {
237  return itemNames_;
238 }
239 
240 
241 //=============================================================================
242 //=============================================================================
const QList< const QObject * > & plugins()
Get plugins in side area.
Definition: SideArea.cc:230
void restoreState(QSettings &_settings)
restores the state
Definition: SideElement.cc:274
void moveItemToPosition(const QString &_name, int _position)
Move a toolbox widget to a given position.
Definition: SideArea.cc:90
void setElementActive(QString _name, bool _active)
set the active state of given element
Definition: SideArea.cc:218
SideArea(QWidget *_parent=0)
Definition: SideArea.cc:60
const QString & name()
return the name
Definition: SideElement.cc:304
void setActive(bool _active)
Set the element as active.
Definition: SideElement.cc:180
void saveState(QSettings &_settings)
returns the current state
Definition: SideArea.cc:178
int getNumberOfWidgets() const
Get number of widgets.
Definition: SideArea.cc:138
void saveViewModeState(const QString &_viewMode)
saves the active state of _viewMode
Definition: SideArea.cc:202
QWidget const * widget()
returns the pointer to the plugin tool widget
Definition: SideElement.cc:316
std::vector< PluginInfo > plugins_
List of all loaded plugins_.
Definition: Core.hh:1208
const QStringList & names()
Get item names.
Definition: SideArea.cc:236
void restoreViewModeState(const QString &_viewMode)
restores the active state of _viewMode
Definition: SideArea.cc:210
void clear()
clears the whole tool widget area
Definition: SideArea.cc:144
void addItem(QObject const *const _plugin, QWidget *_w, QString _name, QIcon *_icon=0, QWidget *_headerAreaWidget=0)
Definition: SideArea.cc:78
void saveState(QSettings &_settings)
saves the current state
Definition: SideElement.cc:264
void restoreState(QSettings &_settings)
restores the state
Definition: SideArea.cc:190
bool active()
returns if the SideElement is active
Definition: SideElement.cc:310