2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
#include "materialbrowserview.h"
|
2022-08-09 12:56:47 +03:00
|
|
|
|
|
|
|
|
#include "bindingproperty.h"
|
2022-08-24 13:11:33 +02:00
|
|
|
#include "materialbrowserwidget.h"
|
2022-10-26 19:57:41 +03:00
|
|
|
#include "materialbrowsermodel.h"
|
|
|
|
|
#include "materialbrowsertexturesmodel.h"
|
2022-03-18 17:28:28 +02:00
|
|
|
#include "nodeabstractproperty.h"
|
2022-08-12 11:47:36 +03:00
|
|
|
#include "nodemetainfo.h"
|
2022-03-18 17:28:28 +02:00
|
|
|
#include "qmlobjectnode.h"
|
|
|
|
|
#include "variantproperty.h"
|
2022-08-09 12:56:47 +03:00
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2022-08-09 12:56:47 +03:00
|
|
|
#include <designmodecontext.h>
|
2022-03-18 17:28:28 +02:00
|
|
|
#include <nodeinstanceview.h>
|
2022-08-24 13:11:33 +02:00
|
|
|
#include <nodemetainfo.h>
|
2022-09-01 15:03:01 +03:00
|
|
|
#include <nodelistproperty.h>
|
2022-03-18 17:28:28 +02:00
|
|
|
#include <qmldesignerconstants.h>
|
2022-10-06 14:51:11 +03:00
|
|
|
#include <utils/algorithm.h>
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
#include <QQuickItem>
|
2022-09-01 15:03:01 +03:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
#include <QTimer>
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2022-09-15 15:01:49 +02:00
|
|
|
MaterialBrowserView::MaterialBrowserView(ExternalDependenciesInterface &externalDependencies)
|
|
|
|
|
: AbstractView{externalDependencies}
|
2022-11-04 17:59:39 +02:00
|
|
|
{
|
|
|
|
|
m_previewTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_previewTimer, &QTimer::timeout, this, &MaterialBrowserView::requestPreviews);
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
MaterialBrowserView::~MaterialBrowserView()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool MaterialBrowserView::hasWidget() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WidgetInfo MaterialBrowserView::widgetInfo()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget.isNull()) {
|
2022-08-04 12:40:06 +03:00
|
|
|
m_widget = new MaterialBrowserWidget(this);
|
|
|
|
|
|
|
|
|
|
auto matEditorContext = new Internal::MaterialBrowserContext(m_widget.data());
|
|
|
|
|
Core::ICore::addContextObject(matEditorContext);
|
|
|
|
|
|
2022-05-25 21:42:15 +03:00
|
|
|
|
|
|
|
|
// custom notifications below are sent to the MaterialEditor
|
2022-11-17 12:54:19 +02:00
|
|
|
MaterialBrowserModel *matBrowserModel = m_widget->materialBrowserModel().data();
|
2022-05-25 21:42:15 +03:00
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::selectedIndexChanged, this, [&] (int idx) {
|
|
|
|
|
ModelNode matNode = m_widget->materialBrowserModel()->materialAt(idx);
|
|
|
|
|
emitCustomNotification("selected_material_changed", {matNode}, {});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::applyToSelectedTriggered, this,
|
|
|
|
|
[&] (const ModelNode &material, bool add) {
|
|
|
|
|
emitCustomNotification("apply_to_selected_triggered", {material}, {add});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::renameMaterialTriggered, this,
|
|
|
|
|
[&] (const ModelNode &material, const QString &newName) {
|
|
|
|
|
emitCustomNotification("rename_material", {material}, {newName});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::addNewMaterialTriggered, this, [&] {
|
|
|
|
|
emitCustomNotification("add_new_material");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::duplicateMaterialTriggered, this,
|
|
|
|
|
[&] (const ModelNode &material) {
|
|
|
|
|
emitCustomNotification("duplicate_material", {material});
|
|
|
|
|
});
|
2022-08-09 12:56:47 +03:00
|
|
|
|
|
|
|
|
connect(matBrowserModel, &MaterialBrowserModel::pasteMaterialPropertiesTriggered, this,
|
2022-09-29 16:05:48 +03:00
|
|
|
[&] (const ModelNode &material,
|
|
|
|
|
const QList<QmlDesigner::MaterialBrowserModel::PropertyCopyData> &propDatas,
|
|
|
|
|
bool all) {
|
2022-08-09 12:56:47 +03:00
|
|
|
QmlObjectNode mat(material);
|
|
|
|
|
executeInTransaction(__FUNCTION__, [&] {
|
2022-08-12 11:47:36 +03:00
|
|
|
if (all) { // all material properties copied
|
|
|
|
|
// remove current properties
|
2022-09-29 16:05:48 +03:00
|
|
|
PropertyNameList propNames;
|
|
|
|
|
if (mat.isInBaseState()) {
|
2022-09-27 15:05:26 +03:00
|
|
|
const QList<AbstractProperty> baseProps = material.properties();
|
|
|
|
|
for (const auto &baseProp : baseProps) {
|
|
|
|
|
if (!baseProp.isDynamic())
|
|
|
|
|
propNames.append(baseProp.name());
|
|
|
|
|
}
|
2022-09-29 16:05:48 +03:00
|
|
|
} else {
|
|
|
|
|
QmlPropertyChanges changes = mat.propertyChangeForCurrentState();
|
|
|
|
|
if (changes.isValid()) {
|
|
|
|
|
const QList<AbstractProperty> changedProps = changes.targetProperties();
|
2022-09-27 15:05:26 +03:00
|
|
|
for (const auto &changedProp : changedProps) {
|
|
|
|
|
if (!changedProp.isDynamic())
|
|
|
|
|
propNames.append(changedProp.name());
|
|
|
|
|
}
|
2022-09-29 16:05:48 +03:00
|
|
|
}
|
|
|
|
|
}
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const PropertyName &propName : std::as_const(propNames)) {
|
2022-10-21 13:36:29 +03:00
|
|
|
if (propName != "objectName" && propName != "data")
|
2022-08-12 11:47:36 +03:00
|
|
|
mat.removeProperty(propName);
|
|
|
|
|
}
|
2022-08-09 12:56:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// apply pasted properties
|
2022-09-29 16:05:48 +03:00
|
|
|
for (const QmlDesigner::MaterialBrowserModel::PropertyCopyData &propData : propDatas) {
|
|
|
|
|
if (propData.isValid) {
|
2022-09-27 15:05:26 +03:00
|
|
|
const bool isDynamic = !propData.dynamicTypeName.isEmpty();
|
|
|
|
|
const bool isBaseState = currentState().isBaseState();
|
|
|
|
|
const bool hasProperty = mat.hasProperty(propData.name);
|
|
|
|
|
if (propData.isBinding) {
|
|
|
|
|
if (isDynamic && (!hasProperty || isBaseState)) {
|
|
|
|
|
mat.modelNode().bindingProperty(propData.name)
|
|
|
|
|
.setDynamicTypeNameAndExpression(
|
|
|
|
|
propData.dynamicTypeName, propData.value.toString());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-09-29 16:05:48 +03:00
|
|
|
mat.setBindingProperty(propData.name, propData.value.toString());
|
2022-09-27 15:05:26 +03:00
|
|
|
} else {
|
|
|
|
|
const bool isRecording = mat.timelineIsActive()
|
|
|
|
|
&& mat.currentTimeline().isRecording();
|
|
|
|
|
if (isDynamic && (!hasProperty || (isBaseState && !isRecording))) {
|
|
|
|
|
mat.modelNode().variantProperty(propData.name)
|
|
|
|
|
.setDynamicTypeNameAndValue(
|
|
|
|
|
propData.dynamicTypeName, propData.value);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-09-29 16:05:48 +03:00
|
|
|
mat.setVariantProperty(propData.name, propData.value);
|
2022-09-27 15:05:26 +03:00
|
|
|
}
|
2022-09-29 16:05:48 +03:00
|
|
|
} else {
|
|
|
|
|
mat.removeProperty(propData.name);
|
|
|
|
|
}
|
2022-08-09 12:56:47 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-11-17 12:54:19 +02:00
|
|
|
|
|
|
|
|
// custom notifications below are sent to the TextureEditor
|
|
|
|
|
MaterialBrowserTexturesModel *texturesModel = m_widget->materialBrowserTexturesModel().data();
|
|
|
|
|
connect(texturesModel, &MaterialBrowserTexturesModel::selectedIndexChanged, this, [&] (int idx) {
|
|
|
|
|
ModelNode texNode = m_widget->materialBrowserTexturesModel()->textureAt(idx);
|
|
|
|
|
emitCustomNotification("selected_texture_changed", {texNode}, {});
|
|
|
|
|
});
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return createWidgetInfo(m_widget.data(),
|
|
|
|
|
"MaterialBrowser",
|
|
|
|
|
WidgetInfo::LeftPane,
|
|
|
|
|
0,
|
|
|
|
|
tr("Material Browser"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::modelAttached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
AbstractView::modelAttached(model);
|
|
|
|
|
|
|
|
|
|
m_widget->clearSearchFilter();
|
2022-08-24 13:11:33 +02:00
|
|
|
m_widget->materialBrowserModel()->setHasMaterialRoot(
|
|
|
|
|
rootModelNode().metaInfo().isQtQuick3DMaterial());
|
2022-03-18 17:28:28 +02:00
|
|
|
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
2022-06-17 14:10:03 +03:00
|
|
|
|
|
|
|
|
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment
|
|
|
|
|
// before refreshing the model
|
2022-10-27 18:11:48 +02:00
|
|
|
QTimer::singleShot(1000, model, [this]() {
|
2022-06-16 15:30:25 +03:00
|
|
|
refreshModel(true);
|
2022-10-04 11:24:05 +03:00
|
|
|
loadPropertyGroups(); // Needs the delay because it uses metaInfo
|
2022-06-16 15:30:25 +03:00
|
|
|
});
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 15:30:25 +03:00
|
|
|
void MaterialBrowserView::refreshModel(bool updateImages)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
2022-10-31 17:31:31 +02:00
|
|
|
if (!model())
|
2022-06-28 12:38:12 +03:00
|
|
|
return;
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
2022-10-26 19:57:41 +03:00
|
|
|
QList<ModelNode> materials;
|
|
|
|
|
QList<ModelNode> textures;
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
if (m_hasQuick3DImport && matLib.isValid()) {
|
|
|
|
|
const QList <ModelNode> matLibNodes = matLib.directSubModelNodes();
|
|
|
|
|
for (const ModelNode &node : matLibNodes) {
|
|
|
|
|
if (isMaterial(node))
|
|
|
|
|
materials.append(node);
|
2022-10-26 19:57:41 +03:00
|
|
|
else if (isTexture(node))
|
|
|
|
|
textures.append(node);
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 14:46:13 +03:00
|
|
|
m_widget->clearSearchFilter();
|
2022-03-18 17:28:28 +02:00
|
|
|
m_widget->materialBrowserModel()->setMaterials(materials, m_hasQuick3DImport);
|
2022-10-26 19:57:41 +03:00
|
|
|
m_widget->materialBrowserTexturesModel()->setTextures(textures);
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-06-16 15:30:25 +03:00
|
|
|
if (updateImages) {
|
|
|
|
|
for (const ModelNode &node : std::as_const(materials))
|
2022-11-04 17:59:39 +02:00
|
|
|
m_previewRequests.insert(node);
|
|
|
|
|
if (!m_previewRequests.isEmpty())
|
|
|
|
|
m_previewTimer.start(0);
|
2022-06-16 15:30:25 +03:00
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaterialBrowserView::isMaterial(const ModelNode &node) const
|
|
|
|
|
{
|
2022-08-24 13:11:33 +02:00
|
|
|
return node.metaInfo().isQtQuick3DMaterial();
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
bool MaterialBrowserView::isTexture(const ModelNode &node) const
|
|
|
|
|
{
|
|
|
|
|
if (!node.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return node.metaInfo().isQtQuick3DTexture();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
void MaterialBrowserView::modelAboutToBeDetached(Model *model)
|
|
|
|
|
{
|
2022-08-01 14:29:09 +03:00
|
|
|
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
2022-11-14 14:37:04 +02:00
|
|
|
m_widget->clearPreviewCache();
|
2022-08-01 14:29:09 +03:00
|
|
|
|
2022-10-20 17:06:58 +03:00
|
|
|
if (m_propertyGroupsLoaded) {
|
|
|
|
|
m_propertyGroupsLoaded = false;
|
|
|
|
|
m_widget->materialBrowserModel()->unloadPropertyGroups();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
|
2022-07-07 18:04:18 +02:00
|
|
|
[[maybe_unused]] const QList<ModelNode> &lastSelectedNodeList)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
2022-10-06 14:51:11 +03:00
|
|
|
m_selectedModels = Utils::filtered(selectedNodeList, [](const ModelNode &node) {
|
2022-10-18 10:48:46 +02:00
|
|
|
return node.metaInfo().isQtQuick3DModel();
|
2022-10-06 14:51:11 +03:00
|
|
|
});
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-10-06 14:51:11 +03:00
|
|
|
m_widget->materialBrowserModel()->setHasModelSelection(!m_selectedModels.isEmpty());
|
2022-11-17 12:54:19 +02:00
|
|
|
m_widget->materialBrowserTexturesModel()->setHasSingleModelSelection(m_selectedModels.size() == 1);
|
2022-05-24 14:14:14 +03:00
|
|
|
|
2022-10-06 14:51:11 +03:00
|
|
|
// the logic below selects the material of the first selected model if auto selection is on
|
2022-05-24 14:14:14 +03:00
|
|
|
if (!m_autoSelectModelMaterial)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-06 14:51:11 +03:00
|
|
|
if (selectedNodeList.size() > 1 || m_selectedModels.isEmpty())
|
2022-03-18 17:28:28 +02:00
|
|
|
return;
|
|
|
|
|
|
2022-10-06 14:51:11 +03:00
|
|
|
QmlObjectNode qmlObjNode(m_selectedModels.at(0));
|
2022-03-18 17:28:28 +02:00
|
|
|
QString matExp = qmlObjNode.expression("materials");
|
|
|
|
|
if (matExp.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString matId = matExp.remove('[').remove(']').split(',', Qt::SkipEmptyParts).at(0);
|
|
|
|
|
ModelNode mat = modelNodeForId(matId);
|
|
|
|
|
if (!mat.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-05-24 14:14:14 +03:00
|
|
|
// if selected object is a model, select its material in the material browser and editor
|
2022-03-18 17:28:28 +02:00
|
|
|
int idx = m_widget->materialBrowserModel()->materialIndex(mat);
|
|
|
|
|
m_widget->materialBrowserModel()->selectMaterial(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::modelNodePreviewPixmapChanged(const ModelNode &node, const QPixmap &pixmap)
|
|
|
|
|
{
|
|
|
|
|
if (isMaterial(node))
|
|
|
|
|
m_widget->updateMaterialPreview(node, pixmap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::variantPropertiesChanged(const QList<VariantProperty> &propertyList,
|
2022-07-07 18:04:18 +02:00
|
|
|
[[maybe_unused]] PropertyChangeFlags propertyChange)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
|
|
|
|
for (const VariantProperty &property : propertyList) {
|
|
|
|
|
ModelNode node(property.parentModelNode());
|
|
|
|
|
|
|
|
|
|
if (isMaterial(node) && property.name() == "objectName")
|
|
|
|
|
m_widget->materialBrowserModel()->updateMaterialName(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::nodeReparented(const ModelNode &node,
|
|
|
|
|
const NodeAbstractProperty &newPropertyParent,
|
|
|
|
|
const NodeAbstractProperty &oldPropertyParent,
|
2022-07-07 18:04:18 +02:00
|
|
|
[[maybe_unused]] PropertyChangeFlags propertyChange)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
2022-10-26 19:57:41 +03:00
|
|
|
Q_UNUSED(propertyChange)
|
|
|
|
|
|
|
|
|
|
if (!isMaterial(node) && !isTexture(node))
|
2022-03-18 17:28:28 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ModelNode newParentNode = newPropertyParent.parentModelNode();
|
|
|
|
|
ModelNode oldParentNode = oldPropertyParent.parentModelNode();
|
2022-08-31 10:24:05 +02:00
|
|
|
bool matAdded = newParentNode.id() == Constants::MATERIAL_LIB_ID;
|
|
|
|
|
bool matRemoved = oldParentNode.id() == Constants::MATERIAL_LIB_ID;
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
if (matAdded || matRemoved) {
|
2022-06-21 11:14:22 +03:00
|
|
|
if (matAdded && !m_puppetResetPending) {
|
|
|
|
|
// Workaround to fix various material issues all likely caused by QTBUG-103316
|
2022-06-16 15:30:25 +03:00
|
|
|
resetPuppet();
|
2022-06-21 11:14:22 +03:00
|
|
|
m_puppetResetPending = true;
|
|
|
|
|
}
|
2022-06-16 15:30:25 +03:00
|
|
|
refreshModel(!matAdded);
|
2022-03-18 17:28:28 +02:00
|
|
|
int idx = m_widget->materialBrowserModel()->materialIndex(node);
|
|
|
|
|
m_widget->materialBrowserModel()->selectMaterial(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialBrowserView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
2022-11-17 12:54:19 +02:00
|
|
|
// removing the material lib node
|
2022-08-31 10:24:05 +02:00
|
|
|
if (removedNode.id() == Constants::MATERIAL_LIB_ID) {
|
2022-03-18 17:28:28 +02:00
|
|
|
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
2022-11-14 14:37:04 +02:00
|
|
|
m_widget->clearPreviewCache();
|
2022-03-18 17:28:28 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 12:54:19 +02:00
|
|
|
// not under the material lib
|
|
|
|
|
if (removedNode.parentProperty().parentModelNode().id() != Constants::MATERIAL_LIB_ID)
|
2022-03-18 17:28:28 +02:00
|
|
|
return;
|
|
|
|
|
|
2022-11-17 12:54:19 +02:00
|
|
|
if (isMaterial(removedNode))
|
|
|
|
|
m_widget->materialBrowserModel()->removeMaterial(removedNode);
|
|
|
|
|
else if (isTexture(removedNode))
|
|
|
|
|
m_widget->materialBrowserTexturesModel()->removeTexture(removedNode);
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-07 18:04:18 +02:00
|
|
|
void MaterialBrowserView::nodeRemoved([[maybe_unused]] const ModelNode &removedNode,
|
2022-03-18 17:28:28 +02:00
|
|
|
const NodeAbstractProperty &parentProperty,
|
2022-07-07 18:04:18 +02:00
|
|
|
[[maybe_unused]] PropertyChangeFlags propertyChange)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
|
|
|
|
if (parentProperty.parentModelNode().id() != Constants::MATERIAL_LIB_ID)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_widget->materialBrowserModel()->updateSelectedMaterial();
|
2022-11-17 12:54:19 +02:00
|
|
|
m_widget->materialBrowserTexturesModel()->updateSelectedTexture();
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-22 16:09:42 +03:00
|
|
|
void QmlDesigner::MaterialBrowserView::loadPropertyGroups()
|
|
|
|
|
{
|
2022-10-31 17:31:31 +02:00
|
|
|
if (!m_hasQuick3DImport || m_propertyGroupsLoaded || !model())
|
2022-08-22 16:09:42 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString matPropsPath = model()->metaInfo("QtQuick3D.Material").importDirectoryPath()
|
|
|
|
|
+ "/designer/propertyGroups.json";
|
|
|
|
|
m_propertyGroupsLoaded = m_widget->materialBrowserModel()->loadPropertyGroups(matPropsPath);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 17:59:39 +02:00
|
|
|
void MaterialBrowserView::requestPreviews()
|
|
|
|
|
{
|
|
|
|
|
if (model() && model()->nodeInstanceView()) {
|
|
|
|
|
for (const auto &node : std::as_const(m_previewRequests))
|
|
|
|
|
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
|
|
|
|
|
}
|
|
|
|
|
m_previewRequests.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 18:04:18 +02:00
|
|
|
void MaterialBrowserView::importsChanged([[maybe_unused]] const QList<Import> &addedImports,
|
|
|
|
|
[[maybe_unused]] const QList<Import> &removedImports)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
|
|
|
|
bool hasQuick3DImport = model()->hasImport("QtQuick3D");
|
|
|
|
|
|
|
|
|
|
if (hasQuick3DImport == m_hasQuick3DImport)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_hasQuick3DImport = hasQuick3DImport;
|
2022-06-17 14:10:03 +03:00
|
|
|
|
2022-08-22 16:09:42 +03:00
|
|
|
loadPropertyGroups();
|
|
|
|
|
|
2022-06-21 11:14:22 +03:00
|
|
|
// Import change will trigger puppet reset, so we don't want to update previews immediately
|
|
|
|
|
refreshModel(false);
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-07 18:04:18 +02:00
|
|
|
void MaterialBrowserView::customNotification(const AbstractView *view,
|
|
|
|
|
const QString &identifier,
|
|
|
|
|
const QList<ModelNode> &nodeList,
|
|
|
|
|
[[maybe_unused]] const QList<QVariant> &data)
|
2022-03-18 17:28:28 +02:00
|
|
|
{
|
|
|
|
|
if (view == this)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (identifier == "selected_material_changed") {
|
|
|
|
|
int idx = m_widget->materialBrowserModel()->materialIndex(nodeList.first());
|
|
|
|
|
if (idx != -1)
|
|
|
|
|
m_widget->materialBrowserModel()->selectMaterial(idx);
|
2022-08-05 17:14:05 +03:00
|
|
|
} else if (identifier == "refresh_material_browser") {
|
2022-10-27 18:11:48 +02:00
|
|
|
QTimer::singleShot(0, model(), [this]() {
|
2022-08-05 17:14:05 +03:00
|
|
|
refreshModel(true);
|
|
|
|
|
});
|
2022-08-04 12:40:06 +03:00
|
|
|
} else if (identifier == "delete_selected_material") {
|
|
|
|
|
m_widget->materialBrowserModel()->deleteSelectedMaterial();
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 11:14:22 +03:00
|
|
|
void MaterialBrowserView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
|
|
|
|
|
{
|
|
|
|
|
for (const ModelNode &node : completedNodeList) {
|
|
|
|
|
// We use root node completion as indication of puppet reset
|
|
|
|
|
if (node.isRootNode()) {
|
|
|
|
|
m_puppetResetPending = false;
|
|
|
|
|
QTimer::singleShot(1000, this, [this]() {
|
2022-06-27 11:07:32 +03:00
|
|
|
if (!model() || !model()->nodeInstanceView())
|
|
|
|
|
return;
|
2022-06-21 11:14:22 +03:00
|
|
|
const QList<ModelNode> materials = m_widget->materialBrowserModel()->materials();
|
|
|
|
|
for (const ModelNode &node : materials)
|
2022-11-04 17:59:39 +02:00
|
|
|
m_previewRequests.insert(node);
|
|
|
|
|
if (!m_previewRequests.isEmpty())
|
|
|
|
|
m_previewTimer.start(0);
|
2022-06-21 11:14:22 +03:00
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 17:59:39 +02:00
|
|
|
void MaterialBrowserView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &propertyList)
|
|
|
|
|
{
|
|
|
|
|
for (const auto &nodeProp : propertyList) {
|
|
|
|
|
ModelNode node = nodeProp.first;
|
|
|
|
|
if (node.metaInfo().isQtQuick3DMaterial())
|
|
|
|
|
m_previewRequests.insert(node);
|
|
|
|
|
}
|
|
|
|
|
if (!m_previewRequests.isEmpty() && !m_previewTimer.isActive()) {
|
|
|
|
|
// Updating material browser isn't urgent in e.g. timeline scrubbing case, so have a bit
|
|
|
|
|
// of delay to reduce unnecessary rendering
|
|
|
|
|
m_previewTimer.start(500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
} // namespace QmlDesigner
|