forked from qt-creator/qt-creator
QmlDesigner: Add scene root material support to material editor/browser
If the scene root item is Material subclass, material library is not created for the scene. Material editor and browser functionalities that relate to having material library are disabled. Material editor will always show the material that is the scene root. Fixes: QDS-7374 Change-Id: Icd1c212c17b59e4a2caa6b3b4d7e615e68b21eb9 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -342,17 +342,8 @@ void Qt5InformationNodeInstanceServer::resolveImportSupport()
|
|||||||
void Qt5InformationNodeInstanceServer::updateMaterialPreviewData(const QVector<PropertyValueContainer> &valueChanges)
|
void Qt5InformationNodeInstanceServer::updateMaterialPreviewData(const QVector<PropertyValueContainer> &valueChanges)
|
||||||
{
|
{
|
||||||
const PropertyName matPrevPrefix("matPrev");
|
const PropertyName matPrevPrefix("matPrev");
|
||||||
qint32 materialLibraryId = -1;
|
|
||||||
for (const auto &container : valueChanges) {
|
for (const auto &container : valueChanges) {
|
||||||
if (container.name().startsWith(matPrevPrefix)) {
|
if (container.instanceId() == 0) {
|
||||||
if (!hasInstanceForId(container.instanceId()))
|
|
||||||
continue;
|
|
||||||
if (materialLibraryId < 0) {
|
|
||||||
ServerNodeInstance instance = instanceForId(container.instanceId());
|
|
||||||
if (instance.id() == "__materialLibrary__")
|
|
||||||
materialLibraryId = container.instanceId();
|
|
||||||
}
|
|
||||||
if (container.instanceId() == materialLibraryId) {
|
|
||||||
if (container.name() == "matPrevEnv")
|
if (container.name() == "matPrevEnv")
|
||||||
m_materialPreviewData.env = container.value().toString();
|
m_materialPreviewData.env = container.value().toString();
|
||||||
else if (container.name() == "matPrevEnvValue")
|
else if (container.name() == "matPrevEnvValue")
|
||||||
@@ -362,7 +353,6 @@ void Qt5InformationNodeInstanceServer::updateMaterialPreviewData(const QVector<P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Qt5InformationNodeInstanceServer::updateRotationBlocks(const QVector<PropertyValueContainer> &valueChanges)
|
void Qt5InformationNodeInstanceServer::updateRotationBlocks(const QVector<PropertyValueContainer> &valueChanges)
|
||||||
{
|
{
|
||||||
|
@@ -67,10 +67,12 @@ Item {
|
|||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
if (!materialBrowserModel.hasMaterialRoot) {
|
||||||
root.currentMaterial = null
|
root.currentMaterial = null
|
||||||
contextMenu.popup()
|
contextMenu.popup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: materialBrowserModel
|
target: materialBrowserModel
|
||||||
@@ -162,6 +164,7 @@ Item {
|
|||||||
|
|
||||||
Row {
|
Row {
|
||||||
width: root.width
|
width: root.width
|
||||||
|
enabled: !materialBrowserModel.hasMaterialRoot && materialBrowserModel.hasQuick3DImport
|
||||||
|
|
||||||
SearchBox {
|
SearchBox {
|
||||||
id: searchBox
|
id: searchBox
|
||||||
@@ -186,22 +189,22 @@ Item {
|
|||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
font.pixelSize: StudioTheme.Values.baseFontSize
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
visible: materialBrowserModel.hasQuick3DImport && materialBrowserModel.isEmpty && !searchBox.isEmpty()
|
visible: materialBrowserModel.hasQuick3DImport && materialBrowserModel.isEmpty
|
||||||
|
&& !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: qsTr("There are no materials in this project.<br>Select '<b>+</b>' to create one.")
|
text: {
|
||||||
textFormat: Text.RichText
|
if (materialBrowserModel.hasMaterialRoot)
|
||||||
color: StudioTheme.Values.themeTextColor
|
qsTr("<b>Material Browser</b> is disabled inside a material component.")
|
||||||
font.pixelSize: StudioTheme.Values.mediumFontSize
|
else if (!materialBrowserModel.hasQuick3DImport)
|
||||||
horizontalAlignment: Text.AlignHCenter
|
qsTr("To use <b>Material Browser</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
||||||
topPadding: 30
|
else if (materialBrowserModel.isEmpty && searchBox.isEmpty())
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
qsTr("There are no materials in this project.<br>Select '<b>+</b>' to create one.")
|
||||||
visible: materialBrowserModel.hasQuick3DImport && materialBrowserModel.isEmpty && searchBox.isEmpty()
|
else
|
||||||
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("To use <b>Material Browser</b>, first add the QtQuick3D module in the <b>Components</b> view.");
|
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
font.pixelSize: StudioTheme.Values.mediumFontSize
|
font.pixelSize: StudioTheme.Values.mediumFontSize
|
||||||
@@ -209,8 +212,7 @@ Item {
|
|||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
width: root.width
|
width: root.width
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
visible: text !== ""
|
||||||
visible: !materialBrowserModel.hasQuick3DImport
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
@@ -50,7 +50,7 @@ Rectangle {
|
|||||||
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
||||||
iconSize: StudioTheme.Values.bigIconFontSize
|
iconSize: StudioTheme.Values.bigIconFontSize
|
||||||
buttonSize: root.height
|
buttonSize: root.height
|
||||||
enabled: hasMaterial && hasModelSelection && hasQuick3DImport
|
enabled: hasMaterial && hasModelSelection && hasQuick3DImport && !hasMaterialRoot
|
||||||
onClicked: root.toolBarAction(ToolBarAction.ApplyToSelected)
|
onClicked: root.toolBarAction(ToolBarAction.ApplyToSelected)
|
||||||
tooltip: qsTr("Apply material to selected model.")
|
tooltip: qsTr("Apply material to selected model.")
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ Rectangle {
|
|||||||
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
||||||
iconSize: StudioTheme.Values.bigIconFontSize
|
iconSize: StudioTheme.Values.bigIconFontSize
|
||||||
buttonSize: root.height
|
buttonSize: root.height
|
||||||
enabled: hasQuick3DImport
|
enabled: hasQuick3DImport && !hasMaterialRoot
|
||||||
onClicked: root.toolBarAction(ToolBarAction.AddNewMaterial)
|
onClicked: root.toolBarAction(ToolBarAction.AddNewMaterial)
|
||||||
tooltip: qsTr("Create new material.")
|
tooltip: qsTr("Create new material.")
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ Rectangle {
|
|||||||
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
||||||
iconSize: StudioTheme.Values.bigIconFontSize
|
iconSize: StudioTheme.Values.bigIconFontSize
|
||||||
buttonSize: root.height
|
buttonSize: root.height
|
||||||
enabled: hasMaterial && hasQuick3DImport
|
enabled: hasMaterial && hasQuick3DImport && !hasMaterialRoot
|
||||||
onClicked: root.toolBarAction(ToolBarAction.DeleteCurrentMaterial)
|
onClicked: root.toolBarAction(ToolBarAction.DeleteCurrentMaterial)
|
||||||
tooltip: qsTr("Delete current material.")
|
tooltip: qsTr("Delete current material.")
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ Rectangle {
|
|||||||
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
normalColor: StudioTheme.Values.themeSectionHeadBackground
|
||||||
iconSize: StudioTheme.Values.bigIconFontSize
|
iconSize: StudioTheme.Values.bigIconFontSize
|
||||||
buttonSize: root.height
|
buttonSize: root.height
|
||||||
enabled: hasMaterial && hasQuick3DImport
|
enabled: hasMaterial && hasQuick3DImport && !hasMaterialRoot
|
||||||
onClicked: root.toolBarAction(ToolBarAction.OpenMaterialBrowser)
|
onClicked: root.toolBarAction(ToolBarAction.OpenMaterialBrowser)
|
||||||
tooltip: qsTr("Open material browser.")
|
tooltip: qsTr("Open material browser.")
|
||||||
}
|
}
|
||||||
|
@@ -136,7 +136,7 @@ Item {
|
|||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "hover"
|
name: "hover"
|
||||||
when: searchFilterText.hovered && !searchFilterText.activeFocus
|
when: root.enabled && searchFilterText.hovered && !searchFilterText.activeFocus
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundHover
|
color: StudioTheme.Values.themeControlBackgroundHover
|
||||||
|
@@ -124,6 +124,20 @@ void MaterialBrowserModel::setHasModelSelection(bool b)
|
|||||||
emit hasModelSelectionChanged();
|
emit hasModelSelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MaterialBrowserModel::hasMaterialRoot() const
|
||||||
|
{
|
||||||
|
return m_hasMaterialRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaterialBrowserModel::setHasMaterialRoot(bool b)
|
||||||
|
{
|
||||||
|
if (m_hasMaterialRoot == b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_hasMaterialRoot = b;
|
||||||
|
emit hasMaterialRootChanged();
|
||||||
|
}
|
||||||
|
|
||||||
TypeName MaterialBrowserModel::copiedMaterialType() const
|
TypeName MaterialBrowserModel::copiedMaterialType() const
|
||||||
{
|
{
|
||||||
return m_copiedMaterialType;
|
return m_copiedMaterialType;
|
||||||
|
@@ -42,6 +42,7 @@ class MaterialBrowserModel : public QAbstractListModel
|
|||||||
Q_PROPERTY(int selectedIndex MEMBER m_selectedIndex NOTIFY selectedIndexChanged)
|
Q_PROPERTY(int selectedIndex MEMBER m_selectedIndex NOTIFY selectedIndexChanged)
|
||||||
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
|
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
|
||||||
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
|
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
|
||||||
|
Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
|
||||||
Q_PROPERTY(TypeName copiedMaterialType READ copiedMaterialType WRITE setCopiedMaterialType NOTIFY copiedMaterialTypeChanged)
|
Q_PROPERTY(TypeName copiedMaterialType READ copiedMaterialType WRITE setCopiedMaterialType NOTIFY copiedMaterialTypeChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -60,6 +61,9 @@ public:
|
|||||||
bool hasModelSelection() const;
|
bool hasModelSelection() const;
|
||||||
void setHasModelSelection(bool b);
|
void setHasModelSelection(bool b);
|
||||||
|
|
||||||
|
bool hasMaterialRoot() const;
|
||||||
|
void setHasMaterialRoot(bool b);
|
||||||
|
|
||||||
TypeName copiedMaterialType() const;
|
TypeName copiedMaterialType() const;
|
||||||
void setCopiedMaterialType(const TypeName &matType);
|
void setCopiedMaterialType(const TypeName &matType);
|
||||||
|
|
||||||
@@ -88,6 +92,7 @@ signals:
|
|||||||
void isEmptyChanged();
|
void isEmptyChanged();
|
||||||
void hasQuick3DImportChanged();
|
void hasQuick3DImportChanged();
|
||||||
void hasModelSelectionChanged();
|
void hasModelSelectionChanged();
|
||||||
|
void hasMaterialRootChanged();
|
||||||
void copiedMaterialTypeChanged();
|
void copiedMaterialTypeChanged();
|
||||||
void selectedIndexChanged(int idx);
|
void selectedIndexChanged(int idx);
|
||||||
void renameMaterialTriggered(const QmlDesigner::ModelNode &material, const QString &newName);
|
void renameMaterialTriggered(const QmlDesigner::ModelNode &material, const QString &newName);
|
||||||
@@ -110,6 +115,7 @@ private:
|
|||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
bool m_hasQuick3DImport = false;
|
bool m_hasQuick3DImport = false;
|
||||||
bool m_hasModelSelection = false;
|
bool m_hasModelSelection = false;
|
||||||
|
bool m_hasMaterialRoot = false;
|
||||||
TypeName m_copiedMaterialType;
|
TypeName m_copiedMaterialType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -127,6 +127,7 @@ void MaterialBrowserView::modelAttached(Model *model)
|
|||||||
AbstractView::modelAttached(model);
|
AbstractView::modelAttached(model);
|
||||||
|
|
||||||
m_widget->clearSearchFilter();
|
m_widget->clearSearchFilter();
|
||||||
|
m_widget->materialBrowserModel()->setHasMaterialRoot(rootModelNode().isSubclassOf("QtQuick3D.Material"));
|
||||||
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
||||||
|
|
||||||
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment
|
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment
|
||||||
|
@@ -233,6 +233,20 @@ void MaterialEditorContextObject::setHasQuick3DImport(bool b)
|
|||||||
emit hasQuick3DImportChanged();
|
emit hasQuick3DImportChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MaterialEditorContextObject::hasMaterialRoot() const
|
||||||
|
{
|
||||||
|
return m_hasMaterialRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaterialEditorContextObject::setHasMaterialRoot(bool b)
|
||||||
|
{
|
||||||
|
if (b == m_hasMaterialRoot)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_hasMaterialRoot = b;
|
||||||
|
emit hasMaterialRootChanged();
|
||||||
|
}
|
||||||
|
|
||||||
bool MaterialEditorContextObject::hasModelSelection() const
|
bool MaterialEditorContextObject::hasModelSelection() const
|
||||||
{
|
{
|
||||||
return m_hasModelSelection;
|
return m_hasModelSelection;
|
||||||
|
@@ -56,6 +56,7 @@ class MaterialEditorContextObject : public QObject
|
|||||||
Q_PROPERTY(bool hasActiveTimeline READ hasActiveTimeline NOTIFY hasActiveTimelineChanged)
|
Q_PROPERTY(bool hasActiveTimeline READ hasActiveTimeline NOTIFY hasActiveTimelineChanged)
|
||||||
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
|
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
|
||||||
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
|
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
|
||||||
|
Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
|
Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
|
||||||
|
|
||||||
@@ -105,6 +106,9 @@ public:
|
|||||||
bool hasQuick3DImport() const;
|
bool hasQuick3DImport() const;
|
||||||
void setHasQuick3DImport(bool b);
|
void setHasQuick3DImport(bool b);
|
||||||
|
|
||||||
|
bool hasMaterialRoot() const;
|
||||||
|
void setHasMaterialRoot(bool b);
|
||||||
|
|
||||||
bool hasModelSelection() const;
|
bool hasModelSelection() const;
|
||||||
void setHasModelSelection(bool b);
|
void setHasModelSelection(bool b);
|
||||||
|
|
||||||
@@ -134,6 +138,7 @@ signals:
|
|||||||
void hasAliasExportChanged();
|
void hasAliasExportChanged();
|
||||||
void hasActiveTimelineChanged();
|
void hasActiveTimelineChanged();
|
||||||
void hasQuick3DImportChanged();
|
void hasQuick3DImportChanged();
|
||||||
|
void hasMaterialRootChanged();
|
||||||
void hasModelSelectionChanged();
|
void hasModelSelectionChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -155,6 +160,7 @@ private:
|
|||||||
bool m_aliasExport = false;
|
bool m_aliasExport = false;
|
||||||
bool m_hasActiveTimeline = false;
|
bool m_hasActiveTimeline = false;
|
||||||
bool m_hasQuick3DImport = false;
|
bool m_hasQuick3DImport = false;
|
||||||
|
bool m_hasMaterialRoot = false;
|
||||||
bool m_hasModelSelection = false;
|
bool m_hasModelSelection = false;
|
||||||
|
|
||||||
ModelNode m_selectedMaterial;
|
ModelNode m_selectedMaterial;
|
||||||
|
@@ -420,12 +420,15 @@ void MaterialEditorView::handleToolBarAction(int action)
|
|||||||
if (!model())
|
if (!model())
|
||||||
break;
|
break;
|
||||||
executeInTransaction("MaterialEditorView:handleToolBarAction", [&] {
|
executeInTransaction("MaterialEditorView:handleToolBarAction", [&] {
|
||||||
|
ModelNode matLib = materialLibraryNode();
|
||||||
|
if (!matLib.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
NodeMetaInfo metaInfo = model()->metaInfo("QtQuick3D.DefaultMaterial");
|
NodeMetaInfo metaInfo = model()->metaInfo("QtQuick3D.DefaultMaterial");
|
||||||
ModelNode newMatNode = createModelNode("QtQuick3D.DefaultMaterial", metaInfo.majorVersion(),
|
ModelNode newMatNode = createModelNode("QtQuick3D.DefaultMaterial", metaInfo.majorVersion(),
|
||||||
metaInfo.minorVersion());
|
metaInfo.minorVersion());
|
||||||
renameMaterial(newMatNode, "New Material");
|
renameMaterial(newMatNode, "New Material");
|
||||||
|
matLib.defaultNodeListProperty().reparentHere(newMatNode);
|
||||||
materialLibraryNode().defaultNodeListProperty().reparentHere(newMatNode);
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -462,10 +465,8 @@ void MaterialEditorView::handlePreviewEnvChanged(const QString &envAndValue)
|
|||||||
PropertyName matPrevEnvValueAuxProp("matPrevEnvValue");
|
PropertyName matPrevEnvValueAuxProp("matPrevEnvValue");
|
||||||
|
|
||||||
auto renderPreviews = [=](const QString &auxEnv, const QString &auxValue) {
|
auto renderPreviews = [=](const QString &auxEnv, const QString &auxValue) {
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
rootModelNode().setAuxiliaryData(matPrevEnvAuxProp, auxEnv);
|
||||||
QTC_ASSERT(matLib.isValid(), return);
|
rootModelNode().setAuxiliaryData(matPrevEnvValueAuxProp, auxValue);
|
||||||
matLib.setAuxiliaryData(matPrevEnvAuxProp, auxEnv);
|
|
||||||
matLib.setAuxiliaryData(matPrevEnvValueAuxProp, auxValue);
|
|
||||||
QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender);
|
QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender);
|
||||||
emitCustomNotification("refresh_material_browser", {});
|
emitCustomNotification("refresh_material_browser", {});
|
||||||
};
|
};
|
||||||
@@ -473,13 +474,11 @@ void MaterialEditorView::handlePreviewEnvChanged(const QString &envAndValue)
|
|||||||
if (env == "Color") {
|
if (env == "Color") {
|
||||||
m_colorDialog.clear();
|
m_colorDialog.clear();
|
||||||
|
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
|
||||||
QTC_ASSERT(matLib.isValid(), return);
|
|
||||||
// Store color to separate property to persist selection over non-color env changes
|
// Store color to separate property to persist selection over non-color env changes
|
||||||
PropertyName colorAuxProp("matPrevColor");
|
PropertyName colorAuxProp("matPrevColor");
|
||||||
QString oldColor = matLib.auxiliaryData(colorAuxProp).toString();
|
QString oldColor = rootModelNode().auxiliaryData(colorAuxProp).toString();
|
||||||
QString oldEnv = matLib.auxiliaryData(matPrevEnvAuxProp).toString();
|
QString oldEnv = rootModelNode().auxiliaryData(matPrevEnvAuxProp).toString();
|
||||||
QString oldValue = matLib.auxiliaryData(matPrevEnvValueAuxProp).toString();
|
QString oldValue = rootModelNode().auxiliaryData(matPrevEnvValueAuxProp).toString();
|
||||||
|
|
||||||
m_colorDialog = new QColorDialog(Core::ICore::dialogParent());
|
m_colorDialog = new QColorDialog(Core::ICore::dialogParent());
|
||||||
m_colorDialog->setModal(true);
|
m_colorDialog->setModal(true);
|
||||||
@@ -495,9 +494,7 @@ void MaterialEditorView::handlePreviewEnvChanged(const QString &envAndValue)
|
|||||||
QObject::connect(m_colorDialog, &QColorDialog::colorSelected,
|
QObject::connect(m_colorDialog, &QColorDialog::colorSelected,
|
||||||
m_colorDialog, [=](const QColor &color) {
|
m_colorDialog, [=](const QColor &color) {
|
||||||
renderPreviews(env, color.name());
|
renderPreviews(env, color.name());
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
rootModelNode().setAuxiliaryData(colorAuxProp, color.name());
|
||||||
QTC_ASSERT(matLib.isValid(), return);
|
|
||||||
matLib.setAuxiliaryData(colorAuxProp, color.name());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(m_colorDialog, &QColorDialog::rejected,
|
QObject::connect(m_colorDialog, &QColorDialog::rejected,
|
||||||
@@ -519,9 +516,7 @@ void MaterialEditorView::handlePreviewModelChanged(const QString &modelStr)
|
|||||||
QTC_ASSERT(model(), return);
|
QTC_ASSERT(model(), return);
|
||||||
QTC_ASSERT(model()->nodeInstanceView(), return);
|
QTC_ASSERT(model()->nodeInstanceView(), return);
|
||||||
|
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
rootModelNode().setAuxiliaryData("matPrevModel", modelStr);
|
||||||
QTC_ASSERT(matLib.isValid(), return);
|
|
||||||
matLib.setAuxiliaryData("matPrevModel", modelStr);
|
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender);
|
QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender);
|
||||||
emitCustomNotification("refresh_material_browser", {});
|
emitCustomNotification("refresh_material_browser", {});
|
||||||
@@ -570,6 +565,7 @@ void MaterialEditorView::setupQmlBackend()
|
|||||||
|
|
||||||
currentQmlBackend->widget()->installEventFilter(this);
|
currentQmlBackend->widget()->installEventFilter(this);
|
||||||
currentQmlBackend->contextObject()->setHasQuick3DImport(m_hasQuick3DImport);
|
currentQmlBackend->contextObject()->setHasQuick3DImport(m_hasQuick3DImport);
|
||||||
|
currentQmlBackend->contextObject()->setHasMaterialRoot(m_hasMaterialRoot);
|
||||||
|
|
||||||
m_stackedWidget->setCurrentWidget(currentQmlBackend->widget());
|
m_stackedWidget->setCurrentWidget(currentQmlBackend->widget());
|
||||||
|
|
||||||
@@ -623,11 +619,9 @@ bool MaterialEditorView::noValidSelection() const
|
|||||||
void MaterialEditorView::initPreviewData()
|
void MaterialEditorView::initPreviewData()
|
||||||
{
|
{
|
||||||
if (model() && m_qmlBackEnd) {
|
if (model() && m_qmlBackEnd) {
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
QString env = rootModelNode().auxiliaryData("matPrevEnv").toString();
|
||||||
if (matLib.isValid()) {
|
QString envValue = rootModelNode().auxiliaryData("matPrevEnvValue").toString();
|
||||||
QString env = matLib.auxiliaryData("matPrevEnv").toString();
|
QString modelStr = rootModelNode().auxiliaryData("matPrevModel").toString();
|
||||||
QString envValue = matLib.auxiliaryData("matPrevEnvValue").toString();
|
|
||||||
QString modelStr = matLib.auxiliaryData("matPrevModel").toString();
|
|
||||||
if (!envValue.isEmpty() && env != "Color" && env != "Default") {
|
if (!envValue.isEmpty() && env != "Color" && env != "Default") {
|
||||||
env += '=';
|
env += '=';
|
||||||
env += envValue;
|
env += envValue;
|
||||||
@@ -641,7 +635,6 @@ void MaterialEditorView::initPreviewData()
|
|||||||
Q_ARG(QVariant, env), Q_ARG(QVariant, modelStr));
|
Q_ARG(QVariant, env), Q_ARG(QVariant, modelStr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialEditorView::modelAttached(Model *model)
|
void MaterialEditorView::modelAttached(Model *model)
|
||||||
{
|
{
|
||||||
@@ -650,11 +643,15 @@ void MaterialEditorView::modelAttached(Model *model)
|
|||||||
m_locked = true;
|
m_locked = true;
|
||||||
|
|
||||||
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
||||||
|
m_hasMaterialRoot = rootModelNode().isSubclassOf("QtQuick3D.Material");
|
||||||
|
|
||||||
// Creating the material library node on model attach causes errors as long as the type information
|
if (m_hasMaterialRoot) {
|
||||||
// not complete yet, so we keep checking until type info is complete.
|
m_selectedMaterial = rootModelNode();
|
||||||
if (m_hasQuick3DImport)
|
} else if (m_hasQuick3DImport) {
|
||||||
|
// Creating the material library node on model attach causes errors as long as the type
|
||||||
|
// information is not complete yet, so we keep checking until type info is complete.
|
||||||
m_ensureMatLibTimer.start(500);
|
m_ensureMatLibTimer.start(500);
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_setupCompleted) {
|
if (!m_setupCompleted) {
|
||||||
reloadQml();
|
reloadQml();
|
||||||
@@ -868,6 +865,10 @@ void MaterialEditorView::duplicateMaterial(const ModelNode &material)
|
|||||||
QmlObjectNode sourceMat(material);
|
QmlObjectNode sourceMat(material);
|
||||||
|
|
||||||
executeInTransaction(__FUNCTION__, [&] {
|
executeInTransaction(__FUNCTION__, [&] {
|
||||||
|
ModelNode matLib = materialLibraryNode();
|
||||||
|
if (!matLib.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
// create the duplicate material
|
// create the duplicate material
|
||||||
NodeMetaInfo metaInfo = model()->metaInfo(matType);
|
NodeMetaInfo metaInfo = model()->metaInfo(matType);
|
||||||
QmlObjectNode duplicateMat = createModelNode(matType, metaInfo.majorVersion(), metaInfo.minorVersion());
|
QmlObjectNode duplicateMat = createModelNode(matType, metaInfo.majorVersion(), metaInfo.minorVersion());
|
||||||
@@ -889,7 +890,7 @@ void MaterialEditorView::duplicateMaterial(const ModelNode &material)
|
|||||||
duplicateMat.setBindingProperty(prop.name(), prop.toBindingProperty().expression());
|
duplicateMat.setBindingProperty(prop.name(), prop.toBindingProperty().expression());
|
||||||
}
|
}
|
||||||
|
|
||||||
materialLibraryNode().defaultNodeListProperty().reparentHere(duplicateMat);
|
matLib.defaultNodeListProperty().reparentHere(duplicateMat);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -899,8 +900,10 @@ void MaterialEditorView::customNotification(const AbstractView *view, const QStr
|
|||||||
Q_UNUSED(view)
|
Q_UNUSED(view)
|
||||||
|
|
||||||
if (identifier == "selected_material_changed") {
|
if (identifier == "selected_material_changed") {
|
||||||
|
if (!m_hasMaterialRoot) {
|
||||||
m_selectedMaterial = nodeList.first();
|
m_selectedMaterial = nodeList.first();
|
||||||
QTimer::singleShot(0, this, &MaterialEditorView::resetView);
|
QTimer::singleShot(0, this, &MaterialEditorView::resetView);
|
||||||
|
}
|
||||||
} else if (identifier == "apply_to_selected_triggered") {
|
} else if (identifier == "apply_to_selected_triggered") {
|
||||||
applyMaterialToSelectedModels(nodeList.first(), data.first().toBool());
|
applyMaterialToSelectedModels(nodeList.first(), data.first().toBool());
|
||||||
} else if (identifier == "rename_material") {
|
} else if (identifier == "rename_material") {
|
||||||
|
@@ -131,6 +131,7 @@ private:
|
|||||||
bool m_locked = false;
|
bool m_locked = false;
|
||||||
bool m_setupCompleted = false;
|
bool m_setupCompleted = false;
|
||||||
bool m_hasQuick3DImport = false;
|
bool m_hasQuick3DImport = false;
|
||||||
|
bool m_hasMaterialRoot = false;
|
||||||
|
|
||||||
QPointer<QColorDialog> m_colorDialog;
|
QPointer<QColorDialog> m_colorDialog;
|
||||||
};
|
};
|
||||||
|
@@ -834,7 +834,7 @@ void AbstractView::changeRootNodeType(const TypeName &type, int majorVersion, in
|
|||||||
void AbstractView::ensureMaterialLibraryNode()
|
void AbstractView::ensureMaterialLibraryNode()
|
||||||
{
|
{
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
||||||
if (matLib.isValid())
|
if (matLib.isValid() || rootModelNode().isSubclassOf("QtQuick3D.Material"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create material library node
|
// Create material library node
|
||||||
@@ -863,13 +863,11 @@ void AbstractView::ensureMaterialLibraryNode()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns ModelNode for project's material library.
|
// Returns ModelNode for project's material library.
|
||||||
|
// Since this calls ensureMaterialLibraryNode(), it should only be called within a transaction.
|
||||||
ModelNode AbstractView::materialLibraryNode()
|
ModelNode AbstractView::materialLibraryNode()
|
||||||
{
|
{
|
||||||
ensureMaterialLibraryNode();
|
ensureMaterialLibraryNode();
|
||||||
|
|
||||||
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
||||||
QTC_ASSERT(matLib.isValid(), return {});
|
|
||||||
|
|
||||||
return matLib;
|
return matLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user