forked from qt-creator/qt-creator
ADS: Set default minimum size on empty dock widget
* Set a default minimum size on empty dock widgets. Dock widgets are empty if their content minimum size isEmpty (width or height <= 0) * Replace 0 with nullptr as return value * Fix some code formatting Task-number: QDS-11255 Change-Id: Ifa7320fd57e73367f71087232dedd939d19ae490 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
ccc9010d26
commit
f2eee58e00
@@ -161,8 +161,8 @@ bool isSideBarArea(DockWidgetArea area);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for the parent widget of the given type. Returns the parent widget of the given
|
* Searches for the parent widget of the given type. Returns the parent widget of the given
|
||||||
* widget or 0 if the widget is not child of any widget of type T.
|
* widget or nullptr if the widget is not child of any widget of type T.
|
||||||
* It is not safe to use this function in in DockWidget because only the current dock widget has a
|
* It is not safe to use this function in DockWidget, because only the current dock widget has a
|
||||||
* parent. All dock widgets that are not the current dock widget in a dock area have no parent.
|
* parent. All dock widgets that are not the current dock widget in a dock area have no parent.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -171,12 +171,12 @@ T findParent(const QWidget *widget)
|
|||||||
QWidget *parentWidget = widget->parentWidget();
|
QWidget *parentWidget = widget->parentWidget();
|
||||||
while (parentWidget) {
|
while (parentWidget) {
|
||||||
T parentImpl = qobject_cast<T>(parentWidget);
|
T parentImpl = qobject_cast<T>(parentWidget);
|
||||||
if (parentImpl) {
|
if (parentImpl)
|
||||||
return parentImpl;
|
return parentImpl;
|
||||||
}
|
|
||||||
parentWidget = parentWidget->parentWidget();
|
parentWidget = parentWidget->parentWidget();
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -50,10 +50,9 @@ bool DockSplitter::hasVisibleContent() const
|
|||||||
{
|
{
|
||||||
// TODO Cache or precalculate this to speed up
|
// TODO Cache or precalculate this to speed up
|
||||||
for (int i = 0; i < count(); ++i) {
|
for (int i = 0; i < count(); ++i) {
|
||||||
if (!widget(i)->isHidden()) {
|
if (!widget(i)->isHidden())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -70,6 +70,27 @@ static void hideToolButtons(QList<QToolButton*> &buttons)
|
|||||||
button->hide();
|
button->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ensureMinimumSize(QWidget *widget)
|
||||||
|
{
|
||||||
|
if (widget->minimumSize().isEmpty())
|
||||||
|
widget->setMinimumSize(widget->minimumSize().expandedTo(QSize(60, 60)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static ADS::DockWidget *createDockWidget(QWidget *widget,
|
||||||
|
const QString &uniqueId,
|
||||||
|
const QString &title,
|
||||||
|
ADS::DockWidget::eMinimumSizeHintMode minimumSizeHintMode)
|
||||||
|
{
|
||||||
|
ADS::DockWidget *dockWidget = new ADS::DockWidget(uniqueId);
|
||||||
|
dockWidget->setWidget(widget, ADS::DockWidget::ForceNoScrollArea);
|
||||||
|
dockWidget->setWindowTitle(title);
|
||||||
|
dockWidget->setMinimumSizeHintMode(minimumSizeHintMode);
|
||||||
|
|
||||||
|
widget->setObjectName(uniqueId); // Set unique id as object name
|
||||||
|
|
||||||
|
return dockWidget;
|
||||||
|
}
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -308,15 +329,10 @@ void DesignModeWidget::setup()
|
|||||||
sheet += "QLabel { background-color: creatorTheme.DSsectionHeadBackground; }";
|
sheet += "QLabel { background-color: creatorTheme.DSsectionHeadBackground; }";
|
||||||
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||||
|
|
||||||
// Create DockWidget
|
ensureMinimumSize(navigationView.widget);
|
||||||
ADS::DockWidget *dockWidget = new ADS::DockWidget(uniqueId);
|
|
||||||
dockWidget->setWidget(navigationView.widget, ADS::DockWidget::ForceNoScrollArea);
|
|
||||||
dockWidget->setWindowTitle(title);
|
|
||||||
dockWidget->setMinimumSizeHintMode(m_minimumSizeHintMode);
|
|
||||||
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
|
||||||
|
|
||||||
// Set unique id as object name
|
auto dockWidget = createDockWidget(navigationView.widget, uniqueId, title, m_minimumSizeHintMode);
|
||||||
navigationView.widget->setObjectName(uniqueId);
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
||||||
|
|
||||||
// Create menu action
|
// Create menu action
|
||||||
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
||||||
@@ -328,19 +344,17 @@ void DesignModeWidget::setup()
|
|||||||
|
|
||||||
// Afterwards get all the other widgets
|
// Afterwards get all the other widgets
|
||||||
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
||||||
// Create DockWidget
|
ensureMinimumSize(widgetInfo.widget);
|
||||||
ADS::DockWidget *dockWidget = new ADS::DockWidget(widgetInfo.uniqueId);
|
|
||||||
dockWidget->setWidget(widgetInfo.widget, ADS::DockWidget::ForceNoScrollArea);
|
auto dockWidget = createDockWidget(widgetInfo.widget,
|
||||||
dockWidget->setWindowTitle(widgetInfo.tabName);
|
widgetInfo.uniqueId,
|
||||||
dockWidget->setMinimumSizeHintMode(m_minimumSizeHintMode);
|
widgetInfo.tabName,
|
||||||
|
m_minimumSizeHintMode);
|
||||||
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
||||||
|
|
||||||
// Add to view widgets
|
// Add to view widgets
|
||||||
m_viewWidgets.append(widgetInfo.widget);
|
m_viewWidgets.append(widgetInfo.widget);
|
||||||
|
|
||||||
// Set unique id as object name
|
|
||||||
widgetInfo.widget->setObjectName(widgetInfo.uniqueId);
|
|
||||||
|
|
||||||
// Create menu action
|
// Create menu action
|
||||||
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
||||||
actionToggle.withSuffix(
|
actionToggle.withSuffix(
|
||||||
@@ -354,14 +368,14 @@ void DesignModeWidget::setup()
|
|||||||
{
|
{
|
||||||
const QString uniqueId = "OutputPane";
|
const QString uniqueId = "OutputPane";
|
||||||
auto outputPanePlaceholder = new Core::OutputPanePlaceHolder(Core::Constants::MODE_DESIGN);
|
auto outputPanePlaceholder = new Core::OutputPanePlaceHolder(Core::Constants::MODE_DESIGN);
|
||||||
m_outputPaneDockWidget = new ADS::DockWidget(uniqueId);
|
|
||||||
m_outputPaneDockWidget->setWidget(outputPanePlaceholder, ADS::DockWidget::ForceNoScrollArea);
|
|
||||||
m_outputPaneDockWidget->setWindowTitle(tr("Output"));
|
|
||||||
m_outputPaneDockWidget->setMinimumSizeHintMode(m_minimumSizeHintMode);
|
|
||||||
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, m_outputPaneDockWidget);
|
|
||||||
|
|
||||||
// Set unique id as object name
|
ensureMinimumSize(outputPanePlaceholder);
|
||||||
outputPanePlaceholder->setObjectName(uniqueId);
|
|
||||||
|
m_outputPaneDockWidget = createDockWidget(outputPanePlaceholder,
|
||||||
|
uniqueId,
|
||||||
|
tr("Output"),
|
||||||
|
m_minimumSizeHintMode);
|
||||||
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, m_outputPaneDockWidget);
|
||||||
|
|
||||||
// Create menu action
|
// Create menu action
|
||||||
auto command = Core::ActionManager::registerAction(m_outputPaneDockWidget->toggleViewAction(),
|
auto command = Core::ActionManager::registerAction(m_outputPaneDockWidget->toggleViewAction(),
|
||||||
|
Reference in New Issue
Block a user