Skip to content

Commit be727c5

Browse files
Added initial support for inserting dropped dock widgets at a certain sidebar position
1 parent f4fc0da commit be727c5

12 files changed

+107
-48
lines changed

src/AutoHideDockContainer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
689689

690690

691691
//============================================================================
692-
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation)
692+
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation,
693+
int TabIndex)
693694
{
694695
if (NewSideBarLocation == sideBarLocation())
695696
{
@@ -698,7 +699,7 @@ void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBar
698699

699700
auto OldOrientation = orientation();
700701
auto SideBar = dockContainer()->autoHideSideBar(NewSideBarLocation);
701-
SideBar->addAutoHideWidget(this);
702+
SideBar->addAutoHideWidget(this, TabIndex);
702703
// If we move a horizontal auto hide container to a vertical position
703704
// then we resize it to the orginal dock widget size, to avoid
704705
// an extremely streched dock widget after insertion

src/AutoHideDockContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class ADS_EXPORT CAutoHideDockContainer : public QFrame
195195
* Removes the AutoHide container from the current side bar and adds
196196
* it to the new side bar given in SideBarLocation
197197
*/
198-
void moveToNewSideBarLocation(SideBarLocation SideBarLocation);
198+
void moveToNewSideBarLocation(SideBarLocation SideBarLocation, int TabIndex = -1);
199199
};
200200
} // namespace ads
201201

src/AutoHideSideBar.cpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ void CAutoHideSideBar::removeAutoHideWidget(CAutoHideDockContainer* AutoHideWidg
233233
}
234234

235235
//============================================================================
236-
void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget)
236+
void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
237+
int Index)
237238
{
238239
auto SideBar = AutoHideWidget->autoHideTab()->sideBar();
239240
if (SideBar == this)
@@ -248,7 +249,7 @@ void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget)
248249
AutoHideWidget->setParent(d->ContainerWidget);
249250
AutoHideWidget->setSideBarLocation(d->SideTabArea);
250251
d->ContainerWidget->registerAutoHideWidget(AutoHideWidget);
251-
insertTab(-1, AutoHideWidget->autoHideTab());
252+
insertTab(Index, AutoHideWidget->autoHideTab());
252253
}
253254

254255

@@ -302,14 +303,14 @@ Qt::Orientation CAutoHideSideBar::orientation() const
302303

303304

304305
//============================================================================
305-
CAutoHideTab* CAutoHideSideBar::tabAt(int index) const
306+
CAutoHideTab* CAutoHideSideBar::tab(int index) const
306307
{
307308
return qobject_cast<CAutoHideTab*>(d->TabsLayout->itemAt(index)->widget());
308309
}
309310

310311

311312
//============================================================================
312-
int CAutoHideSideBar::tabCount() const
313+
int CAutoHideSideBar::count() const
313314
{
314315
return d->TabsLayout->count() - 1;
315316
}
@@ -318,27 +319,27 @@ int CAutoHideSideBar::tabCount() const
318319
//============================================================================
319320
int CAutoHideSideBar::visibleTabCount() const
320321
{
321-
int count = 0;
322+
int VisibleTabCount = 0;
322323
auto ParentWidget = parentWidget();
323-
for (auto i = 0; i < tabCount(); i++)
324+
for (auto i = 0; i < count(); i++)
324325
{
325-
if (tabAt(i)->isVisibleTo(ParentWidget))
326+
if (tab(i)->isVisibleTo(ParentWidget))
326327
{
327-
count++;
328+
VisibleTabCount++;
328329
}
329330
}
330331

331-
return count;
332+
return VisibleTabCount;
332333
}
333334

334335

335336
//============================================================================
336337
bool CAutoHideSideBar::hasVisibleTabs() const
337338
{
338339
auto ParentWidget = parentWidget();
339-
for (auto i = 0; i < tabCount(); i++)
340+
for (auto i = 0; i < count(); i++)
340341
{
341-
if (tabAt(i)->isVisibleTo(ParentWidget))
342+
if (tab(i)->isVisibleTo(ParentWidget))
342343
{
343344
return true;
344345
}
@@ -358,18 +359,18 @@ SideBarLocation CAutoHideSideBar::sideBarLocation() const
358359
//============================================================================
359360
void CAutoHideSideBar::saveState(QXmlStreamWriter& s) const
360361
{
361-
if (!tabCount())
362+
if (!count())
362363
{
363364
return;
364365
}
365366

366367
s.writeStartElement("SideBar");
367368
s.writeAttribute("Area", QString::number(sideBarLocation()));
368-
s.writeAttribute("Tabs", QString::number(tabCount()));
369+
s.writeAttribute("Tabs", QString::number(count()));
369370

370-
for (auto i = 0; i < tabCount(); ++i)
371+
for (auto i = 0; i < count(); ++i)
371372
{
372-
auto Tab = tabAt(i);
373+
auto Tab = tab(i);
373374
if (!Tab)
374375
{
375376
continue;
@@ -417,5 +418,38 @@ CDockContainerWidget* CAutoHideSideBar::dockContainer() const
417418
return d->ContainerWidget;
418419
}
419420

421+
422+
//===========================================================================
423+
int CAutoHideSideBar::tabAt(const QPoint& Pos) const
424+
{
425+
if (!isVisible())
426+
{
427+
return -2;
428+
}
429+
430+
if (Pos.x() < tab(0)->geometry().x())
431+
{
432+
return -1;
433+
}
434+
435+
for (int i = 0; i < count(); ++i)
436+
{
437+
if (tab(i)->geometry().contains(Pos))
438+
{
439+
return i;
440+
}
441+
}
442+
443+
return count();
444+
}
445+
446+
447+
//===========================================================================
448+
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
449+
{
450+
int Index = tabAt(Pos);
451+
return (Index < 0) ? -1 : Index;
452+
}
453+
420454
} // namespace ads
421455

src/AutoHideSideBar.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
117117
* If the AutoHideWidget is in another sidebar, then it will be removed
118118
* from this sidebar.
119119
*/
120-
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget);
120+
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = -1);
121121

122122
/**
123123
* Returns orientation of side tab.
@@ -127,12 +127,25 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
127127
/*
128128
* get the side tab widget at position, returns nullptr if it's out of bounds
129129
*/
130-
CAutoHideTab* tabAt(int index) const;
130+
CAutoHideTab* tab(int index) const;
131+
132+
/**
133+
* Returns the tab at the given position.
134+
* 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+
*/
138+
int tabAt(const QPoint& Pos) const;
139+
140+
/**
141+
* Returns the tab insertion index for the given mouse cursor position
142+
*/
143+
int tabInsertIndexAt(const QPoint& Pos) const;
131144

132145
/*
133146
* Gets the count of the tab widgets
134147
*/
135-
int tabCount() const;
148+
int count() const;
136149

137150
/**
138151
* Returns the number of visible tabs to its parent widget.

src/DockAreaWidget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ SideBarLocation CDockAreaWidget::calculateSideTabBarArea() const
13051305

13061306

13071307
//============================================================================
1308-
void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
1308+
void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location, int TabIndex)
13091309
{
13101310
if (!isAutoHideFeatureEnabled())
13111311
{
@@ -1324,7 +1324,7 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
13241324
// If this is already an auto hide container, then move it to new location
13251325
if (isAutoHide())
13261326
{
1327-
d->AutoHideDockContainer->moveToNewSideBarLocation(Location);
1327+
d->AutoHideDockContainer->moveToNewSideBarLocation(Location, TabIndex);
13281328
return;
13291329
}
13301330

@@ -1341,7 +1341,7 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
13411341
continue;
13421342
}
13431343

1344-
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget);
1344+
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget, TabIndex++);
13451345
}
13461346
}
13471347

src/DockAreaWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public Q_SLOTS:
400400
* If the dock area is switched to auto hide mode, then all dock widgets
401401
* that are pinable will be added to the sidebar
402402
*/
403-
void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone);
403+
void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone, int TabIndex = -1);
404404

405405
/**
406406
* Switches the dock area to auto hide mode or vice versa depending on its

src/DockContainerWidget.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class DockContainerWidgetPrivate
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);
223+
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = -2);
224224

225225

226226
/**
@@ -777,7 +777,7 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg
777777

778778

779779
//============================================================================
780-
void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area)
780+
void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex)
781781
{
782782
CDockWidget* DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
783783
CDockAreaWidget* DroppedDockArea = qobject_cast<CDockAreaWidget*>(Widget);
@@ -787,18 +787,18 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
787787
{
788788
if (_this == DroppedDockWidget->dockContainer())
789789
{
790-
DroppedDockWidget->setAutoHide(true, SideBarLocation);
790+
DroppedDockWidget->setAutoHide(true, SideBarLocation, TabIndex);
791791
}
792792
else
793793
{
794-
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget);
794+
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget, TabIndex);
795795
}
796796
}
797797
else
798798
{
799799
if (_this == DroppedDockArea->dockContainer())
800800
{
801-
DroppedDockArea->setAutoHide(true, SideBarLocation);
801+
DroppedDockArea->setAutoHide(true, SideBarLocation, TabIndex);
802802
}
803803
else
804804
{
@@ -811,7 +811,7 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
811811
}
812812

813813
_this->createAndSetupAutoHideContainer(SideBarLocation,
814-
DockWidget);
814+
DockWidget, TabIndex++);
815815
}
816816
}
817817
}
@@ -988,7 +988,7 @@ void DockContainerWidgetPrivate::saveAutoHideWidgetsState(QXmlStreamWriter& s)
988988
{
989989
for (const auto sideTabBar : SideTabBarWidgets.values())
990990
{
991-
if (!sideTabBar->tabCount())
991+
if (!sideTabBar->count())
992992
{
993993
continue;
994994
}
@@ -1484,7 +1484,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
14841484

14851485
//============================================================================
14861486
CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
1487-
SideBarLocation area, CDockWidget* DockWidget)
1487+
SideBarLocation area, CDockWidget* DockWidget, int TabIndex)
14881488
{
14891489
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
14901490
{
@@ -1497,7 +1497,8 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
14971497
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
14981498
}
14991499

1500-
return autoHideSideBar(area)->insertDockWidget(-1, DockWidget);
1500+
qDebug() << "CDockContainerWidget::createAndSetupAutoHideContainer TabIndex: " << TabIndex;
1501+
return autoHideSideBar(area)->insertDockWidget(TabIndex, DockWidget);
15011502
}
15021503

15031504

@@ -1794,7 +1795,7 @@ void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea,
17941795
}
17951796
else if (internal::isSideBarArea(DropArea))
17961797
{
1797-
d->moveToAutoHideSideBar(Widget, DropArea);
1798+
d->moveToAutoHideSideBar(Widget, DropArea, TabIndex);
17981799
}
17991800
else
18001801
{

src/DockContainerWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
101101
* Initializing inserts the tabs into the side tab widget and hides it
102102
* Returns nullptr if you try and insert into an area where the configuration is not enabled
103103
*/
104-
CAutoHideDockContainer* createAndSetupAutoHideContainer(SideBarLocation area, CDockWidget* DockWidget);
104+
CAutoHideDockContainer* createAndSetupAutoHideContainer(SideBarLocation area, CDockWidget* DockWidget, int TabIndex = -1);
105105

106106
/**
107107
* The funtion does the same like createAndSetupAutoHideContainer() but checks
@@ -133,7 +133,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
133133
* TargetAreaWidget
134134
*/
135135
void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget,
136-
int TabIndex = -2);
136+
int TabIndex = -1);
137137

138138
/**
139139
* Adds the given dock area to this container widget

0 commit comments

Comments
 (0)