Change splitter proportion from int to double

- Allows for fine grain control (can now set 0.75 or 0.6)
- Makes more sense
This commit is contained in:
Syarif Fakhri 2022-09-13 16:29:39 +08:00
parent 19192541f9
commit d394930d74
4 changed files with 23 additions and 13 deletions

View File

@ -95,7 +95,7 @@ struct DockWidgetPrivate
QList<QAction*> 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;
}

View File

@ -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 -----------------------------------------------
/**

View File

@ -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<int>(static_cast<double>(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;
}
}

View File

@ -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