diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
index 7849dfd9269..d93f236fede 100644
--- a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
+++ b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
@@ -95,24 +95,12 @@ Item {
StudioControls.SearchBox {
id: searchBox
- width: root.width - addMaterialButton.width
+ width: root.width
onSearchChanged: (searchText) => {
rootView.handleSearchFilterChanged(searchText)
}
}
-
- IconButton {
- id: addMaterialButton
-
- tooltip: qsTr("Add a material.")
-
- icon: StudioTheme.Constants.plus
- anchors.verticalCenter: parent.verticalCenter
- buttonSize: searchBox.height
- onClicked: materialBrowserModel.addNewMaterial()
- enabled: materialBrowserModel.hasQuick3DImport
- }
}
Text {
@@ -145,116 +133,154 @@ Item {
interactive: !ctxMenu.opened
Column {
- Section {
- id: materialsSection
-
+ Item {
width: root.width
- caption: qsTr("Materials")
- dropEnabled: true
+ height: materialsSection.height
- onDropEnter: (drag) => {
- drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundlematerial"
- materialsSection.highlight = drag.accepted
- }
+ Section {
+ id: materialsSection
- onDropExit: {
- materialsSection.highlight = false
- }
+ width: root.width
+ caption: qsTr("Materials")
+ dropEnabled: true
- onDrop: {
- materialsSection.highlight = false
- rootView.acceptBundleMaterialDrop()
- }
+ onDropEnter: (drag) => {
+ drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundlematerial"
+ materialsSection.highlight = drag.accepted
+ }
- Grid {
- id: grid
+ onDropExit: {
+ materialsSection.highlight = false
+ }
- width: scrollView.width
- leftPadding: 5
- rightPadding: 5
- bottomPadding: 5
- columns: root.width / root.cellWidth
+ onDrop: {
+ materialsSection.highlight = false
+ rootView.acceptBundleMaterialDrop()
+ }
- Repeater {
- id: materialRepeater
+ Grid {
+ id: grid
- model: materialBrowserModel
- delegate: MaterialItem {
- width: root.cellWidth
- height: root.cellHeight
+ width: scrollView.width
+ leftPadding: 5
+ rightPadding: 5
+ bottomPadding: 5
+ columns: root.width / root.cellWidth
- onShowContextMenu: {
- ctxMenu.popupMenu(this, model)
+ Repeater {
+ id: materialRepeater
+
+ model: materialBrowserModel
+ delegate: MaterialItem {
+ width: root.cellWidth
+ height: root.cellHeight
+
+ onShowContextMenu: {
+ ctxMenu.popupMenu(this, model)
+ }
}
}
}
+
+ Text {
+ text: qsTr("No match found.");
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.baseFontSize
+ leftPadding: 10
+ visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
+ }
+
+ Text {
+ text:qsTr("There are no materials in this project.
Select '+' to create one.")
+ visible: materialBrowserModel.isEmpty && searchBox.isEmpty()
+ textFormat: Text.RichText
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.mediumFontSize
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.WordWrap
+ width: root.width
+ }
}
- Text {
- text: qsTr("No match found.");
- color: StudioTheme.Values.themeTextColor
- font.pixelSize: StudioTheme.Values.baseFontSize
- leftPadding: 10
- visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
- }
+ IconButton {
+ id: addMaterialButton
- Text {
- text:qsTr("There are no materials in this project.
Select '+' to create one.")
- visible: materialBrowserModel.isEmpty && searchBox.isEmpty()
- textFormat: Text.RichText
- color: StudioTheme.Values.themeTextColor
- font.pixelSize: StudioTheme.Values.mediumFontSize
- horizontalAlignment: Text.AlignHCenter
- wrapMode: Text.WordWrap
- width: root.width
+ tooltip: qsTr("Add a material.")
+
+ anchors.right: parent.right
+ anchors.rightMargin: scrollView.verticalScrollBarVisible ? 10 : 0
+ icon: StudioTheme.Constants.plus
+ normalColor: "transparent"
+ buttonSize: StudioTheme.Values.sectionHeadHeight
+ onClicked: materialBrowserModel.addNewMaterial()
+ enabled: materialBrowserModel.hasQuick3DImport
}
}
- Section {
- id: texturesSection
-
+ Item {
width: root.width
- caption: qsTr("Textures")
+ height: texturesSection.height
- Grid {
- width: scrollView.width
- leftPadding: 5
- rightPadding: 5
- bottomPadding: 5
- columns: root.width / root.cellWidth
+ Section {
+ id: texturesSection
- Repeater {
- id: texturesRepeater
+ width: root.width
+ caption: qsTr("Textures")
- model: materialBrowserTexturesModel
- delegate: TextureItem {
- width: root.cellWidth
- height: root.cellWidth
+ Grid {
+ width: scrollView.width
+ leftPadding: 5
+ rightPadding: 5
+ bottomPadding: 5
+ columns: root.width / root.cellWidth
- onShowContextMenu: {
-// ctxMenuTexture.popupMenu(this, model) // TODO: implement textures context menu
+ Repeater {
+ id: texturesRepeater
+
+ model: materialBrowserTexturesModel
+ delegate: TextureItem {
+ width: root.cellWidth
+ height: root.cellWidth
+
+ onShowContextMenu: {
+ // ctxMenuTexture.popupMenu(this, model) // TODO: implement textures context menu
+ }
}
}
}
+
+ Text {
+ text: qsTr("No match found.");
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.baseFontSize
+ leftPadding: 10
+ visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
+ }
+
+ Text {
+ text:qsTr("There are no texture in this project.")
+ visible: materialBrowserTexturesModel.isEmpty && searchBox.isEmpty()
+ textFormat: Text.RichText
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.mediumFontSize
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.WordWrap
+ width: root.width
+ }
}
- Text {
- text: qsTr("No match found.");
- color: StudioTheme.Values.themeTextColor
- font.pixelSize: StudioTheme.Values.baseFontSize
- leftPadding: 10
- visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
- }
+ IconButton {
+ id: addTextureButton
- Text {
- text:qsTr("There are no texture in this project.")
- visible: materialBrowserTexturesModel.isEmpty && searchBox.isEmpty()
- textFormat: Text.RichText
- color: StudioTheme.Values.themeTextColor
- font.pixelSize: StudioTheme.Values.mediumFontSize
- horizontalAlignment: Text.AlignHCenter
- wrapMode: Text.WordWrap
- width: root.width
+ tooltip: qsTr("Add a texture.")
+
+ anchors.right: parent.right
+ anchors.rightMargin: scrollView.verticalScrollBarVisible ? 10 : 0
+ icon: StudioTheme.Constants.plus
+ normalColor: "transparent"
+ buttonSize: StudioTheme.Values.sectionHeadHeight
+ onClicked: materialBrowserTexturesModel.addNewTexture()
+ enabled: materialBrowserModel.hasQuick3DImport
}
}
}
diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.cpp
index 772620cd04e..827fadcab6d 100644
--- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.cpp
+++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.cpp
@@ -154,6 +154,11 @@ void MaterialBrowserTexturesModel::removeTexture(const ModelNode &texture)
}
}
+void MaterialBrowserTexturesModel::addNewTexture()
+{
+ emit addNewTextureTriggered();
+}
+
void MaterialBrowserTexturesModel::deleteSelectedTexture()
{
deleteTexture(m_selectedIndex);
diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.h b/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.h
index f23ca1e48ac..afff53e6ae3 100644
--- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.h
+++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowsertexturesmodel.h
@@ -43,6 +43,7 @@ public:
void resetModel();
Q_INVOKABLE void selectTexture(int idx, bool force = false);
+ Q_INVOKABLE void addNewTexture();
Q_INVOKABLE void duplicateTexture(int idx);
Q_INVOKABLE void deleteTexture(int idx);
@@ -52,6 +53,7 @@ signals:
void materialSectionsChanged();
void selectedIndexChanged(int idx);
void duplicateTextureTriggered(const QmlDesigner::ModelNode &material);
+ void addNewTextureTriggered();
private:
bool isTextureVisible(int idx) const;
diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
index 5238ae0ed3f..b7f493c6154 100644
--- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
+++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
@@ -146,6 +146,10 @@ WidgetInfo MaterialBrowserView::widgetInfo()
ModelNode texNode = m_widget->materialBrowserTexturesModel()->textureAt(idx);
emitCustomNotification("selected_texture_changed", {texNode}, {});
});
+
+ connect(texturesModel, &MaterialBrowserTexturesModel::addNewTextureTriggered, this, [&] {
+ emitCustomNotification("add_new_texture");
+ });
}
return createWidgetInfo(m_widget.data(),
@@ -290,18 +294,25 @@ void MaterialBrowserView::nodeReparented(const ModelNode &node,
ModelNode newParentNode = newPropertyParent.parentModelNode();
ModelNode oldParentNode = oldPropertyParent.parentModelNode();
- bool matAdded = newParentNode.id() == Constants::MATERIAL_LIB_ID;
- bool matRemoved = oldParentNode.id() == Constants::MATERIAL_LIB_ID;
+ bool added = newParentNode.id() == Constants::MATERIAL_LIB_ID;
+ bool removed = oldParentNode.id() == Constants::MATERIAL_LIB_ID;
- if (matAdded || matRemoved) {
- if (matAdded && !m_puppetResetPending) {
+ if (!added && !removed)
+ return;
+
+ refreshModel(removed);
+
+ if (isMaterial(node)) {
+ if (added && !m_puppetResetPending) {
// Workaround to fix various material issues all likely caused by QTBUG-103316
resetPuppet();
m_puppetResetPending = true;
}
- refreshModel(!matAdded);
int idx = m_widget->materialBrowserModel()->materialIndex(node);
m_widget->materialBrowserModel()->selectMaterial(idx);
+ } else { // is texture
+ int idx = m_widget->materialBrowserTexturesModel()->textureIndex(node);
+ m_widget->materialBrowserTexturesModel()->selectTexture(idx);
}
}