diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 518e76f..346d76d 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -320,7 +320,7 @@ void MainWindowPrivate::createContent() appendFeaturStringToWindowTitle(FileSystemWidget); auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget); - // We create a calender widget and clear all flags to prevent the dock area + // We create a calendar widget and clear all flags to prevent the dock area // from closing DockWidget = createCalendarDockWidget(ViewMenu); DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false); @@ -481,6 +481,12 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment the following line if you want to show tabs menu button on DockArea's title bar only when there are more than one tab and at least of them has elided title //CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true); + // uncomment the following line if you want floating container to always show application title instead of active dock widget's title + //CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false); + + // uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon + //CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true); + // Now create the dock manager and its content d->DockManager = new CDockManager(this); diff --git a/src/DockManager.h b/src/DockManager.h index 73f6c22..a94ea41 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -162,6 +162,8 @@ public: DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button DockAreaHideDisabledButtons = 0x10000, //!< If the flag is set disabled dock area buttons will not appear on the tollbar at all (enabling them will bring them back) DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set dock area will disable a tabs menu button when there is only one tab in the area + FloatingContainerHasWidgetTitle = 0x40000, + FloatingContainerHasWidgetIcon = 0x80000, DefaultDockAreaButtons = DockAreaHasCloseButton @@ -170,7 +172,8 @@ public: DefaultBaseConfig = DefaultDockAreaButtons | ActiveTabHasCloseButton - | XmlCompressionEnabled,///< default base configuration settings + | XmlCompressionEnabled + | FloatingContainerHasWidgetTitle,///< default base configuration settings DefaultOpaqueConfig = DefaultBaseConfig | OpaqueSplitterResize diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index e04dce5..ea782d4 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -79,6 +79,14 @@ struct FloatingDockContainerPrivate void titleMouseReleaseEvent(); void updateDropOverlays(const QPoint &GlobalPos); + /** + * Returns true if the given config flag is set + */ + static bool testConfigFlag(CDockManager::eConfigFlag Flag) + { + return CDockManager::configFlags().testFlag(Flag); + } + /** * Tests is a certain state is active */ @@ -100,6 +108,31 @@ struct FloatingDockContainerPrivate _this->setWindowTitle(Text); #endif } + + void reflectCurrentWidget(CDockWidget* CurrentWidget) + { + // reflect CurrentWidget's title if configured to do so, otherwise display application name as window title + if (testConfigFlag(CDockManager::FloatingContainerHasWidgetTitle)) + { + setWindowTitle(CurrentWidget->windowTitle()); + } + else + { + setWindowTitle(qApp->applicationDisplayName()); + } + + // reflect CurrentWidget's icon if configured to do so, otherwise display application icon as window icon + QIcon CurrentWidgetIcon = CurrentWidget->icon(); + if (testConfigFlag(CDockManager::FloatingContainerHasWidgetIcon) + && !CurrentWidgetIcon.isNull()) + { + _this->setWindowIcon(CurrentWidget->icon()); + } + else + { + _this->setWindowIcon(QApplication::windowIcon()); + } + } }; // struct FloatingDockContainerPrivate @@ -537,8 +570,8 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved() if (TopLevelDockArea) { d->SingleDockArea = TopLevelDockArea; - d->setWindowTitle( - d->SingleDockArea->currentDockWidget()->windowTitle()); + CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget(); + d->reflectCurrentWidget(CurrentWidget); connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this, SLOT(onDockAreaCurrentChanged(int))); } @@ -551,6 +584,7 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved() d->SingleDockArea = nullptr; } d->setWindowTitle(qApp->applicationDisplayName()); + setWindowIcon(QApplication::windowIcon()); } } @@ -560,11 +594,13 @@ void CFloatingDockContainer::updateWindowTitle() auto TopLevelDockArea = d->DockContainer->topLevelDockArea(); if (TopLevelDockArea) { - d->setWindowTitle(TopLevelDockArea->currentDockWidget()->windowTitle()); + CDockWidget* CurrentWidget = TopLevelDockArea->currentDockWidget(); + d->reflectCurrentWidget(CurrentWidget); } else { d->setWindowTitle(qApp->applicationDisplayName()); + setWindowIcon(QApplication::windowIcon()); } } @@ -572,7 +608,8 @@ void CFloatingDockContainer::updateWindowTitle() void CFloatingDockContainer::onDockAreaCurrentChanged(int Index) { Q_UNUSED(Index); - d->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle()); + CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget(); + d->reflectCurrentWidget(CurrentWidget); } //============================================================================