Skip to content

Commit f5cfe9e

Browse files
Fixed tab insertion when dragging side tab
1 parent be727c5 commit f5cfe9e

9 files changed

+99
-24
lines changed

src/AutoHideDockContainer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
232232
//============================================================================
233233
void CAutoHideDockContainer::updateSize()
234234
{
235-
qDebug() << "CAutoHideDockContainer::updateSize()";
236235
auto dockContainerParent = dockContainer();
237236
if (!dockContainerParent)
238237
{
@@ -692,7 +691,9 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
692691
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation,
693692
int TabIndex)
694693
{
695-
if (NewSideBarLocation == sideBarLocation())
694+
qDebug() << "CAutoHideDockContainer::moveToNewSideBarLocation TabIndex " <<
695+
TabIndex << " this->tabIndex: " << this->tabIndex();
696+
if (NewSideBarLocation == sideBarLocation() && TabIndex == this->tabIndex())
696697
{
697698
return;
698699
}
@@ -709,5 +710,12 @@ void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBar
709710
}
710711
}
711712

713+
714+
//============================================================================
715+
int CAutoHideDockContainer::tabIndex() const
716+
{
717+
return d->SideTab->tabIndex();
718+
}
719+
712720
}
713721

src/AutoHideDockContainer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class ADS_EXPORT CAutoHideDockContainer : public QFrame
105105
*/
106106
CDockWidget* dockWidget() const;
107107

108+
/**
109+
* Returns the index of this container in the sidebar
110+
*/
111+
int tabIndex() const;
112+
108113
/**
109114
* Adds a dock widget and removes the previous dock widget
110115
*/

src/AutoHideSideBar.cpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,24 @@ void CAutoHideSideBar::removeAutoHideWidget(CAutoHideDockContainer* AutoHideWidg
234234

235235
//============================================================================
236236
void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
237-
int Index)
237+
int TabIndex)
238238
{
239239
auto SideBar = AutoHideWidget->autoHideTab()->sideBar();
240240
if (SideBar == this)
241241
{
242-
return;
242+
// If we move to the same tab index or if we insert before the next
243+
// tab index, then we will end at the same tab position and can leave
244+
if (AutoHideWidget->tabIndex() == TabIndex || (AutoHideWidget->tabIndex() + 1) == TabIndex)
245+
{
246+
return;
247+
}
248+
249+
// We remove this auto hide widget from the sidebar in the code below
250+
// and therefore need to correct the TabIndex here
251+
if (AutoHideWidget->tabIndex() < TabIndex)
252+
{
253+
--TabIndex;
254+
}
243255
}
244256

245257
if (SideBar)
@@ -249,7 +261,7 @@ void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
249261
AutoHideWidget->setParent(d->ContainerWidget);
250262
AutoHideWidget->setSideBarLocation(d->SideTabArea);
251263
d->ContainerWidget->registerAutoHideWidget(AutoHideWidget);
252-
insertTab(Index, AutoHideWidget->autoHideTab());
264+
insertTab(TabIndex, AutoHideWidget->autoHideTab());
253265
}
254266

255267

@@ -349,6 +361,21 @@ bool CAutoHideSideBar::hasVisibleTabs() const
349361
}
350362

351363

364+
//============================================================================
365+
int CAutoHideSideBar::indexOfTab(const CAutoHideTab& Tab) const
366+
{
367+
for (auto i = 0; i < count(); i++)
368+
{
369+
if (tab(i) == &Tab)
370+
{
371+
return i;
372+
}
373+
}
374+
375+
return -1;
376+
}
377+
378+
352379
//============================================================================
353380
SideBarLocation CAutoHideSideBar::sideBarLocation() const
354381
{
@@ -424,13 +451,24 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
424451
{
425452
if (!isVisible())
426453
{
427-
return -2;
454+
return InvalidTabIndex;
428455
}
429456

430-
if (Pos.x() < tab(0)->geometry().x())
457+
if (orientation() == Qt::Horizontal)
431458
{
432-
return -1;
459+
if (Pos.x() < tab(0)->geometry().x())
460+
{
461+
return -1;
462+
}
433463
}
464+
else
465+
{
466+
if (Pos.y() < tab(0)->geometry().y())
467+
{
468+
return -1;
469+
}
470+
}
471+
434472

435473
for (int i = 0; i < count(); ++i)
436474
{
@@ -448,7 +486,14 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
448486
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
449487
{
450488
int Index = tabAt(Pos);
451-
return (Index < 0) ? -1 : Index;
489+
if (Index == InvalidTabIndex)
490+
{
491+
return Append;
492+
}
493+
else
494+
{
495+
return (Index < 0) ? 0 : Index;
496+
}
452497
}
453498

454499
} // namespace ads

src/AutoHideSideBar.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
8484

8585
public:
8686
using Super = QScrollArea;
87+
static constexpr int Append = -1;
88+
static constexpr int InvalidTabIndex = -2;
8789

8890
/**
8991
* Default Constructor
@@ -117,23 +119,23 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
117119
* If the AutoHideWidget is in another sidebar, then it will be removed
118120
* from this sidebar.
119121
*/
120-
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = -1);
122+
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = Append);
121123

122124
/**
123125
* Returns orientation of side tab.
124126
*/
125127
Qt::Orientation orientation() const;
126128

127129
/*
128-
* get the side tab widget at position, returns nullptr if it's out of bounds
130+
* Get the side tab widget at position, returns nullptr if it's out of bounds
129131
*/
130132
CAutoHideTab* tab(int index) const;
131133

132134
/**
133135
* Returns the tab at the given position.
134136
* Returns -1 if the position is left of the first tab and count() if the
135-
* position is right of the last tab. Returns -2 to indicate an invalid
136-
* value.
137+
* position is right of the last tab. Returns InvalidTabIndex (-2) to
138+
* indicate an invalid value.
137139
*/
138140
int tabAt(const QPoint& Pos) const;
139141

@@ -142,6 +144,11 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
142144
*/
143145
int tabInsertIndexAt(const QPoint& Pos) const;
144146

147+
/**
148+
* Returns the index of the given tab
149+
*/
150+
int indexOfTab(const CAutoHideTab& Tab) const;
151+
145152
/*
146153
* Gets the count of the tab widgets
147154
*/

src/AutoHideTab.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,16 @@ void CAutoHideTab::requestCloseDockWidget()
546546
}
547547

548548

549+
//============================================================================
550+
int CAutoHideTab::tabIndex() const
551+
{
552+
if (!d->SideBar)
553+
{
554+
return -1;
555+
}
556+
557+
return d->SideBar->indexOfTab(*this);
558+
}
559+
560+
549561
}

src/AutoHideTab.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ private Q_SLOTS:
140140
*/
141141
CAutoHideSideBar* sideBar() const;
142142

143+
/**
144+
* Returns the index of this tab in the sideBar
145+
*/
146+
int tabIndex() const;
147+
143148
public Q_SLOTS:
144149
/**
145150
* Set the dock widget floating, if it is floatable

src/DockAreaTitleBar.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ void DockAreaTitleBarPrivate::createTabBar()
260260
//============================================================================
261261
IFloatingWidget* DockAreaTitleBarPrivate::makeAreaFloating(const QPoint& Offset, eDragState DragState)
262262
{
263-
qDebug() << "DockAreaTitleBarPrivate::makeAreaFloating " << DockArea->size();
264263
QSize Size = DockArea->size();
265264
this->DragState = DragState;
266265
bool CreateFloatingDockContainer = (DraggingFloatingWidget != DragState);

src/DockContainerWidget.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,13 @@ void DockContainerWidgetPrivate::dropIntoAutoHideSideBar(CFloatingDockContainer*
523523
auto SideBarLocation = internal::toSideBarLocation(area);
524524
auto NewDockAreas = FloatingWidget->findChildren<CDockAreaWidget*>(
525525
QString(), Qt::FindChildrenRecursively);
526+
int TabIndex = DockManager->containerOverlay()->tabIndexUnderCursor();
526527
for (auto DockArea : NewDockAreas)
527528
{
528529
auto DockWidgets = DockArea->dockWidgets();
529530
for (auto DockWidget : DockWidgets)
530531
{
531-
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget);
532+
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget, TabIndex++);
532533
}
533534
}
534535
}
@@ -574,7 +575,6 @@ void DockContainerWidgetPrivate::dropIntoCenterOfSection(
574575
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
575576
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex)
576577
{
577-
qDebug() << "DockContainerWidgetPrivate::dropIntoSection TabIndex: " << TabIndex;
578578
// Dropping into center means all dock widgets in the dropped floating
579579
// widget will become tabs of the drop area
580580
if (CenterDockWidgetArea == area)
@@ -672,8 +672,6 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
672672
void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea,
673673
int TabIndex)
674674
{
675-
qDebug() << "DockContainerWidgetPrivate::moveIntoCenterOfSection TabIndex: "
676-
<< TabIndex;
677675
auto DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
678676
auto DroppedArea = qobject_cast<CDockAreaWidget*>(Widget);
679677

@@ -715,8 +713,6 @@ void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockA
715713
void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area,
716714
int TabIndex)
717715
{
718-
qDebug() << "DockContainerWidgetPrivate::moveToNewSection TabIndex: "
719-
<< TabIndex;
720716
// Dropping into center means all dock widgets in the dropped floating
721717
// widget will become tabs of the drop area
722718
if (CenterDockWidgetArea == area)
@@ -1707,7 +1703,6 @@ int CDockContainerWidget::visibleDockAreaCount() const
17071703
void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget,
17081704
const QPoint& TargetPos)
17091705
{
1710-
//dockContainer()->createAndSetupAutoHideContainer(area, this);
17111706
ADS_PRINT("CDockContainerWidget::dropFloatingWidget");
17121707
CDockWidget* SingleDroppedDockWidget = FloatingWidget->topLevelDockWidget();
17131708
CDockWidget* SingleDockWidget = topLevelDockWidget();
@@ -1716,6 +1711,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
17161711
bool Dropped = false;
17171712

17181713
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
1714+
// mouse is over dock area
17191715
if (DockArea)
17201716
{
17211717
auto dropOverlay = d->DockManager->dockAreaOverlay();
@@ -1736,7 +1732,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
17361732
}
17371733
}
17381734

1739-
// mouse is over container
1735+
// mouse is over container or auto hide side bar
17401736
if (InvalidDockWidgetArea == dropArea && InvalidDockWidgetArea != ContainerDropArea)
17411737
{
17421738
if (internal::isSideBarArea(ContainerDropArea))

src/DockOverlay.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
506506
if (SideBar->isVisible())
507507
{
508508
d->TabIndex = SideBar->tabInsertIndexAt(SideBar->mapFromGlobal(CursorPos));
509-
qDebug() << "TabIndex " << d->TabIndex;
510509
}
511510
}
512511
return Result;
@@ -522,7 +521,6 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
522521
{
523522
auto TabBar = DockArea->titleBar()->tabBar();
524523
d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos));
525-
qDebug() << "TabIndex " << d->TabIndex;
526524
return CenterDockWidgetArea;
527525
}
528526

0 commit comments

Comments
 (0)