QmlDesigner: Add separate + buttons for material browser sections

Fixes: QDS-8343
Change-Id: Id986820c857df241cf25e55416832f189c28bfe0
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2022-11-21 14:17:00 +02:00
parent 9e48f63a07
commit 88ce27736f
4 changed files with 143 additions and 99 deletions

View File

@@ -95,24 +95,12 @@ Item {
StudioControls.SearchBox { StudioControls.SearchBox {
id: searchBox id: searchBox
width: root.width - addMaterialButton.width width: root.width
onSearchChanged: (searchText) => { onSearchChanged: (searchText) => {
rootView.handleSearchFilterChanged(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 { Text {
@@ -145,116 +133,154 @@ Item {
interactive: !ctxMenu.opened interactive: !ctxMenu.opened
Column { Column {
Section { Item {
id: materialsSection
width: root.width width: root.width
caption: qsTr("Materials") height: materialsSection.height
dropEnabled: true
onDropEnter: (drag) => { Section {
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundlematerial" id: materialsSection
materialsSection.highlight = drag.accepted
}
onDropExit: { width: root.width
materialsSection.highlight = false caption: qsTr("Materials")
} dropEnabled: true
onDrop: { onDropEnter: (drag) => {
materialsSection.highlight = false drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundlematerial"
rootView.acceptBundleMaterialDrop() materialsSection.highlight = drag.accepted
} }
Grid { onDropExit: {
id: grid materialsSection.highlight = false
}
width: scrollView.width onDrop: {
leftPadding: 5 materialsSection.highlight = false
rightPadding: 5 rootView.acceptBundleMaterialDrop()
bottomPadding: 5 }
columns: root.width / root.cellWidth
Repeater { Grid {
id: materialRepeater id: grid
model: materialBrowserModel width: scrollView.width
delegate: MaterialItem { leftPadding: 5
width: root.cellWidth rightPadding: 5
height: root.cellHeight bottomPadding: 5
columns: root.width / root.cellWidth
onShowContextMenu: { Repeater {
ctxMenu.popupMenu(this, model) 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.<br>Select '<b>+</b>' 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 { IconButton {
text: qsTr("No match found."); id: addMaterialButton
color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize
leftPadding: 10
visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
}
Text { tooltip: qsTr("Add a material.")
text:qsTr("There are no materials in this project.<br>Select '<b>+</b>' to create one.")
visible: materialBrowserModel.isEmpty && searchBox.isEmpty() anchors.right: parent.right
textFormat: Text.RichText anchors.rightMargin: scrollView.verticalScrollBarVisible ? 10 : 0
color: StudioTheme.Values.themeTextColor icon: StudioTheme.Constants.plus
font.pixelSize: StudioTheme.Values.mediumFontSize normalColor: "transparent"
horizontalAlignment: Text.AlignHCenter buttonSize: StudioTheme.Values.sectionHeadHeight
wrapMode: Text.WordWrap onClicked: materialBrowserModel.addNewMaterial()
width: root.width enabled: materialBrowserModel.hasQuick3DImport
} }
} }
Section { Item {
id: texturesSection
width: root.width width: root.width
caption: qsTr("Textures") height: texturesSection.height
Grid { Section {
width: scrollView.width id: texturesSection
leftPadding: 5
rightPadding: 5
bottomPadding: 5
columns: root.width / root.cellWidth
Repeater { width: root.width
id: texturesRepeater caption: qsTr("Textures")
model: materialBrowserTexturesModel Grid {
delegate: TextureItem { width: scrollView.width
width: root.cellWidth leftPadding: 5
height: root.cellWidth rightPadding: 5
bottomPadding: 5
columns: root.width / root.cellWidth
onShowContextMenu: { Repeater {
// ctxMenuTexture.popupMenu(this, model) // TODO: implement textures context menu 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 { IconButton {
text: qsTr("No match found."); id: addTextureButton
color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize
leftPadding: 10
visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
}
Text { tooltip: qsTr("Add a texture.")
text:qsTr("There are no texture in this project.")
visible: materialBrowserTexturesModel.isEmpty && searchBox.isEmpty() anchors.right: parent.right
textFormat: Text.RichText anchors.rightMargin: scrollView.verticalScrollBarVisible ? 10 : 0
color: StudioTheme.Values.themeTextColor icon: StudioTheme.Constants.plus
font.pixelSize: StudioTheme.Values.mediumFontSize normalColor: "transparent"
horizontalAlignment: Text.AlignHCenter buttonSize: StudioTheme.Values.sectionHeadHeight
wrapMode: Text.WordWrap onClicked: materialBrowserTexturesModel.addNewTexture()
width: root.width enabled: materialBrowserModel.hasQuick3DImport
} }
} }
} }

View File

@@ -154,6 +154,11 @@ void MaterialBrowserTexturesModel::removeTexture(const ModelNode &texture)
} }
} }
void MaterialBrowserTexturesModel::addNewTexture()
{
emit addNewTextureTriggered();
}
void MaterialBrowserTexturesModel::deleteSelectedTexture() void MaterialBrowserTexturesModel::deleteSelectedTexture()
{ {
deleteTexture(m_selectedIndex); deleteTexture(m_selectedIndex);

View File

@@ -43,6 +43,7 @@ public:
void resetModel(); void resetModel();
Q_INVOKABLE void selectTexture(int idx, bool force = false); Q_INVOKABLE void selectTexture(int idx, bool force = false);
Q_INVOKABLE void addNewTexture();
Q_INVOKABLE void duplicateTexture(int idx); Q_INVOKABLE void duplicateTexture(int idx);
Q_INVOKABLE void deleteTexture(int idx); Q_INVOKABLE void deleteTexture(int idx);
@@ -52,6 +53,7 @@ signals:
void materialSectionsChanged(); void materialSectionsChanged();
void selectedIndexChanged(int idx); void selectedIndexChanged(int idx);
void duplicateTextureTriggered(const QmlDesigner::ModelNode &material); void duplicateTextureTriggered(const QmlDesigner::ModelNode &material);
void addNewTextureTriggered();
private: private:
bool isTextureVisible(int idx) const; bool isTextureVisible(int idx) const;

View File

@@ -146,6 +146,10 @@ WidgetInfo MaterialBrowserView::widgetInfo()
ModelNode texNode = m_widget->materialBrowserTexturesModel()->textureAt(idx); ModelNode texNode = m_widget->materialBrowserTexturesModel()->textureAt(idx);
emitCustomNotification("selected_texture_changed", {texNode}, {}); emitCustomNotification("selected_texture_changed", {texNode}, {});
}); });
connect(texturesModel, &MaterialBrowserTexturesModel::addNewTextureTriggered, this, [&] {
emitCustomNotification("add_new_texture");
});
} }
return createWidgetInfo(m_widget.data(), return createWidgetInfo(m_widget.data(),
@@ -290,18 +294,25 @@ void MaterialBrowserView::nodeReparented(const ModelNode &node,
ModelNode newParentNode = newPropertyParent.parentModelNode(); ModelNode newParentNode = newPropertyParent.parentModelNode();
ModelNode oldParentNode = oldPropertyParent.parentModelNode(); ModelNode oldParentNode = oldPropertyParent.parentModelNode();
bool matAdded = newParentNode.id() == Constants::MATERIAL_LIB_ID; bool added = newParentNode.id() == Constants::MATERIAL_LIB_ID;
bool matRemoved = oldParentNode.id() == Constants::MATERIAL_LIB_ID; bool removed = oldParentNode.id() == Constants::MATERIAL_LIB_ID;
if (matAdded || matRemoved) { if (!added && !removed)
if (matAdded && !m_puppetResetPending) { return;
refreshModel(removed);
if (isMaterial(node)) {
if (added && !m_puppetResetPending) {
// Workaround to fix various material issues all likely caused by QTBUG-103316 // Workaround to fix various material issues all likely caused by QTBUG-103316
resetPuppet(); resetPuppet();
m_puppetResetPending = true; m_puppetResetPending = true;
} }
refreshModel(!matAdded);
int idx = m_widget->materialBrowserModel()->materialIndex(node); int idx = m_widget->materialBrowserModel()->materialIndex(node);
m_widget->materialBrowserModel()->selectMaterial(idx); m_widget->materialBrowserModel()->selectMaterial(idx);
} else { // is texture
int idx = m_widget->materialBrowserTexturesModel()->textureIndex(node);
m_widget->materialBrowserTexturesModel()->selectTexture(idx);
} }
} }