Merge pull request #14688 from davesrocketshop/issue_14686
Materials: Set MaterialTreeWidget minimum size
This commit is contained in:
@@ -59,7 +59,9 @@ MaterialTreeWidget::MaterialTreeWidget(const std::shared_ptr<Materials::Material
|
||||
QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_expanded(false)
|
||||
, m_treeSizeHint(minimumTreeWidth, minimumTreeHeight)
|
||||
, _filter(filter)
|
||||
, _recentMax(defaultRecents)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
@@ -69,8 +71,10 @@ MaterialTreeWidget::MaterialTreeWidget(
|
||||
QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_expanded(false)
|
||||
, m_treeSizeHint(minimumTreeWidth, minimumTreeHeight)
|
||||
, _filter(std::make_shared<Materials::MaterialFilter>())
|
||||
, _filterList(filterList)
|
||||
, _recentMax(defaultRecents)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
@@ -78,7 +82,9 @@ MaterialTreeWidget::MaterialTreeWidget(
|
||||
MaterialTreeWidget::MaterialTreeWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_expanded(false)
|
||||
, m_treeSizeHint(minimumTreeWidth, minimumTreeHeight)
|
||||
, _filter(std::make_shared<Materials::MaterialFilter>())
|
||||
, _recentMax(defaultRecents)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
@@ -102,6 +108,30 @@ MaterialTreeWidget::~MaterialTreeWidget()
|
||||
saveMaterialTree();
|
||||
}
|
||||
|
||||
QSize MaterialTreeWidget::sizeHint() const
|
||||
{
|
||||
if (!m_expanded) {
|
||||
// When not expanded, the size height is the same as m_material
|
||||
QSize size = m_material->sizeHint();
|
||||
size.setWidth(minimumWidth);
|
||||
return size;
|
||||
}
|
||||
return QWidget::sizeHint();
|
||||
}
|
||||
|
||||
QSize MaterialTreeWidget::treeSizeHint() const
|
||||
{
|
||||
return m_treeSizeHint;
|
||||
}
|
||||
|
||||
void MaterialTreeWidget::setTreeSizeHint(const QSize& hint)
|
||||
{
|
||||
m_treeSizeHint = hint;
|
||||
m_materialTree->setMinimumSize(m_treeSizeHint);
|
||||
m_materialTree->adjustSize();
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void MaterialTreeWidget::createLayout()
|
||||
{
|
||||
m_material = new QLineEdit(this);
|
||||
@@ -111,12 +141,15 @@ void MaterialTreeWidget::createLayout()
|
||||
m_filterCombo = new QComboBox(this);
|
||||
m_editor = new QPushButton(tr("Launch editor"), this);
|
||||
|
||||
m_materialTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
m_materialTree->setMinimumSize(m_treeSizeHint);
|
||||
m_materialTree->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_materialTree->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
|
||||
auto materialLayout = new QHBoxLayout();
|
||||
materialLayout->addWidget(m_material);
|
||||
materialLayout->addWidget(m_expand);
|
||||
// materialLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
|
||||
auto treeLayout = new QHBoxLayout();
|
||||
treeLayout->addWidget(m_materialTree);
|
||||
@@ -133,6 +166,8 @@ void MaterialTreeWidget::createLayout()
|
||||
layout->addItem(buttonLayout);
|
||||
setLayout(layout);
|
||||
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
||||
|
||||
// Set the filter if using a filter list
|
||||
if (hasMultipleFilters()) {
|
||||
_filter = _filterList->front();
|
||||
@@ -169,6 +204,10 @@ void MaterialTreeWidget::setExpanded(bool open)
|
||||
else {
|
||||
m_expand->setIcon(style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
||||
}
|
||||
|
||||
// m_materialTree->adjustSize();
|
||||
adjustSize();
|
||||
Q_EMIT onExpanded(m_expanded);
|
||||
}
|
||||
|
||||
void MaterialTreeWidget::setFilterVisible(bool open)
|
||||
@@ -404,7 +443,7 @@ void MaterialTreeWidget::getRecents()
|
||||
|
||||
auto param = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Recent");
|
||||
_recentMax = static_cast<int>(param->GetInt("RecentMax", 5));
|
||||
_recentMax = static_cast<int>(param->GetInt("RecentMax", defaultRecents));
|
||||
auto count = param->GetInt("Recent", 0);
|
||||
for (int i = 0; static_cast<long>(i) < count; i++) {
|
||||
QString key = QString::fromLatin1("MRU%1").arg(i);
|
||||
|
||||
@@ -71,6 +71,8 @@ class MaterialTreeWidgetPy;
|
||||
class MatGuiExport MaterialTreeWidget: public QWidget, public Base::BaseClass
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QSize treeSizeHint READ treeSizeHint WRITE
|
||||
setTreeSizeHint) // clazy:exclude=qproperty-without-notify
|
||||
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
@@ -94,7 +96,7 @@ public:
|
||||
void setFilter(const std::shared_ptr<Materials::MaterialFilter>& filter);
|
||||
void setFilter(
|
||||
const std::shared_ptr<std::list<std::shared_ptr<Materials::MaterialFilter>>>& filterList);
|
||||
void setActiveFilter(const QString &name);
|
||||
void setActiveFilter(const QString& name);
|
||||
|
||||
void setExpanded(bool open);
|
||||
bool getExpanded()
|
||||
@@ -158,10 +160,15 @@ public:
|
||||
_filterOptions.setIncludeLegacy(legacy);
|
||||
}
|
||||
|
||||
QSize sizeHint() const override;
|
||||
QSize treeSizeHint() const;
|
||||
void setTreeSizeHint(const QSize& hint);
|
||||
|
||||
Q_SIGNALS:
|
||||
/** Emits this signal when a material has been selected */
|
||||
void materialSelected(const std::shared_ptr<Materials::Material>& material);
|
||||
void onMaterial(const QString& uuid);
|
||||
void onExpanded(bool expanded);
|
||||
|
||||
private Q_SLOTS:
|
||||
void expandClicked(bool checked);
|
||||
@@ -171,6 +178,14 @@ private Q_SLOTS:
|
||||
void onFilter(const QString& text);
|
||||
|
||||
private:
|
||||
// UI minimum sizes
|
||||
static const int minimumWidth = 250;
|
||||
static const int minimumTreeWidth = 250;
|
||||
static const int minimumTreeHeight = 500;
|
||||
|
||||
static const int defaultFavorites = 0;
|
||||
static const int defaultRecents = 5;
|
||||
|
||||
void setup();
|
||||
|
||||
QLineEdit* m_material;
|
||||
@@ -179,6 +194,7 @@ private:
|
||||
QPushButton* m_editor;
|
||||
QComboBox* m_filterCombo;
|
||||
bool m_expanded;
|
||||
QSize m_treeSizeHint;
|
||||
|
||||
QString m_materialDisplay;
|
||||
QString m_uuid;
|
||||
@@ -246,7 +262,8 @@ protected:
|
||||
const Base::Reference<ParameterGrp>& param);
|
||||
void setFilterVisible(bool open);
|
||||
void fillFilterCombo();
|
||||
bool hasMultipleFilters() const {
|
||||
bool hasMultipleFilters() const
|
||||
{
|
||||
return (_filterList && _filterList->size() > 1);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user