OpenWalnut  1.5.0dev
WUIQtGridWidget.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 WUIQTGRIDWIDGET_H
26 #define WUIQTGRIDWIDGET_H
27 
28 #include <memory>
29 #include <string>
30 
31 
32 #include "../WMainWindow.h"
33 #include "../guiElements/WQtDockWidget.h"
34 #include "WUIQtWidgetBase.h"
35 #include "core/ui/WUIGridWidget.h"
36 
37 /**
38  * Implementation of \ref WUIGridWidget.
39  */
41  public WUIQtWidgetBase
42 {
43 public:
44  /**
45  * Convenience typedef for a std::shared_ptr< WUIQtGridWidget >.
46  */
47  typedef std::shared_ptr< WUIQtGridWidget > SPtr;
48 
49  /**
50  * Convenience typedef for a std::shared_ptr< const WUIQtGridWidget >.
51  */
52  typedef std::shared_ptr< const WUIQtGridWidget > ConstSPtr;
53 
54  /**
55  * Default constructor.
56  *
57  * \param mainWindow the main window instance
58  * \param parent the Qt parent. Can be NULL.
59  * \param title the title of the widget
60  */
62  std::string title,
63  WMainWindow* mainWindow,
65 
66  /**
67  * Destructor.
68  */
69  virtual ~WUIQtGridWidget();
70 
71  /**
72  * Title as QString.
73  *
74  * \return the title
75  */
76  virtual QString getTitleQString() const;
77 
78  /**
79  * Show this widget if not yet visible.
80  */
81  virtual void show();
82 
83  /**
84  * Hide/show this widget. Unlike close(), you can show the widget again using show().
85  *
86  * \param visible false to hide widget
87  */
88  virtual void setVisible( bool visible = true );
89 
90  /**
91  * Check if the widget is hidden or not.
92  *
93  * \return true if visible.
94  */
95  virtual bool isVisible() const;
96 
97  /**
98  * Handle shutdown. This includes notification of the creating module and closing the widget. Can be called from any thread.
99  * Implement in your implementation.
100  */
101  virtual void close();
102 
103  /**
104  * Sets the stretch factor of a row to stretch. The first row is number 0. The stretch factor is relative to the other rows in this grid.
105  * Rows with a higher stretch factor take more of the available space. The default stretch factor is 0. If the stretch factor is 0 and no
106  * other row in this table can grow at all, the row may still grow.
107  *
108  * \param row the row to set this value for
109  * \param stretch the stretch
110  */
111  virtual void setRowStretch( int row, int stretch );
112 
113  /**
114  * Sets the stretch factor of a column to stretch. The first column is number 0. The stretch factor is relative to the other columns in this grid.
115  * Columns with a higher stretch factor take more of the available space. The default stretch factor is 0. If the stretch factor is 0 and no
116  * other column in this table can grow at all, the column may still grow.
117  *
118  * \param column the column to set this value for
119  * \param stretch the stretch
120  */
121  virtual void setColumnStretch( int column, int stretch );
122 
123  /**
124  * Implement \ref WUIWidgetBase::addAction.
125  *
126  * \param group the property to use.
127  * \param icon the icon to use. Consider a minimum size of 32x32.
128  */
129  virtual void addAction( WPropGroup group, WGEImage::SPtr icon = WGEImage::SPtr() )
130  {
131  WUIQtWidgetBase::addAction( group, icon );
132  }
133 
134  /**
135  * Implement \ref WUIWidgetBase::addAction.
136  *
137  * \param trigger the property to use.
138  * \param icon the icon to use. Consider a minimum size of 32x32.
139  */
140  virtual void addAction( WPropTrigger trigger, WGEImage::SPtr icon = WGEImage::SPtr() )
141  {
142  WUIQtWidgetBase::addAction( trigger, icon );
143  }
144 
145  /**
146  * Implement \ref WUIWidgetBase::addAction.
147  *
148  * \param toggle the property to use.
149  * \param icon the icon to use. Consider a minimum size of 32x32.
150  */
151  virtual void addAction( WPropBool toggle, WGEImage::SPtr icon = WGEImage::SPtr() )
152  {
153  WUIQtWidgetBase::addAction( toggle, icon );
154  }
155 protected:
156  /**
157  * 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
158  * stuff.
159  */
160  virtual void realizeImpl();
161 
162  /**
163  * Close the widget. When done, the widget can be safely deleted.
164  */
165  virtual void closeImpl();
166 
167  /**
168  * Cleanup the GUI. Do not delete m_widget, or your content widget. This is done by WUIQtWidgetBase. This method allows you to free resources
169  * that are not automatically freed by the Qt delete mechanism.
170  */
171  virtual void cleanUpGT();
172 
173  /**
174  * Place the given widget in this grid at the given coordinates. The widget to be placed must be created with this grid as parent.
175  *
176  * \param widget the widget
177  * \param x x coord ( 0 is left )
178  * \param y y coord ( 0 is top )
179  */
180  virtual void placeWidgetImpl( WUIWidgetBase::SPtr widget, int x, int y );
181 
182  /**
183  * Place the given widget in this grid at the given coordinates. The widget to be placed must be created with this grid as parent. GUI thread
184  * version.
185  *
186  * \param widget the widget
187  * \param x x coord ( 0 is left )
188  * \param y y coord ( 0 is top )
189  */
190  virtual void placeWidgetImplGT( QWidget* widget, int x, int y );
191 private:
192  /**
193  * The grid used for managing child widgets
194  */
195  QGridLayout* m_gridLayout;
196 };
197 
198 #endif // WUIQTGRIDWIDGET_H
199 
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
Widget which is a container for others.
Definition: WUIGridWidget.h:41
Implementation of WUIGridWidget.
virtual void setRowStretch(int row, int stretch)
Sets the stretch factor of a row to stretch.
virtual void closeImpl()
Close the widget.
virtual void placeWidgetImpl(WUIWidgetBase::SPtr widget, int x, int y)
Place the given widget in this grid at the given coordinates.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void addAction(WPropTrigger trigger, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void close()
Handle shutdown.
WUIQtGridWidget(std::string title, WMainWindow *mainWindow, WUIQtWidgetBase::SPtr parent=WUIQtWidgetBase::SPtr())
Default constructor.
virtual void cleanUpGT()
Cleanup the GUI.
virtual void show()
Show this widget if not yet visible.
virtual bool isVisible() const
Check if the widget is hidden or not.
std::shared_ptr< WUIQtGridWidget > SPtr
Convenience typedef for a std::shared_ptr< WUIQtGridWidget >.
virtual QString getTitleQString() const
Title as QString.
virtual void placeWidgetImplGT(QWidget *widget, int x, int y)
Place the given widget in this grid at the given coordinates.
virtual void setVisible(bool visible=true)
Hide/show this widget.
virtual void addAction(WPropBool toggle, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void realizeImpl()
Realize the widget.
std::shared_ptr< const WUIQtGridWidget > ConstSPtr
Convenience typedef for a std::shared_ptr< const WUIQtGridWidget >.
virtual ~WUIQtGridWidget()
Destructor.
virtual void setColumnStretch(int column, int stretch)
Sets the stretch factor of a column to stretch.
QGridLayout * m_gridLayout
The grid 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.
std::shared_ptr< WUIWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
Definition: WUIWidgetBase.h:51