OpenWalnut  1.5.0dev
WQtDockWidget.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 <QAction>
26 #include <QVBoxLayout>
27 #include <QHBoxLayout>
28 #include <QToolButton>
29 #include <QWidgetAction>
30 
31 #include "../WQtGui.h"
32 #include "../WMainWindow.h"
33 #include "../WIconManager.h"
34 
35 #include "core/common/WLogger.h"
36 
37 #include "../controlPanel/WQtPropertyGroupWidget.h"
38 #include "WQtPropertyBoolAction.h"
39 #include "WQtPropertyTriggerAction.h"
40 #include "WQtDockTitleWidget.h"
41 
42 #include "WQtDockWidget.h"
43 
44 WQtDockWidget::WQtDockWidget( const QString& title, QWidget* parent, Qt::WindowFlags flags ):
45  QDockWidget( title, parent, flags )
46 {
47  setObjectName( title );
48 
49  // thats it. we now have the title bar
50  m_titleBar = new WQtDockTitleWidget( this );
51  setTitleBarWidget( m_titleBar );
53 
54  // some standard dock features
55  setAllowedAreas( Qt::AllDockWidgetAreas );
56  setFeatures( QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
57 }
58 
59 WQtDockWidget::WQtDockWidget( QWidget* parent, Qt::WindowFlags flags ):
60  QDockWidget( parent, flags )
61 {
62  // thats it. we now have the title bar
63  m_titleBar = new WQtDockTitleWidget( this );
64  setTitleBarWidget( m_titleBar );
66 
67  // some standard dock features
68  setAllowedAreas( Qt::AllDockWidgetAreas );
69  setFeatures( QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
70 }
71 
73 {
74  // cleanup
75 }
76 
77 void WQtDockWidget::addTitleAction( QAction* action, bool instantPopup )
78 {
79  m_titleBar->addTitleAction( action, instantPopup );
80 }
81 
82 void WQtDockWidget::addTitleButton( QToolButton* button )
83 {
84  m_titleBar->addTitleButton( button );
85 }
86 
88 {
89  m_titleBar->removeTitleAction( action );
90 }
91 
93 {
95 }
96 
97 void WQtDockWidget::addTitleWidget( QWidget* widget )
98 {
99  m_titleBar->addTitleWidget( widget );
100 }
101 
102 void WQtDockWidget::removeTitleWidget( QWidget* widget )
103 {
104  m_titleBar->removeTitleWidget( widget );
105 }
106 
107 void WQtDockWidget::setHelpContext( const QString& id )
108 {
109  m_helpContextId = id;
111 }
112 
114 {
115  return m_helpContextId;
116 }
117 
119 {
120  // do something here
121 }
122 
124 {
125  WQtGui::getSettings().setValue( objectName() + "/geometry", saveGeometry() );
126 }
127 
129 {
130  // nothing to do
131  restoreGeometry( WQtGui::getSettings().value( objectName() + "/geometry", "" ).toByteArray() );
132 }
133 
134 void WQtDockWidget::closeEvent( QCloseEvent *event )
135 {
136  saveSettings();
137  QDockWidget::closeEvent( event );
138 }
139 
141 {
142  m_titleBar->disableCloseButton( disable );
143 }
144 
145 void WQtDockWidget::addTitleProperty( WPropTrigger prop, WGEImage::SPtr icon )
146 {
147  WQtPropertyTriggerAction* propAction = new WQtPropertyTriggerAction( prop, this );
148  if( !icon )
149  {
150  propAction->setIcon( WQtGui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
151  }
152  else
153  {
154  propAction->setIcon( WIconManager::convertToIcon( icon ) );
155  }
156 
157  addTitleAction( propAction );
158 }
159 
161 {
162  WQtPropertyBoolAction* propAction = new WQtPropertyBoolAction( prop, this );
163  if( !icon )
164  {
165  propAction->setIcon( WQtGui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
166  }
167  else
168  {
169  propAction->setIcon( WIconManager::convertToIcon( icon ) );
170  }
171 
172  addTitleAction( propAction );
173 }
174 
175 void WQtDockWidget::addTitleProperty( WPropGroup prop, WGEImage::SPtr icon )
176 {
177  // create property widgets for each effect
179  QWidget* viewPropsBox = WQtPropertyGroupWidget::createPropertyGroupBox( viewPropsWidget );
180 
181  // create container for all the config widgets
182  QWidget* viewConfigWidget = new QWidget();
183  QVBoxLayout* viewConfigLayout = new QVBoxLayout();
184  viewConfigLayout->setAlignment( Qt::AlignTop );
185  viewConfigWidget->setLayout( viewConfigLayout );
186 
187  // force the widget to shrink when the content shrinks.
188  QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
189  sizePolicy.setHorizontalStretch( 0 );
190  sizePolicy.setVerticalStretch( 0 );
191  viewConfigWidget->setSizePolicy( sizePolicy );
192 
193  // add the property widgets to container
194  viewConfigLayout->addWidget( viewPropsBox );
195 
196  // Create the toolbutton and the menu containing the config widgets
197  QWidgetAction* viewerConfigWidgetAction = new QWidgetAction( this );
198  viewerConfigWidgetAction->setDefaultWidget( viewConfigWidget );
199  QMenu* viewerConfigMenu = new QMenu();
200  viewerConfigMenu->addAction( viewerConfigWidgetAction );
201 
202  QToolButton* viewerConfigBtn = new QToolButton( this );
203  viewerConfigBtn->setPopupMode( QToolButton::InstantPopup );
204 
205  if( !icon )
206  {
207  viewerConfigBtn->setIcon( WQtGui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
208  }
209  else
210  {
211  viewerConfigBtn->setIcon( WIconManager::convertToIcon( icon ) );
212  }
213 
214  viewerConfigBtn->setToolTip( QString::fromStdString( prop->getDescription() ) );
215  viewerConfigBtn->setMenu( viewerConfigMenu );
216 
217  // hide config button when properties are hidden
218  connect( viewPropsWidget, SIGNAL( hideSignal( bool ) ), viewerConfigBtn, SLOT( setHidden( bool ) ) );
219 
220  addTitleButton( viewerConfigBtn );
221 }
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
static QIcon convertToIcon(WGEImage::SPtr image)
Convert a WGEImage to an QIcon.
Class for managing dock widget title bars.
virtual void removeTitleAction(QAction *action)
Remove the given action from the list.
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.
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 updateHelp()
Update help button.
virtual void addTitleSeperator()
Add a separator.
virtual void addTitleWidget(QWidget *widget)
Add an arbitrary widget.
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.
static QSettings & getSettings()
Returns the settings object.
Definition: WQtGui.cpp:394
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
Definition: WQtGui.cpp:88
Implements a property action for WPropBool.
Container widget to contain a number of properties for the module context in the control panel.
static QWidget * createPropertyGroupBox(QWidget *widget, bool asScrollArea=false, QWidget *parent=NULL, const QString &title="", int nestingLevel=0)
This function creates the fancy box around your specified group widget.
static WQtPropertyGroupWidget * createPropertyGroupWidget(WPropertyGroupBase::SPtr group, const QString &title="", size_t depth=0, QWidget *parent=0)
Create a property widget using the given group.
Implements a property action for WPropTrigger.