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