Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Prado Gesto <d.pradogesto@ultimaker.com>2018-09-14 15:46:33 +0300
committerDiego Prado Gesto <d.pradogesto@ultimaker.com>2018-09-17 10:09:14 +0300
commitf871a898255dc6614966096d538220a59fafdff8 (patch)
tree2e79f538ccf897e1a39d5e82eee3b97ed4d140e4 /resources
parent972f0bef438dec38bede2e9a93cde6eafdce230f (diff)
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.
Diffstat (limited to 'resources')
-rw-r--r--resources/qml/Preferences/Materials/MaterialsBrandSection.qml46
-rw-r--r--resources/qml/Preferences/Materials/MaterialsList.qml231
-rw-r--r--resources/qml/Preferences/Materials/MaterialsTypeSection.qml14
3 files changed, 156 insertions, 135 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
}
- Connections
+ function updateAfterModelChanges()
{
- target: materialsModel
- onItemsChanged:
+ var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo)
+ if (correctlyExpanded)
{
- var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo)
- if (correctlyExpanded)
+ if (base.toActivateNewMaterial)
{
- if (base.toActivateNewMaterial)
- {
- var position = Cura.ExtruderManager.activeExtruderIndex
- Cura.MachineManager.setMaterial(position, base.currentItem.container_node)
- }
- base.newRootMaterialIdToSwitchTo = ""
- base.toActivateNewMaterial = false
+ var position = Cura.ExtruderManager.activeExtruderIndex
+ Cura.MachineManager.setMaterial(position, base.currentItem.container_node)
}
+ base.newRootMaterialIdToSwitchTo = ""
+ base.toActivateNewMaterial = false
}
}
Connections
{
+ target: materialsModel
+ 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