Changed AutoHide save and restore code

This commit is contained in:
Uwe Kindler 2022-10-27 13:25:40 +02:00
parent 2d67e9e1e5
commit 85d7b3047c
8 changed files with 135 additions and 52 deletions

View File

@ -291,10 +291,16 @@ void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget)
}
d->DockArea->addDockWidget(DockWidget);
d->DockWidget->sideTabWidget()->updateOrientationAndSpacing(d->SideTabBarArea);
// Prevent overriding of d->Size parameter when this function is called during
// state restoring
if (!DockWidget->dockManager()->isRestoringState())
{
// The initial size should be a little bit bigger than the original dock
// area size to prevent that the resize handle of this auto hid dock area
// is near of the splitter of the old dock area.
d->Size = OldDockArea->size() + QSize(16, 16);
}
updateSize();
}
@ -343,7 +349,6 @@ void CAutoHideDockContainer::cleanupAndDelete()
//============================================================================
void CAutoHideDockContainer::saveState(QXmlStreamWriter& s)
{
s.writeAttribute("SideTabBarArea", QString::number(sideTabBarArea()));
s.writeAttribute("Size", QString::number(d->isHorizontal() ? d->Size.height() : d->Size.width()));
qDebug() << ": saveState Size: " << d->Size;

View File

@ -1099,7 +1099,7 @@ void CDockAreaWidget::toggleAutoHideArea(bool Enable)
continue;
}
dockContainer()->createAndInitializeAutoHideDockWidgetContainer(area, DockWidget, DockWidget->autoHideInsertOrder());
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget, DockWidget->autoHideInsertOrder());
}
}
else
@ -1109,7 +1109,7 @@ void CDockAreaWidget::toggleAutoHideArea(bool Enable)
{
return;
}
dockContainer()->createAndInitializeAutoHideDockWidgetContainer(area, DockWidget, DockWidget->autoHideInsertOrder());
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget, DockWidget->autoHideInsertOrder());
}
}

View File

@ -258,9 +258,9 @@ public:
bool restoreAutoHideDockArea(CDockingStateReader& s, SideBarLocation area, bool Testing);
/**
* Restores either a dock area or an auto hide dock area depending on the value in the XML
* Restores a auto hide side bar
*/
bool restoreDockOrAutoHideDockArea(CDockingStateReader& Stream, QWidget*& CreatedWidget,
bool restoreSideBar(CDockingStateReader& Stream, QWidget*& CreatedWidget,
bool Testing);
/**
@ -898,21 +898,32 @@ void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidge
}
}
void DockContainerWidgetPrivate::saveAutoHideWidgetsState(QXmlStreamWriter& Stream)
void DockContainerWidgetPrivate::saveAutoHideWidgetsState(QXmlStreamWriter& s)
{
for (const auto sideTabBar : SideTabBarWidgets.values())
{
for (auto itemIndex = 0; itemIndex < sideTabBar->tabCount(); itemIndex++)
{
const auto sideTab = sideTabBar->tabAt(itemIndex);
if (sideTab == nullptr)
if (!sideTabBar->tabCount())
{
continue;
}
const auto dockArea = sideTab->dockWidget()->dockAreaWidget();
dockArea->saveState(Stream);
s.writeStartElement("SideBar");
s.writeAttribute("Area", QString::number(sideTabBar->sideTabBarArea()));
s.writeAttribute("Tabs", QString::number(sideTabBar->tabCount()));
for (auto i = 0; i < sideTabBar->tabCount(); ++i)
{
auto Tab = sideTabBar->tabAt(i);
if (!Tab)
{
continue;
}
auto DockArea = Tab->dockWidget()->dockAreaWidget();
DockArea->saveState(s);
}
s.writeEndElement();
}
}
@ -1118,29 +1129,6 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s,
}
//============================================================================
bool DockContainerWidgetPrivate::restoreDockOrAutoHideDockArea(CDockingStateReader& Stream, QWidget*& CreatedWidget,
bool Testing)
{
bool Ok;
const auto sideTabAreaValue = Stream.attributes().value("SideTabBarArea");
if (!sideTabAreaValue.isNull())
{
auto sideTabBarArea = static_cast<SideBarLocation>(sideTabAreaValue.toInt(&Ok));
if (!Ok)
{
return false;
}
return restoreAutoHideDockArea(Stream, sideTabBarArea, Testing);
}
// If there's no SideTabBarArea value in the XML, or the value of SideTabBarArea is none, restore the dock area
return restoreDockArea(Stream, CreatedWidget, Testing);
}
//============================================================================
bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing)
@ -1233,6 +1221,42 @@ bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
}
//============================================================================
bool DockContainerWidgetPrivate::restoreSideBar(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing)
{
Q_UNUSED(CreatedWidget)
// Simply ignore side bar auto hide widgets
if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
return true;
}
bool Ok;
//int Tabs = s.attributes().value("Tabs").toInt(&Ok);
auto Area = (ads::SideBarLocation)s.attributes().value("Area").toInt(&Ok);
if (!Ok)
{
return false;
}
while (s.readNextStartElement())
{
if (s.name() != QLatin1String("Area"))
{
continue;
}
if (!restoreAutoHideDockArea(s, Area, Testing))
{
return false;
}
}
return true;
}
//============================================================================
bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing)
@ -1247,9 +1271,14 @@ bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s,
}
else if (s.name() == QLatin1String("Area"))
{
Result = restoreDockOrAutoHideDockArea(s, CreatedWidget, Testing);
Result = restoreDockArea(s, CreatedWidget, Testing);
ADS_PRINT("DockAreaWidget");
}
else if (s.name() == QLatin1String("SideBar"))
{
Result = restoreSideBar(s, CreatedWidget, Testing);
ADS_PRINT("SideBar");
}
else
{
s.skipCurrentElement();
@ -1500,7 +1529,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
//============================================================================
CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWidgetContainer(
CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
SideBarLocation area, CDockWidget* DockWidget, CDockWidget::eAutoHideInsertOrder insertOrder)
{
if (d->DockManager != DockWidget->dockManager())
@ -1518,10 +1547,12 @@ CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWid
sideTabBar(area)->insertSideTab(insertOrder == CDockWidget::First ? 0 : -1, DockWidget->sideTabWidget());
DockWidget->sideTabWidget()->show();
const auto dockContainer = new CAutoHideDockContainer(DockWidget, area, this);
dockContainer->hide();
auto AutoHideContainer = new CAutoHideDockContainer(DockWidget, area, this);
AutoHideContainer->hide();
d->DockManager->dockFocusController()->clearDockWidgetFocus(DockWidget);
return dockContainer;
//auto AutoHideContainer = sideTabBar(area)->insertDockWidget(insertOrder == CDockWidget::First ? 0 : -1, DockWidget);
return AutoHideContainer;
}
@ -1861,7 +1892,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
auto autoHideWidgets = FloatingWidget->dockContainer()->autoHideWidgets();
for (const auto autohideWidget : autoHideWidgets)
{
createAndInitializeAutoHideDockWidgetContainer(autohideWidget->sideTabBarArea(), autohideWidget->dockWidget(), autohideWidget->dockWidget()->autoHideInsertOrder());
createAndSetupAutoHideContainer(autohideWidget->sideTabBarArea(), autohideWidget->dockWidget(), autohideWidget->dockWidget()->autoHideInsertOrder());
}
if (DockArea)

View File

@ -100,7 +100,7 @@ protected:
* Initializing inserts the tabs into the side tab widget and hides it
* Returns nullptr if you try and insert into an area where the configuration is not enabled
*/
CAutoHideDockContainer* createAndInitializeAutoHideDockWidgetContainer(
CAutoHideDockContainer* createAndSetupAutoHideContainer(
SideBarLocation area, CDockWidget* DockWidget, CDockWidget::eAutoHideInsertOrder insertOrder);
/**

View File

@ -718,6 +718,8 @@ QByteArray CDockManager::saveState(int version) const
s.writeEndElement();
s.writeEndDocument();
std::cout << xmldata.toStdString() << std::endl;
return ConfigFlags.testFlag(XmlCompressionEnabled)
? qCompress(xmldata, 9) : xmldata;
}
@ -878,7 +880,7 @@ CAutoHideDockContainer* CDockManager::addAutoHideDockWidgetToContainer(SideBarLo
CDockContainerWidget* DockContainerWidget, CDockWidget::eAutoHideInsertOrder insertOrder)
{
d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget);
auto container = DockContainerWidget->createAndInitializeAutoHideDockWidgetContainer(area, Dockwidget, insertOrder);
auto container = DockContainerWidget->createAndSetupAutoHideContainer(area, Dockwidget, insertOrder);
container->collapseView(true);
Q_EMIT dockWidgetAdded(Dockwidget);

View File

@ -54,6 +54,7 @@ struct DockAreaWidgetPrivate;
class CIconProvider;
class CDockComponentsFactory;
class CDockFocusController;
class CSideTabBar;
/**
* The central dock manager that maintains the complete docking system.
@ -85,6 +86,7 @@ private:
friend struct FloatingDragPreviewPrivate;
friend class CDockAreaTitleBar;
friend class CAutoHideDockContainer;
friend CSideTabBar;
protected:

View File

@ -30,14 +30,17 @@
// INCLUDES
//============================================================================
#include "SideTabBar.h"
#include "DockContainerWidget.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include <QBoxLayout>
#include <QStyleOption>
#include <QPainter>
#include "DockContainerWidget.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include "DockFocusController.h"
#include "AutoHideDockContainer.h"
namespace ads
{
/**
@ -130,6 +133,35 @@ void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
}
//============================================================================
CAutoHideDockContainer* CSideTabBar::insertDockWidget(int Index, CDockWidget* DockWidget)
{
CDockWidgetSideTab* Tab = new CDockWidgetSideTab(DockWidget);
auto area = sideTabBarArea();
qDebug() << "area " << area;
Tab->setSideTabBar(this);
Tab->updateOrientationAndSpacing(area);
d->TabsLayout->insertWidget(Index, Tab);
Tab->show();
auto AutoHideContainer = new CAutoHideDockContainer(DockWidget, area, d->ContainerWidget);
AutoHideContainer->hide();
DockWidget->dockManager()->dockFocusController()->clearDockWidgetFocus(DockWidget);
Tab->updateStyle();
connect(Tab, &CDockWidgetSideTab::pressed, AutoHideContainer, &CAutoHideDockContainer::toggleCollapseState);
show();
return AutoHideContainer;
}
//============================================================================
void CSideTabBar::removeDockWidget(CDockWidget* DockWidget)
{
}
//============================================================================
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
{

View File

@ -38,6 +38,7 @@ namespace ads
struct SideTabBarPrivate;
class CDockContainerWidget;
class CDockWidgetSideTab;
class CAutoHideDockContainer;
/**
* Side tab widget that is shown at the edges of a dock container.
@ -79,6 +80,16 @@ public:
*/
void removeSideTab(CDockWidgetSideTab* SideTab);
/**
* Insert dock widget
*/
CAutoHideDockContainer* insertDockWidget(int Index, CDockWidget* DockWidget);
/**
* Remove dock widget from sidebar
*/
void removeDockWidget(CDockWidget* DockWidget);
/**
* Returns orientation of side tab.
*/