Skip to content

Commit 0e3c3ba

Browse files
chris-seChristian Seiler
andauthored
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 <c.seiler@luxflux.de>
1 parent 3a5c965 commit 0e3c3ba

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/DockManager.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "DockingStateReader.h"
5656
#include "DockAreaTitleBar.h"
5757
#include "DockFocusController.h"
58+
#include "DockSplitter.h"
5859

5960
#ifdef Q_OS_LINUX
6061
#include "linux/FloatingWidgetTitleBar.h"
@@ -1093,6 +1094,34 @@ CDockWidget* CDockManager::focusedDockWidget() const
10931094
}
10941095
}
10951096

1097+
//===========================================================================
1098+
QList<int> CDockManager::splitterSizes(CDockAreaWidget *ContainedArea) const
1099+
{
1100+
if (ContainedArea)
1101+
{
1102+
auto Splitter = internal::findParent<CDockSplitter*>(ContainedArea);
1103+
if (Splitter)
1104+
{
1105+
return Splitter->sizes();
1106+
}
1107+
}
1108+
return QList<int>();
1109+
}
1110+
1111+
//===========================================================================
1112+
void CDockManager::setSplitterSizes(CDockAreaWidget *ContainedArea, const QList<int>& sizes)
1113+
{
1114+
if (!ContainedArea)
1115+
{
1116+
return;
1117+
}
1118+
1119+
auto Splitter = internal::findParent<CDockSplitter*>(ContainedArea);
1120+
if (Splitter && Splitter->count() == sizes.count())
1121+
{
1122+
Splitter->setSizes(sizes);
1123+
}
1124+
}
10961125

10971126
} // namespace ads
10981127

src/DockManager.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,25 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
487487
*/
488488
CDockWidget* focusedDockWidget() const;
489489

490+
/**
491+
* Returns the sizes of the splitter that contains the dock area.
492+
*
493+
* If there is no splitter that contains the area, an empty list will be
494+
* returned.
495+
*/
496+
QList<int> splitterSizes(CDockAreaWidget *ContainedArea) const;
497+
498+
/**
499+
* Update the sizes of a splitter
500+
* Programmatically updates the sizes of a given splitter by calling
501+
* QSplitter::setSizes(). The splitter will be the splitter that
502+
* contains the supplied dock area widget. If there is not splitter
503+
* that contains the dock area, or the sizes supplied does not match
504+
* the number of children of the splitter, this method will have no
505+
* effect.
506+
*/
507+
void setSplitterSizes(CDockAreaWidget *ContainedArea, const QList<int>& sizes);
508+
490509
public slots:
491510
/**
492511
* Opens the perspective with the given name.

0 commit comments

Comments
 (0)