27 #include <QSizePolicy>
28 #include <qtreeview.h>
35 QDockWidget(title, parent, flags)
37 gui::CollapsibleDockWidget::TitleBar* titleBar =
new gui::CollapsibleDockWidget::TitleBar(
this);
38 setTitleBarWidget(titleBar);
42 QDockWidget(parent, flags)
44 gui::CollapsibleDockWidget::TitleBar* titleBar =
new gui::CollapsibleDockWidget::TitleBar(
this);
45 setTitleBarWidget(titleBar);
50 gui::CollapsibleDockWidget::InnerWidgetWrapper* wid =
new gui::CollapsibleDockWidget::InnerWidgetWrapper(
this);
52 QDockWidget::setWidget(wid);
62 gui::CollapsibleDockWidget::InnerWidgetWrapper* innerWidget =
dynamic_cast<gui::CollapsibleDockWidget::InnerWidgetWrapper*
>(widget());
64 if (innerWidget != NULL)
66 innerWidget->setCollapsed(collapsed);
70 std::cerr <<
"DockWidget is not collapsible" << std::endl;
76 gui::CollapsibleDockWidget::InnerWidgetWrapper* innerWidget =
dynamic_cast<gui::CollapsibleDockWidget::InnerWidgetWrapper*
>(widget());
77 return innerWidget != NULL ? innerWidget->isCollapsed() :
false;
82 setCollapsed(!isCollapsed());
87 gui::CollapsibleDockWidget::TitleBar* titleBar =
dynamic_cast<gui::CollapsibleDockWidget::TitleBar*
>(this->titleBarWidget());
91 titleBar->windowTitleChanged();
95 gui::CollapsibleDockWidget::InnerWidgetWrapper::InnerWidgetWrapper(QDockWidget* parent) :
98 hlayout(new QHBoxLayout(this)),
102 this->hlayout->setSpacing(0);
103 this->hlayout->setContentsMargins(0, 0, 0, 0);
104 this->setLayout(this->hlayout);
105 QDockWidget* parentDockWidget =
dynamic_cast<QDockWidget*
>(parent);
106 assert(parentDockWidget != NULL);
107 oldMinimumSizeParent = parentDockWidget->minimumSize();
108 oldMaximumSizeParent = parentDockWidget->maximumSize();
109 oldMinimumSize = minimumSize();
110 oldMaximumSize = maximumSize();
113 void gui::CollapsibleDockWidget::InnerWidgetWrapper::setWidget(QWidget* widget)
115 this->widget = widget;
116 this->widget_height = widget->height();
117 this->layout()->addWidget(widget);
118 this->oldSize = this->size();
119 QDockWidget* parentDockWidget =
dynamic_cast<QDockWidget*
>(this->parent());
120 assert(parentDockWidget != NULL);
121 oldMinimumSizeParent = parentDockWidget->minimumSize();
122 oldMaximumSizeParent = parentDockWidget->maximumSize();
123 oldMinimumSize = minimumSize();
124 oldMaximumSize = maximumSize();
127 bool gui::CollapsibleDockWidget::InnerWidgetWrapper::isCollapsed()
129 return !this->widget->isVisible();
132 void gui::CollapsibleDockWidget::InnerWidgetWrapper::setCollapsed(
bool collapsed)
134 QDockWidget* parentDockWidget =
dynamic_cast<QDockWidget*
>(this->parent());
135 assert(parentDockWidget != NULL);
136 gui::CollapsibleDockWidget::TitleBar* parentDockWidgetTitleBar =
dynamic_cast<gui::CollapsibleDockWidget::TitleBar*
>(parentDockWidget->titleBarWidget());
137 assert(parentDockWidgetTitleBar != NULL);
141 parentDockWidget->setMinimumSize(oldMinimumSizeParent);
142 parentDockWidget->setMaximumSize(oldMaximumSizeParent);
143 this->widget->show();
144 parentDockWidgetTitleBar->showTitle(
true);
145 this->layout()->addWidget(this->widget);
146 this->setMinimumSize(oldMinimumSize);
147 this->setMaximumSize(oldMaximumSize);
148 this->setBaseSize(this->oldSize);
149 this->resize(this->oldSize);
153 this->oldSize = this->size();
154 oldMinimumSizeParent = parentDockWidget->minimumSize();
155 oldMaximumSizeParent = parentDockWidget->maximumSize();
156 oldMinimumSize = minimumSize();
157 oldMaximumSize = maximumSize();
158 this->layout()->removeWidget(this->widget);
159 this->widget->hide();
160 parentDockWidgetTitleBar->showTitle(
false);
161 parentDockWidget->setMinimumSize(25, 25);
162 parentDockWidget->setMaximumSize(25, 25);
163 QTimer::singleShot(1, parentDockWidget, SLOT(setCollapsedSizes()));
167 void gui::CollapsibleDockWidget::setCollapsedSizes()
169 gui::CollapsibleDockWidget::InnerWidgetWrapper* innerWidget =
dynamic_cast<gui::CollapsibleDockWidget::InnerWidgetWrapper*
>(widget());
170 assert(innerWidget != NULL);
171 setMinimumSize(25, 25);
173 if (features() & QDockWidget::DockWidgetVerticalTitleBar)
175 setMaximumSize(25, innerWidget->getOldMaximumSizeParent().height());
179 setMaximumSize(innerWidget->getOldMaximumSizeParent().width(), 25);
183 gui::CollapsibleDockWidget::TitleBar::TitleBar(QWidget* parent) :
185 hlayout(new QHBoxLayout(this)),
186 collapse(new QPushButton(this)),
187 title(new QLabel(parent->windowTitle()))
189 this->hlayout->setDirection(QBoxLayout::Direction::RightToLeft);
190 this->hlayout->setSpacing(0);
191 this->hlayout->setContentsMargins(0, 0, 0, 0);
192 this->setLayout(this->hlayout);
193 this->hlayout->addWidget(collapse);
194 collapse->setIcon(QIcon(
":/images/branch-open.png"));
195 collapse->setCheckable(
false);
196 collapse->setFixedSize(20, 20);
197 connect(collapse, SIGNAL(released()), parent, SLOT(
toggleCollapsed()));
198 this->hlayout->addStretch();
199 this->hlayout->addWidget(title);
202 void gui::CollapsibleDockWidget::TitleBar::windowTitleChanged()
204 QDockWidget* parentDockWidget =
dynamic_cast<QDockWidget*
>(this->parent());
205 title->setText(parentDockWidget->windowTitle());
208 void gui::CollapsibleDockWidget::TitleBar::showTitle(
bool show)
210 title->setVisible(show);
214 collapse->setIcon(QIcon(
":/images/branch-open.png"));
218 collapse->setIcon(QIcon(
":/images/branch-closed.png"));
222 QSize
const& gui::CollapsibleDockWidget::InnerWidgetWrapper::getOldMaximumSizeParent()
const
224 return oldMaximumSizeParent;