From 0e3c3bab456732b5803eaa4dc753a03e7bb60f6c Mon Sep 17 00:00:00 2001 From: Christian Seiler Date: Fri, 23 Oct 2020 20:59:50 +0200 Subject: [PATCH] DockManager: add the ability to programmatically update splitter sizes (#266) Add the ability to programmatically update splitter sizes. The user must specify the dock area that is contained in a splitter and a list of sizes. The list of sizes will be passed to the splitter that immediately contains the specified dock area. If the dock area is not part of a splitter the method will have no effect. Co-authored-by: Christian Seiler --- src/DockManager.cpp | 29 +++++++++++++++++++++++++++++ src/DockManager.h | 19 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 16b2d01..a7b0ddb 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -55,6 +55,7 @@ #include "DockingStateReader.h" #include "DockAreaTitleBar.h" #include "DockFocusController.h" +#include "DockSplitter.h" #ifdef Q_OS_LINUX #include "linux/FloatingWidgetTitleBar.h" @@ -1093,6 +1094,34 @@ CDockWidget* CDockManager::focusedDockWidget() const } } +//=========================================================================== +QList CDockManager::splitterSizes(CDockAreaWidget *ContainedArea) const +{ + if (ContainedArea) + { + auto Splitter = internal::findParent(ContainedArea); + if (Splitter) + { + return Splitter->sizes(); + } + } + return QList(); +} + +//=========================================================================== +void CDockManager::setSplitterSizes(CDockAreaWidget *ContainedArea, const QList& sizes) +{ + if (!ContainedArea) + { + return; + } + + auto Splitter = internal::findParent(ContainedArea); + if (Splitter && Splitter->count() == sizes.count()) + { + Splitter->setSizes(sizes); + } +} } // namespace ads diff --git a/src/DockManager.h b/src/DockManager.h index 8832415..c3924d3 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -487,6 +487,25 @@ public: */ CDockWidget* focusedDockWidget() const; + /** + * Returns the sizes of the splitter that contains the dock area. + * + * If there is no splitter that contains the area, an empty list will be + * returned. + */ + QList splitterSizes(CDockAreaWidget *ContainedArea) const; + + /** + * Update the sizes of a splitter + * Programmatically updates the sizes of a given splitter by calling + * QSplitter::setSizes(). The splitter will be the splitter that + * contains the supplied dock area widget. If there is not splitter + * that contains the dock area, or the sizes supplied does not match + * the number of children of the splitter, this method will have no + * effect. + */ + void setSplitterSizes(CDockAreaWidget *ContainedArea, const QList& sizes); + public slots: /** * Opens the perspective with the given name.