diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 2fb345c..fe9097f 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -968,12 +968,14 @@ CDockAreaTitleBar* CDockAreaWidget::titleBar() const //============================================================================ -bool CDockAreaWidget::isCentralWidgetArea() +bool CDockAreaWidget::isCentralWidgetArea() const { - if(dockWidgetsCount()!=1) + if (dockWidgetsCount()!= 1) + { return false; + } - return dockManager()->centralWidget()==dockWidgets()[0]; + return dockManager()->centralWidget() == dockWidgets()[0]; } diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 231af91..ac7dcb5 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -310,7 +310,7 @@ public: /** * Returns true if the area contains the central widget of it's manager. */ - bool isCentralWidgetArea(); + bool isCentralWidgetArea() const; public slots: /** diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 171a8e0..a10495e 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -323,14 +323,15 @@ public: } /** - * This finction forces the dock container widget to update handles of splitters - * based on resize modes of dock widgets aontained in the container. + * This function forces the dock container widget to update handles of splitters + * based if a central widget exists. */ void updateSplitterHandles(QSplitter* splitter); /** - * This function returns true if the area is not allowed to resize in the direstion - * of the splitter. Otherwise returns true. + * If no central widget exists, the widgets resize with the container. + * If a central widget exists, the widgets surrounding the central widget + * do not resize its height or width. */ bool widgetResizesWithContainer(QWidget* widget); @@ -711,15 +712,14 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg //============================================================================ void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter ) { - if(DockManager->centralWidget()) + if (!DockManager->centralWidget() || !splitter) + { + return; + } + + for (int i = 0; i < splitter->count(); ++i) { - if( splitter ) - { - for( int index = 0; index < splitter->count(); index++ ) - { - splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0); - } - } + splitter->setStretchFactor(i, widgetResizesWithContainer(splitter->widget(i)) ? 1 : 0); } } @@ -727,19 +727,21 @@ void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter ) //============================================================================ bool DockContainerWidgetPrivate::widgetResizesWithContainer(QWidget* widget) { - if(!DockManager->centralWidget()) + if (!DockManager->centralWidget()) + { return true; + } - CDockAreaWidget* Area = dynamic_cast< CDockAreaWidget* >( widget ); + auto Area = qobject_cast(widget); if(Area) { return Area->isCentralWidgetArea(); } - CDockSplitter* innerSplitter = dynamic_cast< CDockSplitter* >( widget ); - if(innerSplitter) + auto innerSplitter = qobject_cast(widget); + if (innerSplitter) { - return innerSplitter->resizeWithContainer(); + return innerSplitter->isResizingWithContainer(); } return false; diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 5e8b8cb..0bc674b 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -156,8 +156,8 @@ protected: QList dockWidgets() const; /** - * This finction forces the dock container widget to update handles of splitters - * based on resize modes of dock widgets aontained in the container. + * This function forces the dock container widget to update handles of splitters + * based on resize modes of dock widgets contained in the container. */ void updateSplitterHandles(QSplitter* splitter); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 503a122..55ef20f 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -831,31 +831,38 @@ void CDockManager::loadPerspectives(QSettings& Settings) Settings.endArray(); } -CDockWidget* CDockManager::centralWidget() + +//============================================================================ +CDockWidget* CDockManager::centralWidget() const { return d->CentralWidget; } -//============================================================================ -CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea) -{ - oldCentralWidget = d->CentralWidget; - if(oldCentralWidget) - { - addDockWidget(oldCentralWidgetArea, oldCentralWidget); - } - if(widget) - { - widget->setFeature(CDockWidget::DockWidgetClosable, false); - widget->setFeature(CDockWidget::DockWidgetMovable, false); - widget->setFeature(CDockWidget::DockWidgetFloatable, false); - d->CentralWidget = widget; - CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget); - CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); - return CentralArea; - } - return nullptr; +//============================================================================ +CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget) +{ + if (!widget) + { + d->CentralWidget = nullptr; + return nullptr; + } + + // Setting a new central widget is now allowed if there is alread a central + // widget + if (d->CentralWidget) + { + return nullptr; + } + + + widget->setFeature(CDockWidget::DockWidgetClosable, false); + widget->setFeature(CDockWidget::DockWidgetMovable, false); + widget->setFeature(CDockWidget::DockWidgetFloatable, false); + d->CentralWidget = widget; + CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget); + CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); + return CentralArea; } //============================================================================ diff --git a/src/DockManager.h b/src/DockManager.h index 07f735c..f56fc13 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -381,16 +381,23 @@ public: /** * This function returns managers central widget or nullptr if no central widget is set. */ - CDockWidget* centralWidget(); + CDockWidget* centralWidget() const; /** - * Adds dockwidget into the central area and marks it as central widget. + * Adds dockwidget widget into the central area and marks it as central widget. * If central widget is set, it will be the only dock widget - * that will resize with the dock container. - * If a central widget does exist, it will be docked to oldCentralWidgetArea - * and returned in oldCentralWidget. + * that will resize with the dock container. A central widget if not + * movable, floatable or closable and the titlebar of the central + * dock area is not visible. + * If the given widget could be set as central widget, the function returns + * the created cok area. If the widget could not be set, because there + * is already a central widget, this function returns a nullptr. + * To clear the central widget, pass a nullptr to the function. + * \retval != 0 The dock area that contains the central widget + * \retval nullptr Indicates that the given widget can not be set as central + * widget because there is already a central widget. */ - CDockAreaWidget* setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget = nullptr, DockWidgetArea oldCentralWidgetArea = DockWidgetArea::RightDockWidgetArea); + CDockAreaWidget* setCentralWidget(CDockWidget* widget); /** * Adds a toggle view action to the the internal view menu. diff --git a/src/DockSplitter.cpp b/src/DockSplitter.cpp index 2be1f07..047f0f4 100644 --- a/src/DockSplitter.cpp +++ b/src/DockSplitter.cpp @@ -103,16 +103,16 @@ QWidget* CDockSplitter::lastWidget() const } //============================================================================ -bool CDockSplitter::resizeWithContainer() +bool CDockSplitter::isResizingWithContainer() const { - QList areas = findChildren(); - - for(int i=0; i()) { - CDockAreaWidget* area = areas.at(i); if(area->isCentralWidgetArea()) + { return true; + } } + return false; } diff --git a/src/DockSplitter.h b/src/DockSplitter.h index 9dacdf8..1cc766c 100644 --- a/src/DockSplitter.h +++ b/src/DockSplitter.h @@ -75,7 +75,7 @@ public: /** * Returns true if the splitter contains central widget of dock manager. */ - bool resizeWithContainer(); + bool isResizingWithContainer() const; }; // class CDockSplitter } // namespace ads diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 22b282b..0893e2d 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -463,7 +463,8 @@ void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode) } -bool CDockWidget::isCentralWidget() +//============================================================================ +bool CDockWidget::isCentralWidget() const { return dockManager()->centralWidget() == this; } diff --git a/src/DockWidget.h b/src/DockWidget.h index b574fa4..b5fb5a1 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -361,9 +361,9 @@ public: void setMinimumSizeHintMode(eMinimumSizeHintMode Mode); /** - * Returns true if the dock wisget is set as central widget of it's dock manager + * Returns true if the dock widget is set as central widget of it's dock manager */ - bool isCentralWidget(); + bool isCentralWidget() const; /** * Sets the dock widget icon that is shown in tabs and in toggle view