diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 535ff2b..43df868 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -411,6 +411,7 @@ void CAutoHideDockContainer::moveContentsToParent() //============================================================================ void CAutoHideDockContainer::cleanupAndDelete() { + std::cout << "CAutoHideDockContainer::cleanupAndDelete()" << std::endl; const auto dockWidget = d->DockWidget; if (dockWidget) { @@ -690,5 +691,26 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize() } } + +//============================================================================ +void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation) +{ + if (NewSideBarLocation == sideBarLocation()) + { + return; + } + + auto OldOrientation = orientation(); + auto SideBar = dockContainer()->autoHideSideBar(NewSideBarLocation); + SideBar->addAutoHideWidget(this); + // If we move a horizontal auto hide container to a vertical position + // then we resize it to the orginal dock widget size, to avoid + // an extremely streched dock widget after insertion + if (SideBar->orientation() != OldOrientation) + { + resetToInitialDockWidgetSize(); + } +} + } diff --git a/src/AutoHideDockContainer.h b/src/AutoHideDockContainer.h index 7ff6ac9..3183682 100644 --- a/src/AutoHideDockContainer.h +++ b/src/AutoHideDockContainer.h @@ -190,6 +190,12 @@ public: * side bar. */ Qt::Orientation orientation() const; + + /** + * Removes the AutoHide container from the current side bar and adds + * it to the new side bar given in SideBarLocation + */ + void moveToNewSideBarLocation(SideBarLocation SideBarLocation); }; } // namespace ads diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 4cd8b86..8b1bdc8 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1323,11 +1323,18 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location) { if (isAutoHide()) { - autoHideDockContainer()->moveContentsToParent(); + d->AutoHideDockContainer->moveContentsToParent(); } return; } + // If this is already an auto hide container, then move it to new location + if (isAutoHide()) + { + d->AutoHideDockContainer->moveToNewSideBarLocation(Location); + return; + } + auto area = (SideBarNone == Location) ? calculateSideTabBarArea() : Location; for (const auto DockWidget : openedDockWidgets()) { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index d95f519..f1412e8 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -221,7 +221,6 @@ public: */ bool isAutoHide() const; - /** * Sets the current auto hide dock container */ diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index f968515..0655ce2 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -776,18 +776,34 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg if (DroppedDockWidget) { - _this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget); + if (_this == DroppedDockWidget->dockContainer()) + { + DroppedDockWidget->setAutoHide(true, SideBarLocation); + } + else + { + _this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget); + } } else { - for (const auto DockWidget : DroppedDockArea->openedDockWidgets()) + if (_this == DroppedDockArea->dockContainer()) { - if (!DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable)) + DroppedDockArea->setAutoHide(true, SideBarLocation); + } + else + { + for (const auto DockWidget : DroppedDockArea->openedDockWidgets()) { - continue; - } + if (!DockWidget->features().testFlag( + CDockWidget::DockWidgetPinnable)) + { + continue; + } - _this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget); + _this->createAndSetupAutoHideContainer(SideBarLocation, + DockWidget); + } } } } diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 9327e2c..af00a50 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -1219,23 +1219,14 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location) } auto DockArea = dockAreaWidget(); + if (!Enable) { DockArea->setAutoHide(false); } else if (isAutoHide()) { - auto AutoHideContainer = autoHideDockContainer(); - auto OldOrientation = AutoHideContainer->orientation(); - auto SideBar = dockContainer()->autoHideSideBar(Location); - SideBar->addAutoHideWidget(AutoHideContainer); - // If we move a horizontal auto hide container to a vertical position - // then we resize it to the orginal dock widget size, to avoid - // an extremely streched dock widget after insertion - if (SideBar->orientation() != OldOrientation) - { - AutoHideContainer->resetToInitialDockWidgetSize(); - } + autoHideDockContainer()->moveToNewSideBarLocation(Location); } else { diff --git a/src/FloatingDragPreview.cpp b/src/FloatingDragPreview.cpp index 7291b2c..5e52a09 100644 --- a/src/FloatingDragPreview.cpp +++ b/src/FloatingDragPreview.cpp @@ -22,6 +22,8 @@ #include "DockManager.h" #include "DockContainerWidget.h" #include "DockOverlay.h" +#include "AutoHideDockContainer.h" +#include "ads_globals.h" namespace ads { @@ -373,7 +375,7 @@ void CFloatingDragPreview::finishDragging() // state if they are dragged into a floating window if (ValidDropArea || d->isContentFloatable()) { - cleanupAutoHideContainerWidget(); + cleanupAutoHideContainerWidget(ContainerDropArea); } if (!d->DropContainer) @@ -408,18 +410,29 @@ void CFloatingDragPreview::finishDragging() //============================================================================ -void CFloatingDragPreview::cleanupAutoHideContainerWidget() +void CFloatingDragPreview::cleanupAutoHideContainerWidget(DockWidgetArea ContainerDropArea) { auto DroppedDockWidget = qobject_cast(d->Content); auto DroppedArea = qobject_cast(d->Content); - if (DroppedDockWidget && DroppedDockWidget->autoHideDockContainer()) + auto AutoHideContainer = DroppedDockWidget + ? DroppedDockWidget->autoHideDockContainer() + : DroppedArea->autoHideDockContainer(); + + if (!AutoHideContainer) { - DroppedDockWidget->autoHideDockContainer()->cleanupAndDelete(); + return; } - if (DroppedArea && DroppedArea->autoHideDockContainer()) + + // If the dropped widget is already an auto hide widget and if it is moved + // to a new side bar location in the same container, then we do not need + // to cleanup + if (ads::internal::isSideBarArea(ContainerDropArea) + && (d->DropContainer == AutoHideContainer->dockContainer())) { - DroppedArea->autoHideDockContainer()->cleanupAndDelete(); + return; } + + AutoHideContainer->cleanupAndDelete(); } diff --git a/src/FloatingDragPreview.h b/src/FloatingDragPreview.h index 236f80e..68e3e5c 100644 --- a/src/FloatingDragPreview.h +++ b/src/FloatingDragPreview.h @@ -95,7 +95,7 @@ public: // implements IFloatingWidget ----------------------------------------- /** * Cleanup auto hide container if the dragged widget has one */ - void cleanupAutoHideContainerWidget(); + void cleanupAutoHideContainerWidget(DockWidgetArea ContainerDropArea); Q_SIGNALS: /**