mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Properly persist dock area HideSingleWidgetTitleBar flag (and all other dock area flags)
This commit is contained in:
parent
81a0234b05
commit
c78cc17730
@ -400,8 +400,8 @@ void MainWindowPrivate::createContent()
|
||||
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
|
||||
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
|
||||
// Uncomment the next line if you would like to test the
|
||||
// setHideSingleWidgetTitleBar() functionality
|
||||
// TopDockArea->setHideSingleWidgetTitleBar(true);
|
||||
// HideSingleWidgetTitleBar functionality
|
||||
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
|
||||
ads::CDockComponentsFactory::resetDefaultFactory();
|
||||
|
||||
// We create a calendar widget and clear all flags to prevent the dock area
|
||||
|
@ -250,8 +250,8 @@ struct DockAreaWidgetPrivate
|
||||
CDockManager* DockManager = nullptr;
|
||||
bool UpdateTitleBarButtons = false;
|
||||
DockWidgetAreas AllowedAreas = DefaultAllowedAreas;
|
||||
bool HideSingleWidgetTitleBar = false;
|
||||
QSize MinSizeHint;
|
||||
CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags};
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -747,7 +747,7 @@ void CDockAreaWidget::updateTitleBarVisibility()
|
||||
{
|
||||
bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating()
|
||||
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
|
||||
Hidden |= (d->HideSingleWidgetTitleBar && openDockWidgetsCount() == 1);
|
||||
Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
|
||||
d->TitleBar->setVisible(!Hidden);
|
||||
}
|
||||
}
|
||||
@ -772,12 +772,16 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
||||
auto CurrentDockWidget = currentDockWidget();
|
||||
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
|
||||
s.writeAttribute("Current", Name);
|
||||
auto AllowedAreas = allowedAreas();
|
||||
// To keep the saved XML data small, we only save the allowed areas if
|
||||
// the value is different from the default value
|
||||
if (AllowedAreas != DefaultAllowedAreas)
|
||||
// To keep the saved XML data small, we only save the allowed areas and the
|
||||
// dock area flags if the values are different from the default values
|
||||
if (d->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()
|
||||
<< " Current: " << Name);
|
||||
@ -872,11 +876,32 @@ DockWidgetAreas CDockAreaWidget::allowedAreas() const
|
||||
return d->AllowedAreas;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setHideSingleWidgetTitleBar(bool hide)
|
||||
CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const
|
||||
{
|
||||
d->HideSingleWidgetTitleBar = hide;
|
||||
updateTitleBarVisibility();
|
||||
return d->Flags;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags)
|
||||
{
|
||||
auto ChangedFlags = d->Flags ^ Flags;
|
||||
d->Flags = Flags;
|
||||
if (ChangedFlags.testFlag(HideSingleWidgetTitleBar))
|
||||
{
|
||||
updateTitleBarVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On)
|
||||
{
|
||||
auto flags = dockAreaFlags();
|
||||
internal::setFlag(flags, Flag, On);
|
||||
setDockAreaFlags(flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,6 +143,16 @@ protected slots:
|
||||
public:
|
||||
using Super = QFrame;
|
||||
|
||||
/**
|
||||
* Dock area related flags
|
||||
*/
|
||||
enum eDockAreaFlag
|
||||
{
|
||||
HideSingleWidgetTitleBar = 0x0001,
|
||||
DefaultFlags = 0x0000
|
||||
};
|
||||
Q_DECLARE_FLAGS(DockAreaFlags, eDockAreaFlag)
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
@ -272,17 +282,30 @@ public:
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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:
|
||||
/**
|
||||
* This activates the tab for the given tab index.
|
||||
|
@ -947,6 +947,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
|
||||
{
|
||||
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())
|
||||
|
@ -513,7 +513,7 @@ signals:
|
||||
|
||||
/**
|
||||
* This signal is emitted just before the given dock widget is removed
|
||||
* from the
|
||||
* from the dock manager
|
||||
*/
|
||||
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user