Skip to content

Commit c78cc17

Browse files
Properly persist dock area HideSingleWidgetTitleBar flag (and all other dock area flags)
1 parent 81a0234 commit c78cc17

File tree

5 files changed

+72
-18
lines changed

5 files changed

+72
-18
lines changed

demo/MainWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ void MainWindowPrivate::createContent()
400400
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
401401
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
402402
// Uncomment the next line if you would like to test the
403-
// setHideSingleWidgetTitleBar() functionality
404-
// TopDockArea->setHideSingleWidgetTitleBar(true);
403+
// HideSingleWidgetTitleBar functionality
404+
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
405405
ads::CDockComponentsFactory::resetDefaultFactory();
406406

407407
// We create a calendar widget and clear all flags to prevent the dock area

src/DockAreaWidget.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ struct DockAreaWidgetPrivate
250250
CDockManager* DockManager = nullptr;
251251
bool UpdateTitleBarButtons = false;
252252
DockWidgetAreas AllowedAreas = DefaultAllowedAreas;
253-
bool HideSingleWidgetTitleBar = false;
254253
QSize MinSizeHint;
254+
CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags};
255255

256256
/**
257257
* Private data constructor
@@ -747,7 +747,7 @@ void CDockAreaWidget::updateTitleBarVisibility()
747747
{
748748
bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating()
749749
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
750-
Hidden |= (d->HideSingleWidgetTitleBar && openDockWidgetsCount() == 1);
750+
Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
751751
d->TitleBar->setVisible(!Hidden);
752752
}
753753
}
@@ -772,12 +772,16 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
772772
auto CurrentDockWidget = currentDockWidget();
773773
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
774774
s.writeAttribute("Current", Name);
775-
auto AllowedAreas = allowedAreas();
776-
// To keep the saved XML data small, we only save the allowed areas if
777-
// the value is different from the default value
778-
if (AllowedAreas != DefaultAllowedAreas)
775+
// To keep the saved XML data small, we only save the allowed areas and the
776+
// dock area flags if the values are different from the default values
777+
if (d->AllowedAreas != DefaultAllowedAreas)
779778
{
780-
s.writeAttribute("AllowedAreas", QString::number(AllowedAreas, 16));
779+
s.writeAttribute("AllowedAreas", QString::number(d->AllowedAreas, 16));
780+
}
781+
782+
if (d->Flags != DefaultFlags)
783+
{
784+
s.writeAttribute("Flags", QString::number(d->Flags, 16));
781785
}
782786
ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
783787
<< " Current: " << Name);
@@ -872,11 +876,32 @@ DockWidgetAreas CDockAreaWidget::allowedAreas() const
872876
return d->AllowedAreas;
873877
}
874878

879+
875880
//============================================================================
876-
void CDockAreaWidget::setHideSingleWidgetTitleBar(bool hide)
881+
CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const
877882
{
878-
d->HideSingleWidgetTitleBar = hide;
879-
updateTitleBarVisibility();
883+
return d->Flags;
884+
}
885+
886+
887+
//============================================================================
888+
void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags)
889+
{
890+
auto ChangedFlags = d->Flags ^ Flags;
891+
d->Flags = Flags;
892+
if (ChangedFlags.testFlag(HideSingleWidgetTitleBar))
893+
{
894+
updateTitleBarVisibility();
895+
}
896+
}
897+
898+
899+
//============================================================================
900+
void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On)
901+
{
902+
auto flags = dockAreaFlags();
903+
internal::setFlag(flags, Flag, On);
904+
setDockAreaFlags(flags);
880905
}
881906

882907

src/DockAreaWidget.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ protected slots:
143143
public:
144144
using Super = QFrame;
145145

146+
/**
147+
* Dock area related flags
148+
*/
149+
enum eDockAreaFlag
150+
{
151+
HideSingleWidgetTitleBar = 0x0001,
152+
DefaultFlags = 0x0000
153+
};
154+
Q_DECLARE_FLAGS(DockAreaFlags, eDockAreaFlag)
155+
146156
/**
147157
* Default Constructor
148158
*/
@@ -273,15 +283,28 @@ protected slots:
273283
DockWidgetAreas allowedAreas() const;
274284

275285
/**
276-
* Will hide the title bar when set to true and there is only one
277-
* dock widget in this area
286+
* Returns the title bar of this dock area
278287
*/
279-
void setHideSingleWidgetTitleBar(bool hide);
288+
CDockAreaTitleBar* titleBar() const;
280289

281290
/**
282-
* Returns the title bar of this dock area
291+
* Returns the dock area flags - a combination of flags that configure the
292+
* appearance and features of the dock area.
293+
* \see setDockAreaFlasg()
283294
*/
284-
CDockAreaTitleBar* titleBar() const;
295+
DockAreaFlags dockAreaFlags() const;
296+
297+
/**
298+
* Sets the dock area flags - a combination of flags that configure the
299+
* appearance and features of the dock area
300+
*/
301+
void setDockAreaFlags(DockAreaFlags Flags);
302+
303+
/**
304+
* Sets the dock area flag Flag on this widget if on is true; otherwise
305+
* clears the flag.
306+
*/
307+
void setDockAreaFlag(eDockAreaFlag Flag, bool On);
285308

286309
public slots:
287310
/**

src/DockContainerWidget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
947947
{
948948
DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16));
949949
}
950+
951+
const auto FlagsAttribute = s.attributes().value("Flags");
952+
if (!FlagsAttribute.isEmpty())
953+
{
954+
DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16));
955+
}
950956
}
951957

952958
while (s.readNextStartElement())

src/DockManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public slots:
513513

514514
/**
515515
* This signal is emitted just before the given dock widget is removed
516-
* from the
516+
* from the dock manager
517517
*/
518518
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
519519

0 commit comments

Comments
 (0)