Skip to content

Commit 7ba20f3

Browse files
authored
Icon of floating window (#116)
* FloatingContainerHasWidgetTitle and FloatingContainerHasWidgetIcon config flags
1 parent a4ef161 commit 7ba20f3

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
@@ -320,7 +320,7 @@ void MainWindowPrivate::createContent()
320320
appendFeaturStringToWindowTitle(FileSystemWidget);
321321
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
322322

323-
// We create a calender widget and clear all flags to prevent the dock area
323+
// We create a calendar widget and clear all flags to prevent the dock area
324324
// from closing
325325
DockWidget = createCalendarDockWidget(ViewMenu);
326326
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
@@ -481,6 +481,12 @@ CMainWindow::CMainWindow(QWidget *parent) :
481481
// 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
482482
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
483483

484+
// uncomment the following line if you want floating container to always show application title instead of active dock widget's title
485+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false);
486+
487+
// uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon
488+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true);
489+
484490
// Now create the dock manager and its content
485491
d->DockManager = new CDockManager(this);
486492

src/DockManager.h

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

166168

167169
DefaultDockAreaButtons = DockAreaHasCloseButton
@@ -170,7 +172,8 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
170172

171173
DefaultBaseConfig = DefaultDockAreaButtons
172174
| ActiveTabHasCloseButton
173-
| XmlCompressionEnabled,///< default base configuration settings
175+
| XmlCompressionEnabled
176+
| FloatingContainerHasWidgetTitle,///< default base configuration settings
174177

175178
DefaultOpaqueConfig = DefaultBaseConfig
176179
| 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)