OpenWalnut  1.5.0dev
WQtDockWidget.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 WQTDOCKWIDGET_H
26 #define WQTDOCKWIDGET_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 "core/common/WProperties.h"
37 #include "core/graphicsEngine/WGEImage.h"
38 
39 #include "WScaleLabel.h"
40 
41 /**
42  * Used for the title bar.
43  */
44 class WQtDockTitleWidget;
45 
46 /**
47  * Advanced QDockWidget. This class allows you to add actions to the titlebar of the dock widget
48  */
50 {
51  Q_OBJECT
52 public:
53  /**
54  * Construct dock widget with title.
55  *
56  * \param title the title of the widget
57  * \param parent the parent widget
58  * \param flags optional window flags
59  */
60  WQtDockWidget( const QString& title, QWidget* parent = 0, Qt::WindowFlags flags = Qt::WindowFlags() );
61 
62  /**
63  * Construct dock widget.
64  *
65  * \param parent the parent widget
66  * \param flags optional window flags
67  */
68  WQtDockWidget( QWidget* parent = 0, Qt::WindowFlags flags = Qt::WindowFlags() );
69 
70  /**
71  * Destructor.
72  */
73  virtual ~WQtDockWidget();
74 
75  /**
76  * Add a property to the title of this dock. Image should be specified but is optional.
77  *
78  * \param prop the property
79  * \param icon the icon to use.
80  */
81  virtual void addTitleProperty( WPropTrigger prop, WGEImage::SPtr icon = WGEImage::SPtr() );
82 
83  /**
84  * Add a property to the title of this dock. Image should be specified but is optional.
85  *
86  * \param prop the property
87  * \param icon the icon to use.
88  */
89  virtual void addTitleProperty( WPropBool prop, WGEImage::SPtr icon = WGEImage::SPtr() );
90 
91  /**
92  * Add a property to the title of this dock. Image should be specified but is optional.
93  *
94  * \param prop the property
95  * \param icon the icon to use.
96  */
97  virtual void addTitleProperty( WPropGroup prop, WGEImage::SPtr icon = WGEImage::SPtr() );
98 
99  /**
100  * Add the given action to the titlebar. It gets added after the previously added ones.
101  *
102  * \param action the action to add.
103  * \param instantPopup if true, the button does not trigger an action. Instead, it directly opens the menu.
104  */
105  virtual void addTitleAction( QAction* action, bool instantPopup = false );
106 
107  /**
108  * Add the given tool button to the titlebar. It gets added after the previously added ones.
109  *
110  * \param button the action to add.
111  */
112  virtual void addTitleButton( QToolButton* button );
113 
114  /**
115  * Remove the given action from the list
116  *
117  * \param action the action to add
118  */
119  virtual void removeTitleAction( QAction* action );
120 
121  /**
122  * Add a separator.
123  */
124  virtual void addTitleSeperator();
125 
126  /**
127  * Add an arbitrary widget. Please take care of its size! This method sets a size policy and a fixed height.
128  *
129  * \param widget the widget to add
130  */
131  virtual void addTitleWidget( QWidget* widget );
132 
133  /**
134  * Remove the specified widget from the title bar.
135  *
136  * \param widget the widget to remove
137  */
138  virtual void removeTitleWidget( QWidget* widget );
139 
140  /**
141  * Set a string which identifies help material for this dock. If you specify a help ID which then leads to multiple help documents, a help
142  * menu is shown instead of a simple help button. If no help context id was specified, the help button is not show.
143  *
144  * \param id the help context id for this dock
145  */
146  virtual void setHelpContext( const QString& id );
147 
148  /**
149  * Return the help context id.
150  *
151  * \return the id.
152  */
153  virtual const QString& getHelpContext();
154 
155  /**
156  * Save settings.
157  */
158  virtual void saveSettings();
159 
160  /**
161  * Restore settings
162  */
163  virtual void restoreSettings();
164 
165  /**
166  * Disable close button? Might come in handy when embedding these widgets into others
167  *
168  * \param disable true to disable
169  */
170  void disableCloseButton( bool disable = true );
171 
172 public slots:
173  /**
174  * Show help.
175  */
176  void showHelp();
177 
178 protected:
179  /**
180  * Called whenever a close event is received.
181  *
182  * \param event the event.
183  */
184  virtual void closeEvent( QCloseEvent *event );
185 
186 private:
187  /**
188  * Title widget.
189  */
191 
192  /**
193  * The ID for the help context associated with this dock.
194  */
196 };
197 
198 #endif // WQTDOCKWIDGET_H
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
Class for managing dock widget title bars.
Advanced QDockWidget.
Definition: WQtDockWidget.h:50
virtual void closeEvent(QCloseEvent *event)
Called whenever a close event is received.
WQtDockTitleWidget * m_titleBar
Title widget.
QString m_helpContextId
The ID for the help context associated with this dock.
virtual void addTitleSeperator()
Add a separator.
virtual void saveSettings()
Save settings.
virtual void removeTitleAction(QAction *action)
Remove the given action from the list.
virtual const QString & getHelpContext()
Return the help context id.
virtual void addTitleWidget(QWidget *widget)
Add an arbitrary widget.
virtual void addTitleButton(QToolButton *button)
Add the given tool button to the titlebar.
virtual void removeTitleWidget(QWidget *widget)
Remove the specified widget from the title bar.
virtual void addTitleAction(QAction *action, bool instantPopup=false)
Add the given action to the titlebar.
virtual void restoreSettings()
Restore settings.
WQtDockWidget(const QString &title, QWidget *parent=0, Qt::WindowFlags flags=Qt::WindowFlags())
Construct dock widget with title.
virtual void setHelpContext(const QString &id)
Set a string which identifies help material for this dock.
virtual void addTitleProperty(WPropTrigger prop, WGEImage::SPtr icon=WGEImage::SPtr())
Add a property to the title of this dock.
void disableCloseButton(bool disable=true)
Disable close button? Might come in handy when embedding these widgets into others.
virtual ~WQtDockWidget()
Destructor.
void showHelp()
Show help.