Skip to content

Commit 6843703

Browse files
author
Uwe Kindler
committed
Fixed title bar button minimum size to enable stylesheet styling, fixed restore functionality
1 parent 115a9a5 commit 6843703

File tree

5 files changed

+132
-60
lines changed

5 files changed

+132
-60
lines changed

src/DockAreaTitleBar.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,12 @@ void DockAreaTitleBarPrivate::createButtons()
115115
TabsMenuButton->setAutoRaise(true);
116116
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
117117
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
118-
TabsMenuButton->setMaximumWidth(TabsMenuButton->iconSize().width());
119118

120119
QMenu* TabsMenu = new QMenu(TabsMenuButton);
121120
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
122121
TabsMenuButton->setMenu(TabsMenu);
123-
TopLayout->addWidget(TabsMenuButton, 0);
124122
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
123+
TopLayout->addWidget(TabsMenuButton, 0);
125124
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
126125
SLOT(onTabsMenuActionTriggered(QAction*)));
127126

@@ -130,7 +129,7 @@ void DockAreaTitleBarPrivate::createButtons()
130129
UndockButton->setObjectName("undockButton");
131130
UndockButton->setAutoRaise(true);
132131
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
133-
UndockButton->setMaximumWidth(UndockButton->iconSize().width());
132+
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
134133
TopLayout->addWidget(UndockButton, 0);
135134
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
136135

src/DockAreaWidget.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,21 @@ QList<CDockWidget*> CDockAreaWidget::openedDockWidgets() const
600600
}
601601

602602

603+
//============================================================================
604+
int CDockAreaWidget::indexOfFirstOpenDockWidget() const
605+
{
606+
for (int i = 0; i < d->ContentsLayout->count(); ++i)
607+
{
608+
if (!dockWidget(i)->isClosed())
609+
{
610+
return i;
611+
}
612+
}
613+
614+
return -1;
615+
}
616+
617+
603618
//============================================================================
604619
int CDockAreaWidget::dockWidgetsCount() const
605620
{

src/DockAreaWidget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ private slots:
196196
*/
197197
int currentIndex() const;
198198

199+
/**
200+
* Returns the index of the first open dock widgets in the list of
201+
* dock widgets.
202+
* This function is here for performance reasons. Normally it would
203+
* be possible to take the first dock widget from the list returned by
204+
* openedDockWidgets() function. But that function enumerates all
205+
* dock widgets while this functions stops after the first open dock widget.
206+
* If there are no open dock widgets, the function returns -1.
207+
*/
208+
int indexOfFirstOpenDockWidget() const;
209+
199210
/**
200211
* Returns the current active dock widget or a nullptr if there is no
201212
* active dock widget (i.e. if all dock widgets are closed)

src/DockContainerWidget.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,40 +1185,6 @@ bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
11851185
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
11861186
OldRoot->deleteLater();
11871187

1188-
// All dock widgets, that have not been processed in the restore state
1189-
// function are invisible to the user now and have no assigned dock area
1190-
// They do not belong to any dock container, until the user toggles the
1191-
// toggle view action the next time
1192-
for (auto DockWidget : dockWidgets())
1193-
{
1194-
if (DockWidget->property("dirty").toBool())
1195-
{
1196-
DockWidget->flagAsUnassigned();
1197-
}
1198-
else
1199-
{
1200-
DockWidget->toggleViewInternal(!DockWidget->property("closed").toBool());
1201-
}
1202-
}
1203-
1204-
// Finally we need to send the topLevelChanged() signals for all dock
1205-
// widgets if top level changed
1206-
CDockWidget* TopLevelDockWidget = topLevelDockWidget();
1207-
if (TopLevelDockWidget)
1208-
{
1209-
TopLevelDockWidget->emitTopLevelChanged(true);
1210-
}
1211-
else
1212-
{
1213-
for (auto DockArea : d->DockAreas)
1214-
{
1215-
for (auto DockWidget : DockArea->dockWidgets())
1216-
{
1217-
DockWidget->emitTopLevelChanged(false);
1218-
}
1219-
}
1220-
}
1221-
12221188
return true;
12231189
}
12241190

src/DockManager.cpp

Lines changed: 104 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ struct DockManagerPrivate
9696
*/
9797
bool restoreState(const QByteArray &state, int version);
9898

99+
void restoreDockWidgetsOpenState();
100+
void restoreDockAreasIndices();
101+
void emitTopLevelEvents();
102+
103+
void hideFloatingWidgets()
104+
{
105+
// Hide updates of floating widgets from use
106+
for (auto FloatingWidget : FloatingWidgets)
107+
{
108+
FloatingWidget->hide();
109+
}
110+
}
111+
112+
void markDockWidgetsDirty()
113+
{
114+
for (auto DockWidget : DockWidgetsMap)
115+
{
116+
DockWidget->setProperty("dirty", true);
117+
}
118+
}
119+
99120
/**
100121
* Restores the container with the given index
101122
*/
@@ -229,31 +250,29 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
229250

230251

231252
//============================================================================
232-
bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
253+
void DockManagerPrivate::restoreDockWidgetsOpenState()
233254
{
234-
if (!checkFormat(state, version))
235-
{
236-
qDebug() << "checkFormat: Error checking format!!!!!!!";
237-
return false;
238-
}
239-
240-
// Hide updates of floatingf widgets from use
241-
for (auto FloatingWidget : FloatingWidgets)
242-
{
243-
FloatingWidget->hide();
244-
}
245-
255+
// All dock widgets, that have not been processed in the restore state
256+
// function are invisible to the user now and have no assigned dock area
257+
// They do not belong to any dock container, until the user toggles the
258+
// toggle view action the next time
246259
for (auto DockWidget : DockWidgetsMap)
247260
{
248-
DockWidget->setProperty("dirty", true);
261+
if (DockWidget->property("dirty").toBool())
262+
{
263+
DockWidget->flagAsUnassigned();
264+
}
265+
else
266+
{
267+
DockWidget->toggleViewInternal(!DockWidget->property("closed").toBool());
268+
}
249269
}
270+
}
250271

251-
if (!restoreStateFromXml(state, version))
252-
{
253-
qDebug() << "restoreState: Error restoring state!!!!!!!";
254-
return false;
255-
}
256272

273+
//============================================================================
274+
void DockManagerPrivate::restoreDockAreasIndices()
275+
{
257276
// Now all dock areas are properly restored and we setup the index of
258277
// The dock areas because the previous toggleView() action has changed
259278
// the dock area index
@@ -265,18 +284,80 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
265284
{
266285
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
267286
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
268-
if (DockWidgetName.isEmpty())
287+
CDockWidget* DockWidget = nullptr;
288+
if (!DockWidgetName.isEmpty())
269289
{
270-
continue;
290+
DockWidget = _this->findDockWidget(DockWidgetName);
271291
}
272292

273-
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
274-
if (!DockWidget->isClosed())
293+
if (!DockWidget || DockWidget->isClosed())
294+
{
295+
int Index = DockArea->indexOfFirstOpenDockWidget();
296+
if (Index < 0)
297+
{
298+
continue;
299+
}
300+
DockArea->setCurrentIndex(Index);
301+
}
302+
else
275303
{
276304
DockArea->internalSetCurrentDockWidget(DockWidget);
277305
}
278306
}
279307
}
308+
}
309+
310+
311+
312+
//============================================================================
313+
void DockManagerPrivate::emitTopLevelEvents()
314+
{
315+
// Finally we need to send the topLevelChanged() signals for all dock
316+
// widgets if top level changed
317+
for (auto DockContainer : Containers)
318+
{
319+
CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
320+
if (TopLevelDockWidget)
321+
{
322+
TopLevelDockWidget->emitTopLevelChanged(true);
323+
}
324+
else
325+
{
326+
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
327+
{
328+
auto DockArea = DockContainer->dockArea(i);
329+
for (auto DockWidget : DockArea->dockWidgets())
330+
{
331+
DockWidget->emitTopLevelChanged(false);
332+
}
333+
}
334+
}
335+
}
336+
}
337+
338+
339+
//============================================================================
340+
bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
341+
{
342+
if (!checkFormat(state, version))
343+
{
344+
qDebug() << "checkFormat: Error checking format!!!!!!!";
345+
return false;
346+
}
347+
348+
// Hide updates of floating widgets from use
349+
hideFloatingWidgets();
350+
markDockWidgetsDirty();
351+
352+
if (!restoreStateFromXml(state, version))
353+
{
354+
qDebug() << "restoreState: Error restoring state!!!!!!!";
355+
return false;
356+
}
357+
358+
restoreDockWidgetsOpenState();
359+
restoreDockAreasIndices();
360+
emitTopLevelEvents();
280361

281362
return true;
282363
}

0 commit comments

Comments
 (0)