Fix docking behavior when there is a central widget

This commit is contained in:
Syarif Fakhri 2022-09-13 16:02:14 +08:00
parent 42498b2021
commit 8ddabc4cc8
4 changed files with 23 additions and 10 deletions

View File

@ -1129,6 +1129,22 @@ bool CDockAreaWidget::isCentralWidgetArea() const
} }
//============================================================================
bool CDockAreaWidget::containsCentralWidget() const
{
auto centralWidget = dockManager()->centralWidget();
for (const auto &dockWidget : dockWidgets())
{
if (dockWidget == centralWidget)
{
return true;
}
}
return false;
}
//============================================================================ //============================================================================
QSize CDockAreaWidget::minimumSizeHint() const QSize CDockAreaWidget::minimumSizeHint() const
{ {

View File

@ -358,10 +358,15 @@ public:
void setDockAreaFlag(eDockAreaFlag Flag, bool On); void setDockAreaFlag(eDockAreaFlag Flag, bool On);
/** /**
* Returns true if the area contains the central widget of it's manager. * Returns true if the area has a single dock widget and contains the central widget of it's manager.
*/ */
bool isCentralWidgetArea() const; bool isCentralWidgetArea() const;
/**
* Returns true if the area contains the central widget of it's manager.
*/
bool containsCentralWidget() const;
public Q_SLOTS: public Q_SLOTS:
/** /**
* This activates the tab for the given tab index. * This activates the tab for the given tab index.

View File

@ -1898,8 +1898,6 @@ QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
//============================================================================ //============================================================================
QList<CDockWidget*> CDockContainerWidget::openedDockWidgets() const QList<CDockWidget*> CDockContainerWidget::openedDockWidgets() const
{ {
// todo: cleanup
qInfo() << "Opened Dock Widgets: ";
QList<CDockWidget*> DockWidgetList; QList<CDockWidget*> DockWidgetList;
for (auto DockArea : d->DockAreas) for (auto DockArea : d->DockAreas)
{ {
@ -1909,12 +1907,6 @@ QList<CDockWidget*> CDockContainerWidget::openedDockWidgets() const
} }
} }
// todo: cleanup
for (auto dockWidget : DockWidgetList)
{
qInfo() << "Opened dock widgets: " << dockWidget->objectName();
}
return DockWidgetList; return DockWidgetList;
} }

View File

@ -282,7 +282,7 @@ void COverlayDockContainer::moveContentsToParent()
const auto position = mapToGlobal(d->Area == CDockWidgetSideTab::Left ? QPoint(1,height() / 2) : QPoint(width() - 1, height() / 2)); const auto position = mapToGlobal(d->Area == CDockWidgetSideTab::Left ? QPoint(1,height() / 2) : QPoint(width() - 1, height() / 2));
const auto dockAreaWidget = parentContainer()->dockAreaAt(position); const auto dockAreaWidget = parentContainer()->dockAreaAt(position);
if (dockAreaWidget != nullptr && !dockAreaWidget->isCentralWidgetArea()) if (dockAreaWidget != nullptr && !dockAreaWidget->containsCentralWidget())
{ {
parentContainer()->addDockWidget(CenterDockWidgetArea, d->DockWidget, dockAreaWidget); parentContainer()->addDockWidget(CenterDockWidgetArea, d->DockWidget, dockAreaWidget);
} }