Skip to content

Commit 7b30229

Browse files
authored
feat: add preferred auto-hide sidebar location per dock widget (#829)
Add preferredAutoHideSideBarLocation property to CDockWidget that allows applications to specify where a widget should be pinned, overriding geometry-based detection. When unpinning, widgets with the same preferred location merge as tabs instead of creating new splits. Default is SideBarNone (existing geometry-based behavior preserved).
1 parent 4a0b636 commit 7b30229

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

src/AutoHideDockContainer.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,31 @@ void CAutoHideDockContainer::moveContentsToParent()
415415
// to the user and he does not have to search where the widget was inserted.
416416
d->DockWidget->setDockArea(nullptr);
417417
auto DockContainer = dockContainer();
418-
DockContainer->addDockWidget(d->getDockWidgetArea(d->SideTabBarArea), d->DockWidget);
418+
auto targetArea = d->getDockWidgetArea(d->SideTabBarArea);
419+
420+
// If the widget has a preferred auto-hide location, try to find an existing
421+
// opened dock area that contains a widget with the same preferred location
422+
// and merge as a tab instead of creating a new split.
423+
auto preferred = d->DockWidget->preferredAutoHideSideBarLocation();
424+
if (preferred != SideBarNone)
425+
{
426+
for (auto area : DockContainer->openedDockAreas())
427+
{
428+
if (!area || area->isAutoHide()) continue;
429+
// Check if any widget in this area has the same preferred location
430+
for (auto dw : area->dockWidgets())
431+
{
432+
if (dw && dw->preferredAutoHideSideBarLocation() == preferred)
433+
{
434+
DockContainer->addDockWidget(CenterDockWidgetArea,
435+
d->DockWidget, area);
436+
return;
437+
}
438+
}
439+
}
440+
}
441+
442+
DockContainer->addDockWidget(targetArea, d->DockWidget);
419443
}
420444

421445

src/DockWidget.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ struct DockWidgetPrivate
9696
WidgetFactory* Factory = nullptr;
9797
QPointer<CAutoHideTab> SideTabWidget;
9898
CDockWidget::eToolBarStyleSource ToolBarStyleSource = CDockWidget::ToolBarStyleFromDockManager;
99-
99+
SideBarLocation PreferredAutoHideSideBarLocation = SideBarNone;
100+
100101
/**
101102
* Private data constructor
102103
*/
@@ -654,6 +655,20 @@ SideBarLocation CDockWidget::autoHideLocation() const
654655
}
655656

656657

658+
//============================================================================
659+
void CDockWidget::setPreferredAutoHideSideBarLocation(SideBarLocation Location)
660+
{
661+
d->PreferredAutoHideSideBarLocation = Location;
662+
}
663+
664+
665+
//============================================================================
666+
SideBarLocation CDockWidget::preferredAutoHideSideBarLocation() const
667+
{
668+
return d->PreferredAutoHideSideBarLocation;
669+
}
670+
671+
657672
//============================================================================
658673
bool CDockWidget::isFloating() const
659674
{
@@ -1337,7 +1352,15 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location, int TabInde
13371352
}
13381353
else
13391354
{
1340-
auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location;
1355+
auto area = Location;
1356+
if (SideBarNone == area && d->PreferredAutoHideSideBarLocation != SideBarNone)
1357+
{
1358+
area = d->PreferredAutoHideSideBarLocation;
1359+
}
1360+
else if (SideBarNone == area)
1361+
{
1362+
area = DockArea->calculateSideTabBarArea();
1363+
}
13411364
dockContainer()->createAndSetupAutoHideContainer(area, this, TabIndex);
13421365
}
13431366
}

src/DockWidget.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ private Q_SLOTS:
422422
*/
423423
SideBarLocation autoHideLocation() const;
424424

425+
/**
426+
* Sets the preferred auto-hide sidebar location for this dock widget.
427+
* When set to a value other than SideBarNone, the pin button will place
428+
* this widget in the specified sidebar instead of using geometry-based
429+
* detection. When unpinning, widgets with the same preferred location
430+
* will be merged as tabs in the same dock area.
431+
* Set to SideBarNone (default) to use the original geometry-based behavior.
432+
*/
433+
void setPreferredAutoHideSideBarLocation(SideBarLocation Location);
434+
435+
/**
436+
* Returns the preferred auto-hide sidebar location, or SideBarNone
437+
* if no preference is set (geometry-based detection will be used).
438+
*/
439+
SideBarLocation preferredAutoHideSideBarLocation() const;
440+
425441
/**
426442
* This property holds whether the dock widget is floating.
427443
* A dock widget is only floating, if it is the one and only widget inside

0 commit comments

Comments
 (0)