From 8637c89a6b6de04f2df4fd09b446bca8c81ba5bd Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 12 Oct 2018 15:18:05 +0200 Subject: [PATCH] Added proper support for closable feature, now the close button is disabled for floating widgets --- src/DockAreaWidget.cpp | 13 +++++++++++++ src/DockAreaWidget.h | 11 ++++++++++- src/DockContainerWidget.cpp | 13 +++++++++++++ src/DockContainerWidget.h | 11 ++++++++++- src/FloatingDockContainer.cpp | 23 +++++++++++++++++++++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 97fa5d9..a75e6de 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -654,6 +654,19 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const } } + +//============================================================================ +CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const +{ + CDockWidget::DockWidgetFeatures Features; + for (const auto DockWidget : dockWidgets()) + { + Features &= DockWidget->features(); + } + + return Features; +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 0e6ae20..c76c135 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -33,6 +33,7 @@ #include #include "ads_globals.h" +#include "DockWidget.h" class QXmlStreamWriter; @@ -42,7 +43,6 @@ struct DockAreaWidgetPrivate; class CDockManager; class CDockContainerWidget; struct DockContainerWidgetPrivate; -class CDockWidget; /** @@ -206,6 +206,15 @@ public: */ void saveState(QXmlStreamWriter& Stream) const; + /** + * This functions returns the dock widget features of all dock widget in + * this area. + * A bitwise and is used to combine the flags of all dock widgets. That + * means, if only dock widget does not support a certain flag, the whole + * dock are does not support the flag. + */ + CDockWidget::DockWidgetFeatures features() const; + public slots: /** * This activates the tab for the given tab index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index c328b7e..0daecdc 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1153,6 +1153,19 @@ QList CDockContainerWidget::dockWidgets() const } +//============================================================================ +CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const +{ + CDockWidget::DockWidgetFeatures Features; + for (const auto DockArea : d->DockAreas) + { + Features &= DockArea->features(); + } + + return Features; +} + + } // namespace ads diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index b73a079..d07f688 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -33,7 +33,7 @@ #include #include "ads_globals.h" - +#include "DockWidget.h" class QXmlStreamWriter; class QXmlStreamReader; @@ -206,6 +206,15 @@ public: */ void dumpLayout(); + /** + * This functions returns the dock widget features of all dock widget in + * this container. + * A bitwise and is used to combine the flags of all dock widgets. That + * means, if only dock widget does not support a certain flag, the whole + * dock are does not support the flag. + */ + CDockWidget::DockWidgetFeatures features() const; + signals: /** * This signal is emitted if one or multiple dock areas has been added to diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 0d151f6..95e5536 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -91,6 +91,17 @@ struct FloatingDockContainerPrivate { DraggingState = StateId; } + + /** + * Disables the window close button if the content is not closable + */ + void disableCloseButton() + { + auto Flags = _this->windowFlags(); + Flags |= Qt::CustomizeWindowHint; + Flags &= ~Qt::WindowCloseButtonHint; + _this->setWindowFlags(Flags); + } }; // struct FloatingDockContainerPrivate @@ -250,6 +261,10 @@ CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget* DockArea) : CFloatingDockContainer(DockArea->dockManager()) { d->DockContainer->addDockArea(DockArea); + if (!DockArea->features().testFlag(CDockWidget::DockWidgetClosable)) + { + d->disableCloseButton(); + } } @@ -258,6 +273,10 @@ CFloatingDockContainer::CFloatingDockContainer(CDockWidget* DockWidget) : CFloatingDockContainer(DockWidget->dockManager()) { d->DockContainer->addDockWidget(CenterDockWidgetArea, DockWidget); + if (!DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)) + { + d->disableCloseButton(); + } } //============================================================================ @@ -515,6 +534,10 @@ bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing { return false; } + if (!d->DockContainer->features().testFlag(CDockWidget::DockWidgetClosable)) + { + d->disableCloseButton(); + } onDockAreasAddedOrRemoved(); return true; }