CollapsibleDockWidget.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include <QDockWidget>
27 #include <QWidget>
28 #include <QHBoxLayout>
29 #include <QSize>
30 #include <QPushButton>
31 #include <QLabel>
32 #include <QPointer>
33 
34 namespace gui
35 {
36  /**
37  * A QDockWidget which provides the possibility to collapse the dock.
38  *
39  * @see QDockWidget
40  */
42  public QDockWidget
43  {
44  Q_OBJECT
45 
46  public:
47  /**
48  * Creates a new CollapsibleDockWidget.
49  * This calls the constructor of the QDockWidget.
50  *
51  * @param title The window title of the DockWidget.
52  * @param parent The parent QWidget.
53  * @param The flags to create the DockWidget with.
54  *
55  * @see QDockWidget
56  */
57  explicit CollapsibleDockWidget(const QString& title, QWidget* parent = 0, Qt::WindowFlags flags = 0);
58 
59  /**
60  * Creates a new CollapsibleDockWidget.
61  * This calls the constructor of the QDockWidget.
62  *
63  * @param parent The parent QWidget.
64  * @param The flags to create the DockWidget with.
65  *
66  * @see QDockWidget
67  */
68  explicit CollapsibleDockWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
69 
70  /**
71  * Sets a QWidget to show in the DockWidget.
72  * If you use this method the DockWidget is collapsible.
73  *
74  * @param w The widget to set.
75  */
76  void setCollapsibleWidget(QWidget* w);
77 
78  /**
79  * Returns is the widget is collapsed.
80  *
81  * @return The current state of the widdget.
82  */
83  bool isCollapsed();
84 
85  /**
86  * A method to inform the widget, that the window title has been changed.
87  */
88  void windowTitleChanged();
89 
90  public slots:
91  /**
92  * Sets the collapsed state. The widget will be collapsed if and only if "collapsed" is true.
93  *
94  * @param collapsed The new state of the widget.
95  */
96  void setCollapsed(bool collapsed);
97 
98  /**
99  * Toggles the collapsed state of the widget.
100  */
101  void toggleCollapsed();
102 
103  private:
104  class InnerWidgetWrapper :
105  public QWidget
106  {
107  public:
108  InnerWidgetWrapper(QDockWidget* parent);
109 
110  void setWidget(QWidget* widget);
111 
112  bool isCollapsed();
113 
114  void setCollapsed(bool collapsed);
115 
116  QSize const& getOldMaximumSizeParent() const;
117 
118  private:
119  QPointer<QWidget> widget;
120  QPointer<QHBoxLayout> hlayout;
121  int widget_height;
122  QSize oldSize;
123  QSize oldMinimumSizeParent;
124  QSize oldMaximumSizeParent;
125  QSize oldMinimumSize;
126  QSize oldMaximumSize;
127  };
128 
129  class TitleBar :
130  public QWidget
131  {
132  public:
133  TitleBar(QWidget* parent);
134 
135  void windowTitleChanged();
136 
137  void showTitle(bool show);
138 
139  private:
140  QPointer<QHBoxLayout> hlayout;
141  QPointer<QPushButton> collapse;
142  QPointer<QLabel> title;
143  };
144 
145  private slots:
146  void setCollapsedSizes();
147  };
148 }
149 
gui::CollapsibleDockWidget::toggleCollapsed
void toggleCollapsed()
Toggles the collapsed state of the widget.
Definition: CollapsibleDockWidget.cpp:80
gui::CollapsibleDockWidget::isCollapsed
bool isCollapsed()
Returns is the widget is collapsed.
Definition: CollapsibleDockWidget.cpp:74
gui::CollapsibleDockWidget::setCollapsibleWidget
void setCollapsibleWidget(QWidget *w)
Sets a QWidget to show in the DockWidget.
Definition: CollapsibleDockWidget.cpp:48
gui::CollapsibleDockWidget::CollapsibleDockWidget
CollapsibleDockWidget(const QString &title, QWidget *parent=0, Qt::WindowFlags flags=0)
Creates a new CollapsibleDockWidget.
Definition: CollapsibleDockWidget.cpp:34
gui::CollapsibleDockWidget::windowTitleChanged
void windowTitleChanged()
A method to inform the widget, that the window title has been changed.
Definition: CollapsibleDockWidget.cpp:85
gui::CollapsibleDockWidget
A QDockWidget which provides the possibility to collapse the dock.
Definition: CollapsibleDockWidget.h:41
gui::CollapsibleDockWidget::setCollapsed
void setCollapsed(bool collapsed)
Sets the collapsed state.
Definition: CollapsibleDockWidget.cpp:60