Skip to content

Commit 7140e5e

Browse files
Properly handle dragging of dock widget into DockWidgetTabBar and AutoHideSideBar
1 parent f5cfe9e commit 7140e5e

File tree

7 files changed

+41
-16
lines changed

7 files changed

+41
-16
lines changed

src/AutoHideSideBar.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ void CAutoHideSideBar::insertTab(int Index, CAutoHideTab* SideTab)
196196
{
197197
SideTab->setSideBar(this);
198198
SideTab->installEventFilter(this);
199+
// Default insertion is append
199200
if (Index < 0)
200201
{
201202
d->TabsLayout->insertWidget(d->TabsLayout->count() - 1, SideTab);
@@ -451,7 +452,7 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
451452
{
452453
if (!isVisible())
453454
{
454-
return InvalidTabIndex;
455+
return TabInvalidIndex;
455456
}
456457

457458
if (orientation() == Qt::Horizontal)
@@ -486,9 +487,9 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
486487
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
487488
{
488489
int Index = tabAt(Pos);
489-
if (Index == InvalidTabIndex)
490+
if (Index == TabInvalidIndex)
490491
{
491-
return Append;
492+
return TabDefaultInsertIndex;
492493
}
493494
else
494495
{

src/AutoHideSideBar.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ 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;
8987

9088
/**
9189
* Default Constructor
@@ -119,7 +117,7 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
119117
* If the AutoHideWidget is in another sidebar, then it will be removed
120118
* from this sidebar.
121119
*/
122-
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = Append);
120+
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = TabDefaultInsertIndex);
123121

124122
/**
125123
* Returns orientation of side tab.

src/DockAreaTabBar.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ int CDockAreaTabBar::tabAt(const QPoint& Pos) const
510510
{
511511
if (!isVisible())
512512
{
513-
return -2;
513+
return TabInvalidIndex;
514514
}
515515

516516
if (Pos.x() < tab(0)->geometry().x())
@@ -529,6 +529,21 @@ int CDockAreaTabBar::tabAt(const QPoint& Pos) const
529529
return count();
530530
}
531531

532+
533+
//===========================================================================
534+
int CDockAreaTabBar::tabInsertIndexAt(const QPoint& Pos) const
535+
{
536+
int Index = tabAt(Pos);
537+
if (Index == TabInvalidIndex)
538+
{
539+
return TabDefaultInsertIndex;
540+
}
541+
else
542+
{
543+
return (Index < 0) ? 0 : Index;
544+
}
545+
}
546+
532547
} // namespace ads
533548

534549

src/DockAreaTabBar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ private Q_SLOTS:
121121
*/
122122
int tabAt(const QPoint& Pos) const;
123123

124+
/**
125+
* Returns the tab insertion index for the given mouse cursor position
126+
*/
127+
int tabInsertIndexAt(const QPoint& Pos) const;
128+
124129
/**
125130
* Filters the tab widget events
126131
*/

src/DockContainerWidget.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@ class DockContainerWidgetPrivate
190190
* Creates a new tab for a widget dropped into the center of a section
191191
*/
192192
void dropIntoCenterOfSection(CFloatingDockContainer* FloatingWidget,
193-
CDockAreaWidget* TargetArea, int TabIndex = -2);
193+
CDockAreaWidget* TargetArea, int TabIndex = 0);
194194

195195
/**
196196
* Drop floating widget into dock area
197197
*/
198198
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
199-
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex = -2);
199+
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex = 0);
200200

201201
/**
202202
* Moves the dock widget or dock area given in Widget parameter to a
203203
* new dock widget area
204204
*/
205205
void moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area,
206-
int TabIndex = -2);
206+
int TabIndex = 0);
207207

208208
/**
209209
* Moves the dock widget or dock area given in Widget parameter to a
@@ -214,13 +214,13 @@ class DockContainerWidgetPrivate
214214
/**
215215
* Creates a new tab for a widget dropped into the center of a section
216216
*/
217-
void moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea, int TabIndex = -2);
217+
void moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea, int TabIndex = 0);
218218

219219
/**
220220
* Moves the dock widget or dock area given in Widget parameter to
221221
* a auto hide sidebar area
222222
*/
223-
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = -2);
223+
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = TabDefaultInsertIndex);
224224

225225

226226
/**
@@ -543,7 +543,7 @@ void DockContainerWidgetPrivate::dropIntoCenterOfSection(
543543
auto NewDockWidgets = FloatingContainer->dockWidgets();
544544
auto TopLevelDockArea = FloatingContainer->topLevelDockArea();
545545
int NewCurrentIndex = -1;
546-
TabIndex = (TabIndex < 0) ? 0 : TabIndex;
546+
TabIndex = qMax(0, TabIndex);
547547

548548
// If the floating widget contains only one single dock are, then the
549549
// current dock widget of the dock area will also be the future current
@@ -675,7 +675,7 @@ void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockA
675675
auto DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
676676
auto DroppedArea = qobject_cast<CDockAreaWidget*>(Widget);
677677

678-
TabIndex = (TabIndex < 0) ? 0 : TabIndex;
678+
TabIndex = qMax(0, TabIndex);
679679
if (DroppedDockWidget)
680680
{
681681
CDockAreaWidget* OldDockArea = DroppedDockWidget->dockAreaWidget();
@@ -1493,7 +1493,6 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
14931493
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
14941494
}
14951495

1496-
qDebug() << "CDockContainerWidget::createAndSetupAutoHideContainer TabIndex: " << TabIndex;
14971496
return autoHideSideBar(area)->insertDockWidget(TabIndex, DockWidget);
14981497
}
14991498

src/DockOverlay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
520520
&& DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(CursorPos)))
521521
{
522522
auto TabBar = DockArea->titleBar()->tabBar();
523-
d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos));
523+
d->TabIndex = TabBar->tabInsertIndexAt(TabBar->mapFromGlobal(CursorPos));
524524
return CenterDockWidgetArea;
525525
}
526526

src/ads_globals.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ enum DockWidgetArea
9595
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
9696

9797

98+
enum eTabIndex
99+
{
100+
TabDefaultInsertIndex = -1,
101+
TabInvalidIndex = -2
102+
};
103+
104+
98105
enum TitleBarButton
99106
{
100107
TitleBarButtonTabsMenu,

0 commit comments

Comments
 (0)