From 8ddabc4cc83a11d4e29b97c3755834cd2c15ed24 Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Tue, 13 Sep 2022 16:02:14 +0800 Subject: [PATCH] Fix docking behavior when there is a central widget --- src/DockAreaWidget.cpp | 16 ++++++++++++++++ src/DockAreaWidget.h | 7 ++++++- src/DockContainerWidget.cpp | 8 -------- src/OverlayDockContainer.cpp | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 598ac78..526e7ee 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1129,6 +1129,22 @@ bool CDockAreaWidget::isCentralWidgetArea() const } +//============================================================================ +bool CDockAreaWidget::containsCentralWidget() const +{ + auto centralWidget = dockManager()->centralWidget(); + for (const auto &dockWidget : dockWidgets()) + { + if (dockWidget == centralWidget) + { + return true; + } + } + + return false; +} + + //============================================================================ QSize CDockAreaWidget::minimumSizeHint() const { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index f94fc34..9e26554 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -358,10 +358,15 @@ public: void setDockAreaFlag(eDockAreaFlag Flag, bool On); /** - * Returns true if the area contains the central widget of it's manager. + * Returns true if the area has a single dock widget and contains the central widget of it's manager. */ bool isCentralWidgetArea() const; + /** + * Returns true if the area contains the central widget of it's manager. + */ + bool containsCentralWidget() const; + public Q_SLOTS: /** * This activates the tab for the given tab index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 9f51828..bcf53bd 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1898,8 +1898,6 @@ QList CDockContainerWidget::openedDockAreas() const //============================================================================ QList CDockContainerWidget::openedDockWidgets() const { - // todo: cleanup - qInfo() << "Opened Dock Widgets: "; QList DockWidgetList; for (auto DockArea : d->DockAreas) { @@ -1909,12 +1907,6 @@ QList CDockContainerWidget::openedDockWidgets() const } } - // todo: cleanup - for (auto dockWidget : DockWidgetList) - { - qInfo() << "Opened dock widgets: " << dockWidget->objectName(); - } - return DockWidgetList; } diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index b4069fa..ebb72d9 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -282,7 +282,7 @@ void COverlayDockContainer::moveContentsToParent() const auto position = mapToGlobal(d->Area == CDockWidgetSideTab::Left ? QPoint(1,height() / 2) : QPoint(width() - 1, height() / 2)); const auto dockAreaWidget = parentContainer()->dockAreaAt(position); - if (dockAreaWidget != nullptr && !dockAreaWidget->isCentralWidgetArea()) + if (dockAreaWidget != nullptr && !dockAreaWidget->containsCentralWidget()) { parentContainer()->addDockWidget(CenterDockWidgetArea, d->DockWidget, dockAreaWidget); }