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 <QHBoxLayout>
28 #include <QLabel>
29 #include <QPointer>
30 #include <QPushButton>
31 #include <QSize>
32 #include <QWidget>
33 
34 namespace gui
35 {
36  /**
37  * A QDockWidget which provides the possibility to collapse the dock.
38  *
39  * @see QDockWidget
40  */
41  class CollapsibleDockWidget : public QDockWidget
42  {
43  Q_OBJECT
44 
45  public:
46  /**
47  * Creates a new CollapsibleDockWidget.
48  * This calls the constructor of the QDockWidget.
49  *
50  * @param title The window title of the DockWidget.
51  * @param parent The parent QWidget.
52  * @param The flags to create the DockWidget with.
53  *
54  * @see QDockWidget
55  */
56  explicit CollapsibleDockWidget(const QString& title,
57  QWidget* parent = 0,
58  Qt::WindowFlags flags = 0);
59 
60  /**
61  * Creates a new CollapsibleDockWidget.
62  * This calls the constructor of the QDockWidget.
63  *
64  * @param parent The parent QWidget.
65  * @param The flags to create the DockWidget with.
66  *
67  * @see QDockWidget
68  */
69  explicit CollapsibleDockWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
70 
71  /**
72  * Sets a QWidget to show in the DockWidget.
73  * If you use this method the DockWidget is collapsible.
74  *
75  * @param w The widget to set.
76  */
77  void setCollapsibleWidget(QWidget* w);
78 
79  /**
80  * Returns is the widget is collapsed.
81  *
82  * @return The current state of the widdget.
83  */
84  bool isCollapsed();
85 
86  /**
87  * A method to inform the widget, that the window title has been changed.
88  */
89  void windowTitleChanged();
90 
91  public slots:
92  /**
93  * Sets the collapsed state. The widget will be collapsed if and only if "collapsed" is true.
94  *
95  * @param collapsed The new state of the widget.
96  */
97  void setCollapsed(bool collapsed);
98 
99  /**
100  * Toggles the collapsed state of the widget.
101  */
102  void toggleCollapsed();
103 
104  private:
105  class InnerWidgetWrapper : 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 : public QWidget
130  {
131  public:
132  TitleBar(QWidget* parent);
133 
134  void windowTitleChanged();
135 
136  void showTitle(bool show);
137 
138  private:
139  QPointer<QHBoxLayout> hlayout;
140  QPointer<QPushButton> collapse;
141  QPointer<QLabel> title;
142  };
143 
144  private slots:
145  void setCollapsedSizes();
146  };
147 } // namespace gui
gui::CollapsibleDockWidget::toggleCollapsed
void toggleCollapsed()
Toggles the collapsed state of the widget.
Definition: CollapsibleDockWidget.cpp:92
gui::CollapsibleDockWidget::isCollapsed
bool isCollapsed()
Returns is the widget is collapsed.
Definition: CollapsibleDockWidget.cpp:84
gui::CollapsibleDockWidget::setCollapsibleWidget
void setCollapsibleWidget(QWidget *w)
Sets a QWidget to show in the DockWidget.
Definition: CollapsibleDockWidget.cpp:54
gui::CollapsibleDockWidget::CollapsibleDockWidget
CollapsibleDockWidget(const QString &title, QWidget *parent=0, Qt::WindowFlags flags=0)
Creates a new CollapsibleDockWidget.
Definition: CollapsibleDockWidget.cpp:37
gui::CollapsibleDockWidget::windowTitleChanged
void windowTitleChanged()
A method to inform the widget, that the window title has been changed.
Definition: CollapsibleDockWidget.cpp:98
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:68