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.
This commit is contained in:
Diego Prado Gesto 2018-09-17 12:08:41 +02:00
parent f871a89825
commit bafc2b98c9
6 changed files with 61 additions and 148 deletions

View file

@ -48,7 +48,7 @@ Rectangle
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
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
leftPadding: 4 leftPadding: (UM.Theme.getSize("default_margin").width / 2) | 0
} }
Button Button
{ {
@ -101,6 +101,7 @@ Rectangle
} }
Column Column
{ {
id: brandMaterialList
anchors.top: brand_header.bottom anchors.top: brand_header.bottom
width: parent.width width: parent.width
anchors.left: parent.left anchors.left: parent.left
@ -110,26 +111,14 @@ Rectangle
Repeater Repeater
{ {
model: elementsModel model: elementsModel
delegate: Item delegate: Loader
{ {
Loader id: loader
{ width: parent.width
id: loader property var element: model
property var element: model sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
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 Component

View file

@ -18,8 +18,11 @@ Item
onCurrentItemChanged: onCurrentItemChanged:
{ {
// When the current item changes, the detail view needs to be updated // When the current item changes, the detail view needs to be updated
updateMaterialPropertiesObject() if (currentItem != null)
materialDetailsView.currentMaterialNode = currentItem.container_node {
updateMaterialPropertiesObject()
materialDetailsView.currentMaterialNode = currentItem.container_node
}
} }
function updateMaterialPropertiesObject() function updateMaterialPropertiesObject()

View file

@ -13,7 +13,6 @@ import Cura 1.0 as Cura
Item Item
{ {
id: materialList id: materialList
width: materialScrollView.width - 17
height: childrenRect.height height: childrenRect.height
// Children // Children
@ -121,93 +120,16 @@ Item
Column Column
{ {
// Rectangle width: materialList.width
// { height: childrenRect.height
// 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
// }
// }
// }
// }
// MaterialsBrandSection MaterialsBrandSection
// { {
// id: favoriteSection id: favoriteSection
// sectionName: "Favorites" sectionName: "Favorites"
// elementsModel: favoriteMaterialsModel elementsModel: favoriteMaterialsModel
// hasMaterialTypes: false hasMaterialTypes: false
// expanded: true }
// }
MaterialsBrandSection MaterialsBrandSection
{ {
@ -216,18 +138,17 @@ Item
elementsModel: genericMaterialsModel elementsModel: genericMaterialsModel
hasMaterialTypes: false hasMaterialTypes: false
} }
//
// Repeater Repeater
// { {
// id: brand_list model: materialsModel
// model: materialsModel delegate: MaterialsBrandSection
// delegate: MaterialsBrandSection {
// { id: brandSection
// id: brandSection sectionName: model.name
// sectionName: model.name elementsModel: model.material_types
// elementsModel: model.material_types hasMaterialTypes: true
// hasMaterialTypes: true }
// } }
// }
} }
} }

View file

@ -225,13 +225,14 @@ Item
color: palette.light color: palette.light
} }
width: true ? (parent.width * 0.4) | 0 : parent.width width: (parent.width * 0.4) | 0
frameVisible: true frameVisible: true
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
MaterialsList MaterialsList
{ {
id: materialListView id: materialListView
width: materialScrollView.viewport.width
} }
} }

View file

@ -12,34 +12,34 @@ import Cura 1.0 as Cura
Rectangle Rectangle
{ {
id: material_slot id: materialSlot
property var material property var material: null
property var hovered: false 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 height: UM.Theme.getSize("favorites_row").height
width: parent.width 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 Rectangle
{ {
id: swatch id: swatch
color: material.color_code color: material != null ? material.color_code : "transparent"
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
border.color: "black" border.color: "black"
width: UM.Theme.getSize("favorites_button_icon").width width: UM.Theme.getSize("favorites_button_icon").width
height: UM.Theme.getSize("favorites_button_icon").height height: UM.Theme.getSize("favorites_button_icon").height
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: materialSlot.verticalCenter
anchors.left: parent.left anchors.left: materialSlot.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
} }
Label Label
{ {
text: material.brand + " " + material.name text: material != null ? material.brand + " " + material.name : ""
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
height: parent.height height: parent.height
anchors.left: swatch.right anchors.left: swatch.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: materialSlot.verticalCenter
anchors.leftMargin: UM.Theme.getSize("narrow_margin").width anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
} }
MouseArea MouseArea
@ -52,8 +52,8 @@ Rectangle
base.currentItem = material base.currentItem = material
} }
hoverEnabled: true hoverEnabled: true
onEntered: { material_slot.hovered = true } onEntered: { materialSlot.hovered = true }
onExited: { material_slot.hovered = false } onExited: { materialSlot.hovered = false }
} }
Button Button
{ {
@ -61,21 +61,21 @@ Rectangle
text: "" text: ""
implicitWidth: UM.Theme.getSize("favorites_button").width implicitWidth: UM.Theme.getSize("favorites_button").width
implicitHeight: UM.Theme.getSize("favorites_button").height 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 anchors
{ {
right: parent.right right: materialSlot.right
verticalCenter: parent.verticalCenter verticalCenter: materialSlot.verticalCenter
} }
onClicked: onClicked:
{ {
if (material_slot.is_favorite) { if (materialSlot.is_favorite) {
base.materialManager.removeFavorite(material.root_material_id) base.materialManager.removeFavorite(material.root_material_id)
material_slot.is_favorite = false materialSlot.is_favorite = false
return return
} }
base.materialManager.addFavorite(material.root_material_id) base.materialManager.addFavorite(material.root_material_id)
material_slot.is_favorite = true materialSlot.is_favorite = true
return return
} }
style: ButtonStyle style: ButtonStyle
@ -89,8 +89,8 @@ Rectangle
UM.RecolorImage { UM.RecolorImage {
anchors anchors
{ {
verticalCenter: parent.verticalCenter verticalCenter: favorite_button.verticalCenter
horizontalCenter: parent.horizontalCenter horizontalCenter: favorite_button.horizontalCenter
} }
width: UM.Theme.getSize("favorites_button_icon").width width: UM.Theme.getSize("favorites_button_icon").width
height: UM.Theme.getSize("favorites_button_icon").height height: UM.Theme.getSize("favorites_button_icon").height
@ -104,7 +104,7 @@ Rectangle
} }
else else
{ {
if (material_slot.is_favorite) if (materialSlot.is_favorite)
{ {
return UM.Theme.getColor("primary") 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")
} }
} }
} }

View file

@ -38,7 +38,7 @@ Rectangle
Rectangle Rectangle
{ {
id: material_type_header_border id: material_type_header_border
color: UM.Theme.getColor("lining") color: UM.Theme.getColor("favorites_header_bar")
anchors.bottom: material_type_header.bottom anchors.bottom: material_type_header.bottom
anchors.left: material_type_header.left anchors.left: material_type_header.left
height: UM.Theme.getSize("default_lining").height height: UM.Theme.getSize("default_lining").height
@ -47,17 +47,17 @@ Rectangle
Row Row
{ {
id: material_type_header id: material_type_header
width: parent.width - 8 width: parent.width
leftPadding: UM.Theme.getSize("default_margin").width
anchors anchors
{ {
left: parent.left left: parent.left
leftMargin: 8
} }
Label Label
{ {
text: materialType.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 - parent.leftPadding - UM.Theme.getSize("favorites_button").width
id: material_type_name id: material_type_name
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
@ -117,7 +117,6 @@ Rectangle
visible: material_type_section.expanded visible: material_type_section.expanded
width: parent.width width: parent.width
anchors.top: material_type_header.bottom anchors.top: material_type_header.bottom
anchors.left: parent.left
Repeater Repeater
{ {
model: colorsModel model: colorsModel