mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Properly implemented drag and drop of auto hide tabs
This commit is contained in:
parent
bf22e54fc3
commit
0a6c58fd66
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -221,7 +221,6 @@ public:
|
||||
*/
|
||||
bool isAutoHide() const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the current auto hide dock container
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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:
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user