7 #include "fwGuiQt/widget/QfwToolbox.hpp" 9 #include <QApplication> 13 #include <QStyleOption> 14 #include <QVBoxLayout> 21 static const char* branch_closed[] = {
46 static const char* branch_open[] = {
60 QfwToolBox::~QfwToolBox()
66 QfwToolBox::QfwToolBox(QWidget* parent, Qt::WindowFlags f) : QFrame(parent, f)
68 this->layout =
new QFormLayout(
this);
69 this->layout->setMargin(0);
70 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
71 layout->setHorizontalSpacing(0);
72 layout->setVerticalSpacing(1);
73 setBackgroundRole(QPalette::Button);
85 for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
87 if ((*i).widget == widget)
99 if (index >= 0 && index < pageList.size())
101 return &pageList[index];
108 const ::fwGuiQt::widget::Page* QfwToolBox::page(
int index)
const 110 if (index >= 0 && index < pageList.size())
112 return &pageList.at(index);
119 void QfwToolBox::collapseItem(
int index)
121 Page* page = this->page(index);
124 page->sv->setVisible(
false);
125 page->button->setChecked(
false);
131 void QfwToolBox::expandItem(
int index)
133 Page* page = this->page(index);
136 page->sv->setVisible(
true);
137 page->button->setChecked(
true);
143 int QfwToolBox::addItem(QWidget* item,
const QString& text)
145 return insertItem(-1, item, text);
150 int QfwToolBox::insertItem(
int index, QWidget* widget,
const QString& text)
157 connect(widget, SIGNAL(destroyed(QObject*)),
this, SLOT(widgetDestroyed(QObject*)));
161 c.button =
new QPushButton(
this);
162 c.button->setObjectName(
"QfwToolBoxButton");
163 c.button->setBackgroundRole(QPalette::Window);
164 c.button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
165 c.button->setFocusPolicy(Qt::NoFocus);
166 c.button->setCheckable(
true);
167 QPixmap pixOpen(branch_open);
168 QPixmap pixClose(branch_closed);
170 bIcon.addPixmap( pixClose, QIcon::Normal, QIcon::Off );
171 bIcon.addPixmap( pixOpen, QIcon::Active, QIcon::On );
173 if(qApp->styleSheet().isEmpty())
177 "background-color: lightgray;" 178 "border-style: solid;" 180 "border-color: darkgray;" 183 c.button->setStyleSheet(style);
185 connect(c.button, SIGNAL(toggled(
bool)),
this, SLOT(buttonToggled(
bool)));
187 c.sv =
new QFrame(
this);
188 QVBoxLayout* verticalLayout =
new QVBoxLayout(c.sv);
189 verticalLayout->setMargin(0);
190 verticalLayout->addWidget(widget);
192 c.sv->setFrameStyle(QFrame::NoFrame);
196 if (index < 0 || index >= (
int)this->pageList.count())
198 index = this->pageList.count();
199 this->pageList.append(c);
200 this->layout->addWidget(c.button);
201 this->layout->addWidget(c.sv);
205 this->pageList.insert(index, c);
214 void QfwToolBox::buttonToggled(
bool checked)
216 QPushButton* tb = qobject_cast<QPushButton*>(this->sender());
218 for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
220 if ((*i).button == tb)
226 int index = this->indexOf(item);
227 Page* page = this->page(index);
228 page->sv->setVisible(checked);
233 int QfwToolBox::count()
const 235 return this->pageList.count();
240 void QfwToolBox::relayout()
243 layout =
new QFormLayout(
this);
244 layout->setMargin(0);
245 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
246 layout->setHorizontalSpacing(0);
247 layout->setVerticalSpacing(1);
248 for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
250 layout->addWidget((*i).button);
251 layout->addWidget((*i).sv);
257 void QfwToolBox::widgetDestroyed(QObject*
object)
259 QWidget* p = (QWidget*)
object;
266 layout->removeWidget(c->sv);
267 layout->removeWidget(c->button);
268 c->sv->deleteLater();
270 pageList.removeAll(*c);
275 void QfwToolBox::removeItem(
int index)
277 if (QWidget* w = widget(index))
279 disconnect(w, SIGNAL(destroyed(QObject*)),
this, SLOT(widgetDestroyed(QObject*)));
281 this->widgetDestroyed(w);
287 QWidget* QfwToolBox::widget(
int index)
const 289 if (index < 0 || index >= (
int) this->pageList.size())
293 return this->pageList.at(index).widget;
298 int QfwToolBox::indexOf(QWidget* widget)
const 300 Page* c = (widget ? this->page(widget) : 0);
301 return c ? this->pageList.indexOf(*c) : -1;
306 void QfwToolBox::setItemEnabled(
int index,
bool enabled)
308 Page* c = this->page(index);
314 c->button->setEnabled(enabled);
319 void QfwToolBox::setItemText(
int index,
const QString& text)
321 Page* c = this->page(index);
330 void QfwToolBox::setItemToolTip(
int index,
const QString& toolTip)
332 Page* c = this->page(index);
335 c->setToolTip(toolTip);
341 bool QfwToolBox::isItemEnabled(
int index)
const 343 const Page* c = this->page(index);
344 return c && c->button->isEnabled();
349 QString QfwToolBox::itemText(
int index)
const 351 const Page* c = this->page(index);
352 return (c ? c->text() : QString());
357 QString QfwToolBox::itemToolTip(
int index)
const 359 const Page* c = this->page(index);
360 return (c ? c->toolTip() : QString());
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...