OpenWalnut  1.5.0dev
WUIQtGridWidget.cpp
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 #include <string>
26 
27 #include <QGridLayout>
28 
29 #include "core/common/WConditionOneShot.h"
30 #include "core/common/WFlag.h"
31 
32 #include "WUIQtGridWidget.h"
33 
35  std::string title,
36  WMainWindow* mainWindow,
37  WUIQtWidgetBase::SPtr parent ):
38  WUIGridWidget( title ),
39  WUIQtWidgetBase( mainWindow, parent ),
40  m_gridLayout( NULL )
41 {
42  // initialize members
43 }
44 
46 {
47  // cleanup
48 }
49 
51 {
52  return QString::fromStdString( getTitle() );
53 }
54 
56 {
58 }
59 
60 void WUIQtGridWidget::setVisible( bool visible )
61 {
62  WUIQtWidgetBase::setVisible( visible );
63 }
64 
66 {
68 }
69 
71 {
72  // nothing to do
73 }
74 
76 {
77  // use WUIGridWidget to handle this
79 }
80 
82 {
83  // notify child widgets
85 }
86 
88 {
89  // this is called from withing the GUI thread -> we can safely create QT widgets here
90 
91  // then we use a plain QWidget
92  // create the actual grid widget (using a QGridLayout)
93  QWidget* gridWidget = new QWidget( getCompellingQParent() );
94  m_gridLayout = new QGridLayout();
95  gridWidget->setLayout( m_gridLayout );
96 
97  embedContent( gridWidget );
98 
99  // spacing?
100  m_gridLayout->setSpacing( 0 );
101  m_widget->setContentsMargins( 0, 0, 0, 0 );
102  m_gridLayout->setContentsMargins( 1, 1, 1, 1 );
103 }
104 
106 {
107  // get the real Qt widget
108  WUIQtWidgetBase* widgetQt = dynamic_cast< WUIQtWidgetBase* >( widget.get() );
109  QWidget* widgetQtwidget = NULL;
110  if( widgetQt )
111  {
112  widgetQtwidget = widgetQt->getWidget();
113  }
114 
115  // and forward call to GUI thread
116  if( widgetQtwidget )
117  {
118  WQtGui::execInGUIThread( boost::bind( &WUIQtGridWidget::placeWidgetImplGT, this, widgetQtwidget, x, y ) );
119  }
120 }
121 
122 void WUIQtGridWidget::placeWidgetImplGT( QWidget* widget, int x, int y )
123 {
124  if( m_gridLayout )
125  {
126  m_gridLayout->addWidget( widget, x, y );
127  }
128 }
129 
130 void WUIQtGridWidget::setRowStretch( int row, int stretch )
131 {
132  if( m_gridLayout )
133  {
134  WQtGui::execInGUIThread( boost::bind( &QGridLayout::setRowStretch, m_gridLayout, row, stretch ) );
135  }
136 }
137 
138 void WUIQtGridWidget::setColumnStretch( int column, int stretch )
139 {
140  if( m_gridLayout )
141  {
142  WQtGui::execInGUIThread( boost::bind( &QGridLayout::setColumnStretch, m_gridLayout, column, stretch ) );
143  }
144 }
145 
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
static void execInGUIThread(boost::function< void(void) > functor, WCondition::SPtr notify=WCondition::SPtr())
Call a given function from within the GUI thread.
Definition: WQtGui.cpp:409
Widget which is a container for others.
Definition: WUIGridWidget.h:41
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 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.
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 realizeImpl()
Realize the widget.
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.
QWidget * m_widget
The widget representing this abstract UI element.
QWidget * getCompellingQParent() const
Returns the parent to use for your implementation in realizeImpl.
virtual void show()
Show this widget if not yet visible.
std::shared_ptr< WUIQtWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIQtWidgetBase >.
virtual void setVisible(bool visible=true)
Hide/show this widget.
virtual bool isVisible() const
Check if the widget is hidden or not.
QWidget * getWidget() const
Get the widget representation.
virtual void closeImpl()
Close the widget.
QWidget * embedContent(QWidget *content)
This method can be used if you just create some QWidget and do not want to take care about embedding ...
std::shared_ptr< WUIWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
Definition: WUIWidgetBase.h:51
void close()
Close the widget.
virtual std::string getTitle() const
Get the title of the widget.