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->DockArea->addDockWidget(DockWidget);
d->DockWidget->sideTabWidget()->updateOrientationAndSpacing(d->SideTabBarArea); d->DockWidget->sideTabWidget()->updateOrientationAndSpacing(d->SideTabBarArea);
// 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 // Prevent overriding of d->Size parameter when this function is called during
// is near of the splitter of the old dock area. // state restoring
d->Size = OldDockArea->size() + QSize(16, 16); 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(); updateSize();
} }
@ -343,7 +349,6 @@ void CAutoHideDockContainer::cleanupAndDelete()
//============================================================================ //============================================================================
void CAutoHideDockContainer::saveState(QXmlStreamWriter& s) void CAutoHideDockContainer::saveState(QXmlStreamWriter& s)
{ {
s.writeAttribute("SideTabBarArea", QString::number(sideTabBarArea()));
s.writeAttribute("Size", QString::number(d->isHorizontal() ? d->Size.height() : d->Size.width())); s.writeAttribute("Size", QString::number(d->isHorizontal() ? d->Size.height() : d->Size.width()));
qDebug() << ": saveState Size: " << d->Size; qDebug() << ": saveState Size: " << d->Size;

View File

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

View File

@ -257,10 +257,10 @@ public:
*/ */
bool restoreAutoHideDockArea(CDockingStateReader& s, SideBarLocation area, bool Testing); 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); 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 (const auto sideTabBar : SideTabBarWidgets.values())
{ {
for (auto itemIndex = 0; itemIndex < sideTabBar->tabCount(); itemIndex++) if (!sideTabBar->tabCount())
{ {
const auto sideTab = sideTabBar->tabAt(itemIndex); continue;
if (sideTab == nullptr) }
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; continue;
} }
const auto dockArea = sideTab->dockWidget()->dockAreaWidget(); auto DockArea = Tab->dockWidget()->dockAreaWidget();
dockArea->saveState(Stream); 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, bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing) 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, bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s,
QWidget*& CreatedWidget, bool Testing) QWidget*& CreatedWidget, bool Testing)
@ -1247,9 +1271,14 @@ bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s,
} }
else if (s.name() == QLatin1String("Area")) else if (s.name() == QLatin1String("Area"))
{ {
Result = restoreDockOrAutoHideDockArea(s, CreatedWidget, Testing); Result = restoreDockArea(s, CreatedWidget, Testing);
ADS_PRINT("DockAreaWidget"); ADS_PRINT("DockAreaWidget");
} }
else if (s.name() == QLatin1String("SideBar"))
{
Result = restoreSideBar(s, CreatedWidget, Testing);
ADS_PRINT("SideBar");
}
else else
{ {
s.skipCurrentElement(); 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) SideBarLocation area, CDockWidget* DockWidget, CDockWidget::eAutoHideInsertOrder insertOrder)
{ {
if (d->DockManager != DockWidget->dockManager()) if (d->DockManager != DockWidget->dockManager())
@ -1518,10 +1547,12 @@ CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWid
sideTabBar(area)->insertSideTab(insertOrder == CDockWidget::First ? 0 : -1, DockWidget->sideTabWidget()); sideTabBar(area)->insertSideTab(insertOrder == CDockWidget::First ? 0 : -1, DockWidget->sideTabWidget());
DockWidget->sideTabWidget()->show(); DockWidget->sideTabWidget()->show();
const auto dockContainer = new CAutoHideDockContainer(DockWidget, area, this); auto AutoHideContainer = new CAutoHideDockContainer(DockWidget, area, this);
dockContainer->hide(); AutoHideContainer->hide();
d->DockManager->dockFocusController()->clearDockWidgetFocus(DockWidget); 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(); auto autoHideWidgets = FloatingWidget->dockContainer()->autoHideWidgets();
for (const auto autohideWidget : autoHideWidgets) for (const auto autohideWidget : autoHideWidgets)
{ {
createAndInitializeAutoHideDockWidgetContainer(autohideWidget->sideTabBarArea(), autohideWidget->dockWidget(), autohideWidget->dockWidget()->autoHideInsertOrder()); createAndSetupAutoHideContainer(autohideWidget->sideTabBarArea(), autohideWidget->dockWidget(), autohideWidget->dockWidget()->autoHideInsertOrder());
} }
if (DockArea) if (DockArea)

View File

@ -100,7 +100,7 @@ protected:
* Initializing inserts the tabs into the side tab widget and hides it * 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 * 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); SideBarLocation area, CDockWidget* DockWidget, CDockWidget::eAutoHideInsertOrder insertOrder);
/** /**

View File

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

View File

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

View File

@ -30,14 +30,17 @@
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include "SideTabBar.h" #include "SideTabBar.h"
#include "DockContainerWidget.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QStyleOption> #include <QStyleOption>
#include <QPainter> #include <QPainter>
#include "DockContainerWidget.h"
#include "DockWidgetSideTab.h"
#include "DockWidgetTab.h"
#include "DockFocusController.h"
#include "AutoHideDockContainer.h"
namespace ads 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) void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
{ {

View File

@ -38,6 +38,7 @@ namespace ads
struct SideTabBarPrivate; struct SideTabBarPrivate;
class CDockContainerWidget; class CDockContainerWidget;
class CDockWidgetSideTab; class CDockWidgetSideTab;
class CAutoHideDockContainer;
/** /**
* Side tab widget that is shown at the edges of a dock container. * Side tab widget that is shown at the edges of a dock container.
@ -79,6 +80,16 @@ public:
*/ */
void removeSideTab(CDockWidgetSideTab* SideTab); 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. * Returns orientation of side tab.
*/ */