OpenWalnut  1.5.0dev
WUIQtTabbedWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUIQTTABBEDWIDGET_H
26 #define WUIQTTABBEDWIDGET_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <QTabWidget>
32 
33 #include "../WMainWindow.h"
34 #include "../guiElements/WQtDockWidget.h"
35 #include "WUIQtWidgetBase.h"
36 #include "core/ui/WUITabbedWidget.h"
37 
38 /**
39  * Implementation of \ref WUITabbedWidget.
40  */
42  public WUIQtWidgetBase
43 {
44 public:
45  /**
46  * Convenience typedef for a std::shared_ptr< WUIQtTabbedWidget >.
47  */
48  typedef std::shared_ptr< WUIQtTabbedWidget > SPtr;
49 
50  /**
51  * Convenience typedef for a std::shared_ptr< const WUIQtTabbedWidget >.
52  */
53  typedef std::shared_ptr< const WUIQtTabbedWidget > ConstSPtr;
54 
55  /**
56  * Default constructor.
57  *
58  * \param mainWindow the main window instance
59  * \param parent the Qt parent. Can be NULL.
60  * \param title the title of the widget
61  */
63  std::string title,
64  WMainWindow* mainWindow,
66 
67  /**
68  * Destructor.
69  */
70  virtual ~WUIQtTabbedWidget();
71 
72  /**
73  * Title as QString.
74  *
75  * \return the title
76  */
77  virtual QString getTitleQString() const;
78 
79  /**
80  * Show this widget if not yet visible.
81  */
82  virtual void show();
83 
84  /**
85  * Hide/show this widget. Unlike close(), you can show the widget again using show().
86  *
87  * \param visible false to hide widget
88  */
89  virtual void setVisible( bool visible = true );
90 
91  /**
92  * Check if the widget is hidden or not.
93  *
94  * \return true if visible.
95  */
96  virtual bool isVisible() const;
97 
98  /**
99  * Handle shutdown. This includes notification of the creating module and closing the widget. Can be called from any thread.
100  * Implement in your implementation.
101  */
102  virtual void close();
103 
104  /**
105  * Set label of the tab with given index. If the tab does not exist, nothing happens.
106  *
107  * \param index the index of the tab
108  * \param label the label of the tab
109  */
110  virtual void setTabText( int index, const std::string& label );
111 
112  /**
113  * Set the given tab active. If it not exists, the current tab stays active.
114  *
115  * \param index the index of the tab
116  */
117  virtual void setActiveTab( int index );
118 
119  /**
120  * Get the index of the currently active tab.
121  *
122  * \return the index, or -1 if error
123  */
124  virtual int getActiveTab() const;
125 
126  /**
127  * Query the number of tabs.
128  *
129  * \return the number of tabs, or -1 if error.
130  */
131  virtual int getNumTabs() const;
132 
133  /**
134  * Write some tool tip for a given tab. If the index is invalid, nothing happens.
135  *
136  * \param index the tab index
137  * \param tip the tooltip text
138  */
139  virtual void setTabToolTip( int index, const std::string& tip );
140 
141  /**
142  * Allows en/disabling a tab. If the index is invalid, nothing happens.
143  *
144  * \param index the index.
145  * \param enable true to enable
146  */
147  virtual void setTabEnabled( int index, bool enable );
148 
149  /**
150  * Specify where to place the tabs
151  *
152  * \param position the position
153  */
154  virtual void setTabPosition( TabPosition position );
155 
156  /**
157  * Implement \ref WUIWidgetBase::addAction.
158  *
159  * \param group the property to use.
160  * \param icon the icon to use. Consider a minimum size of 32x32.
161  */
162  virtual void addAction( WPropGroup group, WGEImage::SPtr icon = WGEImage::SPtr() )
163  {
164  WUIQtWidgetBase::addAction( group, icon );
165  }
166 
167  /**
168  * Implement \ref WUIWidgetBase::addAction.
169  *
170  * \param trigger the property to use.
171  * \param icon the icon to use. Consider a minimum size of 32x32.
172  */
173  virtual void addAction( WPropTrigger trigger, WGEImage::SPtr icon = WGEImage::SPtr() )
174  {
175  WUIQtWidgetBase::addAction( trigger, icon );
176  }
177 
178  /**
179  * Implement \ref WUIWidgetBase::addAction.
180  *
181  * \param toggle the property to use.
182  * \param icon the icon to use. Consider a minimum size of 32x32.
183  */
184  virtual void addAction( WPropBool toggle, WGEImage::SPtr icon = WGEImage::SPtr() )
185  {
186  WUIQtWidgetBase::addAction( toggle, icon );
187  }
188 protected:
189  /**
190  * Realize the widget. This method blocks until the GUI thread created the widget. Called from within the GUI thread! So you can safely do Qt
191  * stuff.
192  */
193  virtual void realizeImpl();
194 
195  /**
196  * Close the widget. When done, the widget can be safely deleted.
197  */
198  virtual void closeImpl();
199 
200  /**
201  * Cleanup the GUI. Do not delete m_widget, or your content widget. This is done by WUIQtWidgetBase. This method allows you to free resources
202  * that are not automatically freed by the Qt delete mechanism.
203  */
204  virtual void cleanUpGT();
205 
206  /**
207  * Place the given widget in this tab widget in a new tab with a given label. The widget to be placed must be created with this tab widget as parent or an
208  * exception will be thrown.
209  *
210  * \param widget the widget
211  * \param label the label of the tab
212  *
213  * \return the index of the new tab
214  */
215  virtual int addTabImpl( WUIWidgetBase::SPtr widget, std::string label );
216 private:
217  /**
218  * The tab widget used for managing child widgets
219  */
220  QTabWidget* m_tabWidget;
221 };
222 
223 #endif // WUIQTTABBEDWIDGET_H
224 
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
Implementation of WUITabbedWidget.
virtual void close()
Handle shutdown.
virtual ~WUIQtTabbedWidget()
Destructor.
virtual QString getTitleQString() const
Title as QString.
virtual void setTabText(int index, const std::string &label)
Set label of the tab with given index.
virtual void show()
Show this widget if not yet visible.
virtual void setActiveTab(int index)
Set the given tab active.
virtual void addAction(WPropBool toggle, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void closeImpl()
Close the widget.
virtual int getNumTabs() const
Query the number of tabs.
std::shared_ptr< const WUIQtTabbedWidget > ConstSPtr
Convenience typedef for a std::shared_ptr< const WUIQtTabbedWidget >.
virtual void setTabEnabled(int index, bool enable)
Allows en/disabling a tab.
virtual void addAction(WPropTrigger trigger, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
WUIQtTabbedWidget(std::string title, WMainWindow *mainWindow, WUIQtWidgetBase::SPtr parent=WUIQtWidgetBase::SPtr())
Default constructor.
virtual void setTabPosition(TabPosition position)
Specify where to place the tabs.
virtual int addTabImpl(WUIWidgetBase::SPtr widget, std::string label)
Place the given widget in this tab widget in a new tab with a given label.
virtual void cleanUpGT()
Cleanup the GUI.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
std::shared_ptr< WUIQtTabbedWidget > SPtr
Convenience typedef for a std::shared_ptr< WUIQtTabbedWidget >.
virtual void setVisible(bool visible=true)
Hide/show this widget.
virtual bool isVisible() const
Check if the widget is hidden or not.
virtual void setTabToolTip(int index, const std::string &tip)
Write some tool tip for a given tab.
virtual int getActiveTab() const
Get the index of the currently active tab.
virtual void realizeImpl()
Realize the widget.
QTabWidget * m_tabWidget
The tab widget used for managing child widgets.
Implementation of WUIWidgetBase.
std::shared_ptr< WUIQtWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIQtWidgetBase >.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
Widget which is a container for others.
TabPosition
Tab positions.
std::shared_ptr< WUIWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
Definition: WUIWidgetBase.h:51