From 1bcefaf9b14d7784bc0cfcc6b40ba31116f75ca7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 4 Mar 2024 17:41:55 +0100 Subject: [PATCH] GUI: Follow the widget indications when docking them (#12530) * GUI: Follow the widget indications when docking them The overlay manager handles the creation and drawing of the title bars for the docked widgets. When adding a QDockWidget the manager ignored the set of features (closable, movable, floatable) provided by the widget and always showed all the actions. Amend the code to take into account the features specified by the widget. Closes #11944 --- src/Gui/OverlayManager.cpp | 29 +++++++++++++++++++++++++++++ src/Gui/OverlayManager.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/Gui/OverlayManager.cpp b/src/Gui/OverlayManager.cpp index 9231ba69ca..6f08761296 100644 --- a/src/Gui/OverlayManager.cpp +++ b/src/Gui/OverlayManager.cpp @@ -989,11 +989,23 @@ public: { OverlayTitleBar *widget = new OverlayTitleBar(parent); widget->setObjectName(QStringLiteral("OverlayTitle")); + QList actions; if (auto tabWidget = qobject_cast(parent)) actions = tabWidget->actions(); + else if (auto dockWidget = qobject_cast(parent)) + { + const QDockWidget::DockWidgetFeatures features = dockWidget->features(); + + actions.append(&_actOverlay); + if (features.testFlag(QDockWidget::DockWidgetFloatable)) + actions.append(&_actFloat); + if (features.testFlag(QDockWidget::DockWidgetClosable)) + actions.append(&_actClose); + } else actions = _actions; + widget->setTitleItem(OverlayTabWidget::prepareTitleWidget(widget, actions)); return widget; } @@ -1528,6 +1540,8 @@ void OverlayManager::initDockWidget(QDockWidget *dw) this, &OverlayManager::onToggleDockWidget); QObject::connect(dw, &QDockWidget::visibilityChanged, this, &OverlayManager::onDockVisibleChange); + QObject::connect(dw, &QDockWidget::featuresChanged, + this, &OverlayManager::onDockFeaturesChange); if (auto widget = dw->widget()) { QObject::connect(widget, &QWidget::windowTitleChanged, this, &OverlayManager::onDockWidgetTitleChange); @@ -1577,6 +1591,21 @@ void OverlayManager::onDockVisibleChange(bool visible) << " visible change " << visible << ", " << dock->isVisible()); } +void OverlayManager::onDockFeaturesChange(QDockWidget::DockWidgetFeatures features) +{ + Q_UNUSED(features); + auto dw = qobject_cast(sender()); + if (!dw) + return; + + // Rebuild the title widget as it may have a different set of buttons shown. + if (QWidget *titleBarWidget = dw->titleBarWidget()) { + dw->setTitleBarWidget(nullptr); + delete titleBarWidget; + } + setupTitleBar(dw); +} + void OverlayManager::onTaskViewUpdate() { auto taskview = qobject_cast(sender()); diff --git a/src/Gui/OverlayManager.h b/src/Gui/OverlayManager.h index 47376fcde6..b7c900d1f2 100644 --- a/src/Gui/OverlayManager.h +++ b/src/Gui/OverlayManager.h @@ -24,6 +24,7 @@ #define FC_OVERLAYMANAGER_H #include +#include #include class QAction; @@ -174,6 +175,7 @@ protected: private: void onToggleDockWidget(bool checked); void onDockVisibleChange(bool visible); + void onDockFeaturesChange(QDockWidget::DockWidgetFeatures features); void onDockWidgetTitleChange(const QString &); void onTaskViewUpdate(); void onFocusChanged(QWidget *, QWidget *);