diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 2112192..fc47706 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1079,12 +1079,10 @@ void CDockAreaWidget::onAutoHideToggleRequested(CDockWidget* DockWidget, bool En if (Enable) { dockContainer()->createAndInitializeDockWidgetOverlayContainer(area, DockWidget); - DockWidget->toggleView(false); } else { overlayDockContainer()->moveContentsToParent(); - DockWidget->toggleView(true); } } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index a6287dd..fb72c92 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1074,6 +1074,12 @@ bool DockContainerWidgetPrivate::restoreOverlayDockArea(CDockingStateReader& s, return false; } + bool Closed = s.attributes().value("Closed").toInt(&Ok); + if (!Ok) + { + return false; + } + s.skipCurrentElement(); CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName.toString()); if (!DockWidget || Testing) @@ -1085,15 +1091,14 @@ bool DockContainerWidgetPrivate::restoreOverlayDockArea(CDockingStateReader& s, // We hide the DockArea here to prevent the short display (the flashing) // of the dock areas during application startup DockArea->hide(); - DockWidget->setToggleViewActionChecked(false); - DockWidget->setClosedState(true); - DockWidget->setProperty(internal::ClosedProperty, true); + DockWidget->setToggleViewActionChecked(!Closed); + DockWidget->setClosedState(Closed); + DockWidget->setProperty(internal::ClosedProperty, Closed); DockWidget->setProperty(internal::DirtyProperty, false); _this->sideTabBar(area)->insertSideTab(0, DockWidget->sideTabWidget()); - DockWidget->toggleView(false); DockArea->overlayDockContainer()->addDockWidget(DockWidget); - DockWidget->sideTabWidget()->show(); DockWidget->sideTabWidget()->updateStyle(); // Needed as the side tab widget get it's left/right property from the overlay dock container which was just added + DockWidget->toggleView(Closed); } if (Testing) diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 5588f65..ea3d55a 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -90,11 +90,6 @@ protected: */ void deleteOverlayWidgets(); - /** - * Access function for overlay widgets - */ - QList overlayWidgets() const; - /** * Access function for the internal root splitter */ @@ -329,6 +324,12 @@ public: */ CSideTabBar* sideTabBar(CDockWidgetSideTab::SideTabBarArea area) const; + + /** + * Access function for overlay widgets + */ + QList overlayWidgets() const; + Q_SIGNALS: /** * This signal is emitted if one or multiple dock areas has been added to diff --git a/src/DockFocusController.cpp b/src/DockFocusController.cpp index f1226b2..d467bdb 100644 --- a/src/DockFocusController.cpp +++ b/src/DockFocusController.cpp @@ -191,7 +191,7 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) if (old && old->overlayDockContainer() && old->overlayDockContainer()->isVisible() && old != FocusedDockWidget) { - old->toggleView(false); + old->overlayDockContainer()->collapseView(true); } if (old == DockWidget && !ForceFocusChangedSignal) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 6708552..0a3442e 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -873,8 +873,7 @@ COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(CDockWidget { d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); auto container = DockContainerWidget->createAndInitializeDockWidgetOverlayContainer(area, Dockwidget); - container->dockAreaWidget()->toggleView(false); - Dockwidget->toggleView(false); + container->collapseView(true); Q_EMIT dockWidgetAdded(Dockwidget); return container; diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index f8b1cf1..ecc2662 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -118,6 +118,12 @@ struct DockWidgetPrivate */ void updateParentDockArea(); + /** + * Closes all overlayed dock widgets if there are no more opened dock areas + * This prevents the overlayed dock widgets from being pinned to an empty dock area + */ + void closeOverlayDockWidgetsIfNeeded(); + /** * Setup the top tool bar */ @@ -187,9 +193,10 @@ void DockWidgetPrivate::showDockWidget() FloatingWidget->show(); } - if (DockArea->isOverlayed()) + // If this widget is pinned and there are no opened dock widgets, unpin the overlay widget by moving it's contents to parent container + if (Container->openedDockWidgets().count() == 0 && DockArea->isOverlayed()) { - DockArea->overlayDockContainer()->show(); + DockArea->overlayDockContainer()->moveContentsToParent(); } } } @@ -200,17 +207,14 @@ void DockWidgetPrivate::hideDockWidget() { TabWidget->hide(); updateParentDockArea(); - + + closeOverlayDockWidgetsIfNeeded(); + if (Features.testFlag(CDockWidget::DeleteContentOnClose)) { Widget->deleteLater(); Widget = nullptr; } - - if (DockArea->isOverlayed()) - { - DockArea->overlayDockContainer()->hide(); - } } @@ -239,6 +243,22 @@ void DockWidgetPrivate::updateParentDockArea() } } +void DockWidgetPrivate::closeOverlayDockWidgetsIfNeeded() +{ + if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty()) + { + for (auto overlayWidget : _this->dockContainer()->overlayWidgets()) + { + if (overlayWidget->dockWidget() == _this) + { + continue; + } + + overlayWidget->dockWidget()->toggleView(false); + } + } +} + //============================================================================ void DockWidgetPrivate::setupToolBar() @@ -611,6 +631,8 @@ void CDockWidget::toggleViewInternal(bool Open) CDockWidget* TopLevelDockWidgetBefore = DockContainer ? DockContainer->topLevelDockWidget() : nullptr; + d->Closed = !Open; + if (Open) { d->showDockWidget(); @@ -619,7 +641,7 @@ void CDockWidget::toggleViewInternal(bool Open) { d->hideDockWidget(); } - d->Closed = !Open; + d->ToggleViewAction->blockSignals(true); d->ToggleViewAction->setChecked(Open); d->ToggleViewAction->blockSignals(false); @@ -628,6 +650,11 @@ void CDockWidget::toggleViewInternal(bool Open) d->DockArea->toggleDockWidgetView(this, Open); } + if (d->DockArea->isOverlayed()) + { + d->DockArea->overlayDockContainer()->toggleView(Open); + } + if (Open && TopLevelDockWidgetBefore) { CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidgetBefore, false); @@ -1051,9 +1078,8 @@ void CDockWidget::onDockWidgetSideTabClicked() } overlayContainer->raise(); - const auto show = !overlayContainer->isVisible(); - overlayContainer->setVisible(show); - toggleView(show); + const auto shouldCollapse = overlayContainer->isVisible(); + overlayContainer->collapseView(shouldCollapse); if (overlayContainer->isVisible()) { // d->DockManager->setDockWidgetFocused(this) does not diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index d50b010..28be352 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -281,6 +281,43 @@ bool COverlayDockContainer::restoreState(CDockingStateReader& s, bool Testing) return true; } +void COverlayDockContainer::toggleView(bool Enable) +{ + if (Enable) + { + const auto dockWidget = d->DockWidget; + if (dockWidget) + { + dockWidget->sideTabWidget()->show(); + } + } + else + { + const auto dockWidget = d->DockWidget; + if (dockWidget) + { + dockWidget->sideTabWidget()->hide(); + } + hide(); + } +} + +void COverlayDockContainer::collapseView(bool Enable) +{ + if (Enable) + { + hide(); + d->DockArea->hide(); + d->DockWidget->hide(); + } + else + { + show(); + d->DockArea->show(); + d->DockWidget->show(); + } +} + //============================================================================ bool COverlayDockContainer::areaExistsInConfig(CDockWidgetSideTab::SideTabBarArea area) diff --git a/src/OverlayDockContainer.h b/src/OverlayDockContainer.h index 4a53172..a0c8ab3 100644 --- a/src/OverlayDockContainer.h +++ b/src/OverlayDockContainer.h @@ -126,6 +126,18 @@ public: */ bool restoreState(CDockingStateReader& Stream, bool Testing); + /* + * Toggles the overlay dock container widget + * This will also hide the side tab widget + */ + void toggleView(bool Enable); + + /* + * Collapses the overlay dock container widget + * Does not hide the side tab widget + */ + void collapseView(bool Enable); + /* * Convenience function fr determining if area exists in config */