From 409d4489ccaadfaa11555bea0b5d41fce22bf418 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 3 Nov 2022 16:44:40 +0100 Subject: [PATCH] Added support for auto hiding a dock area / widget to a specific border via context menu --- demo/MainWindow.cpp | 1 + src/AutoHideSideBar.h | 3 --- src/DockAreaTitleBar.cpp | 17 ++++++++--------- src/DockAreaWidget.cpp | 22 ++++++++++------------ src/DockWidgetTab.cpp | 38 +++++++++++++++++++++++--------------- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index e46bd7c..f980b84 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -655,6 +655,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment the following line to enable focus highlighting of the dock // widget that has the focus CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); + CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true); // uncomment if you would like to enable dock widget auto hiding CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); diff --git a/src/AutoHideSideBar.h b/src/AutoHideSideBar.h index 3e57e2b..b452ee0 100644 --- a/src/AutoHideSideBar.h +++ b/src/AutoHideSideBar.h @@ -150,9 +150,6 @@ public: * Setter for spacing property - sets the spacing */ void setSpacing(int Spacing); - -Q_SIGNALS: - void sideTabAutoHideToggleRequested(); }; } // namespace ads //----------------------------------------------------------------------------- diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 951a42e..ed06c18 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -689,22 +689,22 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) return; } - bool IsAutoHide = d->DockArea->isAutoHide(); - bool IsTopLevelArea = d->DockArea->isTopLevelArea(); + const bool isAutoHide = d->DockArea->isAutoHide(); + const bool isTopLevelArea = d->DockArea->isTopLevelArea(); QAction* Action; QMenu Menu(this); - if (!IsTopLevelArea) + if (!isTopLevelArea) { - Action = Menu.addAction(IsAutoHide ? tr("Detach") : tr("Detach Group"), + Action = Menu.addAction(isAutoHide ? tr("Detach") : tr("Detach Group"), this, SLOT(onUndockButtonClicked())); Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)); if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) { - Action = Menu.addAction(IsAutoHide ? tr("Dock") : tr("Auto Hide Group"), this, SLOT(onAutoHideDockAreaActionClicked())); + Action = Menu.addAction(isAutoHide ? tr("Dock") : tr("Auto Hide Group"), this, SLOT(onAutoHideDockAreaActionClicked())); auto AreaIsPinnable = d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable); Action->setEnabled(AreaIsPinnable); - if (!IsAutoHide) + if (!isAutoHide) { auto menu = Menu.addMenu(tr("Auto Hide Group To...")); menu->setEnabled(AreaIsPinnable); @@ -716,12 +716,11 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) } Menu.addSeparator(); } - Action = Menu.addAction(IsAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked())); + Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked())); Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable)); - if (!IsAutoHide) + if (!isAutoHide && !isTopLevelArea) { Action = Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas())); - Action->setEnabled(!IsTopLevelArea); } Menu.exec(ev->globalPos()); } diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 4054ec1..1697ad6 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -537,7 +537,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) { setCurrentDockWidget(NextOpenDockWidget); } - else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1) // Don't remove empty dock areas that are auto hidden, they'll be deleted by the auto hide dock + else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1) { ADS_PRINT("Dock Area empty"); DockContainer->removeDockArea(this); @@ -827,22 +827,20 @@ void CDockAreaWidget::updateTitleBarVisibility() return; } - if (CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs)) - { - return; - } - if (!d->TitleBar) { return; } - bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating() - || CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)); - Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1); - bool IsAutoHide = isAutoHide(); - Hidden &= !IsAutoHide; // Titlebar must always be visible when auto hidden so it can be dragged - d->TitleBar->setVisible(!Hidden); + bool IsAutoHide = isAutoHide(); + if (!CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs)) + { + bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating() + || CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)); + Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1); + Hidden &= !IsAutoHide; // Titlebar must always be visible when auto hidden so it can be dragged + d->TitleBar->setVisible(!Hidden); + } if (isAutoHideFeatureEnabled()) { diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 844a9fb..5d1ce04 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -518,32 +518,40 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) } d->saveDragStartMousePosition(ev->globalPos()); - QMenu Menu(this); const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable); const bool isNotOnlyTabInContainer = !d->DockArea->dockContainer()->hasTopLevelDockWidget(); - + const bool isTopLevelArea = d->DockArea->isTopLevelArea(); const bool isDetachable = isFloatable && isNotOnlyTabInContainer; + QAction* Action; + QMenu Menu(this); - auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget())); - Action->setEnabled(isDetachable); - if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) + if (!isTopLevelArea) { - Action = Menu.addAction(tr("Auto Hide"), this, SLOT(autoHideDockWidget())); - auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable); - Action->setEnabled(IsPinnable); + Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget())); + Action->setEnabled(isDetachable); + if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) + { + Action = Menu.addAction(tr("Auto Hide"), this, SLOT(autoHideDockWidget())); + auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable); + Action->setEnabled(IsPinnable); - auto menu = Menu.addMenu(tr("Auto Hide To...")); - menu->setEnabled(IsPinnable); - d->createAutoHideToAction(tr("Top"), SideBarTop, menu); - d->createAutoHideToAction(tr("Left"), SideBarLeft, menu); - d->createAutoHideToAction(tr("Right"), SideBarRight, menu); - d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu); + auto menu = Menu.addMenu(tr("Auto Hide To...")); + menu->setEnabled(IsPinnable); + d->createAutoHideToAction(tr("Top"), SideBarTop, menu); + d->createAutoHideToAction(tr("Left"), SideBarLeft, menu); + d->createAutoHideToAction(tr("Right"), SideBarRight, menu); + d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu); + } } + Menu.addSeparator(); Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); Action->setEnabled(isClosable()); - Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested())); + if (d->DockArea->openDockWidgetsCount() > 1) + { + Action = Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested())); + } Menu.exec(ev->globalPos()); }