fw4spl
QfwToolbox.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 /*
8  * Based on (and also inspired by) QToolbox: http://doc.qt.nokia.com/4.7/qtoolbox.html
9  */
10 
11 #ifndef __FWGUIQT_WIDGET_QFWTOOLBOX_HPP__
12 #define __FWGUIQT_WIDGET_QFWTOOLBOX_HPP__
13 
14 #include <QObject>
15 #include <QScrollArea>
16 #include <QString>
17 #include <QFormLayout>
18 #include <QPushButton>
19 
20 #include "fwGuiQt/config.hpp"
21 
22 namespace fwGuiQt
23 {
24 namespace widget
25 {
26 
27 
28 class Page
29 {
30 public:
31  void setText(const QString &text)
32  {
33  button->setText(text);
34  }
35  void setIcon(const QIcon &is)
36  {
37  button->setIcon(is);
38  }
39  void setToolTip(const QString &tip)
40  {
41  button->setToolTip(tip);
42  }
43  QString toolTip() const
44  {
45  return button->toolTip();
46  }
47  QString text() const
48  {
49  return button->text();
50  }
51  QIcon icon() const
52  {
53  return button->icon();
54  }
55 
56  inline bool operator==(const Page& other) const
57  {
58  return widget == other.widget;
59  }
60 
61  QPushButton *button;
62  QFrame* sv;
63  QWidget *widget;
64 };
65 
66 class FWGUIQT_CLASS_API QfwToolBox : public QFrame
67 {
68 Q_OBJECT
69 
70 public:
71  FWGUIQT_API QfwToolBox(QWidget *parent = 0, Qt::WindowFlags f = 0);
72  FWGUIQT_API virtual ~QfwToolBox();
73 
74  FWGUIQT_API int addItem(QWidget *widget, const QString &text);
75  FWGUIQT_API int insertItem(int index, QWidget *widget, const QString &text);
76 
77  FWGUIQT_API void removeItem(int index);
78 
79  FWGUIQT_API void setItemEnabled(int index, bool enabled);
80  FWGUIQT_API bool isItemEnabled(int index) const;
81 
82  FWGUIQT_API void setItemText(int index, const QString &text);
83  FWGUIQT_API QString itemText(int index) const;
84 
85  FWGUIQT_API void setItemToolTip(int index, const QString &toolTip);
86  FWGUIQT_API QString itemToolTip(int index) const;
87 
88  FWGUIQT_API QWidget *widget(int index) const;
89 
90  FWGUIQT_API int indexOf(QWidget *widget) const;
91  FWGUIQT_API int count() const;
92 
93  FWGUIQT_API void collapseItem(int index);
94  FWGUIQT_API void expandItem(int index);
95 
96 protected:
97 
98  typedef QList< ::fwGuiQt::widget::Page > PageList;
99 
100 private Q_SLOTS:
101  void buttonToggled(bool checked);
102  void widgetDestroyed(QObject*);
103 
104 private:
105 
106  ::fwGuiQt::widget::Page* page(QWidget *widget) const;
107  const ::fwGuiQt::widget::Page* page(int index) const;
108  ::fwGuiQt::widget::Page* page(int index);
109 
110  void relayout();
111 
112  PageList pageList;
113  QFormLayout* layout;
114 };
115 
116 
117 } // namespace widget
118 } // namespace fwGuiQt
119 
120 #endif // __FWGUIQT_WIDGET_QFWTOOLBOX_HPP__
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
Definition: WindowLevel.hpp:32