DockAreaWidget now properly considers minimumSizeHint() of contained DockWidgets

Added setMinimumSizeHintMode() test in demo MainWindow
This commit is contained in:
Uwe Kindler 2020-03-28 19:32:07 +01:00
parent d0f4ce3248
commit 0e88467f94
5 changed files with 59 additions and 2 deletions

View File

@ -224,11 +224,27 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
}
//===========================================================================
/**
* Custom QTableWidget with a minimum size hint to test CDockWidget
* setMinimumSizeHintMode() function of CDockWidget
*/
class CMinSizeTableWidget : public QTableWidget
{
public:
using QTableWidget::QTableWidget;
virtual QSize minimumSizeHint() const override
{
return QSize(300, 100);
}
};
//============================================================================
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
{
static int TableCount = 0;
QTableWidget* w = new QTableWidget();
auto w = new CMinSizeTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
@ -244,6 +260,7 @@ static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
}
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
DockWidget->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent);
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
}

View File

@ -50,6 +50,12 @@ public:
ForceScrollArea,
ForceNoScrollArea
};
enum eMinimumSizeHintMode
{
MinimumSizeHintFromDockWidget,
MinimumSizeHintFromContent
};
enum eToggleViewActionMode
{
@ -76,6 +82,7 @@ public:
bool isClosed() const;
QAction* toggleViewAction() const;
void setToggleViewActionMode(ads::CDockWidget::eToggleViewActionMode Mode);
void setMinimumSizeHintMode(ads::CDockWidget::eMinimumSizeHintMode Mode);
void setIcon(const QIcon& Icon);
QIcon icon() const;
QToolBar* toolBar() const;

View File

@ -247,6 +247,7 @@ struct DockAreaWidgetPrivate
CDockManager* DockManager = nullptr;
bool UpdateTitleBarButtons = false;
DockWidgetAreas AllowedAreas = AllDockAreas;
QSize MinSizeHint;
/**
* Private data constructor
@ -303,6 +304,20 @@ struct DockAreaWidgetPrivate
* Udpates the enable state of the close and detach button
*/
void updateTitleBarButtonStates();
/**
* Scans all contained dock widgets for the max. minimum size hint
*/
void updateMinimumSizeHint()
{
MinSizeHint = QSize();
for (int i = 0; i < ContentsLayout->count(); ++i)
{
auto Widget = ContentsLayout->widget(i);
MinSizeHint.setHeight(qMax(MinSizeHint.height(), Widget->minimumSizeHint().height()));
MinSizeHint.setWidth(qMax(MinSizeHint.width(), Widget->minimumSizeHint().width()));
}
}
};
// struct DockAreaWidgetPrivate
@ -407,6 +422,8 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
d->tabBar()->blockSignals(false);
TabWidget->setVisible(!DockWidget->isClosed());
DockWidget->setProperty(INDEX_PROPERTY, index);
d->MinSizeHint.setHeight(qMax(d->MinSizeHint.height(), DockWidget->minimumSizeHint().height()));
d->MinSizeHint.setWidth(qMax(d->MinSizeHint.width(), DockWidget->minimumSizeHint().width()));
if (Activate)
{
setCurrentIndex(index);
@ -447,6 +464,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
d->updateTitleBarButtonStates();
updateTitleBarVisibility();
d->updateMinimumSizeHint();
auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
if (TopLevelDockWidget)
{
@ -863,6 +881,13 @@ CDockAreaTitleBar* CDockAreaWidget::titleBar() const
{
return d->TitleBar;
}
//============================================================================
QSize CDockAreaWidget::minimumSizeHint() const
{
return d->MinSizeHint.isValid() ? d->MinSizeHint : Super::minimumSizeHint();
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -164,6 +164,13 @@ public:
*/
CDockContainerWidget* dockContainer() const;
/**
* Returns the largest minimumSizeHint() of the dock widgets in this
* area.
* The minimum size hint is updated if a dock widget is removed or added.
*/
virtual QSize minimumSizeHint() const override;
/**
* Returns the rectangle of the title area
*/

View File

@ -242,7 +242,8 @@ public:
virtual ~CDockWidget();
/**
* We return a fixed minimum size hint for all dock widgets
* We return a fixed minimum size hint or the size hint of the content
* widget if minimum size hint mode is MinimumSizeHintFromContent
*/
virtual QSize minimumSizeHint() const override;