From d394930d742306253706402469b9e2956b9e86fc Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Tue, 13 Sep 2022 16:29:39 +0800 Subject: [PATCH] Change splitter proportion from int to double - Allows for fine grain control (can now set 0.75 or 0.6) - Makes more sense --- src/DockWidget.cpp | 8 +++++--- src/DockWidget.h | 8 ++++---- src/OverlayDockContainer.cpp | 14 +++++++++++--- src/OverlayDockContainer.h | 6 +++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 1a97b03..f633e27 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -95,7 +95,7 @@ struct DockWidgetPrivate QList TitleBarActions; CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget; WidgetFactory* Factory = nullptr; - int DefaultOverlayDockProportion = 4; + double DefaultOverlayDockProportion = 0.25; /** * Private data constructor @@ -1135,12 +1135,14 @@ bool CDockWidget::isCurrentTab() const //============================================================================ -void CDockWidget::setDefaultOverlayDockProportion(int Proportion) +void CDockWidget::setDefaultOverlayDockProportion(double Proportion) { d->DefaultOverlayDockProportion = Proportion; } -int CDockWidget::DefaultOverlayDockProportion() const + +//============================================================================ +double CDockWidget::DefaultOverlayDockProportion() const { return d->DefaultOverlayDockProportion; } diff --git a/src/DockWidget.h b/src/DockWidget.h index 373f068..da0000c 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -514,15 +514,15 @@ public: /* * Set default dock proportion when overlayed - * 4 is a quarter of the size, 2 is half the size, 1 is the entire size + * see *DefaultOverlayDockProportion() */ - void setDefaultOverlayDockProportion(int Proportion); + void setDefaultOverlayDockProportion(double Proportion); /* * Set default dock proportion when overlayed - * 4 is a quarter of the size, 2 is half the size, 1 is the entire size + * 0.25 is a quarter of the size, 0.5 is half the size, 1 is the entire size */ - int DefaultOverlayDockProportion() const; + double DefaultOverlayDockProportion() const; public: // reimplements QFrame ----------------------------------------------- /** diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index ebb72d9..1aca25e 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -243,20 +243,28 @@ void COverlayDockContainer::addDockWidget(CDockWidget* DockWidget) //============================================================================ -void COverlayDockContainer::setDockSizeProportion(int SplitterProportion) +void COverlayDockContainer::setDockSizeProportion(double SplitterProportion) { + if (SplitterProportion < 0 || SplitterProportion > 1) + { + ADS_PRINT("SplitterProportion must be set between 0 and 1."); + return; + } + + const auto dockSize = static_cast(static_cast(INT_MAX) * SplitterProportion); + const auto remainingSize = INT_MAX - dockSize; switch (d->Area) { case CDockWidgetSideTab::Left: { - d->Splitter->setSizes({ INT_MAX / SplitterProportion, INT_MAX - INT_MAX / SplitterProportion }); + d->Splitter->setSizes({ dockSize, remainingSize }); break; } case CDockWidgetSideTab::Right: [[fallthrough]]; case CDockWidgetSideTab::Bottom: { - d->Splitter->setSizes({ INT_MAX - INT_MAX / SplitterProportion, INT_MAX / SplitterProportion }); + d->Splitter->setSizes({ remainingSize, dockSize }); break; } } diff --git a/src/OverlayDockContainer.h b/src/OverlayDockContainer.h index b723ca7..175a1b8 100644 --- a/src/OverlayDockContainer.h +++ b/src/OverlayDockContainer.h @@ -98,10 +98,10 @@ public: /* * Set default splitter sizes. Don't use when restoring state * As we want the size from the XML - * Takes an int which determines the size proportion of the child dock - * E.g. 4 is a quarter of the size, 2 is half the size and 1 is the entire size of the container + * Takes a float between 0 and 1 + * E.g. 0.25 is a quarter of the size, 0.5 is half the size and 1 is the entire size of the container */ - void setDockSizeProportion(int SplitterProportion = 4); + void setDockSizeProportion(double SplitterProportion = 0.25); /** * Returns the side tab bar area of this overlay dock container