mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-13 07:29:03 +08:00
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.
This commit is contained in:
parent
972f0bef43
commit
f871a89825
@ -15,7 +15,7 @@ Rectangle
|
|||||||
id: brand_section
|
id: brand_section
|
||||||
|
|
||||||
property var sectionName: ""
|
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 hasMaterialTypes: true // It indicates wheather it has material types or not
|
||||||
property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1
|
property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1
|
||||||
|
|
||||||
@ -109,22 +109,44 @@ Rectangle
|
|||||||
|
|
||||||
Repeater
|
Repeater
|
||||||
{
|
{
|
||||||
model: elements
|
model: elementsModel
|
||||||
delegate: MaterialsTypeSection
|
delegate: Item
|
||||||
{
|
{
|
||||||
visible: hasMaterialTypes
|
Loader
|
||||||
materialType: model
|
{
|
||||||
|
id: loader
|
||||||
|
property var element: model
|
||||||
|
sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// In case there are no types, we create a material slot
|
// In case there are no types, we create a material slot
|
||||||
Repeater
|
// Repeater
|
||||||
{
|
// {
|
||||||
model: elements
|
// model: elementsModel
|
||||||
delegate: MaterialsSlot
|
// delegate: MaterialsSlot
|
||||||
{
|
// {
|
||||||
visible: !hasMaterialTypes
|
// visible: !hasMaterialTypes
|
||||||
material: model
|
// material: model
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component
|
||||||
|
{
|
||||||
|
id: materialsTypeSection
|
||||||
|
MaterialsTypeSection
|
||||||
|
{
|
||||||
|
materialType: element
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component
|
||||||
|
{
|
||||||
|
id: materialSlot
|
||||||
|
MaterialsSlot
|
||||||
|
{
|
||||||
|
material: element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +92,7 @@ Item
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
function updateAfterModelChanges()
|
||||||
{
|
|
||||||
target: materialsModel
|
|
||||||
onItemsChanged:
|
|
||||||
{
|
{
|
||||||
var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo)
|
var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo)
|
||||||
if (correctlyExpanded)
|
if (correctlyExpanded)
|
||||||
@ -109,126 +106,128 @@ Item
|
|||||||
base.toActivateNewMaterial = false
|
base.toActivateNewMaterial = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections
|
||||||
|
{
|
||||||
|
target: materialsModel
|
||||||
|
onItemsChanged: updateAfterModelChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: genericMaterialsModel
|
target: genericMaterialsModel
|
||||||
onItemsChanged:
|
onItemsChanged: 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column
|
Column
|
||||||
{
|
{
|
||||||
Rectangle
|
// Rectangle
|
||||||
{
|
// {
|
||||||
property var expanded: true
|
// 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
|
// MaterialsBrandSection
|
||||||
height: childrenRect.height
|
// {
|
||||||
width: materialList.width
|
// id: favoriteSection
|
||||||
Rectangle
|
// sectionName: "Favorites"
|
||||||
{
|
// elementsModel: favoriteMaterialsModel
|
||||||
id: favorites_header_background
|
// hasMaterialTypes: false
|
||||||
color: UM.Theme.getColor("favorites_header_bar")
|
// expanded: true
|
||||||
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
|
MaterialsBrandSection
|
||||||
{
|
{
|
||||||
id: genericSection
|
id: genericSection
|
||||||
sectionName: "Generic"
|
sectionName: "Generic"
|
||||||
elements: genericMaterialsModel
|
elementsModel: genericMaterialsModel
|
||||||
hasMaterialTypes: false
|
hasMaterialTypes: false
|
||||||
}
|
}
|
||||||
Repeater
|
//
|
||||||
{
|
// Repeater
|
||||||
id: brand_list
|
// {
|
||||||
model: materialsModel
|
// id: brand_list
|
||||||
delegate: MaterialsBrandSection
|
// model: materialsModel
|
||||||
{
|
// delegate: MaterialsBrandSection
|
||||||
id: brandSection
|
// {
|
||||||
sectionName: model.name
|
// id: brandSection
|
||||||
elements: model.material_types
|
// sectionName: model.name
|
||||||
hasMaterialTypes: true
|
// elementsModel: model.material_types
|
||||||
}
|
// hasMaterialTypes: true
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,8 +14,8 @@ Rectangle
|
|||||||
{
|
{
|
||||||
id: material_type_section
|
id: material_type_section
|
||||||
property var materialType
|
property var materialType
|
||||||
property var expanded: materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1
|
property var expanded: materialList.expandedTypes.indexOf(materialType.brand + "_" + materialType.name) > -1
|
||||||
property var colors_model: model.colors
|
property var colorsModel: materialType.colors
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
Rectangle
|
Rectangle
|
||||||
@ -23,7 +23,7 @@ Rectangle
|
|||||||
id: material_type_header_background
|
id: material_type_header_background
|
||||||
color:
|
color:
|
||||||
{
|
{
|
||||||
if(!expanded && model.brand + "_" + model.name == materialList.currentType)
|
if(!expanded && materialType.brand + "_" + materialType.name == materialList.currentType)
|
||||||
{
|
{
|
||||||
return UM.Theme.getColor("favorites_row_selected")
|
return UM.Theme.getColor("favorites_row_selected")
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ Rectangle
|
|||||||
}
|
}
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
text: model.name
|
text: materialType.name
|
||||||
height: UM.Theme.getSize("favorites_row").height
|
height: UM.Theme.getSize("favorites_row").height
|
||||||
width: parent.width - UM.Theme.getSize("favorites_button").width
|
width: parent.width - UM.Theme.getSize("favorites_button").width
|
||||||
id: material_type_name
|
id: material_type_name
|
||||||
@ -94,7 +94,7 @@ Rectangle
|
|||||||
anchors.fill: material_type_header
|
anchors.fill: material_type_header
|
||||||
onPressed:
|
onPressed:
|
||||||
{
|
{
|
||||||
const identifier = model.brand + "_" + model.name;
|
const identifier = materialType.brand + "_" + materialType.name;
|
||||||
const i = materialList.expandedTypes.indexOf(identifier)
|
const i = materialList.expandedTypes.indexOf(identifier)
|
||||||
if (i > -1)
|
if (i > -1)
|
||||||
{
|
{
|
||||||
@ -120,7 +120,7 @@ Rectangle
|
|||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
Repeater
|
Repeater
|
||||||
{
|
{
|
||||||
model: colors_model
|
model: colorsModel
|
||||||
delegate: MaterialsSlot
|
delegate: MaterialsSlot
|
||||||
{
|
{
|
||||||
material: model
|
material: model
|
||||||
@ -133,7 +133,7 @@ Rectangle
|
|||||||
target: UM.Preferences
|
target: UM.Preferences
|
||||||
onPreferenceChanged:
|
onPreferenceChanged:
|
||||||
{
|
{
|
||||||
expanded = materialList.expandedTypes.indexOf(model.brand + "_" + model.name) > -1
|
expanded = materialList.expandedTypes.indexOf(materialType.brand + "_" + materialType.name) > -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user