Set splitter sizes based on proportion settable in the dock widget

This commit is contained in:
Syarif Fakhri 2022-09-13 11:20:46 +08:00
parent 214c415fa2
commit 4841d9b896
5 changed files with 61 additions and 29 deletions

View File

@ -46,7 +46,7 @@ CMainWindow::CMainWindow(QWidget *parent)
TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
TableDockWidget->resize(250, 150);
TableDockWidget->setMinimumSize(200,150);
TableDockWidget->setFeature(CDockWidget::DockWidgetDeleteOnClose, true);
TableDockWidget->setDefaultOverlayDockProportion(2);
DockManager->addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea::Left, TableDockWidget);
ui->menuView->addAction(TableDockWidget->toggleViewAction());

View File

@ -95,6 +95,7 @@ struct DockWidgetPrivate
QList<QAction*> TitleBarActions;
CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget;
WidgetFactory* Factory = nullptr;
int DefaultOverlayDockProportion = 4;
/**
* Private data constructor
@ -1133,6 +1134,18 @@ bool CDockWidget::isCurrentTab() const
}
//============================================================================
void CDockWidget::setDefaultOverlayDockProportion(int Proportion)
{
d->DefaultOverlayDockProportion = Proportion;
}
int CDockWidget::DefaultOverlayDockProportion() const
{
return d->DefaultOverlayDockProportion;
}
//============================================================================
void CDockWidget::raise()
{

View File

@ -511,6 +511,18 @@ public:
*/
bool isCurrentTab() const;
/*
* Set default dock proportion when overlayed
* 4 is a quarter of the size, 2 is half the size, 1 is the entire size
*/
void setDefaultOverlayDockProportion(int Proportion);
/*
* Set default dock proportion when overlayed
* 4 is a quarter of the size, 2 is half the size, 1 is the entire size
*/
int DefaultOverlayDockProportion() const;
public: // reimplements QFrame -----------------------------------------------
/**
* Emits titleChanged signal if title change event occurs

View File

@ -188,6 +188,7 @@ COverlayDockContainer::COverlayDockContainer(CDockWidget* DockWidget, CDockWidge
COverlayDockContainer(DockWidget->dockManager(), area, parent)
{
addDockWidget(DockWidget);
setDockSizeProportion(DockWidget->DefaultOverlayDockProportion());
}
//============================================================================
@ -234,30 +235,6 @@ void COverlayDockContainer::addDockWidget(CDockWidget* DockWidget)
OldDockArea->removeDockWidget(DockWidget);
}
d->DockArea->addDockWidget(DockWidget);
const auto dockContainerParent = parentContainer();
const auto rootSplitter = dockContainerParent->rootSplitter();
const auto rect = rootSplitter->frameGeometry();
const auto dockWidth = DockWidget->sizeHint().width();
switch (d->Area)
{
case CDockWidgetSideTab::Left:
{
d->Splitter->setSizes({ dockWidth, rect.width() - dockWidth });
break;
}
case CDockWidgetSideTab::Right:
{
d->Splitter->setSizes({ rect.width() - dockWidth, dockWidth });
break;
}
case CDockWidgetSideTab::Bottom:
{
d->Splitter->setSizes({ rect.width() - dockWidth, dockWidth });
break;
}
}
d->DockWidget->sideTabWidget()->updateOrientationAndSpacing(d->Area);
updateSize();
@ -265,6 +242,28 @@ void COverlayDockContainer::addDockWidget(CDockWidget* DockWidget)
}
//============================================================================
void COverlayDockContainer::setDockSizeProportion(int SplitterProportion)
{
switch (d->Area)
{
case CDockWidgetSideTab::Left:
{
d->Splitter->setSizes({ INT_MAX / SplitterProportion, INT_MAX - INT_MAX / SplitterProportion });
break;
}
case CDockWidgetSideTab::Right:
[[fallthrough]];
case CDockWidgetSideTab::Bottom:
{
d->Splitter->setSizes({ INT_MAX - INT_MAX / SplitterProportion, INT_MAX / SplitterProportion });
break;
}
}
}
//============================================================================
CDockWidgetSideTab::SideTabBarArea COverlayDockContainer::sideTabBarArea() const
{

View File

@ -49,17 +49,17 @@ class CDockingStateReader;
class ADS_EXPORT COverlayDockContainer : public QFrame
{
Q_OBJECT
Q_OBJECT
private:
OverlayDockContainerPrivate* d; ///< private data (pimpl)
friend struct OverlayDockContainerPrivate;
OverlayDockContainerPrivate* d; ///< private data (pimpl)
friend struct OverlayDockContainerPrivate;
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
void updateMask();
void updateMask();
void updateSize();
CDockContainerWidget* parentContainer() const;
@ -95,6 +95,14 @@ public:
*/
void addDockWidget(CDockWidget* DockWidget);
/*
* 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
*/
void setDockSizeProportion(int SplitterProportion = 4);
/**
* Returns the side tab bar area of this overlay dock container
*/