Skip to content

Commit f387c6a

Browse files
2 parents 41173d0 + 7ba20f3 commit f387c6a

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

demo/MainWindow.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void MainWindowPrivate::createContent()
346346
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
347347
ads::CDockComponentsFactory::resetDefaultFactory();
348348

349-
// We create a calender widget and clear all flags to prevent the dock area
349+
// We create a calendar widget and clear all flags to prevent the dock area
350350
// from closing
351351
DockWidget = createCalendarDockWidget(ViewMenu);
352352
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
@@ -507,6 +507,12 @@ CMainWindow::CMainWindow(QWidget *parent) :
507507
// 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
508508
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
509509

510+
// uncomment the following line if you want floating container to always show application title instead of active dock widget's title
511+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false);
512+
513+
// uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon
514+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true);
515+
510516
// Now create the dock manager and its content
511517
d->DockManager = new CDockManager(this);
512518

src/DockManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
163163
DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button
164164
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)
165165
DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set dock area will disable a tabs menu button when there is only one tab in the area
166+
FloatingContainerHasWidgetTitle = 0x40000,
167+
FloatingContainerHasWidgetIcon = 0x80000,
166168

167169

168170
DefaultDockAreaButtons = DockAreaHasCloseButton
@@ -171,7 +173,8 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
171173

172174
DefaultBaseConfig = DefaultDockAreaButtons
173175
| ActiveTabHasCloseButton
174-
| XmlCompressionEnabled,///< default base configuration settings
176+
| XmlCompressionEnabled
177+
| FloatingContainerHasWidgetTitle,///< default base configuration settings
175178

176179
DefaultOpaqueConfig = DefaultBaseConfig
177180
| OpaqueSplitterResize

src/FloatingDockContainer.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ struct FloatingDockContainerPrivate
7979
void titleMouseReleaseEvent();
8080
void updateDropOverlays(const QPoint &GlobalPos);
8181

82+
/**
83+
* Returns true if the given config flag is set
84+
*/
85+
static bool testConfigFlag(CDockManager::eConfigFlag Flag)
86+
{
87+
return CDockManager::configFlags().testFlag(Flag);
88+
}
89+
8290
/**
8391
* Tests is a certain state is active
8492
*/
@@ -100,6 +108,31 @@ struct FloatingDockContainerPrivate
100108
_this->setWindowTitle(Text);
101109
#endif
102110
}
111+
112+
void reflectCurrentWidget(CDockWidget* CurrentWidget)
113+
{
114+
// reflect CurrentWidget's title if configured to do so, otherwise display application name as window title
115+
if (testConfigFlag(CDockManager::FloatingContainerHasWidgetTitle))
116+
{
117+
setWindowTitle(CurrentWidget->windowTitle());
118+
}
119+
else
120+
{
121+
setWindowTitle(qApp->applicationDisplayName());
122+
}
123+
124+
// reflect CurrentWidget's icon if configured to do so, otherwise display application icon as window icon
125+
QIcon CurrentWidgetIcon = CurrentWidget->icon();
126+
if (testConfigFlag(CDockManager::FloatingContainerHasWidgetIcon)
127+
&& !CurrentWidgetIcon.isNull())
128+
{
129+
_this->setWindowIcon(CurrentWidget->icon());
130+
}
131+
else
132+
{
133+
_this->setWindowIcon(QApplication::windowIcon());
134+
}
135+
}
103136
};
104137
// struct FloatingDockContainerPrivate
105138

@@ -537,8 +570,8 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
537570
if (TopLevelDockArea)
538571
{
539572
d->SingleDockArea = TopLevelDockArea;
540-
d->setWindowTitle(
541-
d->SingleDockArea->currentDockWidget()->windowTitle());
573+
CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget();
574+
d->reflectCurrentWidget(CurrentWidget);
542575
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
543576
SLOT(onDockAreaCurrentChanged(int)));
544577
}
@@ -551,6 +584,7 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
551584
d->SingleDockArea = nullptr;
552585
}
553586
d->setWindowTitle(qApp->applicationDisplayName());
587+
setWindowIcon(QApplication::windowIcon());
554588
}
555589
}
556590

@@ -560,19 +594,22 @@ void CFloatingDockContainer::updateWindowTitle()
560594
auto TopLevelDockArea = d->DockContainer->topLevelDockArea();
561595
if (TopLevelDockArea)
562596
{
563-
d->setWindowTitle(TopLevelDockArea->currentDockWidget()->windowTitle());
597+
CDockWidget* CurrentWidget = TopLevelDockArea->currentDockWidget();
598+
d->reflectCurrentWidget(CurrentWidget);
564599
}
565600
else
566601
{
567602
d->setWindowTitle(qApp->applicationDisplayName());
603+
setWindowIcon(QApplication::windowIcon());
568604
}
569605
}
570606

571607
//============================================================================
572608
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
573609
{
574610
Q_UNUSED(Index);
575-
d->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
611+
CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget();
612+
d->reflectCurrentWidget(CurrentWidget);
576613
}
577614

578615
//============================================================================

0 commit comments

Comments
 (0)