Skip to content

Commit 0a6c58f

Browse files
Properly implemented drag and drop of auto hide tabs
1 parent bf22e54 commit 0a6c58f

8 files changed

+80
-26
lines changed

src/AutoHideDockContainer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ void CAutoHideDockContainer::moveContentsToParent()
411411
//============================================================================
412412
void CAutoHideDockContainer::cleanupAndDelete()
413413
{
414+
std::cout << "CAutoHideDockContainer::cleanupAndDelete()" << std::endl;
414415
const auto dockWidget = d->DockWidget;
415416
if (dockWidget)
416417
{
@@ -690,5 +691,26 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
690691
}
691692
}
692693

694+
695+
//============================================================================
696+
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation)
697+
{
698+
if (NewSideBarLocation == sideBarLocation())
699+
{
700+
return;
701+
}
702+
703+
auto OldOrientation = orientation();
704+
auto SideBar = dockContainer()->autoHideSideBar(NewSideBarLocation);
705+
SideBar->addAutoHideWidget(this);
706+
// If we move a horizontal auto hide container to a vertical position
707+
// then we resize it to the orginal dock widget size, to avoid
708+
// an extremely streched dock widget after insertion
709+
if (SideBar->orientation() != OldOrientation)
710+
{
711+
resetToInitialDockWidgetSize();
712+
}
713+
}
714+
693715
}
694716

src/AutoHideDockContainer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ class ADS_EXPORT CAutoHideDockContainer : public QFrame
190190
* side bar.
191191
*/
192192
Qt::Orientation orientation() const;
193+
194+
/**
195+
* Removes the AutoHide container from the current side bar and adds
196+
* it to the new side bar given in SideBarLocation
197+
*/
198+
void moveToNewSideBarLocation(SideBarLocation SideBarLocation);
193199
};
194200
} // namespace ads
195201

src/DockAreaWidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,11 +1323,18 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
13231323
{
13241324
if (isAutoHide())
13251325
{
1326-
autoHideDockContainer()->moveContentsToParent();
1326+
d->AutoHideDockContainer->moveContentsToParent();
13271327
}
13281328
return;
13291329
}
13301330

1331+
// If this is already an auto hide container, then move it to new location
1332+
if (isAutoHide())
1333+
{
1334+
d->AutoHideDockContainer->moveToNewSideBarLocation(Location);
1335+
return;
1336+
}
1337+
13311338
auto area = (SideBarNone == Location) ? calculateSideTabBarArea() : Location;
13321339
for (const auto DockWidget : openedDockWidgets())
13331340
{

src/DockAreaWidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ protected Q_SLOTS:
221221
*/
222222
bool isAutoHide() const;
223223

224-
225224
/**
226225
* Sets the current auto hide dock container
227226
*/

src/DockContainerWidget.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,18 +776,34 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
776776

777777
if (DroppedDockWidget)
778778
{
779-
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget);
779+
if (_this == DroppedDockWidget->dockContainer())
780+
{
781+
DroppedDockWidget->setAutoHide(true, SideBarLocation);
782+
}
783+
else
784+
{
785+
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget);
786+
}
780787
}
781788
else
782789
{
783-
for (const auto DockWidget : DroppedDockArea->openedDockWidgets())
790+
if (_this == DroppedDockArea->dockContainer())
784791
{
785-
if (!DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable))
792+
DroppedDockArea->setAutoHide(true, SideBarLocation);
793+
}
794+
else
795+
{
796+
for (const auto DockWidget : DroppedDockArea->openedDockWidgets())
786797
{
787-
continue;
798+
if (!DockWidget->features().testFlag(
799+
CDockWidget::DockWidgetPinnable))
800+
{
801+
continue;
802+
}
803+
804+
_this->createAndSetupAutoHideContainer(SideBarLocation,
805+
DockWidget);
788806
}
789-
790-
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget);
791807
}
792808
}
793809
}

src/DockWidget.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,23 +1219,14 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
12191219
}
12201220

12211221
auto DockArea = dockAreaWidget();
1222+
12221223
if (!Enable)
12231224
{
12241225
DockArea->setAutoHide(false);
12251226
}
12261227
else if (isAutoHide())
12271228
{
1228-
auto AutoHideContainer = autoHideDockContainer();
1229-
auto OldOrientation = AutoHideContainer->orientation();
1230-
auto SideBar = dockContainer()->autoHideSideBar(Location);
1231-
SideBar->addAutoHideWidget(AutoHideContainer);
1232-
// If we move a horizontal auto hide container to a vertical position
1233-
// then we resize it to the orginal dock widget size, to avoid
1234-
// an extremely streched dock widget after insertion
1235-
if (SideBar->orientation() != OldOrientation)
1236-
{
1237-
AutoHideContainer->resetToInitialDockWidgetSize();
1238-
}
1229+
autoHideDockContainer()->moveToNewSideBarLocation(Location);
12391230
}
12401231
else
12411232
{

src/FloatingDragPreview.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "DockManager.h"
2323
#include "DockContainerWidget.h"
2424
#include "DockOverlay.h"
25+
#include "AutoHideDockContainer.h"
26+
#include "ads_globals.h"
2527

2628
namespace ads
2729
{
@@ -373,7 +375,7 @@ void CFloatingDragPreview::finishDragging()
373375
// state if they are dragged into a floating window
374376
if (ValidDropArea || d->isContentFloatable())
375377
{
376-
cleanupAutoHideContainerWidget();
378+
cleanupAutoHideContainerWidget(ContainerDropArea);
377379
}
378380

379381
if (!d->DropContainer)
@@ -408,18 +410,29 @@ void CFloatingDragPreview::finishDragging()
408410

409411

410412
//============================================================================
411-
void CFloatingDragPreview::cleanupAutoHideContainerWidget()
413+
void CFloatingDragPreview::cleanupAutoHideContainerWidget(DockWidgetArea ContainerDropArea)
412414
{
413415
auto DroppedDockWidget = qobject_cast<CDockWidget*>(d->Content);
414416
auto DroppedArea = qobject_cast<CDockAreaWidget*>(d->Content);
415-
if (DroppedDockWidget && DroppedDockWidget->autoHideDockContainer())
417+
auto AutoHideContainer = DroppedDockWidget
418+
? DroppedDockWidget->autoHideDockContainer()
419+
: DroppedArea->autoHideDockContainer();
420+
421+
if (!AutoHideContainer)
416422
{
417-
DroppedDockWidget->autoHideDockContainer()->cleanupAndDelete();
423+
return;
418424
}
419-
if (DroppedArea && DroppedArea->autoHideDockContainer())
425+
426+
// If the dropped widget is already an auto hide widget and if it is moved
427+
// to a new side bar location in the same container, then we do not need
428+
// to cleanup
429+
if (ads::internal::isSideBarArea(ContainerDropArea)
430+
&& (d->DropContainer == AutoHideContainer->dockContainer()))
420431
{
421-
DroppedArea->autoHideDockContainer()->cleanupAndDelete();
432+
return;
422433
}
434+
435+
AutoHideContainer->cleanupAndDelete();
423436
}
424437

425438

src/FloatingDragPreview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private Q_SLOTS:
9595
/**
9696
* Cleanup auto hide container if the dragged widget has one
9797
*/
98-
void cleanupAutoHideContainerWidget();
98+
void cleanupAutoHideContainerWidget(DockWidgetArea ContainerDropArea);
9999

100100
Q_SIGNALS:
101101
/**

0 commit comments

Comments
 (0)