Developer Documentation

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
45
46 //== INCLUDES =================================================================
47
48 #include <QVBoxLayout>
49
50 #include "SideArea.hh"
51 #include "SideElement.hh"
52 //== IMPLEMENTATION ==========================================================
53
54 SideArea::SideArea (QWidget *_parent) :
55 QWidget (_parent),
56 lastPos_(0)
57 {
58
59 layout_ = new QVBoxLayout;
60 layout_->setSpacing (0);
61
62 QVBoxLayout *l = new QVBoxLayout;
63 l->addLayout (layout_);
64 l->addStretch(1);
65 l->setContentsMargins(2, 2, 2, 2);
66
67 setLayout (l);
68 }
69
70 //-----------------------------------------------------------------------------
71
72 void SideArea::addItem (QObject const * const _plugin, QWidget *_w, QString _name,
73 QIcon *_icon, QWidget *_headerAreaWidget)
74 {
75 SideElement *e = new SideElement (this, _w, _name, _icon, _headerAreaWidget);
76 layout_->addWidget (e);
77 items_.push_back (e);
78 plugins_.push_back(_plugin);
79 itemNames_.push_back(_name);
80 }
81
82 //-----------------------------------------------------------------------------
83
84 void SideArea::moveItemToPosition(const QString& _name, int _position) {
85
86 // Position is in valid range
87 if(_position < 0 || _position >= items_.size())
88 return;
89
90 // Search item
91 QVector<SideElement*>::iterator it = items_.begin();
92 for(; it != items_.end(); ++it) {
93 if( (*it)->name() == _name )
94 break;
95 }
96
97 if(it != items_.end()) {
98 layout_->removeWidget(*it);
99 layout_->insertWidget(_position, (*it));
100 }
101 }
102
103 //-----------------------------------------------------------------------------
104
105 void SideArea::moveItemToPosition(QObject const * const _plugin, const QString& _name, int _position) {
106
107 // Position is in valid range
108 if(_position < 0 || _position >= items_.size())
109 return;
110
111 // Search item
112 QVector<SideElement*>::iterator it = items_.begin();
113 int i = 0;
114 for(; it != items_.end(); ++it, ++i) {
115 if( ((*it)->name() == _name)
116 && (plugins_[i] == _plugin) )
117 break;
118 }
119
120 bool active = (*it)->active();
121
122 if(it != items_.end()) {
123 layout_->removeWidget(*it);
124 layout_->insertWidget(_position, (*it));
125 if (active)
126 (*it)->show();
127 }
128 }
129
130 //-----------------------------------------------------------------------------
131
132 int SideArea::getNumberOfWidgets() const {
133 return items_.size();
134 }
135
136 //-----------------------------------------------------------------------------
137
138 void SideArea::clear ()
139 {
140 foreach (SideElement *e, items_)
141 {
142 layout_->removeWidget (e);
143 delete e;
144 }
145 items_.clear ();
146 plugins_.clear();
147 itemNames_.clear();
148 lastPos_ = 0;
149 }
150
151 //-----------------------------------------------------------------------------
152
153 void SideArea::expandAll()
154 {
155 foreach (SideElement *e, items_)
156 {
157 e->setActive(true);
158 }
159 }
160
161 void SideArea::expand(QWidget *sideElementWidget, bool expand)
162 {
163 foreach (SideElement *e, items_)
164 {
165 if (e->widget() == sideElementWidget)
166 e->setActive(expand);
167 }
168 }
169
170 //-----------------------------------------------------------------------------
171
172 void SideArea::saveState (QSettings &_settings)
173 {
174 _settings.beginGroup ("SideArea");
175 foreach (SideElement *e, items_)
176 {
177 e->saveState (_settings);
178 }
179 _settings.endGroup ();
180 }
181
182 //-----------------------------------------------------------------------------
183
184 void SideArea::restoreState (QSettings &_settings)
185 {
186 _settings.beginGroup ("SideArea");
187 foreach (SideElement *e, items_)
188 {
189 e->restoreState (_settings);
190 }
191 _settings.endGroup ();
192 }
193
194 //-----------------------------------------------------------------------------
195
196 void SideArea::saveViewModeState(const QString& _viewMode) {
197 foreach (SideElement *e, items_) {
198 sideElementState_[_viewMode + e->name()] = e->active();
199 }
200 }
201
202 //-----------------------------------------------------------------------------
203
204 void SideArea::restoreViewModeState(const QString& _viewMode) {
205 foreach (SideElement *e, items_) {
206 e->setActive(sideElementState_[_viewMode + e->name()]);
207 }
208 }
209
210 //-----------------------------------------------------------------------------
211
212 void SideArea::setElementActive(QString _name, bool _active)
213 {
214 for (int i=0; i < items_.count(); i++)
215 if ( items_[i]->name() == _name ){
216 items_[i]->setActive(_active);
217
218 return;
219 }
220 }
221
222 //-----------------------------------------------------------------------------
223
224 const QList<const QObject *>& SideArea::plugins() {
225 return plugins_;
226 }
227
228 //-----------------------------------------------------------------------------
229
230 const QStringList& SideArea::names() {
231 return itemNames_;
232 }
233
234
235 //=============================================================================
236 //=============================================================================
SideElement::active
bool active()
returns if the SideElement is active
Definition: SideElement.cc:304
SideArea::SideArea
SideArea(QWidget *_parent=0)
Definition: SideArea.cc:54
SideElement
Definition: SideElement.hh:79
SideArea::restoreViewModeState
void restoreViewModeState(const QString &_viewMode)
restores the active state of _viewMode
Definition: SideArea.cc:204
SideElement::saveState
void saveState(QSettings &_settings)
saves the current state
Definition: SideElement.cc:258
SideArea::moveItemToPosition
void moveItemToPosition(const QString &_name, int _position)
Move a toolbox widget to a given position.
Definition: SideArea.cc:84
SideElement::restoreState
void restoreState(QSettings &_settings)
restores the state
Definition: SideElement.cc:268
SideArea::names
const QStringList & names()
Get item names.
Definition: SideArea.cc:230
SideElement::name
const QString & name()
return the name
Definition: SideElement.cc:298
SideElement::widget
QWidget const * widget()
returns the pointer to the plugin tool widget
Definition: SideElement.cc:310
SideElement::setActive
void setActive(bool _active)
Set the element as active.
Definition: SideElement.cc:174
SideArea::saveViewModeState
void saveViewModeState(const QString &_viewMode)
saves the active state of _viewMode
Definition: SideArea.cc:196
SideArea::setElementActive
void setElementActive(QString _name, bool _active)
set the active state of given element
Definition: SideArea.cc:212
SideArea::saveState
void saveState(QSettings &_settings)
returns the current state
Definition: SideArea.cc:172
SideArea::plugins
const QList< const QObject * > & plugins()
Get plugins in side area.
Definition: SideArea.cc:224
SideArea::getNumberOfWidgets
int getNumberOfWidgets() const
Get number of widgets.
Definition: SideArea.cc:132
SideArea::clear
void clear()
clears the whole tool widget area
Definition: SideArea.cc:138
SideArea::restoreState
void restoreState(QSettings &_settings)
restores the state
Definition: SideArea.cc:184
SideArea::addItem
void addItem(QObject const *const _plugin, QWidget *_w, QString _name, QIcon *_icon=0, QWidget *_headerAreaWidget=0)
Definition: SideArea.cc:72