Merge branch 'dev'

This commit is contained in:
Uwe Kindler 2020-03-28 19:32:59 +01:00
commit 1b6e449b4a
6 changed files with 99 additions and 3 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 ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
{ {
static int TableCount = 0; static int TableCount = 0;
QTableWidget* w = new QTableWidget(); auto w = new CMinSizeTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++)); ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5; static int colCount = 5;
static int rowCount = 30; static int rowCount = 30;
@ -244,6 +260,7 @@ static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
} }
DockWidget->setWidget(w); DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
DockWidget->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent);
ViewMenu->addAction(DockWidget->toggleViewAction()); ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget; return DockWidget;
} }

View File

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

View File

@ -247,6 +247,7 @@ struct DockAreaWidgetPrivate
CDockManager* DockManager = nullptr; CDockManager* DockManager = nullptr;
bool UpdateTitleBarButtons = false; bool UpdateTitleBarButtons = false;
DockWidgetAreas AllowedAreas = AllDockAreas; DockWidgetAreas AllowedAreas = AllDockAreas;
QSize MinSizeHint;
/** /**
* Private data constructor * Private data constructor
@ -303,6 +304,20 @@ struct DockAreaWidgetPrivate
* Udpates the enable state of the close and detach button * Udpates the enable state of the close and detach button
*/ */
void updateTitleBarButtonStates(); 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 // struct DockAreaWidgetPrivate
@ -407,6 +422,8 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
d->tabBar()->blockSignals(false); d->tabBar()->blockSignals(false);
TabWidget->setVisible(!DockWidget->isClosed()); TabWidget->setVisible(!DockWidget->isClosed());
DockWidget->setProperty(INDEX_PROPERTY, index); 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) if (Activate)
{ {
setCurrentIndex(index); setCurrentIndex(index);
@ -447,6 +464,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
d->updateTitleBarButtonStates(); d->updateTitleBarButtonStates();
updateTitleBarVisibility(); updateTitleBarVisibility();
d->updateMinimumSizeHint();
auto TopLevelDockWidget = DockContainer->topLevelDockWidget(); auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
if (TopLevelDockWidget) if (TopLevelDockWidget)
{ {
@ -863,6 +881,13 @@ CDockAreaTitleBar* CDockAreaWidget::titleBar() const
{ {
return d->TitleBar; return d->TitleBar;
} }
//============================================================================
QSize CDockAreaWidget::minimumSizeHint() const
{
return d->MinSizeHint.isValid() ? d->MinSizeHint : Super::minimumSizeHint();
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -164,6 +164,13 @@ public:
*/ */
CDockContainerWidget* dockContainer() const; 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 * Returns the rectangle of the title area
*/ */

View File

@ -82,6 +82,7 @@ struct DockWidgetPrivate
QSize ToolBarIconSizeFloating = QSize(24, 24); QSize ToolBarIconSizeFloating = QSize(24, 24);
bool IsFloatingTopLevel = false; bool IsFloatingTopLevel = false;
QList<QAction*> TitleBarActions; QList<QAction*> TitleBarActions;
CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget;
/** /**
* Private data constructor * Private data constructor
@ -424,6 +425,13 @@ void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode)
} }
//============================================================================
void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode)
{
d->MinimumSizeHintMode = Mode;
}
//============================================================================ //============================================================================
void CDockWidget::toggleView(bool Open) void CDockWidget::toggleView(bool Open)
{ {
@ -753,7 +761,14 @@ void CDockWidget::setClosedState(bool Closed)
//============================================================================ //============================================================================
QSize CDockWidget::minimumSizeHint() const QSize CDockWidget::minimumSizeHint() const
{ {
return QSize(60, 40); if (d->MinimumSizeHintMode == CDockWidget::MinimumSizeHintFromDockWidget || !d->Widget)
{
return QSize(60, 40);
}
else
{
return d->Widget->minimumSizeHint();
}
} }

View File

@ -189,6 +189,23 @@ public:
ForceNoScrollArea ForceNoScrollArea
}; };
/**
* The mode of the minimumSizeHint() that is returned by the DockWidget
* minimumSizeHint() function.
* To ensure, that a dock widget does not block resizing, the dock widget
* reimplements minimumSizeHint() function to return a very small minimum
* size hint. If you would like to adhere the minimumSizeHint() from the
* content widget, the set the minimumSizeHintMode() to
* MinimumSizeHintFromContent.
*/
enum eMinimumSizeHintMode
{
MinimumSizeHintFromDockWidget,
MinimumSizeHintFromContent
};
/** /**
* This mode configures the behavior of the toggle view action. * This mode configures the behavior of the toggle view action.
* If the mode if ActionModeToggle, then the toggle view action is * If the mode if ActionModeToggle, then the toggle view action is
@ -225,7 +242,8 @@ public:
virtual ~CDockWidget(); 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; virtual QSize minimumSizeHint() const override;
@ -334,6 +352,13 @@ public:
*/ */
void setToggleViewActionMode(eToggleViewActionMode Mode); void setToggleViewActionMode(eToggleViewActionMode Mode);
/**
* Configures the minimum size hint that is returned by the
* minimumSizeHint() function.
* \see eMinimumSizeHintMode for a detailed description
*/
void setMinimumSizeHintMode(eMinimumSizeHintMode Mode);
/** /**
* Sets the dock widget icon that is shown in tabs and in toggle view * Sets the dock widget icon that is shown in tabs and in toggle view
* actions * actions