Properly implemented drag and drop of auto hide tabs

This commit is contained in:
Uwe Kindler 2023-07-10 09:34:11 +02:00
parent bf22e54fc3
commit 0a6c58fd66
8 changed files with 80 additions and 26 deletions

View File

@ -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();
}
}
}

View File

@ -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

View File

@ -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())
{

View File

@ -221,7 +221,6 @@ public:
*/
bool isAutoHide() const;
/**
* Sets the current auto hide dock container
*/

View File

@ -775,19 +775,35 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
auto SideBarLocation = internal::toSideBarLocation(area);
if (DroppedDockWidget)
{
if (_this == DroppedDockWidget->dockContainer())
{
DroppedDockWidget->setAutoHide(true, SideBarLocation);
}
else
{
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget);
}
}
else
{
if (_this == DroppedDockArea->dockContainer())
{
DroppedDockArea->setAutoHide(true, SideBarLocation);
}
else
{
for (const auto DockWidget : DroppedDockArea->openedDockWidgets())
{
if (!DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable))
if (!DockWidget->features().testFlag(
CDockWidget::DockWidgetPinnable))
{
continue;
}
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget);
_this->createAndSetupAutoHideContainer(SideBarLocation,
DockWidget);
}
}
}
}

View File

@ -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
{

View File

@ -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<CDockWidget*>(d->Content);
auto DroppedArea = qobject_cast<CDockAreaWidget*>(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();
}

View File

@ -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:
/**