diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index ebd22d1..e2f7732 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -54,6 +54,8 @@ #include "DockSplitter.h" #include "DockAreaTitleBar.h" +#include + namespace ads { @@ -242,6 +244,7 @@ struct DockAreaWidgetPrivate DockAreaLayout* ContentsLayout; CDockAreaTitleBar* TitleBar; CDockManager* DockManager = nullptr; + bool UpdateCloseButton = false; /** * Private data constructor @@ -293,6 +296,11 @@ struct DockAreaWidgetPrivate { return TitleBar->tabBar(); } + + /** + * Udpates the enable state of the close button + */ + void updateCloseButtonState(); }; // struct DockAreaWidgetPrivate @@ -319,6 +327,25 @@ void DockAreaWidgetPrivate::createTitleBar() } +//============================================================================ +void DockAreaWidgetPrivate::updateCloseButtonState() +{ + if (_this->isHidden()) + { + UpdateCloseButton = true; + return; + } + + if (!UpdateCloseButton) + { + return; + } + TitleBar->button(TitleBarButtonClose)->setEnabled( + _this->features().testFlag(CDockWidget::DockWidgetClosable)); + UpdateCloseButton = false; +} + + //============================================================================ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) : QFrame(parent), @@ -383,6 +410,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, setCurrentIndex(index); } DockWidget->setDockArea(this); + d->updateCloseButtonState(); } @@ -414,6 +442,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) hideAreaWithNoVisibleContent(); } + d->updateCloseButtonState(); updateTitleBarVisibility(); auto TopLevelDockWidget = dockContainer()->topLevelDockWidget(); if (TopLevelDockWidget) @@ -730,10 +759,19 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const void CDockAreaWidget::toggleView(bool Open) { setVisible(Open); + emit viewToggled(Open); } +//============================================================================ +void CDockAreaWidget::setVisible(bool Visible) +{ + Super::setVisible(Visible); + d->updateCloseButtonState(); +} + + //============================================================================ QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index fbc3cbf..7c26899 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -241,6 +241,11 @@ public: */ QAbstractButton* titleBarButton(TitleBarButton which) const; + /** + * Update the close button if visibility changed + */ + virtual void setVisible(bool Visible) override; + public slots: /** * This activates the tab for the given tab index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index a6638c9..8a73147 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -627,11 +627,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s, } qDebug() << "Dock Widget found - parent " << DockWidget->parent(); - DockArea->addDockWidget(DockWidget); - // We hide the DockArea here to prevent the short display (the flashing) // of the dock areas during application startup DockArea->hide(); + DockArea->addDockWidget(DockWidget); DockWidget->setToggleViewActionChecked(!Closed); DockWidget->setClosedState(Closed); DockWidget->setProperty("closed", Closed); diff --git a/src/DockWidget.h b/src/DockWidget.h index 81ec2f2..08dce26 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -152,6 +152,23 @@ public: StateFloating }; + /** + * Sets the widget for the dock widget to widget. + * The InsertMode defines how the widget is inserted into the dock widget. + * The content of a dock widget should be resizable do a very small size to + * prevent the dock widget from blocking the resizing. To ensure, that a + * dock widget can be resized very well, it is better to insert the content+ + * widget into a scroll area or to provide a widget that is already a scroll + * area or that contains a scroll area. + * If the InsertMode is AutoScrollArea, the DockWidget tries to automatically + * detect how to insert the given widget. If the widget is derived from + * QScrollArea (i.e. an QAbstractItemView), then the widget is inserted + * directly. If the given widget is not a scroll area, the widget will be + * inserted into a scroll area. + * To force insertion into a scroll area, you can also provide the InsertMode + * ForceScrollArea. To prevent insertion into a scroll area, you can + * provide the InsertMode ForceNoScrollArea + */ enum eInsertMode { AutoScrollArea,