OpenWalnut  1.5.0dev
WQtDockTitleWidget.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 WQTDOCKTITLEWIDGET_H
26 #define WQTDOCKTITLEWIDGET_H
27 
28 #include <QDockWidget>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
31 #include <QToolButton>
32 #include <QLabel>
33 #include <QResizeEvent>
34 #include <QWidgetAction>
35 
36 #include "WScaleLabel.h"
37 
38 /**
39  * We need the dock widget class.
40  */
41 class WQtDockWidget;
42 
43 /**
44  * Class for managing dock widget title bars.
45  */
46 class WQtDockTitleWidget: public QWidget
47 {
48  Q_OBJECT
49 public:
50  /**
51  * Constructor.
52  *
53  * \param parent the parent
54  */
55  explicit WQtDockTitleWidget( WQtDockWidget* parent );
56 
57  /**
58  * Add the given action to the titlebar. It gets added after the previously added ones.
59  *
60  * \param action the action to add.
61  * \param instantPopup if true, the button does not trigger an action. Instead, it directly opens the menu.
62  */
63  virtual void addTitleAction( QAction* action, bool instantPopup = false );
64 
65  /**
66  * Add the given tool button to the titlebar. It gets added after the previously added ones.
67  *
68  * \param button the action to add.
69  */
70  virtual void addTitleButton( QToolButton* button );
71 
72  /**
73  * Remove the given action from the list
74  *
75  * \param action the action to add
76  */
77  virtual void removeTitleAction( QAction* action );
78 
79  /**
80  * Add a separator.
81  */
82  virtual void addTitleSeperator();
83 
84  /**
85  * Add an arbitrary widget. Please take care of its size! This method sets a size policy and a fixed height.
86  *
87  * \param widget the widget to add
88  */
89  virtual void addTitleWidget( QWidget* widget );
90 
91  /**
92  * Remove the specified widget from the title bar.
93  *
94  * \param widget the widget to remove
95  */
96  virtual void removeTitleWidget( QWidget* widget );
97 
98  /**
99  * Update help button.
100  */
101  virtual void updateHelp();
102 
103  /**
104  * Disable close button? Might come in handy when embedding these widgets into others
105  *
106  * \param disable true to disable
107  */
108  void disableCloseButton( bool disable = true );
109 protected:
110  /**
111  * Called upon resize. Used to switch between the more menu and the tools widget
112  *
113  * \param event the event
114  */
115  virtual void resizeEvent( QResizeEvent* event );
116 
117  /**
118  * Apply default settings for dock widget title buttons.
119  *
120  * \param btn the button to setup
121  */
122  virtual void setupButton( QToolButton* btn );
123 
124  /**
125  * Apply size setup to a given widget.
126  *
127  * \param widget the widget to setup
128  */
129  virtual void setupSizeConstraints( QWidget* widget );
130 private:
131  /**
132  * Construct the title and configure the widget.
133  */
134  void construct();
135 
136  /**
137  * Updates the layouts according to the new width
138  *
139  * \param width the new width.
140  */
141  void updateLayouts( int width );
142 
143  /**
144  * The tools buttons
145  */
146  QWidget* m_tools;
147 
148  /**
149  * The tool inside the menu
150  */
151  QWidget* m_toolsMenu;
152 
153  /**
154  * Layout containing the tools
155  */
156  QHBoxLayout* m_toolsLayout;
157 
158  /**
159  * The tool button used when shrinking the title bar too much
160  */
161  QToolButton* m_moreBtn;
162 
163  /**
164  * LAyout of the items in the moreBtn menu
165  */
166  QHBoxLayout* m_toolsMenuLayout;
167 
168  /**
169  * Title label
170  */
172 
173  /**
174  * Close button
175  */
176  QToolButton* m_closeBtn;
177 
178  /**
179  * Help button
180  */
181  QToolButton* m_helpBtn;
182 
183  /**
184  * The parent as dock pointer
185  */
187 
188  /**
189  * We keep track of the widgets that we add
190  */
192 };
193 
194 #endif // WQTDOCKTITLEWIDGET_H
195 
Class for managing dock widget title bars.
WQtDockWidget * m_dockParent
The parent as dock pointer.
virtual void removeTitleAction(QAction *action)
Remove the given action from the list.
QList< QWidget * > m_titleActionWidgets
We keep track of the widgets that we add.
void updateLayouts(int width)
Updates the layouts according to the new width.
QToolButton * m_helpBtn
Help button.
virtual void addTitleButton(QToolButton *button)
Add the given tool button to the titlebar.
void disableCloseButton(bool disable=true)
Disable close button? Might come in handy when embedding these widgets into others.
QToolButton * m_moreBtn
The tool button used when shrinking the title bar too much.
virtual void removeTitleWidget(QWidget *widget)
Remove the specified widget from the title bar.
WQtDockTitleWidget(WQtDockWidget *parent)
Constructor.
QWidget * m_tools
The tools buttons.
virtual void setupButton(QToolButton *btn)
Apply default settings for dock widget title buttons.
QToolButton * m_closeBtn
Close button.
virtual void addTitleAction(QAction *action, bool instantPopup=false)
Add the given action to the titlebar.
virtual void updateHelp()
Update help button.
virtual void resizeEvent(QResizeEvent *event)
Called upon resize.
virtual void addTitleSeperator()
Add a separator.
QWidget * m_toolsMenu
The tool inside the menu.
void construct()
Construct the title and configure the widget.
virtual void addTitleWidget(QWidget *widget)
Add an arbitrary widget.
QHBoxLayout * m_toolsMenuLayout
LAyout of the items in the moreBtn menu.
WScaleLabel * m_title
Title label.
virtual void setupSizeConstraints(QWidget *widget)
Apply size setup to a given widget.
QHBoxLayout * m_toolsLayout
Layout containing the tools.
Advanced QDockWidget.
Definition: WQtDockWidget.h:50
Special Label that can shrink and expand in a layout.
Definition: WScaleLabel.h:37