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 {
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.<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 {
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.<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
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
}
}
}

View File

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

View File

@@ -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;

View File

@@ -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);
}
}