From c1df05b55d1032432c9c9ee5b774da0fe3883ba5 Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Thu, 8 Sep 2022 16:08:20 +0800 Subject: [PATCH] Fix bug where undock button would be show incorrectly in floating dock widgets when toggling overlay Also centralized and simplified the logic for the title bar button visibility --- src/DockAreaWidget.cpp | 41 ++++++++++++++++++++++++++++++++++--- src/DockAreaWidget.h | 5 +++++ src/DockContainerWidget.cpp | 9 ++------ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index be27e6d..60261cc 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -310,6 +310,11 @@ struct DockAreaWidgetPrivate */ void updateTitleBarButtonStates(); + /** + * Udpates the enable state of the close and detach button + */ + void updateTitleBarButtonVisibility(bool isTopLevel); + /** * Scans all contained dock widgets for the max. minimum size hint */ @@ -358,14 +363,38 @@ void DockAreaWidgetPrivate::updateTitleBarButtonStates() _this->features().testFlag(CDockWidget::DockWidgetClosable)); TitleBar->button(TitleBarButtonUndock)->setEnabled( _this->features().testFlag(CDockWidget::DockWidgetFloatable)); - // Undock and tabs should never show when overlayed - TitleBar->button(TitleBarButtonUndock)->setVisible(!_this->isOverlayed()); - TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isOverlayed()); TitleBar->updateDockWidgetActionsButtons(); UpdateTitleBarButtons = false; } +//============================================================================ +void DockAreaWidgetPrivate::updateTitleBarButtonVisibility(bool IsTopLevel) +{ + auto *const container = _this->dockContainer(); + if (!container) + { + return; + } + + if (IsTopLevel) + { + TitleBar->button(TitleBarButtonClose)->setVisible(!container->isFloating()); + TitleBar->button(TitleBarButtonAutoHide)->setVisible(!container->isFloating()); + // Undock and tabs should never show when overlayed + TitleBar->button(TitleBarButtonUndock)->setVisible(!container->isFloating() && !_this->isOverlayed()); + TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isOverlayed()); + } + else + { + TitleBar->button(TitleBarButtonClose)->setVisible(true); + TitleBar->button(TitleBarButtonAutoHide)->setVisible(true); + TitleBar->button(TitleBarButtonUndock)->setVisible(!_this->isOverlayed()); + TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isOverlayed()); + } +} + + //============================================================================ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) : QFrame(parent), @@ -787,6 +816,7 @@ void CDockAreaWidget::updateTitleBarVisibility() auto tabBar = d->TitleBar->tabBar(); tabBar->setVisible(isOverlayed() ? false : !Hidden); // Never show tab bar when overlayed d->TitleBar->overlayTitleLabel()->setVisible(isOverlayed()); // Always show when overlayed, never otherwise + updateTitleBarButtonVisibility(Container->topLevelDockArea() == this); } } @@ -810,6 +840,11 @@ void CDockAreaWidget::updateAutoHidebuttonCheckState() autoHideButton->blockSignals(false); } +void CDockAreaWidget::updateTitleBarButtonVisibility(bool IsTopLevel) const +{ + d->updateTitleBarButtonVisibility(IsTopLevel); +} + //============================================================================ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 67063b6..503df45 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -156,6 +156,11 @@ protected: */ void updateAutoHidebuttonCheckState(); + /* + * Update the title bar button visibility based on if it's top level or not + */ + void updateTitleBarButtonVisibility(bool IsTopLevel) const; + protected Q_SLOTS: void toggleView(bool Open); diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 3e6d014..a6287dd 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -428,15 +428,11 @@ void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged() if (TopLevelDockArea) { this->TopLevelDockArea = TopLevelDockArea; - TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false || !_this->isFloating()); - TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(false || !_this->isFloating()); - TopLevelDockArea->titleBarButton(TitleBarButtonAutoHide)->setVisible(false || !_this->isFloating()); + TopLevelDockArea->updateTitleBarButtonVisibility(true); } else if (this->TopLevelDockArea) { - this->TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true); - this->TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); - this->TopLevelDockArea->titleBarButton(TitleBarButtonAutoHide)->setVisible(true); + this->TopLevelDockArea->updateTitleBarButtonVisibility(false); this->TopLevelDockArea = nullptr; } } @@ -833,7 +829,6 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QListtitleBarButton(TitleBarButtonUndock)->setVisible(true); DockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); DockArea->titleBarButton(TitleBarButtonAutoHide)->setVisible(true); }