From 78a4166e4292913318b46615124006b40d3ebc8d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 25 Mar 2022 13:31:40 +0100 Subject: [PATCH] Updated CFloatingDockContainer::closeEvent() function to delete all dock widgets with DockWidgetDeleteOnClose flag set --- src/DockContainerWidget.cpp | 16 ++++++++++++ src/DockContainerWidget.h | 5 ++++ src/FloatingDockContainer.cpp | 46 +++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 63a049b..5451eb3 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1625,6 +1625,22 @@ QList CDockContainerWidget::openedDockAreas() const } +//============================================================================ +QList CDockContainerWidget::openedDockWidgets() const +{ + QList DockWidgetList; + for (auto DockArea : d->DockAreas) + { + if (!DockArea->isHidden()) + { + DockWidgetList.append(DockArea->openedDockWidgets()); + } + } + + return DockWidgetList; +} + + //============================================================================ bool CDockContainerWidget::hasOpenDockAreas() const { diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 06ea710..73c8982 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -216,6 +216,11 @@ public: */ QList openedDockAreas() const; + /** + * Returns a list for all open dock widgets in all open dock areas + */ + QList openedDockWidgets() const; + /** * This function returns true, if the container has open dock areas. * This functions is a little bit faster than calling openedDockAreas().isEmpty() diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index b1aaba9..b3250c8 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -802,29 +802,33 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event) ADS_PRINT("CFloatingDockContainer closeEvent"); d->setState(DraggingInactive); event->ignore(); - - if (isClosable()) + if (!isClosable()) { - auto TopLevelDockWidget = topLevelDockWidget(); - if (TopLevelDockWidget && TopLevelDockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) - { - if (!TopLevelDockWidget->closeDockWidgetInternal()) - { - return; - } - } - - // In Qt version after 5.9.2 there seems to be a bug that causes the - // QWidget::event() function to not receive any NonClientArea mouse - // events anymore after a close/show cycle. The bug is reported here: - // https://bugreports.qt.io/browse/QTBUG-73295 - // The following code is a workaround for Qt versions > 5.9.2 that seems - // to work - // Starting from Qt version 5.12.2 this seems to work again. But - // now the QEvent::NonClientAreaMouseButtonPress function returns always - // Qt::RightButton even if the left button was pressed - this->hide(); + return; } + + for (auto DockWidget : d->DockContainer->openedDockWidgets()) + { + if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) + { + DockWidget->closeDockWidgetInternal(); + } + else + { + DockWidget->toggleView(false); + } + } + + // In Qt version after 5.9.2 there seems to be a bug that causes the + // QWidget::event() function to not receive any NonClientArea mouse + // events anymore after a close/show cycle. The bug is reported here: + // https://bugreports.qt.io/browse/QTBUG-73295 + // The following code is a workaround for Qt versions > 5.9.2 that seems + // to work + // Starting from Qt version 5.12.2 this seems to work again. But + // now the QEvent::NonClientAreaMouseButtonPress function returns always + // Qt::RightButton even if the left button was pressed + this->hide(); } //============================================================================