From 2afe62ec77c558c6c81435b479a99c0a188c5113 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 6 Dec 2021 09:42:12 +0100 Subject: [PATCH] Fixed issue #378 - Don't show empty floating containers on startup --- demo/MainWindow.cpp | 9 +++++++++ src/DockContainerWidget.cpp | 15 +++++++++++++++ src/DockContainerWidget.h | 7 +++++++ src/DockManager.cpp | 7 ++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 9745755..52605f0 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -466,6 +466,15 @@ void MainWindowPrivate::createContent() Action = ui.menuTests->addAction(QString("Raise %1").arg(DockWidget->windowTitle())); DockWidget->connect(Action, SIGNAL(triggered()), SLOT(raise())); + // Test hidden floating dock widget + DockWidget = createLongTextLabelDockWidget(); + DockManager->addDockWidgetFloating(DockWidget); + DockWidget->toggleView(false); + + // Test visible floating dock widget + DockWidget = createCalendarDockWidget(); + DockManager->addDockWidgetFloating(DockWidget); + #ifdef Q_OS_WIN #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index afd2b9c..797fbb2 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1625,6 +1625,21 @@ QList CDockContainerWidget::openedDockAreas() const } +//============================================================================ +bool CDockContainerWidget::hasOpenDockAreas() const +{ + for (auto DockArea : d->DockAreas) + { + if (!DockArea->isHidden()) + { + return true; + } + } + + return false; +} + + //============================================================================ void CDockContainerWidget::saveState(QXmlStreamWriter& s) const { diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 8a323ba..06ea710 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -216,6 +216,13 @@ public: */ QList openedDockAreas() const; + /** + * This function returns true, if the container has open dock areas. + * This functions is a little bit faster than calling openedDockAreas().isEmpty() + * because it returns as soon as it finds an open dock area + */ + bool hasOpenDockAreas() const; + /** * This function returns true if this dock area has only one single * visible dock widget. diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 9df3a5a..d56e930 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -762,7 +762,12 @@ void CDockManager::showEvent(QShowEvent *event) for (auto FloatingWidget : d->UninitializedFloatingWidgets) { - FloatingWidget->show(); + // Check, if someone closed a floating dock widget before the dock + // manager is shown + if (FloatingWidget->dockContainer()->hasOpenDockAreas()) + { + FloatingWidget->show(); + } } d->UninitializedFloatingWidgets.clear(); }