1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-03-16 02:59:51 +08:00

Properly persist dock area HideSingleWidgetTitleBar flag (and all other dock area flags)

This commit is contained in:
Uwe Kindler 2020-08-18 10:48:35 +02:00
parent 81a0234b05
commit c78cc17730
5 changed files with 73 additions and 19 deletions

View File

@ -400,8 +400,8 @@ void MainWindowPrivate::createContent()
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory()); ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget); auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
// Uncomment the next line if you would like to test the // Uncomment the next line if you would like to test the
// setHideSingleWidgetTitleBar() functionality // HideSingleWidgetTitleBar functionality
// TopDockArea->setHideSingleWidgetTitleBar(true); // TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
ads::CDockComponentsFactory::resetDefaultFactory(); ads::CDockComponentsFactory::resetDefaultFactory();
// We create a calendar widget and clear all flags to prevent the dock area // We create a calendar widget and clear all flags to prevent the dock area

View File

@ -250,8 +250,8 @@ struct DockAreaWidgetPrivate
CDockManager* DockManager = nullptr; CDockManager* DockManager = nullptr;
bool UpdateTitleBarButtons = false; bool UpdateTitleBarButtons = false;
DockWidgetAreas AllowedAreas = DefaultAllowedAreas; DockWidgetAreas AllowedAreas = DefaultAllowedAreas;
bool HideSingleWidgetTitleBar = false;
QSize MinSizeHint; QSize MinSizeHint;
CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags};
/** /**
* Private data constructor * Private data constructor
@ -747,7 +747,7 @@ void CDockAreaWidget::updateTitleBarVisibility()
{ {
bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating() bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating()
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)); || CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
Hidden |= (d->HideSingleWidgetTitleBar && openDockWidgetsCount() == 1); Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
d->TitleBar->setVisible(!Hidden); d->TitleBar->setVisible(!Hidden);
} }
} }
@ -772,12 +772,16 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
auto CurrentDockWidget = currentDockWidget(); auto CurrentDockWidget = currentDockWidget();
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : ""; QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
s.writeAttribute("Current", Name); s.writeAttribute("Current", Name);
auto AllowedAreas = allowedAreas(); // To keep the saved XML data small, we only save the allowed areas and the
// To keep the saved XML data small, we only save the allowed areas if // dock area flags if the values are different from the default values
// the value is different from the default value if (d->AllowedAreas != DefaultAllowedAreas)
if (AllowedAreas != DefaultAllowedAreas)
{ {
s.writeAttribute("AllowedAreas", QString::number(AllowedAreas, 16)); s.writeAttribute("AllowedAreas", QString::number(d->AllowedAreas, 16));
}
if (d->Flags != DefaultFlags)
{
s.writeAttribute("Flags", QString::number(d->Flags, 16));
} }
ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count() ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
<< " Current: " << Name); << " Current: " << Name);
@ -872,12 +876,33 @@ DockWidgetAreas CDockAreaWidget::allowedAreas() const
return d->AllowedAreas; return d->AllowedAreas;
} }
//============================================================================ //============================================================================
void CDockAreaWidget::setHideSingleWidgetTitleBar(bool hide) CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const
{
return d->Flags;
}
//============================================================================
void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags)
{
auto ChangedFlags = d->Flags ^ Flags;
d->Flags = Flags;
if (ChangedFlags.testFlag(HideSingleWidgetTitleBar))
{ {
d->HideSingleWidgetTitleBar = hide;
updateTitleBarVisibility(); updateTitleBarVisibility();
} }
}
//============================================================================
void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On)
{
auto flags = dockAreaFlags();
internal::setFlag(flags, Flag, On);
setDockAreaFlags(flags);
}
//============================================================================ //============================================================================

View File

@ -143,6 +143,16 @@ protected slots:
public: public:
using Super = QFrame; using Super = QFrame;
/**
* Dock area related flags
*/
enum eDockAreaFlag
{
HideSingleWidgetTitleBar = 0x0001,
DefaultFlags = 0x0000
};
Q_DECLARE_FLAGS(DockAreaFlags, eDockAreaFlag)
/** /**
* Default Constructor * Default Constructor
*/ */
@ -272,17 +282,30 @@ public:
*/ */
DockWidgetAreas allowedAreas() const; DockWidgetAreas allowedAreas() const;
/**
* Will hide the title bar when set to true and there is only one
* dock widget in this area
*/
void setHideSingleWidgetTitleBar(bool hide);
/** /**
* Returns the title bar of this dock area * Returns the title bar of this dock area
*/ */
CDockAreaTitleBar* titleBar() const; CDockAreaTitleBar* titleBar() const;
/**
* Returns the dock area flags - a combination of flags that configure the
* appearance and features of the dock area.
* \see setDockAreaFlasg()
*/
DockAreaFlags dockAreaFlags() const;
/**
* Sets the dock area flags - a combination of flags that configure the
* appearance and features of the dock area
*/
void setDockAreaFlags(DockAreaFlags Flags);
/**
* Sets the dock area flag Flag on this widget if on is true; otherwise
* clears the flag.
*/
void setDockAreaFlag(eDockAreaFlag Flag, bool On);
public slots: public slots:
/** /**
* This activates the tab for the given tab index. * This activates the tab for the given tab index.

View File

@ -947,6 +947,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
{ {
DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16)); DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16));
} }
const auto FlagsAttribute = s.attributes().value("Flags");
if (!FlagsAttribute.isEmpty())
{
DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16));
}
} }
while (s.readNextStartElement()) while (s.readNextStartElement())

View File

@ -513,7 +513,7 @@ signals:
/** /**
* This signal is emitted just before the given dock widget is removed * This signal is emitted just before the given dock widget is removed
* from the * from the dock manager
*/ */
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget); void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);