From 4841d9b89675f59cd553271b51115a6d61e5067e Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Tue, 13 Sep 2022 11:20:46 +0800 Subject: [PATCH] Set splitter sizes based on proportion settable in the dock widget --- examples/autohide/mainwindow.cpp | 2 +- src/DockWidget.cpp | 13 +++++++++ src/DockWidget.h | 12 ++++++++ src/OverlayDockContainer.cpp | 47 ++++++++++++++++---------------- src/OverlayDockContainer.h | 16 ++++++++--- 5 files changed, 61 insertions(+), 29 deletions(-) diff --git a/examples/autohide/mainwindow.cpp b/examples/autohide/mainwindow.cpp index 1e9a448..ef5da7d 100644 --- a/examples/autohide/mainwindow.cpp +++ b/examples/autohide/mainwindow.cpp @@ -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()); diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index a87ac04..1a97b03 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -95,6 +95,7 @@ struct DockWidgetPrivate QList 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() { diff --git a/src/DockWidget.h b/src/DockWidget.h index 1bcd03b..5fa176f 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -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 diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index 6007e5b..b4069fa 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -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 { diff --git a/src/OverlayDockContainer.h b/src/OverlayDockContainer.h index a0c8ab3..b723ca7 100644 --- a/src/OverlayDockContainer.h +++ b/src/OverlayDockContainer.h @@ -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 */