diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index bd3f14a..7e8bae4 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -291,10 +291,16 @@ void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget) } d->DockArea->addDockWidget(DockWidget); 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 - // is near of the splitter of the old dock area. - d->Size = OldDockArea->size() + QSize(16, 16); + + // 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; diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 94fa8b8..c116e3b 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -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()); } } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index fad92b8..3fb36e2 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -257,10 +257,10 @@ 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 - */ - bool restoreDockOrAutoHideDockArea(CDockingStateReader& Stream, QWidget*& CreatedWidget, + /** + * Restores a auto hide side bar + */ + 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 (const auto sideTabBar : SideTabBarWidgets.values()) { - for (auto itemIndex = 0; itemIndex < sideTabBar->tabCount(); itemIndex++) + if (!sideTabBar->tabCount()) { - const auto sideTab = sideTabBar->tabAt(itemIndex); - if (sideTab == nullptr) + continue; + } + + 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; } - const auto dockArea = sideTab->dockWidget()->dockAreaWidget(); - dockArea->saveState(Stream); + 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(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) diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 0efc75d..709d555 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -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); /** diff --git a/src/DockManager.cpp b/src/DockManager.cpp index d1aed23..cb55869 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -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); diff --git a/src/DockManager.h b/src/DockManager.h index f68367a..19ea2a0 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -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: diff --git a/src/SideTabBar.cpp b/src/SideTabBar.cpp index 3089983..8f81a87 100644 --- a/src/SideTabBar.cpp +++ b/src/SideTabBar.cpp @@ -30,14 +30,17 @@ // INCLUDES //============================================================================ #include "SideTabBar.h" -#include "DockContainerWidget.h" -#include "DockWidgetSideTab.h" -#include "DockWidgetTab.h" #include #include #include +#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) { diff --git a/src/SideTabBar.h b/src/SideTabBar.h index f3baa8f..ecafb6e 100644 --- a/src/SideTabBar.h +++ b/src/SideTabBar.h @@ -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. */