OpenWalnut  1.5.0dev
WUIQtTabbedWidget.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 "WUIQtTabbedWidget.h"
28 
30  std::string title,
31  WMainWindow* mainWindow,
32  WUIQtWidgetBase::SPtr parent ):
33  WUITabbedWidget( title ),
34  WUIQtWidgetBase( mainWindow, parent )
35 {
36  // initialize members
37 }
38 
40 {
41  // cleanup
42 }
43 
45 {
46  return QString::fromStdString( getTitle() );
47 }
48 
50 {
52 }
53 
54 void WUIQtTabbedWidget::setVisible( bool visible )
55 {
56  WUIQtWidgetBase::setVisible( visible );
57 }
58 
60 {
62 }
63 
65 {
66  // nothing to do
67 }
68 
70 {
71  // use WUITabbedWidget to handle this
73 }
74 
76 {
77  // notify child widgets
79 }
80 
82 {
83  // this is called from withing the GUI thread -> we can safely create QT widgets here
84 
85  // use QTabWidget
86  m_tabWidget = new QTabWidget( getCompellingQParent() );
88 }
89 
90 int WUIQtTabbedWidget::addTabImpl( WUIWidgetBase::SPtr widget, std::string label )
91 {
92  // get the real Qt widget
93  WUIQtWidgetBase* widgetQt = dynamic_cast< WUIQtWidgetBase* >( widget.get() );
94  QWidget* widgetQtwidget = NULL;
95  if( widgetQt )
96  {
97  widgetQtwidget = widgetQt->getWidget();
98  }
99 
100  // and forward call to GUI thread
101  if( widgetQtwidget )
102  {
103  QString s = QString::fromStdString( label );
104  return WQtGui::execInGUIThread< int >( boost::bind( &QTabWidget::addTab, m_tabWidget, widgetQtwidget, s ) );
105  }
106 
107  return -1;
108 }
109 
110 void WUIQtTabbedWidget::setTabText( int index, const std::string& label )
111 {
112  if( m_tabWidget )
113  {
114  QString s = QString::fromStdString( label );
115  WQtGui::execInGUIThread( boost::bind( &QTabWidget::setTabText, m_tabWidget, index, s ) );
116  }
117 }
118 
120 {
121  if( m_tabWidget )
122  {
123  WQtGui::execInGUIThread( boost::bind( &QTabWidget::setCurrentIndex, m_tabWidget, index ) );
124  }
125 }
126 
127 void WUIQtTabbedWidget::setTabToolTip( int index, const std::string& tip )
128 {
129  if( m_tabWidget )
130  {
131  QString s = QString::fromStdString( tip );
132  WQtGui::execInGUIThread( boost::bind( &QTabWidget::setTabToolTip, m_tabWidget, index, s ) );
133  }
134 }
135 
136 void WUIQtTabbedWidget::setTabEnabled( int index, bool enable )
137 {
138  if( m_tabWidget )
139  {
140  WQtGui::execInGUIThread( boost::bind( &QTabWidget::setTabEnabled, m_tabWidget, index, enable ) );
141  }
142 }
143 
145 {
146  QTabWidget::TabPosition posInQt = static_cast< QTabWidget::TabPosition >( position );
147  if( m_tabWidget )
148  {
149  WQtGui::execInGUIThread( boost::bind( &QTabWidget::setTabPosition, m_tabWidget, posInQt ) );
150  }
151 }
152 
154 {
155  if( m_tabWidget )
156  {
157  return WQtGui::execInGUIThread< int >( boost::bind( &QTabWidget::currentIndex, m_tabWidget ) );
158  }
159  return -1;
160 }
161 
163 {
164  if( m_tabWidget )
165  {
166  return WQtGui::execInGUIThread< int >( boost::bind( &QTabWidget::count, m_tabWidget ) );
167  }
168  return -1;
169 }
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
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 closeImpl()
Close the widget.
virtual int getNumTabs() const
Query the number of tabs.
virtual void setTabEnabled(int index, bool enable)
Allows en/disabling a tab.
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 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.
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 ...
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
void close()
Close the widget.
virtual std::string getTitle() const
Get the title of the widget.