From d2c08aca701710c2ee2e3cfe111becd38c551197 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 2 Nov 2022 13:06:42 +0100 Subject: [PATCH] Improved context menu of DockAreaWidget --- src/DockAreaTitleBar.cpp | 26 ++++++++++++++++---------- src/DockAreaWidget.cpp | 13 +++++++++++++ src/DockAreaWidget.h | 6 ++++++ src/DockContainerWidget.h | 3 ++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 30314b5..87d3c51 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -665,21 +665,27 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) } bool IsAutoHide = d->DockArea->isAutoHide(); + bool IsTopLevelArea = d->DockArea->isTopLevelArea(); + QAction* Action; QMenu Menu(this); - auto 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(onAutoHideDockAreaClicked())); - Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable)); - } - Menu.addSeparator(); + if (!IsTopLevelArea) + { + 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(onAutoHideDockAreaClicked())); + Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable)); + } + Menu.addSeparator(); + } Action = Menu.addAction(IsAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked())); Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable)); if (!IsAutoHide) { - Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas())); + 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 4cfb7ac..fc90cc7 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1405,6 +1405,19 @@ void CDockAreaWidget::onDockWidgetFeaturesChanged() } +//============================================================================ +bool CDockAreaWidget::isTopLevelArea() const +{ + auto Container = dockContainer(); + if (!Container) + { + return false; + } + + return (Container->topLevelDockArea() == this); +} + + #ifdef Q_OS_WIN //============================================================================ bool CDockAreaWidget::event(QEvent *e) diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 8e8a0aa..b79107c 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -376,6 +376,12 @@ public: */ bool containsCentralWidget() const; + /** + * If this dock area is the one and only visible area in a container, then + * this function returns true + */ + bool isTopLevelArea() const; + public Q_SLOTS: /** diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 421939b..6153cd7 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -163,7 +163,8 @@ protected: CDockWidget* topLevelDockWidget() const; /** - * Returns the top level dock area. + * If the container has only one single visible dock area, then this + * functions returns this top level dock area */ CDockAreaWidget* topLevelDockArea() const;