From 9e56d6d29f62995243988a0b2c96e86d46596094 Mon Sep 17 00:00:00 2001 From: Ian Paschal Date: Wed, 5 Sep 2018 17:16:06 +0200 Subject: [PATCH 01/19] Improved expansion behavior Contributes to CURA-5682 - Active material is now expanded by default when opening the manager - Expanded and collapsed sections are saved to preferences - Sections are now highlighted when collapsed and having a selected material inside - Bug with losing focus between fields is not yet fixed --- cura/CuraApplication.py | 4 +- cura/Machines/Models/MaterialBrandsModel.py | 4 +- .../Materials/MaterialsBrandSection.qml | 29 ++++++-- .../Preferences/Materials/MaterialsList.qml | 2 +- .../Preferences/Materials/MaterialsPage.qml | 66 +++++++++++++------ .../Preferences/Materials/MaterialsSlot.qml | 12 +++- .../Materials/MaterialsTypeSection.qml | 36 ++++++++-- 7 files changed, 119 insertions(+), 34 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 833f43e29c..e8b0930264 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -480,7 +480,9 @@ class CuraApplication(QtApplication): preferences.addPreference("view/filter_current_build_plate", False) preferences.addPreference("cura/sidebar_collapsed", False) - preferences.addPreference("cura/favorite_materials", ";".join([])) + preferences.addPreference("cura/favorite_materials", "") + preferences.addPreference("cura/expanded_brands", "") + preferences.addPreference("cura/expanded_types", "") self._need_to_show_user_agreement = not preferences.getValue("general/accepted_user_agreement") diff --git a/cura/Machines/Models/MaterialBrandsModel.py b/cura/Machines/Models/MaterialBrandsModel.py index 3f917abb16..2e2232c2dc 100644 --- a/cura/Machines/Models/MaterialBrandsModel.py +++ b/cura/Machines/Models/MaterialBrandsModel.py @@ -12,7 +12,8 @@ class MaterialTypesModel(ListModel): super().__init__(parent) self.addRoleName(Qt.UserRole + 1, "name") - self.addRoleName(Qt.UserRole + 2, "colors") + self.addRoleName(Qt.UserRole + 2, "brand") + self.addRoleName(Qt.UserRole + 3, "colors") class MaterialBrandsModel(BaseMaterialsModel): @@ -86,6 +87,7 @@ class MaterialBrandsModel(BaseMaterialsModel): for material_type, material_list in material_dict.items(): material_type_item = { "name": material_type, + "brand": brand, "colors": BaseMaterialsModel(self) } material_type_item["colors"].clear() diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index 1077cbff6f..5afe61abf1 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -13,14 +13,24 @@ import Cura 1.0 as Cura Rectangle { id: brand_section - property var expanded: base.collapsed_brands.indexOf(model.name) > -1 + property var expanded: base.expanded_brands.indexOf(model.name) > -1 property var types_model: model.material_types height: childrenRect.height width: parent.width Rectangle { id: brand_header_background - color: UM.Theme.getColor("favorites_header_bar") + color: + { + if(!expanded && model.name == base.current_brand) + { + return UM.Theme.getColor("favorites_row_selected") + } + else + { + return UM.Theme.getColor("favorites_header_bar") + } + } anchors.fill: brand_header } Row @@ -69,19 +79,20 @@ Rectangle anchors.fill: brand_header onPressed: { - const i = base.collapsed_brands.indexOf(model.name) + const i = base.expanded_brands.indexOf(model.name) if (i > -1) { // Remove it - base.collapsed_brands.splice(i, 1) + base.expanded_brands.splice(i, 1) brand_section.expanded = false } else { // Add it - base.collapsed_brands.push(model.name) + base.expanded_brands.push(model.name) brand_section.expanded = true } + UM.Preferences.setValue("cura/expanded_brands", base.expanded_brands.join(";")); } } Column @@ -97,4 +108,12 @@ Rectangle delegate: MaterialsTypeSection {} } } + + Connections { + target: UM.Preferences + onPreferenceChanged: + { + expanded = base.expanded_brands.indexOf(model.name) > -1 + } + } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 4a1a330ed6..be077c6329 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -102,7 +102,7 @@ Item } Rectangle { - property var expanded: base.collapsed_brands.indexOf("Generic") > -1 + property var expanded: base.expanded_brands.indexOf("Generic") > -1 id: generic_section height: childrenRect.height diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 0b81df5fa1..0b35440552 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -17,6 +17,8 @@ Item // Keep PreferencesDialog happy property var resetEnabled: false property var currentItem: null + property var current_type: null + property var current_brand: null property var isCurrentItemActivated: { const extruder_position = Cura.ExtruderManager.activeExtruderIndex; @@ -26,49 +28,71 @@ Item property string newRootMaterialIdToSwitchTo: "" property bool toActivateNewMaterial: false - // TODO: Save these to preferences - property var collapsed_brands: [] - property var collapsed_types: [] + property var expanded_brands: UM.Preferences.getValue("cura/expanded_brands").split(";") + property var expanded_types: UM.Preferences.getValue("cura/expanded_types").split(";") + property var extruder_position: Cura.ExtruderManager.activeExtruderIndex + property var active_root_material_id: Cura.MachineManager.currentRootMaterialId[extruder_position] UM.I18nCatalog { id: catalog name: "cura" } - Cura.MaterialBrandsModel { id: materialsModel } - function findModelByRootId( search_root_id ) + Cura.MaterialBrandsModel { id: materials_model } + Cura.GenericMaterialsModel { id: generic_materials_model } + + function expandActiveMaterial( search_root_id ) { - for (var i = 0; i < materialsModel.rowCount(); i++) + for (var n = 0; n < generic_materials_model.rowCount(); n++) { - var types_model = materialsModel.getItem(i).material_types; + var material = generic_materials_model.getItem(n); + if (material.root_material_id == search_root_id) + { + if (base.expanded_brands.indexOf("Generic") == -1) + { + base.expanded_brands.push("Generic"); + base.current_brand = "Generic" + } + } + } + for (var i = 0; i < materials_model.rowCount(); i++) + { + var brand = materials_model.getItem(i); + var types_model = brand.material_types; + for (var j = 0; j < types_model.rowCount(); j++) { - var colors_model = types_model.getItem(j).colors; + var type = types_model.getItem(j); + var colors_model = type.colors; for (var k = 0; k < colors_model.rowCount(); k++) { var material = colors_model.getItem(k); if (material.root_material_id == search_root_id) { - return material + if (base.expanded_brands.indexOf(brand.name) == -1) + { + base.expanded_brands.push(brand.name); + base.current_brand = brand.name + } + if (base.expanded_types.indexOf(brand.name+"_"+type.name) == -1) + { + base.expanded_types.push(brand.name+"_"+type.name) + base.current_type = brand.name+"_"+type.name + } } } } } + UM.Preferences.setValue("cura/expanded_brands", base.expanded_brands.join(";")); + UM.Preferences.setValue("cura/expanded_types", base.expanded_types.join(";")); } - Component.onCompleted: - { - // Select the activated material when this page shows up - const extruder_position = Cura.ExtruderManager.activeExtruderIndex; - const active_root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position]; - console.log("goign to search for", active_root_material_id) - base.currentItem = findModelByRootId(active_root_material_id) - } + Component.onCompleted: { expandActiveMaterial(active_root_material_id) } onCurrentItemChanged: { MaterialsDetailsPanel.currentItem = currentItem } Connections { - target: materialsModel + target: materials_model onItemsChanged: { var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id; @@ -80,9 +104,9 @@ Item base.newRootMaterialIdToSwitchTo = currentItemId; } - for (var idx = 0; idx < materialsModel.rowCount(); ++idx) + for (var idx = 0; idx < materials_model.rowCount(); ++idx) { - var item = materialsModel.getItem(idx); + var item = materials_model.getItem(idx); if (item.root_material_id == base.newRootMaterialIdToSwitchTo) { // Switch to the newly created profile if needed @@ -102,7 +126,7 @@ Item materialListView.activateDetailsWithIndex(materialListView.currentIndex); if (base.toActivateNewMaterial) { - Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node); + Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node); } base.newRootMaterialIdToSwitchTo = ""; base.toActivateNewMaterial = false; diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index ab0dd23750..65c32c59e3 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -20,6 +20,12 @@ Rectangle height: UM.Theme.getSize("favorites_row").height width: parent.width color: base.currentItem == model ? UM.Theme.getColor("favorites_row_selected") : "transparent" + + Component.onCompleted: { + if (material.root_material_id == base.active_root_material_id) { + base.currentItem = material + } + } Item { @@ -49,7 +55,11 @@ Rectangle MouseArea { anchors.fill: parent - onClicked: { base.currentItem = material } + onClicked: { + base.currentItem = material + base.current_brand = material.brand + base.current_type = material.brand+"_"+material.material + } hoverEnabled: true onEntered: { material_slot.hovered = true } onExited: { material_slot.hovered = false } diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index 11bf2385e1..c915390c5a 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -13,13 +13,30 @@ import Cura 1.0 as Cura Rectangle { id: material_type_section - property var expanded: base.collapsed_types.indexOf(model.brand + "_" + model.name) > -1 + property var expanded: base.expanded_types.indexOf(model.brand + "_" + model.name) > -1 property var colors_model: model.colors height: childrenRect.height width: parent.width Rectangle { id: material_type_header_background + color: + { + if(!expanded && model.brand+"_"+model.name == base.current_type) + { + return UM.Theme.getColor("favorites_row_selected") + } + else + { + return "transparent" + } + } + width: parent.width + height: material_type_header.height + } + Rectangle + { + id: material_type_header_border color: UM.Theme.getColor("lining") anchors.bottom: material_type_header.bottom anchors.left: material_type_header.left @@ -42,6 +59,7 @@ Rectangle width: parent.width - UM.Theme.getSize("favorites_button").width id: material_type_name verticalAlignment: Text.AlignVCenter + } Button { @@ -76,19 +94,21 @@ Rectangle anchors.fill: material_type_header onPressed: { - const i = base.collapsed_types.indexOf(model.brand + "_" + model.name) + const identifier = model.brand + "_" + model.name; + const i = base.expanded_types.indexOf(identifier) if (i > -1) { // Remove it - base.collapsed_types.splice(i, 1) + base.expanded_types.splice(i, 1) material_type_section.expanded = false } else { // Add it - base.collapsed_types.push(model.brand + "_" + model.name) + base.expanded_types.push(identifier) material_type_section.expanded = true } + UM.Preferences.setValue("cura/expanded_types", base.expanded_types.join(";")); } } Column @@ -106,4 +126,12 @@ Rectangle } } } + + Connections { + target: UM.Preferences + onPreferenceChanged: + { + expanded = base.expanded_types.indexOf(model.brand + "_" + model.name) > -1 + } + } } \ No newline at end of file From c1ef9abf1d68193f919d71dd550d60037c07cec8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 6 Sep 2018 17:23:16 +0200 Subject: [PATCH 02/19] Fix code style These changed in the same pull request so I'll remove them here. Contributes to issue CURA-5682. --- .../qml/Preferences/Materials/MaterialsBrandSection.qml | 3 ++- resources/qml/Preferences/Materials/MaterialsPage.qml | 2 +- resources/qml/Preferences/Materials/MaterialsSlot.qml | 6 ++++-- .../qml/Preferences/Materials/MaterialsTypeSection.qml | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index 5afe61abf1..e3a3f7a7b8 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -109,7 +109,8 @@ Rectangle } } - Connections { + Connections + { target: UM.Preferences onPreferenceChanged: { diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 0b35440552..96fea6a951 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -42,7 +42,7 @@ Item Cura.MaterialBrandsModel { id: materials_model } Cura.GenericMaterialsModel { id: generic_materials_model } - function expandActiveMaterial( search_root_id ) + function expandActiveMaterial(search_root_id) { for (var n = 0; n < generic_materials_model.rowCount(); n++) { diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index 65c32c59e3..88d613c718 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -21,7 +21,8 @@ Rectangle width: parent.width color: base.currentItem == model ? UM.Theme.getColor("favorites_row_selected") : "transparent" - Component.onCompleted: { + Component.onCompleted: + { if (material.root_material_id == base.active_root_material_id) { base.currentItem = material } @@ -55,7 +56,8 @@ Rectangle MouseArea { anchors.fill: parent - onClicked: { + onClicked: + { base.currentItem = material base.current_brand = material.brand base.current_type = material.brand+"_"+material.material diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index c915390c5a..728748b300 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -59,7 +59,6 @@ Rectangle width: parent.width - UM.Theme.getSize("favorites_button").width id: material_type_name verticalAlignment: Text.AlignVCenter - } Button { @@ -127,7 +126,8 @@ Rectangle } } - Connections { + Connections + { target: UM.Preferences onPreferenceChanged: { From 51b0497f843c243a034e3219ea3f3a424117e02e Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Mon, 10 Sep 2018 14:28:41 +0200 Subject: [PATCH 03/19] Fix the collapsable panel of the Generic materials. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsList.qml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index be077c6329..d5e4443a8c 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -158,17 +158,18 @@ Item anchors.fill: generic_header onPressed: { - const i = base.collapsed_brands.indexOf("Generic") - if (i > -1) + const index = base.expanded_brands.indexOf("Generic") + + if (index > -1) { // Remove it - base.collapsed_brands.splice(i, 1) + base.expanded_brands.splice(index, 1) generic_section.expanded = false } else { // Add it - base.collapsed_brands.push("Generic") + base.expanded_brands.push("Generic") generic_section.expanded = true } } From fe256b35628284427683416c080cb9e4f1b0c6c2 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Mon, 10 Sep 2018 15:57:19 +0200 Subject: [PATCH 04/19] Fix some issues in the material preference page. Now the generic section collapses and expands correctly. Some qml error was also fixed. Contributes to CURA-5682. --- .../Materials/MaterialsDetailsPanel.qml | 18 +++++---- .../Preferences/Materials/MaterialsList.qml | 4 +- .../Preferences/Materials/MaterialsPage.qml | 39 +++++++++++-------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml index ad9f0e3766..738a1fa6d2 100644 --- a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml +++ b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml @@ -15,19 +15,23 @@ Item property var currentItem: base.currentItem - onCurrentItemChanged: { updateMaterialPropertiesObject(currentItem) } + onCurrentItemChanged: { updateMaterialPropertiesObject() } - function updateMaterialPropertiesObject( currentItem ) + function updateMaterialPropertiesObject() { + if (currentItem === null) + { + return + } materialProperties.name = currentItem.name || "Unknown" - materialProperties.guid = currentItem.GUID; + materialProperties.guid = currentItem.GUID materialProperties.container_id = currentItem.id materialProperties.brand = currentItem.brand || "Unknown" materialProperties.material = currentItem.material || "Unknown" materialProperties.color_name = currentItem.color_name || "Yellow" materialProperties.color_code = currentItem.color_code || "yellow" materialProperties.description = currentItem.description || "" - materialProperties.adhesion_info = currentItem.adhesion_info || ""; + materialProperties.adhesion_info = currentItem.adhesion_info || "" materialProperties.density = currentItem.density || 0.0 materialProperties.diameter = currentItem.diameter || 0.0 materialProperties.approximate_diameter = currentItem.approximate_diameter || "0" @@ -62,11 +66,11 @@ Item bottom: parent.bottom } - editingEnabled: base.currentItem != null && !base.currentItem.is_read_only + editingEnabled: currentItem != null && !currentItem.is_read_only properties: materialProperties - containerId: base.currentItem != null ? base.currentItem.id : "" - currentMaterialNode: base.currentItem.container_node + containerId: currentItem != null ? currentItem.id : "" + currentMaterialNode: currentItem.container_node } diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index d5e4443a8c..8b870e75be 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -181,10 +181,12 @@ Item anchors.left: parent.left height: generic_section.expanded ? childrenRect.height : 0 visible: generic_section.expanded + Repeater { model: genericMaterialsModel - delegate: MaterialsSlot { + delegate: MaterialsSlot + { material: model } } diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 96fea6a951..bcf875be27 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -19,6 +19,8 @@ Item property var currentItem: null property var current_type: null property var current_brand: null + + property var hasCurrentItem: base.currentItem != null property var isCurrentItemActivated: { const extruder_position = Cura.ExtruderManager.activeExtruderIndex; @@ -89,47 +91,48 @@ Item } Component.onCompleted: { expandActiveMaterial(active_root_material_id) } - onCurrentItemChanged: { MaterialsDetailsPanel.currentItem = currentItem } + onCurrentItemChanged: { materialDetailsPanel.currentItem = currentItem } + Connections { target: materials_model onItemsChanged: { - var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id; - var position = Cura.ExtruderManager.activeExtruderIndex; + var currentItemId = hasCurrentItem ? base.currentItem.root_material_id : "" + var position = Cura.ExtruderManager.activeExtruderIndex // try to pick the currently selected item; it may have been moved if (base.newRootMaterialIdToSwitchTo == "") { - base.newRootMaterialIdToSwitchTo = currentItemId; + base.newRootMaterialIdToSwitchTo = currentItemId } for (var idx = 0; idx < materials_model.rowCount(); ++idx) { - var item = materials_model.getItem(idx); + var item = materials_model.getItem(idx) if (item.root_material_id == base.newRootMaterialIdToSwitchTo) { // Switch to the newly created profile if needed - materialListView.currentIndex = idx; - materialListView.activateDetailsWithIndex(materialListView.currentIndex); + materialDetailsPanel.currentIndex = idx + materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex) if (base.toActivateNewMaterial) { - Cura.MachineManager.setMaterial(position, item.container_node); + Cura.MachineManager.setMaterial(position, item.container_node) } - base.newRootMaterialIdToSwitchTo = ""; - base.toActivateNewMaterial = false; + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false return } } - materialListView.currentIndex = 0; - materialListView.activateDetailsWithIndex(materialListView.currentIndex); + materialListView.currentIndex = 0 + materialListView.activateDetailsWithIndex(materialListView.currentIndex) if (base.toActivateNewMaterial) { - Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node); + Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node) } - base.newRootMaterialIdToSwitchTo = ""; - base.toActivateNewMaterial = false; + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false } } @@ -313,11 +316,15 @@ Item frameVisible: true verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn - MaterialsList {} + MaterialsList + { + id: materialListView + } } MaterialsDetailsPanel { + id: materialDetailsPanel anchors { left: materialScrollView.right From a909c8f0298c95cf3e63a1e97389a6eef78fb876 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 11 Sep 2018 22:05:39 +0200 Subject: [PATCH 05/19] Don't emit signal if the favorite list didn't change. Contributes to CURA-5682. --- cura/Machines/MaterialManager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cura/Machines/MaterialManager.py b/cura/Machines/MaterialManager.py index 1463f2e40e..96572354b5 100644 --- a/cura/Machines/MaterialManager.py +++ b/cura/Machines/MaterialManager.py @@ -199,9 +199,14 @@ class MaterialManager(QObject): self.materialsUpdated.emit() favorites = self._application.getPreferences().getValue("cura/favorite_materials") + favorite_added = False for item in favorites.split(";"): - self._favorites.add(item) - self.favoritesUpdated.emit() + if item not in self._favorites: + self._favorites.add(item) + favorite_added = True + + if favorite_added: + self.favoritesUpdated.emit() def __addMaterialMetadataIntoLookupTree(self, material_metadata: dict) -> None: material_id = material_metadata["id"] From 9ba4c723f7f5052e4e315fad432c19d657058fd5 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 11 Sep 2018 22:07:14 +0200 Subject: [PATCH 06/19] Fix the linked materials button. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsView.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index a03e5c48d7..3bba9a9791 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -40,7 +40,7 @@ TabView { return "" } - var linkedMaterials = Cura.ContainerManager.getLinkedMaterials(base.currentItem.container_node, true); + var linkedMaterials = Cura.ContainerManager.getLinkedMaterials(base.currentMaterialNode, true); if (linkedMaterials.length == 0) { return "" From f298d371341c6fb3aa6a57f3c7c18b68888e0d17 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 11 Sep 2018 22:12:54 +0200 Subject: [PATCH 07/19] WIP: Moving current selected material to the material list instead of the page. Change all the previous references to the currentItem in the page. Automatically and correctly select the element that is selected in the extruder. Contributes to CURA-5682. --- .../Materials/MaterialsBrandSection.qml | 14 +-- .../Preferences/Materials/MaterialsList.qml | 113 +++++++++++++++++- .../Preferences/Materials/MaterialsPage.qml | 99 +-------------- .../Preferences/Materials/MaterialsSlot.qml | 4 +- .../Materials/MaterialsTypeSection.qml | 14 +-- 5 files changed, 127 insertions(+), 117 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index e3a3f7a7b8..ef9866632f 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -13,7 +13,7 @@ import Cura 1.0 as Cura Rectangle { id: brand_section - property var expanded: base.expanded_brands.indexOf(model.name) > -1 + property var expanded: materialList.expandedBrands.indexOf(model.name) > -1 property var types_model: model.material_types height: childrenRect.height width: parent.width @@ -22,7 +22,7 @@ Rectangle id: brand_header_background color: { - if(!expanded && model.name == base.current_brand) + if(!expanded && model.name == materialList.currentBrand) { return UM.Theme.getColor("favorites_row_selected") } @@ -79,20 +79,20 @@ Rectangle anchors.fill: brand_header onPressed: { - const i = base.expanded_brands.indexOf(model.name) + const i = materialList.expandedBrands.indexOf(model.name) if (i > -1) { // Remove it - base.expanded_brands.splice(i, 1) + materialList.expandedBrands.splice(i, 1) brand_section.expanded = false } else { // Add it - base.expanded_brands.push(model.name) + materialList.expandedBrands.push(model.name) brand_section.expanded = true } - UM.Preferences.setValue("cura/expanded_brands", base.expanded_brands.join(";")); + UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";")); } } Column @@ -114,7 +114,7 @@ Rectangle target: UM.Preferences onPreferenceChanged: { - expanded = base.expanded_brands.indexOf(model.name) > -1 + expanded = materialList.expandedBrands.indexOf(model.name) > -1 } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 8b870e75be..e763b7f209 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -21,6 +21,111 @@ Item Cura.MaterialBrandsModel { id: materialsModel } Cura.FavoriteMaterialsModel { id: favoriteMaterialsModel } Cura.GenericMaterialsModel { id: genericMaterialsModel } + + property var currentType: null + property var currentBrand: null + property var expandedBrands: UM.Preferences.getValue("cura/expanded_brands").split(";") + property var expandedTypes: UM.Preferences.getValue("cura/expanded_types").split(";") + + function expandActiveMaterial(search_root_id) + { + for (var n = 0; n < genericMaterialsModel.rowCount(); n++) + { + var material = genericMaterialsModel.getItem(n); + if (material.root_material_id == search_root_id) + { + if (materialList.expandedBrands.indexOf("Generic") == -1) + { + materialList.expandedBrands.push("Generic"); + materialList.currentBrand = "Generic" + } + } + } + for (var i = 0; i < materialsModel.rowCount(); i++) + { + var brand = materialsModel.getItem(i); + var types_model = brand.material_types; + + for (var j = 0; j < types_model.rowCount(); j++) + { + var type = types_model.getItem(j); + var colors_model = type.colors; + for (var k = 0; k < colors_model.rowCount(); k++) + { + var material = colors_model.getItem(k); + if (material.root_material_id == search_root_id) + { + if (materialList.expandedBrands.indexOf(brand.name) == -1) + { + materialList.expandedBrands.push(brand.name); + materialList.currentBrand = brand.name + } + if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1) + { + materialList.expandedTypes.push(brand.name + "_" + type.name) + materialList.currentType = brand.name + "_" + type.name + } + } + } + } + } + UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";")); + UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";")); + } + +// Connections +// { +// target: materialsModel +// onItemsChanged: +// { +// var currentItemId = base.hasCurrentItem ? base.currentItem.root_material_id : "" +// var position = Cura.ExtruderManager.activeExtruderIndex +// console.log("!!!!!!!!!!!!!!!!!!! on items changed:", base.newRootMaterialIdToSwitchTo) +// +// // try to pick the currently selected item; it may have been moved +// if (base.newRootMaterialIdToSwitchTo == "") +// { +// console.log("material id is empty, setting to ", currentItemId) +// base.newRootMaterialIdToSwitchTo = currentItemId +// } +// +// console.log("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", materialsModel.rowCount()) +// for (var brand_idx = 0; brand_idx < materialsModel.rowCount(); ++brand_idx) +// { +// var brand = materialsModel.getItem(brand_idx) +// console.log(item.root_material_id, "=", base.newRootMaterialIdToSwitchTo) +// +// for (var type_idx = 0; type_idx < brand.material_types.rowCount(); ++type_idx) +// { +// var type = brand.material_types.getItem(type_idx) +// if (type.root_material_id == base.newRootMaterialIdToSwitchTo) +// { +// // Switch to the newly created profile if needed +// base.currentItem = item +// // materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex) +// // if (base.toActivateNewMaterial) +// // { +// // Cura.MachineManager.setMaterial(position, item.container_node) +// // } +// base.newRootMaterialIdToSwitchTo = "" +// base.toActivateNewMaterial = false +// return +// } +// } +// } +// +// // If the new id can't be found, then do nothing +//// materialListView.currentIndex = 0 +//// materialListView.activateDetailsWithIndex(materialListView.currentIndex) +//// if (base.toActivateNewMaterial) +//// { +//// Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node) +//// } +// base.newRootMaterialIdToSwitchTo = "" +// base.toActivateNewMaterial = false +// } +// } + Column { Rectangle @@ -102,7 +207,7 @@ Item } Rectangle { - property var expanded: base.expanded_brands.indexOf("Generic") > -1 + property var expanded: materialList.expandedBrands.indexOf("Generic") > -1 id: generic_section height: childrenRect.height @@ -158,18 +263,18 @@ Item anchors.fill: generic_header onPressed: { - const index = base.expanded_brands.indexOf("Generic") + const index = materialList.expandedBrands.indexOf("Generic") if (index > -1) { // Remove it - base.expanded_brands.splice(index, 1) + materialList.expandedBrands.splice(index, 1) generic_section.expanded = false } else { // Add it - base.expanded_brands.push("Generic") + materialList.expandedBrands.push("Generic") generic_section.expanded = true } } diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index bcf875be27..c8ccb51fcc 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -17,8 +17,6 @@ Item // Keep PreferencesDialog happy property var resetEnabled: false property var currentItem: null - property var current_type: null - property var current_brand: null property var hasCurrentItem: base.currentItem != null property var isCurrentItemActivated: @@ -30,8 +28,6 @@ Item property string newRootMaterialIdToSwitchTo: "" property bool toActivateNewMaterial: false - property var expanded_brands: UM.Preferences.getValue("cura/expanded_brands").split(";") - property var expanded_types: UM.Preferences.getValue("cura/expanded_types").split(";") property var extruder_position: Cura.ExtruderManager.activeExtruderIndex property var active_root_material_id: Cura.MachineManager.currentRootMaterialId[extruder_position] @@ -41,101 +37,10 @@ Item name: "cura" } - Cura.MaterialBrandsModel { id: materials_model } - Cura.GenericMaterialsModel { id: generic_materials_model } - - function expandActiveMaterial(search_root_id) - { - for (var n = 0; n < generic_materials_model.rowCount(); n++) - { - var material = generic_materials_model.getItem(n); - if (material.root_material_id == search_root_id) - { - if (base.expanded_brands.indexOf("Generic") == -1) - { - base.expanded_brands.push("Generic"); - base.current_brand = "Generic" - } - } - } - for (var i = 0; i < materials_model.rowCount(); i++) - { - var brand = materials_model.getItem(i); - var types_model = brand.material_types; - - for (var j = 0; j < types_model.rowCount(); j++) - { - var type = types_model.getItem(j); - var colors_model = type.colors; - for (var k = 0; k < colors_model.rowCount(); k++) - { - var material = colors_model.getItem(k); - if (material.root_material_id == search_root_id) - { - if (base.expanded_brands.indexOf(brand.name) == -1) - { - base.expanded_brands.push(brand.name); - base.current_brand = brand.name - } - if (base.expanded_types.indexOf(brand.name+"_"+type.name) == -1) - { - base.expanded_types.push(brand.name+"_"+type.name) - base.current_type = brand.name+"_"+type.name - } - } - } - } - } - UM.Preferences.setValue("cura/expanded_brands", base.expanded_brands.join(";")); - UM.Preferences.setValue("cura/expanded_types", base.expanded_types.join(";")); - } - Component.onCompleted: { expandActiveMaterial(active_root_material_id) } + Component.onCompleted: { materialListView.expandActiveMaterial(active_root_material_id) } onCurrentItemChanged: { materialDetailsPanel.currentItem = currentItem } - Connections - { - target: materials_model - onItemsChanged: - { - var currentItemId = hasCurrentItem ? base.currentItem.root_material_id : "" - var position = Cura.ExtruderManager.activeExtruderIndex - - // try to pick the currently selected item; it may have been moved - if (base.newRootMaterialIdToSwitchTo == "") - { - base.newRootMaterialIdToSwitchTo = currentItemId - } - - for (var idx = 0; idx < materials_model.rowCount(); ++idx) - { - var item = materials_model.getItem(idx) - if (item.root_material_id == base.newRootMaterialIdToSwitchTo) - { - // Switch to the newly created profile if needed - materialDetailsPanel.currentIndex = idx - materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex) - if (base.toActivateNewMaterial) - { - Cura.MachineManager.setMaterial(position, item.container_node) - } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false - return - } - } - - materialListView.currentIndex = 0 - materialListView.activateDetailsWithIndex(materialListView.currentIndex) - if (base.toActivateNewMaterial) - { - Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node) - } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false - } - } - // Main layout Label { @@ -241,7 +146,7 @@ Item forceActiveFocus(); exportMaterialDialog.open(); } - enabled: currentItem != null + enabled: base.hasCurrentItem } } diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index 88d613c718..88ff34e4d5 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -59,8 +59,8 @@ Rectangle onClicked: { base.currentItem = material - base.current_brand = material.brand - base.current_type = material.brand+"_"+material.material + materialList.currentBrand = material.brand + materialList.currentType = material.brand + "_" + material.material } hoverEnabled: true onEntered: { material_slot.hovered = true } diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index 728748b300..38fc0d6a45 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -13,7 +13,7 @@ import Cura 1.0 as Cura Rectangle { id: material_type_section - property var expanded: base.expanded_types.indexOf(model.brand + "_" + model.name) > -1 + property var expanded: materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1 property var colors_model: model.colors height: childrenRect.height width: parent.width @@ -22,7 +22,7 @@ Rectangle id: material_type_header_background color: { - if(!expanded && model.brand+"_"+model.name == base.current_type) + if(!expanded && model.brand + "_" + model.name == materialList.currentType) { return UM.Theme.getColor("favorites_row_selected") } @@ -94,20 +94,20 @@ Rectangle onPressed: { const identifier = model.brand + "_" + model.name; - const i = base.expanded_types.indexOf(identifier) + const i = materialList.expandedTypes.indexOf(identifier) if (i > -1) { // Remove it - base.expanded_types.splice(i, 1) + materialList.expandedTypes.splice(i, 1) material_type_section.expanded = false } else { // Add it - base.expanded_types.push(identifier) + materialList.expandedTypes.push(identifier) material_type_section.expanded = true } - UM.Preferences.setValue("cura/expanded_types", base.expanded_types.join(";")); + UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";")); } } Column @@ -131,7 +131,7 @@ Rectangle target: UM.Preferences onPreferenceChanged: { - expanded = base.expanded_types.indexOf(model.brand + "_" + model.name) > -1 + expanded = materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1 } } } \ No newline at end of file From 6d2492e5cbe62d593b5a31cf23aea20a59ad926b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 12:59:13 +0200 Subject: [PATCH 08/19] Remove spurious signal, it does the same as materialsUpdated. Contributes to CURA-5682. --- cura/Machines/MaterialManager.py | 15 ++++----------- cura/Machines/Models/BaseMaterialsModel.py | 3 --- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/cura/Machines/MaterialManager.py b/cura/Machines/MaterialManager.py index 96572354b5..7075eaa004 100644 --- a/cura/Machines/MaterialManager.py +++ b/cura/Machines/MaterialManager.py @@ -40,7 +40,6 @@ if TYPE_CHECKING: class MaterialManager(QObject): materialsUpdated = pyqtSignal() # Emitted whenever the material lookup tables are updated. - favoritesUpdated = pyqtSignal() # Emitted whenever the favorites are changed def __init__(self, container_registry, parent = None): super().__init__(parent) @@ -196,17 +195,11 @@ class MaterialManager(QObject): for material_metadata in material_metadatas.values(): self.__addMaterialMetadataIntoLookupTree(material_metadata) - self.materialsUpdated.emit() - favorites = self._application.getPreferences().getValue("cura/favorite_materials") - favorite_added = False for item in favorites.split(";"): - if item not in self._favorites: - self._favorites.add(item) - favorite_added = True + self._favorites.add(item) - if favorite_added: - self.favoritesUpdated.emit() + self.materialsUpdated.emit() def __addMaterialMetadataIntoLookupTree(self, material_metadata: dict) -> None: material_id = material_metadata["id"] @@ -626,7 +619,7 @@ class MaterialManager(QObject): @pyqtSlot(str) def addFavorite(self, root_material_id: str): self._favorites.add(root_material_id) - self.favoritesUpdated.emit() + self.materialsUpdated.emit() # Ensure all settings are saved. self._application.getPreferences().setValue("cura/favorite_materials", ";".join(list(self._favorites))) @@ -635,7 +628,7 @@ class MaterialManager(QObject): @pyqtSlot(str) def removeFavorite(self, root_material_id: str): self._favorites.remove(root_material_id) - self.favoritesUpdated.emit() + self.materialsUpdated.emit() # Ensure all settings are saved. self._application.getPreferences().setValue("cura/favorite_materials", ";".join(list(self._favorites))) diff --git a/cura/Machines/Models/BaseMaterialsModel.py b/cura/Machines/Models/BaseMaterialsModel.py index 1b20e1188c..c08013566b 100644 --- a/cura/Machines/Models/BaseMaterialsModel.py +++ b/cura/Machines/Models/BaseMaterialsModel.py @@ -34,9 +34,6 @@ class BaseMaterialsModel(ListModel): # Update this model when list of materials changes self._material_manager.materialsUpdated.connect(self._update) - # Update this model when list of favorites changes - self._material_manager.favoritesUpdated.connect(self._update) - self.addRoleName(Qt.UserRole + 1, "root_material_id") self.addRoleName(Qt.UserRole + 2, "id") self.addRoleName(Qt.UserRole + 3, "GUID") From 56dcc2dded230137fd7ac61e577b81f36b72a6ba Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 14:09:29 +0200 Subject: [PATCH 09/19] Highlight the material that is currently selected. Contributes to CURA-5682. --- .../Preferences/Materials/MaterialsSlot.qml | 158 ++++++++---------- 1 file changed, 73 insertions(+), 85 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index 88ff34e4d5..63d40068ce 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -19,114 +19,102 @@ Rectangle height: UM.Theme.getSize("favorites_row").height width: parent.width - color: base.currentItem == model ? UM.Theme.getColor("favorites_row_selected") : "transparent" + color: base.currentItem.root_material_id == material.root_material_id ? UM.Theme.getColor("favorites_row_selected") : "transparent" - Component.onCompleted: + Rectangle { - if (material.root_material_id == base.active_root_material_id) { + id: swatch + color: material.color_code + border.width: UM.Theme.getSize("default_lining").width + border.color: "black" + width: UM.Theme.getSize("favorites_button_icon").width + height: UM.Theme.getSize("favorites_button_icon").height + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: UM.Theme.getSize("default_margin").width + } + Label + { + text: material.brand + " " + material.name + verticalAlignment: Text.AlignVCenter + height: parent.height + anchors.left: swatch.right + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: UM.Theme.getSize("narrow_margin").width + } + MouseArea + { + anchors.fill: parent + onClicked: + { + materialList.currentBrand = material.brand + materialList.currentType = material.brand + "_" + material.material base.currentItem = material } + hoverEnabled: true + onEntered: { material_slot.hovered = true } + onExited: { material_slot.hovered = false } } - - Item + Button { - height: parent.height - width: parent.width - Rectangle + id: favorite_button + text: "" + implicitWidth: UM.Theme.getSize("favorites_button").width + implicitHeight: UM.Theme.getSize("favorites_button").height + visible: material_slot.hovered || material_slot.is_favorite || favorite_button.hovered + anchors { - id: swatch - color: material.color_code - border.width: UM.Theme.getSize("default_lining").width - border.color: "black" - width: UM.Theme.getSize("favorites_button_icon").width - height: UM.Theme.getSize("favorites_button_icon").height - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.leftMargin: UM.Theme.getSize("default_margin").width + right: parent.right + verticalCenter: parent.verticalCenter } - Label + onClicked: { - text: material.brand + " " + material.name - verticalAlignment: Text.AlignVCenter - height: parent.height - anchors.left: swatch.right - anchors.verticalCenter: parent.verticalCenter - anchors.leftMargin: UM.Theme.getSize("narrow_margin").width - } - MouseArea - { - anchors.fill: parent - onClicked: - { - base.currentItem = material - materialList.currentBrand = material.brand - materialList.currentType = material.brand + "_" + material.material - } - hoverEnabled: true - onEntered: { material_slot.hovered = true } - onExited: { material_slot.hovered = false } - } - Button - { - id: favorite_button - text: "" - implicitWidth: UM.Theme.getSize("favorites_button").width - implicitHeight: UM.Theme.getSize("favorites_button").height - visible: material_slot.hovered || material_slot.is_favorite || favorite_button.hovered - anchors - { - right: parent.right - verticalCenter: parent.verticalCenter - } - onClicked: - { - if (material_slot.is_favorite) { - base.materialManager.removeFavorite(material.root_material_id) - material_slot.is_favorite = false - return - } - base.materialManager.addFavorite(material.root_material_id) - material_slot.is_favorite = true + if (material_slot.is_favorite) { + base.materialManager.removeFavorite(material.root_material_id) + material_slot.is_favorite = false return } - style: ButtonStyle + base.materialManager.addFavorite(material.root_material_id) + material_slot.is_favorite = true + return + } + style: ButtonStyle + { + background: Rectangle { - background: Rectangle - { - anchors.fill: parent - color: "transparent" - } + anchors.fill: parent + color: "transparent" } - UM.RecolorImage { - anchors + } + UM.RecolorImage { + anchors + { + verticalCenter: parent.verticalCenter + horizontalCenter: parent.horizontalCenter + } + width: UM.Theme.getSize("favorites_button_icon").width + height: UM.Theme.getSize("favorites_button_icon").height + sourceSize.width: width + sourceSize.height: height + color: + { + if (favorite_button.hovered) { - verticalCenter: parent.verticalCenter - horizontalCenter: parent.horizontalCenter + return UM.Theme.getColor("primary_hover") } - width: UM.Theme.getSize("favorites_button_icon").width - height: UM.Theme.getSize("favorites_button_icon").height - sourceSize.width: width - sourceSize.height: height - color: + else { - if (favorite_button.hovered) + if (material_slot.is_favorite) { - return UM.Theme.getColor("primary_hover") + return UM.Theme.getColor("primary") } else { - if (material_slot.is_favorite) - { - return UM.Theme.getColor("primary") - } - else - { - UM.Theme.getColor("text_inactive") - } + UM.Theme.getColor("text_inactive") } } - source: material_slot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty") } + source: material_slot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty") } } } \ No newline at end of file From 921b11974cbb6dc8f437589b1c5214bfd0cf69d4 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 15:42:02 +0200 Subject: [PATCH 10/19] Improve the way the categories are highlighted. When a material is selected, but the brand or the type is collapsed, those components are also highlighted to indicate the path to the material. Reuse the MaterialBrandSection also for the generic materials, that allow us to only mantain one component. Contributes to CURA-5682. --- .../Materials/MaterialsBrandSection.qml | 37 ++- .../Materials/MaterialsDetailsPanel.qml | 2 +- .../Preferences/Materials/MaterialsList.qml | 213 +++++------------- .../Preferences/Materials/MaterialsPage.qml | 16 +- .../Materials/MaterialsTypeSection.qml | 4 +- 5 files changed, 98 insertions(+), 174 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index ef9866632f..91fecb3e53 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -13,8 +13,12 @@ import Cura 1.0 as Cura Rectangle { id: brand_section - property var expanded: materialList.expandedBrands.indexOf(model.name) > -1 - property var types_model: model.material_types + + property var sectionName: "" + property var elements // This can be a MaterialTypesModel or GenericMaterialsModel + property var hasMaterialTypes: true // It indicates wheather it has material types or not + property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1 + height: childrenRect.height width: parent.width Rectangle @@ -22,7 +26,7 @@ Rectangle id: brand_header_background color: { - if(!expanded && model.name == materialList.currentBrand) + if(!expanded && sectionName == materialList.currentBrand) { return UM.Theme.getColor("favorites_row_selected") } @@ -40,7 +44,7 @@ Rectangle Label { id: brand_name - text: model.name + text: sectionName height: UM.Theme.getSize("favorites_row").height width: parent.width - UM.Theme.getSize("favorites_button").width verticalAlignment: Text.AlignVCenter @@ -79,7 +83,7 @@ Rectangle anchors.fill: brand_header onPressed: { - const i = materialList.expandedBrands.indexOf(model.name) + const i = materialList.expandedBrands.indexOf(sectionName) if (i > -1) { // Remove it @@ -89,7 +93,7 @@ Rectangle else { // Add it - materialList.expandedBrands.push(model.name) + materialList.expandedBrands.push(sectionName) brand_section.expanded = true } UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";")); @@ -102,10 +106,25 @@ Rectangle anchors.left: parent.left height: brand_section.expanded ? childrenRect.height : 0 visible: brand_section.expanded + Repeater { - model: types_model - delegate: MaterialsTypeSection {} + model: elements + delegate: MaterialsTypeSection + { + visible: hasMaterialTypes + materialType: model + } + } + // In case there are no types, we create a material slot + Repeater + { + model: elements + delegate: MaterialsSlot + { + visible: !hasMaterialTypes + material: model + } } } @@ -114,7 +133,7 @@ Rectangle target: UM.Preferences onPreferenceChanged: { - expanded = materialList.expandedBrands.indexOf(model.name) > -1 + expanded = materialList.expandedBrands.indexOf(sectionName) > -1 } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml index 738a1fa6d2..ec5f694c18 100644 --- a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml +++ b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml @@ -15,7 +15,7 @@ Item property var currentItem: base.currentItem - onCurrentItemChanged: { updateMaterialPropertiesObject() } + onCurrentItemChanged: updateMaterialPropertiesObject() function updateMaterialPropertiesObject() { diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index e763b7f209..abc07a6455 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -26,12 +26,20 @@ Item property var currentBrand: null property var expandedBrands: UM.Preferences.getValue("cura/expanded_brands").split(";") property var expandedTypes: UM.Preferences.getValue("cura/expanded_types").split(";") - + + // Store information about which parts of the tree are expanded + function persistExpandedCategories() + { + UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";")) + UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";")) + } + + // Expand the list of materials in order to select the current material function expandActiveMaterial(search_root_id) { - for (var n = 0; n < genericMaterialsModel.rowCount(); n++) + for (var material_idx = 0; material_idx < genericMaterialsModel.rowCount(); material_idx++) { - var material = genericMaterialsModel.getItem(n); + var material = genericMaterialsModel.getItem(material_idx) if (material.root_material_id == search_root_id) { if (materialList.expandedBrands.indexOf("Generic") == -1) @@ -39,20 +47,22 @@ Item materialList.expandedBrands.push("Generic"); materialList.currentBrand = "Generic" } + base.currentItem = material + persistExpandedCategories() + return true } } - for (var i = 0; i < materialsModel.rowCount(); i++) + for (var brand_idx = 0; brand_idx < materialsModel.rowCount(); brand_idx++) { - var brand = materialsModel.getItem(i); - var types_model = brand.material_types; - - for (var j = 0; j < types_model.rowCount(); j++) + var brand = materialsModel.getItem(brand_idx) + var types_model = brand.material_types + for (var type_idx = 0; type_idx < types_model.rowCount(); type_idx++) { - var type = types_model.getItem(j); - var colors_model = type.colors; - for (var k = 0; k < colors_model.rowCount(); k++) + var type = types_model.getItem(type_idx) + var colors_model = type.colors + for (var material_idx = 0; material_idx < colors_model.rowCount(); material_idx++) { - var material = colors_model.getItem(k); + var material = colors_model.getItem(material_idx) if (material.root_material_id == search_root_id) { if (materialList.expandedBrands.indexOf(brand.name) == -1) @@ -65,66 +75,30 @@ Item materialList.expandedTypes.push(brand.name + "_" + type.name) materialList.currentType = brand.name + "_" + type.name } + base.currentItem = material + persistExpandedCategories() + return true } } } + return false } - UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";")); - UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";")); } -// Connections -// { -// target: materialsModel -// onItemsChanged: -// { -// var currentItemId = base.hasCurrentItem ? base.currentItem.root_material_id : "" -// var position = Cura.ExtruderManager.activeExtruderIndex -// console.log("!!!!!!!!!!!!!!!!!!! on items changed:", base.newRootMaterialIdToSwitchTo) -// -// // try to pick the currently selected item; it may have been moved -// if (base.newRootMaterialIdToSwitchTo == "") -// { -// console.log("material id is empty, setting to ", currentItemId) -// base.newRootMaterialIdToSwitchTo = currentItemId -// } -// -// console.log("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", materialsModel.rowCount()) -// for (var brand_idx = 0; brand_idx < materialsModel.rowCount(); ++brand_idx) -// { -// var brand = materialsModel.getItem(brand_idx) -// console.log(item.root_material_id, "=", base.newRootMaterialIdToSwitchTo) -// -// for (var type_idx = 0; type_idx < brand.material_types.rowCount(); ++type_idx) -// { -// var type = brand.material_types.getItem(type_idx) -// if (type.root_material_id == base.newRootMaterialIdToSwitchTo) -// { -// // Switch to the newly created profile if needed -// base.currentItem = item -// // materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex) -// // if (base.toActivateNewMaterial) -// // { -// // Cura.MachineManager.setMaterial(position, item.container_node) -// // } -// base.newRootMaterialIdToSwitchTo = "" -// base.toActivateNewMaterial = false -// return -// } -// } -// } -// -// // If the new id can't be found, then do nothing -//// materialListView.currentIndex = 0 -//// materialListView.activateDetailsWithIndex(materialListView.currentIndex) -//// if (base.toActivateNewMaterial) -//// { -//// Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node) -//// } -// base.newRootMaterialIdToSwitchTo = "" -// base.toActivateNewMaterial = false -// } -// } + Connections + { + target: materialsModel + onItemsChanged: + { + var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) +// if (base.toActivateNewMaterial) +// { +// Cura.MachineManager.setMaterial(position, material.container_node) +// } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false + } + } Column { @@ -199,97 +173,6 @@ Item Repeater { model: favoriteMaterialsModel - delegate: MaterialsSlot { - material: model - } - } - } - } - Rectangle - { - property var expanded: materialList.expandedBrands.indexOf("Generic") > -1 - - id: generic_section - height: childrenRect.height - width: materialList.width - Rectangle - { - id: generic_header_background - color: UM.Theme.getColor("favorites_header_bar") - anchors.fill: generic_header - } - Row - { - id: generic_header - Label - { - id: generic_name - text: "Generic" - height: UM.Theme.getSize("favorites_row").height - width: materialList.width - UM.Theme.getSize("favorites_button").width - verticalAlignment: Text.AlignVCenter - leftPadding: 4 - } - Button - { - text: "" - implicitWidth: UM.Theme.getSize("favorites_button").width - implicitHeight: UM.Theme.getSize("favorites_button").height - UM.RecolorImage { - anchors - { - verticalCenter: parent.verticalCenter - horizontalCenter: parent.horizontalCenter - } - width: UM.Theme.getSize("standard_arrow").width - height: UM.Theme.getSize("standard_arrow").height - sourceSize.width: width - sourceSize.height: height - color: "black" - source: generic_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left") - } - style: ButtonStyle - { - background: Rectangle - { - anchors.fill: parent - color: "transparent" - } - } - } - } - MouseArea - { - anchors.fill: generic_header - onPressed: - { - const index = materialList.expandedBrands.indexOf("Generic") - - if (index > -1) - { - // Remove it - materialList.expandedBrands.splice(index, 1) - generic_section.expanded = false - } - else - { - // Add it - materialList.expandedBrands.push("Generic") - generic_section.expanded = true - } - } - } - Column - { - anchors.top: generic_header.bottom - width: materialList.width - anchors.left: parent.left - height: generic_section.expanded ? childrenRect.height : 0 - visible: generic_section.expanded - - Repeater - { - model: genericMaterialsModel delegate: MaterialsSlot { material: model @@ -297,11 +180,25 @@ Item } } } + + MaterialsBrandSection + { + id: genericSection + sectionName: "Generic" + elements: genericMaterialsModel + hasMaterialTypes: false + } Repeater { id: brand_list model: materialsModel - delegate: MaterialsBrandSection {} + delegate: MaterialsBrandSection + { + id: brandSection + sectionName: model.name + elements: model.material_types + hasMaterialTypes: true + } } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index c8ccb51fcc..c77d4eb226 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -21,9 +21,13 @@ Item property var hasCurrentItem: base.currentItem != null property var isCurrentItemActivated: { - const extruder_position = Cura.ExtruderManager.activeExtruderIndex; - const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position]; - return base.currentItem.root_material_id == root_material_id; + if (!hasCurrentItem) + { + return false + } + const extruder_position = Cura.ExtruderManager.activeExtruderIndex + const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position] + return base.currentItem.root_material_id == root_material_id } property string newRootMaterialIdToSwitchTo: "" property bool toActivateNewMaterial: false @@ -37,9 +41,11 @@ Item name: "cura" } - Component.onCompleted: { materialListView.expandActiveMaterial(active_root_material_id) } + // When loaded, try to select the active material in the tree + Component.onCompleted: materialListView.expandActiveMaterial(active_root_material_id) - onCurrentItemChanged: { materialDetailsPanel.currentItem = currentItem } + // Every time the selected item has changed, notify to the details panel + onCurrentItemChanged: materialDetailsPanel.currentItem = currentItem // Main layout Label diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index 38fc0d6a45..42ca338cf0 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -13,6 +13,7 @@ import Cura 1.0 as Cura Rectangle { id: material_type_section + property var materialType property var expanded: materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1 property var colors_model: model.colors height: childrenRect.height @@ -120,7 +121,8 @@ Rectangle Repeater { model: colors_model - delegate: MaterialsSlot { + delegate: MaterialsSlot + { material: model } } From 6183a07d7603ae5fb5d914c6e35fead79bbe3993 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 16:35:01 +0200 Subject: [PATCH 11/19] Activate the material right after it was created or duplicated. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsList.qml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index abc07a6455..510d030445 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -91,10 +91,11 @@ Item onItemsChanged: { var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) -// if (base.toActivateNewMaterial) -// { -// Cura.MachineManager.setMaterial(position, material.container_node) -// } + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } base.newRootMaterialIdToSwitchTo = "" base.toActivateNewMaterial = false } From e3f67f1147b05a83ce9490a3d9e93a14317d610b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 16:37:16 +0200 Subject: [PATCH 12/19] Fix code style. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsView.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index 3bba9a9791..30a02f2741 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -567,7 +567,7 @@ TabView // don't change when new name is the same if (old_name == new_name) { - return; + return } // update the values @@ -576,14 +576,14 @@ TabView } // update the type of the material - function updateMaterialType (old_type, new_type) + function updateMaterialType(old_type, new_type) { base.setMetaDataEntry("material", old_type, new_type); - materialProperties.material= new_type; + materialProperties.material = new_type; } // update the brand of the material - function updateMaterialBrand (old_brand, new_brand) + function updateMaterialBrand(old_brand, new_brand) { base.setMetaDataEntry("brand", old_brand, new_brand); materialProperties.brand = new_brand; From 3368428dbb480f794f199db58ffebbed944bfec4 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 16:57:43 +0200 Subject: [PATCH 13/19] Fix text field alignment. The color text field was too short in many cases, when the color name is long. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsView.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index 30a02f2741..b1eb787cd2 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -191,6 +191,7 @@ TabView ReadOnlyTextField { id: colorLabel; + width: parent.width - colorSelector.width - parent.spacing text: properties.color_name; readOnly: !base.editingEnabled onEditingFinished: base.setMetaDataEntry("color_name", properties.color_name, text) From 6dc53cc60a8b53a4303b141c0e305aecdd4654c3 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 12 Sep 2018 18:39:19 +0200 Subject: [PATCH 14/19] Select the next selected material when it is activated or removed. Contributes to CURA-5682. --- resources/qml/Preferences/Materials/MaterialsPage.qml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index c77d4eb226..7a7a2b885f 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -84,8 +84,10 @@ Item { forceActiveFocus() - const extruder_position = Cura.ExtruderManager.activeExtruderIndex; - Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node); + // Set the current material as the one to be activated (needed to force the UI update) + base.newRootMaterialIdToSwitchTo = base.currentItem.root_material_id + const extruder_position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node) } } @@ -258,6 +260,8 @@ Item modality: Qt.ApplicationModal onYes: { + // Set the active material as the fallback. It will be selected when the current material is deleted + base.newRootMaterialIdToSwitchTo = base.active_root_material_id base.materialManager.removeMaterial(base.currentItem.container_node); } } From 972f0bef438dec38bede2e9a93cde6eafdce230f Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 14 Sep 2018 10:51:56 +0200 Subject: [PATCH 15/19] WIP Fix an error in which the current selected material was not correctly selected when there is more than one brand (stupid mistake). Also fix problems when the user changes some material information. Contributes to CURA-5682. --- .../Materials/MaterialsDetailsPanel.qml | 15 +++--- .../Preferences/Materials/MaterialsList.qml | 51 +++++++++++++++---- .../Preferences/Materials/MaterialsView.qml | 12 ++--- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml index ec5f694c18..43e98d63a6 100644 --- a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml +++ b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml @@ -13,16 +13,17 @@ Item { id: detailsPanel - property var currentItem: base.currentItem + property var currentItem: null - onCurrentItemChanged: updateMaterialPropertiesObject() + onCurrentItemChanged: + { + // When the current item changes, the detail view needs to be updated + updateMaterialPropertiesObject() + materialDetailsView.currentMaterialNode = currentItem.container_node + } function updateMaterialPropertiesObject() { - if (currentItem === null) - { - return - } materialProperties.name = currentItem.name || "Unknown" materialProperties.guid = currentItem.GUID materialProperties.container_id = currentItem.id @@ -71,8 +72,6 @@ Item properties: materialProperties containerId: currentItem != null ? currentItem.id : "" currentMaterialNode: currentItem.container_node - - } QtObject diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 510d030445..0854371655 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -37,6 +37,13 @@ Item // Expand the list of materials in order to select the current material function expandActiveMaterial(search_root_id) { + if (search_root_id == "") + { + // When this happens it means that the information of one of the materials has changed, so the model + // was updated and the list has to highlight the current item. + var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id + search_root_id = currentItemId + } for (var material_idx = 0; material_idx < genericMaterialsModel.rowCount(); material_idx++) { var material = genericMaterialsModel.getItem(material_idx) @@ -44,9 +51,9 @@ Item { if (materialList.expandedBrands.indexOf("Generic") == -1) { - materialList.expandedBrands.push("Generic"); - materialList.currentBrand = "Generic" + materialList.expandedBrands.push("Generic") } + materialList.currentBrand = "Generic" base.currentItem = material persistExpandedCategories() return true @@ -67,22 +74,22 @@ Item { if (materialList.expandedBrands.indexOf(brand.name) == -1) { - materialList.expandedBrands.push(brand.name); - materialList.currentBrand = brand.name + materialList.expandedBrands.push(brand.name) } + materialList.currentBrand = brand.name if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1) { materialList.expandedTypes.push(brand.name + "_" + type.name) - materialList.currentType = brand.name + "_" + type.name } + materialList.currentType = brand.name + "_" + type.name base.currentItem = material persistExpandedCategories() return true } } } - return false } + return false } Connections @@ -91,13 +98,35 @@ Item onItemsChanged: { var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) - if (base.toActivateNewMaterial) + if (correctlyExpanded) { - var position = Cura.ExtruderManager.activeExtruderIndex - Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false + } + } + } + + Connections + { + target: genericMaterialsModel + onItemsChanged: + { + var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) + if (correctlyExpanded) + { + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false } } diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index b1eb787cd2..56fa12877f 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -572,21 +572,21 @@ TabView } // update the values - base.materialManager.setMaterialName(base.currentMaterialNode, new_name); - materialProperties.name = new_name; + base.materialManager.setMaterialName(base.currentMaterialNode, new_name) + properties.name = new_name } // update the type of the material function updateMaterialType(old_type, new_type) { - base.setMetaDataEntry("material", old_type, new_type); - materialProperties.material = new_type; + base.setMetaDataEntry("material", old_type, new_type) + properties.material = new_type } // update the brand of the material function updateMaterialBrand(old_brand, new_brand) { - base.setMetaDataEntry("brand", old_brand, new_brand); - materialProperties.brand = new_brand; + base.setMetaDataEntry("brand", old_brand, new_brand) + properties.brand = new_brand } } From f871a898255dc6614966096d538220a59fafdff8 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 14 Sep 2018 14:46:33 +0200 Subject: [PATCH 16/19] Clean up the code by removing duplicate code. Also try to unify the MaterialsBrandSection to use the same component for favorites, generic and branded materials. Contributes to CURA-5682. --- .../Materials/MaterialsBrandSection.qml | 46 +++- .../Preferences/Materials/MaterialsList.qml | 235 +++++++++--------- .../Materials/MaterialsTypeSection.qml | 14 +- 3 files changed, 158 insertions(+), 137 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index 91fecb3e53..ef3a773835 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -15,7 +15,7 @@ Rectangle id: brand_section property var sectionName: "" - property var elements // This can be a MaterialTypesModel or GenericMaterialsModel + property var elementsModel // This can be a MaterialTypesModel or GenericMaterialsModel or FavoriteMaterialsModel property var hasMaterialTypes: true // It indicates wheather it has material types or not property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1 @@ -109,22 +109,44 @@ Rectangle Repeater { - model: elements - delegate: MaterialsTypeSection + model: elementsModel + delegate: Item { - visible: hasMaterialTypes - materialType: model + Loader + { + id: loader + property var element: model + sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot + } } } // In case there are no types, we create a material slot - Repeater +// Repeater +// { +// model: elementsModel +// delegate: MaterialsSlot +// { +// visible: !hasMaterialTypes +// material: model +// } +// } + } + + Component + { + id: materialsTypeSection + MaterialsTypeSection { - model: elements - delegate: MaterialsSlot - { - visible: !hasMaterialTypes - material: model - } + materialType: element + } + } + + Component + { + id: materialSlot + MaterialsSlot + { + material: element } } diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 0854371655..9b8903d7da 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -92,143 +92,142 @@ Item return false } + function updateAfterModelChanges() + { + var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) + if (correctlyExpanded) + { + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false + } + } + Connections { target: materialsModel - onItemsChanged: - { - var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) - if (correctlyExpanded) - { - if (base.toActivateNewMaterial) - { - var position = Cura.ExtruderManager.activeExtruderIndex - Cura.MachineManager.setMaterial(position, base.currentItem.container_node) - } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false - } - } + onItemsChanged: updateAfterModelChanges() } Connections { target: genericMaterialsModel - onItemsChanged: - { - var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) - if (correctlyExpanded) - { - if (base.toActivateNewMaterial) - { - var position = Cura.ExtruderManager.activeExtruderIndex - Cura.MachineManager.setMaterial(position, base.currentItem.container_node) - } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false - } - } + onItemsChanged: updateAfterModelChanges() } Column { - Rectangle - { - property var expanded: true +// Rectangle +// { +// property var expanded: true +// +// id: favorites_section +// height: childrenRect.height +// width: materialList.width +// Rectangle +// { +// id: favorites_header_background +// color: UM.Theme.getColor("favorites_header_bar") +// anchors.fill: favorites_header +// } +// Row +// { +// id: favorites_header +// Label +// { +// id: favorites_name +// text: "Favorites" +// height: UM.Theme.getSize("favorites_row").height +// width: materialList.width - UM.Theme.getSize("favorites_button").width +// verticalAlignment: Text.AlignVCenter +// leftPadding: 4 +// } +// Button +// { +// text: "" +// implicitWidth: UM.Theme.getSize("favorites_button").width +// implicitHeight: UM.Theme.getSize("favorites_button").height +// UM.RecolorImage { +// anchors +// { +// verticalCenter: parent.verticalCenter +// horizontalCenter: parent.horizontalCenter +// } +// width: UM.Theme.getSize("standard_arrow").width +// height: UM.Theme.getSize("standard_arrow").height +// sourceSize.width: width +// sourceSize.height: height +// color: "black" +// source: favorites_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left") +// } +// style: ButtonStyle +// { +// background: Rectangle +// { +// anchors.fill: parent +// color: "transparent" +// } +// } +// } +// } +// MouseArea +// { +// anchors.fill: favorites_header +// onPressed: +// { +// favorites_section.expanded = !favorites_section.expanded +// } +// } +// Column +// { +// anchors.top: favorites_header.bottom +// anchors.left: parent.left +// width: materialList.width +// height: favorites_section.expanded ? childrenRect.height : 0 +// visible: favorites_section.expanded +// Repeater +// { +// model: favoriteMaterialsModel +// delegate: MaterialsSlot +// { +// material: model +// } +// } +// } +// } - id: favorites_section - height: childrenRect.height - width: materialList.width - Rectangle - { - id: favorites_header_background - color: UM.Theme.getColor("favorites_header_bar") - anchors.fill: favorites_header - } - Row - { - id: favorites_header - Label - { - id: favorites_name - text: "Favorites" - height: UM.Theme.getSize("favorites_row").height - width: materialList.width - UM.Theme.getSize("favorites_button").width - verticalAlignment: Text.AlignVCenter - leftPadding: 4 - } - Button - { - text: "" - implicitWidth: UM.Theme.getSize("favorites_button").width - implicitHeight: UM.Theme.getSize("favorites_button").height - UM.RecolorImage { - anchors - { - verticalCenter: parent.verticalCenter - horizontalCenter: parent.horizontalCenter - } - width: UM.Theme.getSize("standard_arrow").width - height: UM.Theme.getSize("standard_arrow").height - sourceSize.width: width - sourceSize.height: height - color: "black" - source: favorites_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left") - } - style: ButtonStyle - { - background: Rectangle - { - anchors.fill: parent - color: "transparent" - } - } - } - } - MouseArea - { - anchors.fill: favorites_header - onPressed: - { - favorites_section.expanded = !favorites_section.expanded - } - } - Column - { - anchors.top: favorites_header.bottom - anchors.left: parent.left - width: materialList.width - height: favorites_section.expanded ? childrenRect.height : 0 - visible: favorites_section.expanded - Repeater - { - model: favoriteMaterialsModel - delegate: MaterialsSlot - { - material: model - } - } - } - } +// MaterialsBrandSection +// { +// id: favoriteSection +// sectionName: "Favorites" +// elementsModel: favoriteMaterialsModel +// hasMaterialTypes: false +// expanded: true +// } MaterialsBrandSection { id: genericSection sectionName: "Generic" - elements: genericMaterialsModel + elementsModel: genericMaterialsModel hasMaterialTypes: false } - Repeater - { - id: brand_list - model: materialsModel - delegate: MaterialsBrandSection - { - id: brandSection - sectionName: model.name - elements: model.material_types - hasMaterialTypes: true - } - } +// +// Repeater +// { +// id: brand_list +// model: materialsModel +// delegate: MaterialsBrandSection +// { +// id: brandSection +// sectionName: model.name +// elementsModel: model.material_types +// hasMaterialTypes: true +// } +// } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index 42ca338cf0..bbdf2d84da 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -14,8 +14,8 @@ Rectangle { id: material_type_section property var materialType - property var expanded: materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1 - property var colors_model: model.colors + property var expanded: materialList.expandedTypes.indexOf(materialType.brand + "_" + materialType.name) > -1 + property var colorsModel: materialType.colors height: childrenRect.height width: parent.width Rectangle @@ -23,7 +23,7 @@ Rectangle id: material_type_header_background color: { - if(!expanded && model.brand + "_" + model.name == materialList.currentType) + if(!expanded && materialType.brand + "_" + materialType.name == materialList.currentType) { return UM.Theme.getColor("favorites_row_selected") } @@ -55,7 +55,7 @@ Rectangle } Label { - text: model.name + text: materialType.name height: UM.Theme.getSize("favorites_row").height width: parent.width - UM.Theme.getSize("favorites_button").width id: material_type_name @@ -94,7 +94,7 @@ Rectangle anchors.fill: material_type_header onPressed: { - const identifier = model.brand + "_" + model.name; + const identifier = materialType.brand + "_" + materialType.name; const i = materialList.expandedTypes.indexOf(identifier) if (i > -1) { @@ -120,7 +120,7 @@ Rectangle anchors.left: parent.left Repeater { - model: colors_model + model: colorsModel delegate: MaterialsSlot { material: model @@ -133,7 +133,7 @@ Rectangle target: UM.Preferences onPreferenceChanged: { - expanded = materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1 + expanded = materialList.expandedTypes.indexOf(materialType.brand + "_" + materialType.name) > -1 } } } \ No newline at end of file From 1064d837ed4bca4147c89a026acf6131d0962fa6 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 17 Sep 2018 11:46:15 +0200 Subject: [PATCH 17/19] Exclude bundled plugins in the old plugins list --- plugins/Toolbox/src/Toolbox.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 4c1cd94b4f..cf2ac4f5bb 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -1,12 +1,11 @@ # Copyright (c) 2018 Ultimaker B.V. # Toolbox is released under the terms of the LGPLv3 or higher. -from typing import Dict, Optional, Union, Any, cast import json import os import tempfile import platform -from typing import cast, List, TYPE_CHECKING, Tuple, Optional +from typing import cast, Any, Dict, List, Set, TYPE_CHECKING, Tuple, Optional from PyQt5.QtCore import QUrl, QObject, pyqtProperty, pyqtSignal, pyqtSlot from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply @@ -64,7 +63,8 @@ class Toolbox(QObject, Extension): ] self._request_urls = {} # type: Dict[str, QUrl] self._to_update = [] # type: List[str] # Package_ids that are waiting to be updated - self._old_plugin_ids = [] # type: List[str] + self._old_plugin_ids = set() # type: Set[str] + self._old_plugin_metadata = dict() # type: Dict[str, Dict[str, Any]] # Data: self._metadata = { @@ -289,8 +289,8 @@ class Toolbox(QObject, Extension): installed_package_ids = self._package_manager.getAllInstalledPackageIDs() scheduled_to_remove_package_ids = self._package_manager.getToRemovePackageIDs() - self._old_plugin_ids = [] - self._old_plugin_metadata = [] # type: List[Dict[str, Any]] + self._old_plugin_ids = set() + self._old_plugin_metadata = dict() for plugin_id in old_plugin_ids: # Neither the installed packages nor the packages that are scheduled to remove are old plugins @@ -300,12 +300,20 @@ class Toolbox(QObject, Extension): old_metadata = self._plugin_registry.getMetaData(plugin_id) new_metadata = self._convertPluginMetadata(old_metadata) - self._old_plugin_ids.append(plugin_id) - self._old_plugin_metadata.append(new_metadata) + self._old_plugin_ids.add(plugin_id) + self._old_plugin_metadata[new_metadata["package_id"]] = new_metadata all_packages = self._package_manager.getAllInstalledPackagesInfo() if "plugin" in all_packages: - self._metadata["plugins_installed"] = all_packages["plugin"] + self._old_plugin_metadata + # For old plugins, we only want to include the old custom plugin that were installed via the old toolbox. + # The bundled plugins will be included in the "bundled_packages.json", so the bundled plugins should be + # excluded from the old plugins list/dict. + all_plugin_package_ids = set(package["package_id"] for package in all_packages["plugin"]) + self._old_plugin_ids = set(plugin_id for plugin_id in self._old_plugin_ids + if plugin_id not in all_plugin_package_ids) + self._old_plugin_metadata = {k: v for k, v in self._old_plugin_metadata.items() if k in self._old_plugin_ids} + + self._metadata["plugins_installed"] = all_packages["plugin"] + list(self._old_plugin_metadata.values()) self._models["plugins_installed"].setMetadata(self._metadata["plugins_installed"]) self.metadataChanged.emit() if "material" in all_packages: From 3ac5a316d3f4dd339a29edf4f27321bde4dd6ca7 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 17 Sep 2018 12:03:10 +0200 Subject: [PATCH 18/19] Check package upgradable using PM first, old plugins later CURA-5718 For package upgradable, we need to check if a package is installed local. For that, we first check in the package manager, if nothing, then we fall back to check the old plugins. --- plugins/Toolbox/src/Toolbox.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index cf2ac4f5bb..4a1203c412 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -483,12 +483,14 @@ class Toolbox(QObject, Extension): # -------------------------------------------------------------------------- @pyqtSlot(str, result = bool) def canUpdate(self, package_id: str) -> bool: - if self.isOldPlugin(package_id): - return True - local_package = self._package_manager.getInstalledPackageInfo(package_id) if local_package is None: - return False + Logger.log("i", "Could not find package [%s] as installed in the package manager, fall back to check the old plugins", + package_id) + local_package = self.getOldPluginPackageMetadata(package_id) + if local_package is None: + Logger.log("i", "Could not find package [%s] in the old plugins", package_id) + return False remote_package = self.getRemotePackage(package_id) if remote_package is None: @@ -556,12 +558,14 @@ class Toolbox(QObject, Extension): return False # Check for plugins that were installed with the old plugin browser - @pyqtSlot(str, result = bool) def isOldPlugin(self, plugin_id: str) -> bool: if plugin_id in self._old_plugin_ids: return True return False + def getOldPluginPackageMetadata(self, plugin_id: str) -> Optional[Dict[str, Any]]: + return self._old_plugin_metadata.get(plugin_id) + def loadingComplete(self) -> bool: populated = 0 for list in self._metadata.items(): From bafc2b98c9ed1bb913bc387abe81670f54d15f8b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Mon, 17 Sep 2018 12:08:41 +0200 Subject: [PATCH 19/19] Reuse MaterialBrandSection component for Favorites, Generic and branded materials. This component will show different children depending on the hasMaterialTypes flag. Adjust some small UI issues. Contributes to CURA-5682. --- .../Materials/MaterialsBrandSection.qml | 25 +--- .../Materials/MaterialsDetailsPanel.qml | 7 +- .../Preferences/Materials/MaterialsList.qml | 121 +++--------------- .../Preferences/Materials/MaterialsPage.qml | 5 +- .../Preferences/Materials/MaterialsSlot.qml | 42 +++--- .../Materials/MaterialsTypeSection.qml | 9 +- 6 files changed, 61 insertions(+), 148 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml index ef3a773835..c8f391dfb0 100644 --- a/resources/qml/Preferences/Materials/MaterialsBrandSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsBrandSection.qml @@ -48,7 +48,7 @@ Rectangle height: UM.Theme.getSize("favorites_row").height width: parent.width - UM.Theme.getSize("favorites_button").width verticalAlignment: Text.AlignVCenter - leftPadding: 4 + leftPadding: (UM.Theme.getSize("default_margin").width / 2) | 0 } Button { @@ -101,6 +101,7 @@ Rectangle } Column { + id: brandMaterialList anchors.top: brand_header.bottom width: parent.width anchors.left: parent.left @@ -110,26 +111,14 @@ Rectangle Repeater { model: elementsModel - delegate: Item + delegate: Loader { - Loader - { - id: loader - property var element: model - sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot - } + id: loader + width: parent.width + property var element: model + sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot } } - // In case there are no types, we create a material slot -// Repeater -// { -// model: elementsModel -// delegate: MaterialsSlot -// { -// visible: !hasMaterialTypes -// material: model -// } -// } } Component diff --git a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml index 43e98d63a6..f72d93aff3 100644 --- a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml +++ b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml @@ -18,8 +18,11 @@ Item onCurrentItemChanged: { // When the current item changes, the detail view needs to be updated - updateMaterialPropertiesObject() - materialDetailsView.currentMaterialNode = currentItem.container_node + if (currentItem != null) + { + updateMaterialPropertiesObject() + materialDetailsView.currentMaterialNode = currentItem.container_node + } } function updateMaterialPropertiesObject() diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 9b8903d7da..cb5de685e2 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -13,7 +13,6 @@ import Cura 1.0 as Cura Item { id: materialList - width: materialScrollView.width - 17 height: childrenRect.height // Children @@ -121,93 +120,16 @@ Item Column { -// Rectangle -// { -// property var expanded: true -// -// id: favorites_section -// height: childrenRect.height -// width: materialList.width -// Rectangle -// { -// id: favorites_header_background -// color: UM.Theme.getColor("favorites_header_bar") -// anchors.fill: favorites_header -// } -// Row -// { -// id: favorites_header -// Label -// { -// id: favorites_name -// text: "Favorites" -// height: UM.Theme.getSize("favorites_row").height -// width: materialList.width - UM.Theme.getSize("favorites_button").width -// verticalAlignment: Text.AlignVCenter -// leftPadding: 4 -// } -// Button -// { -// text: "" -// implicitWidth: UM.Theme.getSize("favorites_button").width -// implicitHeight: UM.Theme.getSize("favorites_button").height -// UM.RecolorImage { -// anchors -// { -// verticalCenter: parent.verticalCenter -// horizontalCenter: parent.horizontalCenter -// } -// width: UM.Theme.getSize("standard_arrow").width -// height: UM.Theme.getSize("standard_arrow").height -// sourceSize.width: width -// sourceSize.height: height -// color: "black" -// source: favorites_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left") -// } -// style: ButtonStyle -// { -// background: Rectangle -// { -// anchors.fill: parent -// color: "transparent" -// } -// } -// } -// } -// MouseArea -// { -// anchors.fill: favorites_header -// onPressed: -// { -// favorites_section.expanded = !favorites_section.expanded -// } -// } -// Column -// { -// anchors.top: favorites_header.bottom -// anchors.left: parent.left -// width: materialList.width -// height: favorites_section.expanded ? childrenRect.height : 0 -// visible: favorites_section.expanded -// Repeater -// { -// model: favoriteMaterialsModel -// delegate: MaterialsSlot -// { -// material: model -// } -// } -// } -// } + width: materialList.width + height: childrenRect.height -// MaterialsBrandSection -// { -// id: favoriteSection -// sectionName: "Favorites" -// elementsModel: favoriteMaterialsModel -// hasMaterialTypes: false -// expanded: true -// } + MaterialsBrandSection + { + id: favoriteSection + sectionName: "Favorites" + elementsModel: favoriteMaterialsModel + hasMaterialTypes: false + } MaterialsBrandSection { @@ -216,18 +138,17 @@ Item elementsModel: genericMaterialsModel hasMaterialTypes: false } -// -// Repeater -// { -// id: brand_list -// model: materialsModel -// delegate: MaterialsBrandSection -// { -// id: brandSection -// sectionName: model.name -// elementsModel: model.material_types -// hasMaterialTypes: true -// } -// } + + Repeater + { + model: materialsModel + delegate: MaterialsBrandSection + { + id: brandSection + sectionName: model.name + elementsModel: model.material_types + hasMaterialTypes: true + } + } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 7a7a2b885f..2050f59739 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -225,13 +225,14 @@ Item color: palette.light } - width: true ? (parent.width * 0.4) | 0 : parent.width + width: (parent.width * 0.4) | 0 frameVisible: true - verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff MaterialsList { id: materialListView + width: materialScrollView.viewport.width } } diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index 63d40068ce..a474b52838 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -12,34 +12,34 @@ import Cura 1.0 as Cura Rectangle { - id: material_slot - property var material + id: materialSlot + property var material: null property var hovered: false - property var is_favorite: material.is_favorite + property var is_favorite: material != null ? material.is_favorite : false height: UM.Theme.getSize("favorites_row").height width: parent.width - color: base.currentItem.root_material_id == material.root_material_id ? UM.Theme.getColor("favorites_row_selected") : "transparent" + color: material != null ? (base.currentItem.root_material_id == material.root_material_id ? UM.Theme.getColor("favorites_row_selected") : "transparent") : "transparent" Rectangle { id: swatch - color: material.color_code + color: material != null ? material.color_code : "transparent" border.width: UM.Theme.getSize("default_lining").width border.color: "black" width: UM.Theme.getSize("favorites_button_icon").width height: UM.Theme.getSize("favorites_button_icon").height - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left + anchors.verticalCenter: materialSlot.verticalCenter + anchors.left: materialSlot.left anchors.leftMargin: UM.Theme.getSize("default_margin").width } Label { - text: material.brand + " " + material.name + text: material != null ? material.brand + " " + material.name : "" verticalAlignment: Text.AlignVCenter height: parent.height anchors.left: swatch.right - anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenter: materialSlot.verticalCenter anchors.leftMargin: UM.Theme.getSize("narrow_margin").width } MouseArea @@ -52,8 +52,8 @@ Rectangle base.currentItem = material } hoverEnabled: true - onEntered: { material_slot.hovered = true } - onExited: { material_slot.hovered = false } + onEntered: { materialSlot.hovered = true } + onExited: { materialSlot.hovered = false } } Button { @@ -61,21 +61,21 @@ Rectangle text: "" implicitWidth: UM.Theme.getSize("favorites_button").width implicitHeight: UM.Theme.getSize("favorites_button").height - visible: material_slot.hovered || material_slot.is_favorite || favorite_button.hovered + visible: materialSlot.hovered || materialSlot.is_favorite || favorite_button.hovered anchors { - right: parent.right - verticalCenter: parent.verticalCenter + right: materialSlot.right + verticalCenter: materialSlot.verticalCenter } onClicked: { - if (material_slot.is_favorite) { + if (materialSlot.is_favorite) { base.materialManager.removeFavorite(material.root_material_id) - material_slot.is_favorite = false + materialSlot.is_favorite = false return } base.materialManager.addFavorite(material.root_material_id) - material_slot.is_favorite = true + materialSlot.is_favorite = true return } style: ButtonStyle @@ -89,8 +89,8 @@ Rectangle UM.RecolorImage { anchors { - verticalCenter: parent.verticalCenter - horizontalCenter: parent.horizontalCenter + verticalCenter: favorite_button.verticalCenter + horizontalCenter: favorite_button.horizontalCenter } width: UM.Theme.getSize("favorites_button_icon").width height: UM.Theme.getSize("favorites_button_icon").height @@ -104,7 +104,7 @@ Rectangle } else { - if (material_slot.is_favorite) + if (materialSlot.is_favorite) { return UM.Theme.getColor("primary") } @@ -114,7 +114,7 @@ Rectangle } } } - source: material_slot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty") + source: materialSlot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty") } } } \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml index bbdf2d84da..f62fc4ee16 100644 --- a/resources/qml/Preferences/Materials/MaterialsTypeSection.qml +++ b/resources/qml/Preferences/Materials/MaterialsTypeSection.qml @@ -38,7 +38,7 @@ Rectangle Rectangle { id: material_type_header_border - color: UM.Theme.getColor("lining") + color: UM.Theme.getColor("favorites_header_bar") anchors.bottom: material_type_header.bottom anchors.left: material_type_header.left height: UM.Theme.getSize("default_lining").height @@ -47,17 +47,17 @@ Rectangle Row { id: material_type_header - width: parent.width - 8 + width: parent.width + leftPadding: UM.Theme.getSize("default_margin").width anchors { left: parent.left - leftMargin: 8 } Label { text: materialType.name height: UM.Theme.getSize("favorites_row").height - width: parent.width - UM.Theme.getSize("favorites_button").width + width: parent.width - parent.leftPadding - UM.Theme.getSize("favorites_button").width id: material_type_name verticalAlignment: Text.AlignVCenter } @@ -117,7 +117,6 @@ Rectangle visible: material_type_section.expanded width: parent.width anchors.top: material_type_header.bottom - anchors.left: parent.left Repeater { model: colorsModel