Added initial support for inserting dropped dock widgets at a certain sidebar position

This commit is contained in:
Uwe Kindler 2023-07-12 10:42:24 +02:00
parent f4fc0dab29
commit be727c5890
12 changed files with 107 additions and 48 deletions

View File

@ -689,7 +689,8 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
//============================================================================ //============================================================================
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation) void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation,
int TabIndex)
{ {
if (NewSideBarLocation == sideBarLocation()) if (NewSideBarLocation == sideBarLocation())
{ {
@ -698,7 +699,7 @@ void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBar
auto OldOrientation = orientation(); auto OldOrientation = orientation();
auto SideBar = dockContainer()->autoHideSideBar(NewSideBarLocation); auto SideBar = dockContainer()->autoHideSideBar(NewSideBarLocation);
SideBar->addAutoHideWidget(this); SideBar->addAutoHideWidget(this, TabIndex);
// If we move a horizontal auto hide container to a vertical position // If we move a horizontal auto hide container to a vertical position
// then we resize it to the orginal dock widget size, to avoid // then we resize it to the orginal dock widget size, to avoid
// an extremely streched dock widget after insertion // an extremely streched dock widget after insertion

View File

@ -195,7 +195,7 @@ public:
* Removes the AutoHide container from the current side bar and adds * Removes the AutoHide container from the current side bar and adds
* it to the new side bar given in SideBarLocation * it to the new side bar given in SideBarLocation
*/ */
void moveToNewSideBarLocation(SideBarLocation SideBarLocation); void moveToNewSideBarLocation(SideBarLocation SideBarLocation, int TabIndex = -1);
}; };
} // namespace ads } // namespace ads

View File

@ -233,7 +233,8 @@ void CAutoHideSideBar::removeAutoHideWidget(CAutoHideDockContainer* AutoHideWidg
} }
//============================================================================ //============================================================================
void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget) void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
int Index)
{ {
auto SideBar = AutoHideWidget->autoHideTab()->sideBar(); auto SideBar = AutoHideWidget->autoHideTab()->sideBar();
if (SideBar == this) if (SideBar == this)
@ -248,7 +249,7 @@ void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget)
AutoHideWidget->setParent(d->ContainerWidget); AutoHideWidget->setParent(d->ContainerWidget);
AutoHideWidget->setSideBarLocation(d->SideTabArea); AutoHideWidget->setSideBarLocation(d->SideTabArea);
d->ContainerWidget->registerAutoHideWidget(AutoHideWidget); d->ContainerWidget->registerAutoHideWidget(AutoHideWidget);
insertTab(-1, AutoHideWidget->autoHideTab()); insertTab(Index, AutoHideWidget->autoHideTab());
} }
@ -302,14 +303,14 @@ Qt::Orientation CAutoHideSideBar::orientation() const
//============================================================================ //============================================================================
CAutoHideTab* CAutoHideSideBar::tabAt(int index) const CAutoHideTab* CAutoHideSideBar::tab(int index) const
{ {
return qobject_cast<CAutoHideTab*>(d->TabsLayout->itemAt(index)->widget()); return qobject_cast<CAutoHideTab*>(d->TabsLayout->itemAt(index)->widget());
} }
//============================================================================ //============================================================================
int CAutoHideSideBar::tabCount() const int CAutoHideSideBar::count() const
{ {
return d->TabsLayout->count() - 1; return d->TabsLayout->count() - 1;
} }
@ -318,17 +319,17 @@ int CAutoHideSideBar::tabCount() const
//============================================================================ //============================================================================
int CAutoHideSideBar::visibleTabCount() const int CAutoHideSideBar::visibleTabCount() const
{ {
int count = 0; int VisibleTabCount = 0;
auto ParentWidget = parentWidget(); auto ParentWidget = parentWidget();
for (auto i = 0; i < tabCount(); i++) for (auto i = 0; i < count(); i++)
{ {
if (tabAt(i)->isVisibleTo(ParentWidget)) if (tab(i)->isVisibleTo(ParentWidget))
{ {
count++; VisibleTabCount++;
} }
} }
return count; return VisibleTabCount;
} }
@ -336,9 +337,9 @@ int CAutoHideSideBar::visibleTabCount() const
bool CAutoHideSideBar::hasVisibleTabs() const bool CAutoHideSideBar::hasVisibleTabs() const
{ {
auto ParentWidget = parentWidget(); auto ParentWidget = parentWidget();
for (auto i = 0; i < tabCount(); i++) for (auto i = 0; i < count(); i++)
{ {
if (tabAt(i)->isVisibleTo(ParentWidget)) if (tab(i)->isVisibleTo(ParentWidget))
{ {
return true; return true;
} }
@ -358,18 +359,18 @@ SideBarLocation CAutoHideSideBar::sideBarLocation() const
//============================================================================ //============================================================================
void CAutoHideSideBar::saveState(QXmlStreamWriter& s) const void CAutoHideSideBar::saveState(QXmlStreamWriter& s) const
{ {
if (!tabCount()) if (!count())
{ {
return; return;
} }
s.writeStartElement("SideBar"); s.writeStartElement("SideBar");
s.writeAttribute("Area", QString::number(sideBarLocation())); s.writeAttribute("Area", QString::number(sideBarLocation()));
s.writeAttribute("Tabs", QString::number(tabCount())); s.writeAttribute("Tabs", QString::number(count()));
for (auto i = 0; i < tabCount(); ++i) for (auto i = 0; i < count(); ++i)
{ {
auto Tab = tabAt(i); auto Tab = tab(i);
if (!Tab) if (!Tab)
{ {
continue; continue;
@ -417,5 +418,38 @@ CDockContainerWidget* CAutoHideSideBar::dockContainer() const
return d->ContainerWidget; return d->ContainerWidget;
} }
//===========================================================================
int CAutoHideSideBar::tabAt(const QPoint& Pos) const
{
if (!isVisible())
{
return -2;
}
if (Pos.x() < tab(0)->geometry().x())
{
return -1;
}
for (int i = 0; i < count(); ++i)
{
if (tab(i)->geometry().contains(Pos))
{
return i;
}
}
return count();
}
//===========================================================================
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
{
int Index = tabAt(Pos);
return (Index < 0) ? -1 : Index;
}
} // namespace ads } // namespace ads

View File

@ -117,7 +117,7 @@ public:
* If the AutoHideWidget is in another sidebar, then it will be removed * If the AutoHideWidget is in another sidebar, then it will be removed
* from this sidebar. * from this sidebar.
*/ */
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget); void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = -1);
/** /**
* Returns orientation of side tab. * Returns orientation of side tab.
@ -127,12 +127,25 @@ public:
/* /*
* get the side tab widget at position, returns nullptr if it's out of bounds * get the side tab widget at position, returns nullptr if it's out of bounds
*/ */
CAutoHideTab* tabAt(int index) const; CAutoHideTab* tab(int index) const;
/**
* Returns the tab at the given position.
* Returns -1 if the position is left of the first tab and count() if the
* position is right of the last tab. Returns -2 to indicate an invalid
* value.
*/
int tabAt(const QPoint& Pos) const;
/**
* Returns the tab insertion index for the given mouse cursor position
*/
int tabInsertIndexAt(const QPoint& Pos) const;
/* /*
* Gets the count of the tab widgets * Gets the count of the tab widgets
*/ */
int tabCount() const; int count() const;
/** /**
* Returns the number of visible tabs to its parent widget. * Returns the number of visible tabs to its parent widget.

View File

@ -1305,7 +1305,7 @@ SideBarLocation CDockAreaWidget::calculateSideTabBarArea() const
//============================================================================ //============================================================================
void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location) void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location, int TabIndex)
{ {
if (!isAutoHideFeatureEnabled()) if (!isAutoHideFeatureEnabled())
{ {
@ -1324,7 +1324,7 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
// If this is already an auto hide container, then move it to new location // If this is already an auto hide container, then move it to new location
if (isAutoHide()) if (isAutoHide())
{ {
d->AutoHideDockContainer->moveToNewSideBarLocation(Location); d->AutoHideDockContainer->moveToNewSideBarLocation(Location, TabIndex);
return; return;
} }
@ -1341,7 +1341,7 @@ void CDockAreaWidget::setAutoHide(bool Enable, SideBarLocation Location)
continue; continue;
} }
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget); dockContainer()->createAndSetupAutoHideContainer(area, DockWidget, TabIndex++);
} }
} }

View File

@ -400,7 +400,7 @@ public Q_SLOTS:
* If the dock area is switched to auto hide mode, then all dock widgets * If the dock area is switched to auto hide mode, then all dock widgets
* that are pinable will be added to the sidebar * that are pinable will be added to the sidebar
*/ */
void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone); void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone, int TabIndex = -1);
/** /**
* Switches the dock area to auto hide mode or vice versa depending on its * Switches the dock area to auto hide mode or vice versa depending on its

View File

@ -220,7 +220,7 @@ public:
* Moves the dock widget or dock area given in Widget parameter to * Moves the dock widget or dock area given in Widget parameter to
* a auto hide sidebar area * a auto hide sidebar area
*/ */
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area); void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = -2);
/** /**
@ -777,7 +777,7 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg
//============================================================================ //============================================================================
void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area) void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex)
{ {
CDockWidget* DroppedDockWidget = qobject_cast<CDockWidget*>(Widget); CDockWidget* DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
CDockAreaWidget* DroppedDockArea = qobject_cast<CDockAreaWidget*>(Widget); CDockAreaWidget* DroppedDockArea = qobject_cast<CDockAreaWidget*>(Widget);
@ -787,18 +787,18 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
{ {
if (_this == DroppedDockWidget->dockContainer()) if (_this == DroppedDockWidget->dockContainer())
{ {
DroppedDockWidget->setAutoHide(true, SideBarLocation); DroppedDockWidget->setAutoHide(true, SideBarLocation, TabIndex);
} }
else else
{ {
_this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget); _this->createAndSetupAutoHideContainer(SideBarLocation, DroppedDockWidget, TabIndex);
} }
} }
else else
{ {
if (_this == DroppedDockArea->dockContainer()) if (_this == DroppedDockArea->dockContainer())
{ {
DroppedDockArea->setAutoHide(true, SideBarLocation); DroppedDockArea->setAutoHide(true, SideBarLocation, TabIndex);
} }
else else
{ {
@ -811,7 +811,7 @@ void DockContainerWidgetPrivate::moveToAutoHideSideBar(QWidget* Widget, DockWidg
} }
_this->createAndSetupAutoHideContainer(SideBarLocation, _this->createAndSetupAutoHideContainer(SideBarLocation,
DockWidget); DockWidget, TabIndex++);
} }
} }
} }
@ -988,7 +988,7 @@ void DockContainerWidgetPrivate::saveAutoHideWidgetsState(QXmlStreamWriter& s)
{ {
for (const auto sideTabBar : SideTabBarWidgets.values()) for (const auto sideTabBar : SideTabBarWidgets.values())
{ {
if (!sideTabBar->tabCount()) if (!sideTabBar->count())
{ {
continue; continue;
} }
@ -1484,7 +1484,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
//============================================================================ //============================================================================
CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer( CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
SideBarLocation area, CDockWidget* DockWidget) SideBarLocation area, CDockWidget* DockWidget, int TabIndex)
{ {
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
{ {
@ -1497,7 +1497,8 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
} }
return autoHideSideBar(area)->insertDockWidget(-1, DockWidget); qDebug() << "CDockContainerWidget::createAndSetupAutoHideContainer TabIndex: " << TabIndex;
return autoHideSideBar(area)->insertDockWidget(TabIndex, DockWidget);
} }
@ -1794,7 +1795,7 @@ void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea,
} }
else if (internal::isSideBarArea(DropArea)) else if (internal::isSideBarArea(DropArea))
{ {
d->moveToAutoHideSideBar(Widget, DropArea); d->moveToAutoHideSideBar(Widget, DropArea, TabIndex);
} }
else else
{ {

View File

@ -101,7 +101,7 @@ protected:
* Initializing inserts the tabs into the side tab widget and hides it * Initializing inserts the tabs into the side tab widget and hides it
* Returns nullptr if you try and insert into an area where the configuration is not enabled * Returns nullptr if you try and insert into an area where the configuration is not enabled
*/ */
CAutoHideDockContainer* createAndSetupAutoHideContainer(SideBarLocation area, CDockWidget* DockWidget); CAutoHideDockContainer* createAndSetupAutoHideContainer(SideBarLocation area, CDockWidget* DockWidget, int TabIndex = -1);
/** /**
* The funtion does the same like createAndSetupAutoHideContainer() but checks * The funtion does the same like createAndSetupAutoHideContainer() but checks
@ -133,7 +133,7 @@ protected:
* TargetAreaWidget * TargetAreaWidget
*/ */
void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget, void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget,
int TabIndex = -2); int TabIndex = -1);
/** /**
* Adds the given dock area to this container widget * Adds the given dock area to this container widget

View File

@ -471,6 +471,7 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
return Result; return Result;
} }
auto CursorPos = QCursor::pos();
auto DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data()); auto DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data());
if (!DockArea && CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideFeatureEnabled)) if (!DockArea && CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideFeatureEnabled))
{ {
@ -479,26 +480,34 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
if ((pos.x() < d->sideBarMouseZone(SideBarLeft)) if ((pos.x() < d->sideBarMouseZone(SideBarLeft))
&& d->AllowedAreas.testFlag(LeftAutoHideArea)) && d->AllowedAreas.testFlag(LeftAutoHideArea))
{ {
return LeftAutoHideArea; Result = LeftAutoHideArea;
} }
else if (pos.x() > (Rect.width() - d->sideBarMouseZone(SideBarRight)) else if (pos.x() > (Rect.width() - d->sideBarMouseZone(SideBarRight))
&& d->AllowedAreas.testFlag(RightAutoHideArea)) && d->AllowedAreas.testFlag(RightAutoHideArea))
{ {
return RightAutoHideArea; Result = RightAutoHideArea;
} }
else if (pos.y() < d->sideBarMouseZone(SideBarTop) else if (pos.y() < d->sideBarMouseZone(SideBarTop)
&& d->AllowedAreas.testFlag(TopAutoHideArea)) && d->AllowedAreas.testFlag(TopAutoHideArea))
{ {
return TopAutoHideArea; Result = TopAutoHideArea;
} }
else if (pos.y() > (Rect.height() - d->sideBarMouseZone(SideBarBottom)) else if (pos.y() > (Rect.height() - d->sideBarMouseZone(SideBarBottom))
&& d->AllowedAreas.testFlag(BottomAutoHideArea)) && d->AllowedAreas.testFlag(BottomAutoHideArea))
{ {
return BottomAutoHideArea; Result = BottomAutoHideArea;
} }
else
auto SideBarLocation = ads::internal::toSideBarLocation(Result);
if (SideBarLocation != SideBarNone)
{ {
return Result; auto Container = qobject_cast<CDockContainerWidget*>(d->TargetWidget.data());
auto SideBar = Container->autoHideSideBar(SideBarLocation);
if (SideBar->isVisible())
{
d->TabIndex = SideBar->tabInsertIndexAt(SideBar->mapFromGlobal(CursorPos));
qDebug() << "TabIndex " << d->TabIndex;
}
} }
return Result; return Result;
} }
@ -507,13 +516,13 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
return Result; return Result;
} }
auto CursorPos = QCursor::pos();
if (DockArea->allowedAreas().testFlag(CenterDockWidgetArea) if (DockArea->allowedAreas().testFlag(CenterDockWidgetArea)
&& !DockArea->titleBar()->isHidden() && !DockArea->titleBar()->isHidden()
&& DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(CursorPos))) && DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(CursorPos)))
{ {
auto TabBar = DockArea->titleBar()->tabBar(); auto TabBar = DockArea->titleBar()->tabBar();
d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos)); d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos));
qDebug() << "TabIndex " << d->TabIndex;
return CenterDockWidgetArea; return CenterDockWidgetArea;
} }

View File

@ -1221,7 +1221,7 @@ void CDockWidget::raise()
//============================================================================ //============================================================================
void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location) void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location, int TabIndex)
{ {
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
{ {
@ -1247,7 +1247,7 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
else else
{ {
auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location; auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location;
dockContainer()->createAndSetupAutoHideContainer(area, this); dockContainer()->createAndSetupAutoHideContainer(area, this, TabIndex);
} }
} }

View File

@ -621,7 +621,7 @@ public Q_SLOTS:
* Sets the dock widget into auto hide mode if this feature is enabled * Sets the dock widget into auto hide mode if this feature is enabled
* via CDockManager::setAutoHideFlags(CDockManager::AutoHideFeatureEnabled) * via CDockManager::setAutoHideFlags(CDockManager::AutoHideFeatureEnabled)
*/ */
void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone); void setAutoHide(bool Enable, SideBarLocation Location = SideBarNone, int TabIndex = -1);
/** /**
* Switches the dock widget to auto hide mode or vice versa depending on its * Switches the dock widget to auto hide mode or vice versa depending on its

View File

@ -409,7 +409,8 @@ void CFloatingDragPreview::finishDragging()
DockArea = d->DropContainer->dockAreaAt(QCursor::pos()); DockArea = d->DropContainer->dockAreaAt(QCursor::pos());
} }
d->DropContainer->dropWidget(d->Content, ContainerDropArea, DockArea); d->DropContainer->dropWidget(d->Content, ContainerDropArea, DockArea,
d->DockManager->containerOverlay()->tabIndexUnderCursor());
} }
else else
{ {