diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index a4cb640..5127242 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -400,8 +400,8 @@ void MainWindowPrivate::createContent() ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory()); auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget); // Uncomment the next line if you would like to test the - // setHideSingleWidgetTitleBar() functionality - // TopDockArea->setHideSingleWidgetTitleBar(true); + // HideSingleWidgetTitleBar functionality + // TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true); ads::CDockComponentsFactory::resetDefaultFactory(); // We create a calendar widget and clear all flags to prevent the dock area diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index dad429d..092f997 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -250,8 +250,8 @@ struct DockAreaWidgetPrivate CDockManager* DockManager = nullptr; bool UpdateTitleBarButtons = false; DockWidgetAreas AllowedAreas = DefaultAllowedAreas; - bool HideSingleWidgetTitleBar = false; QSize MinSizeHint; + CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags}; /** * Private data constructor @@ -747,7 +747,7 @@ void CDockAreaWidget::updateTitleBarVisibility() { bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating() || CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)); - Hidden |= (d->HideSingleWidgetTitleBar && openDockWidgetsCount() == 1); + Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1); d->TitleBar->setVisible(!Hidden); } } @@ -772,12 +772,16 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const auto CurrentDockWidget = currentDockWidget(); QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : ""; s.writeAttribute("Current", Name); - auto AllowedAreas = allowedAreas(); - // To keep the saved XML data small, we only save the allowed areas if - // the value is different from the default value - if (AllowedAreas != DefaultAllowedAreas) + // To keep the saved XML data small, we only save the allowed areas and the + // dock area flags if the values are different from the default values + if (d->AllowedAreas != DefaultAllowedAreas) { - s.writeAttribute("AllowedAreas", QString::number(AllowedAreas, 16)); + s.writeAttribute("AllowedAreas", QString::number(d->AllowedAreas, 16)); + } + + if (d->Flags != DefaultFlags) + { + s.writeAttribute("Flags", QString::number(d->Flags, 16)); } ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count() << " Current: " << Name); @@ -872,11 +876,32 @@ DockWidgetAreas CDockAreaWidget::allowedAreas() const return d->AllowedAreas; } + //============================================================================ -void CDockAreaWidget::setHideSingleWidgetTitleBar(bool hide) +CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const { - d->HideSingleWidgetTitleBar = hide; - updateTitleBarVisibility(); + return d->Flags; +} + + +//============================================================================ +void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags) +{ + auto ChangedFlags = d->Flags ^ Flags; + d->Flags = Flags; + if (ChangedFlags.testFlag(HideSingleWidgetTitleBar)) + { + updateTitleBarVisibility(); + } +} + + +//============================================================================ +void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On) +{ + auto flags = dockAreaFlags(); + internal::setFlag(flags, Flag, On); + setDockAreaFlags(flags); } diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 3deada4..337eac2 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -143,6 +143,16 @@ protected slots: public: using Super = QFrame; + /** + * Dock area related flags + */ + enum eDockAreaFlag + { + HideSingleWidgetTitleBar = 0x0001, + DefaultFlags = 0x0000 + }; + Q_DECLARE_FLAGS(DockAreaFlags, eDockAreaFlag) + /** * Default Constructor */ @@ -272,17 +282,30 @@ public: */ DockWidgetAreas allowedAreas() const; - /** - * Will hide the title bar when set to true and there is only one - * dock widget in this area - */ - void setHideSingleWidgetTitleBar(bool hide); - /** * Returns the title bar of this dock area */ CDockAreaTitleBar* titleBar() const; + /** + * Returns the dock area flags - a combination of flags that configure the + * appearance and features of the dock area. + * \see setDockAreaFlasg() + */ + DockAreaFlags dockAreaFlags() const; + + /** + * Sets the dock area flags - a combination of flags that configure the + * appearance and features of the dock area + */ + void setDockAreaFlags(DockAreaFlags Flags); + + /** + * Sets the dock area flag Flag on this widget if on is true; otherwise + * clears the flag. + */ + void setDockAreaFlag(eDockAreaFlag Flag, bool On); + public slots: /** * This activates the tab for the given tab index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index c3eecf6..4d716c6 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -947,6 +947,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s, { DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16)); } + + const auto FlagsAttribute = s.attributes().value("Flags"); + if (!FlagsAttribute.isEmpty()) + { + DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16)); + } } while (s.readNextStartElement()) diff --git a/src/DockManager.h b/src/DockManager.h index 2f1df43..b682c43 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -513,7 +513,7 @@ signals: /** * This signal is emitted just before the given dock widget is removed - * from the + * from the dock manager */ void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);