Update materials slot

CURA-8979
This commit is contained in:
casper 2022-03-11 13:22:45 +01:00
parent 2dd440cc0c
commit c6b8abd53e

View File

@ -13,23 +13,31 @@ import Cura 1.5 as Cura
Rectangle Rectangle
{ {
id: materialSlot id: materialSlot
property var material: null property var material: null
property var hovered: false property bool hovered: false
property var is_favorite: material != null && material.is_favorite
height: UM.Theme.getSize("favorites_row").height height: UM.Theme.getSize("favorites_row").height
width: parent.width width: parent.width
color: color: UM.Theme.getColor("main_background")
{
if (material !== null && base.currentItem !== null) states:
[
State
{ {
if (base.currentItem.root_material_id === material.root_material_id) name: "selected"
{ when: material !== null && base.currentItem !== null && base.currentItem.root_material_id === material.root_material_id
return UM.Theme.getColor("favorites_row_selected"); PropertyChanges { target: materialSlot; color: UM.Theme.getColor("background_3") }
} PropertyChanges { target: materialLabel; font: UM.Theme.getFont("default_italic") }
},
State
{
name: "hovered"
when: hovered
PropertyChanges { target: materialSlot; color: UM.Theme.getColor("background_3") }
} }
return "transparent"; ]
}
Rectangle Rectangle
{ {
id: swatch id: swatch
@ -43,79 +51,82 @@ Rectangle
} }
UM.Label UM.Label
{ {
text: material != null ? material.brand + " " + material.name : "" id: materialLabel
text: material != null ? `${material.brand} ${material.name}` : ""
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
height: parent.height
anchors.left: swatch.right anchors.left: swatch.right
anchors.verticalCenter: materialSlot.verticalCenter anchors.verticalCenter: materialSlot.verticalCenter
anchors.leftMargin: UM.Theme.getSize("narrow_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
font.italic: material != null && Cura.MachineManager.currentRootMaterialId[Cura.ExtruderManager.activeExtruderIndex] == material.root_material_id font: UM.Theme.getFont("default")
} }
MouseArea MouseArea
{ {
anchors.fill: parent anchors.fill: parent
onClicked: onClicked:
{ {
materialList.currentBrand = material.brand materialList.currentBrand = material.brand;
materialList.currentType = material.brand + "_" + material.material materialList.currentType = `${material.brand}_${material.material}`;
base.setExpandedActiveMaterial(material.root_material_id) base.setExpandedActiveMaterial(material.root_material_id);
} }
hoverEnabled: true hoverEnabled: true
onEntered: { materialSlot.hovered = true } onEntered: { materialSlot.hovered = true }
onExited: { materialSlot.hovered = false } onExited: { materialSlot.hovered = false }
} }
Button
Item
{ {
id: favorite_button id: favoriteButton
text: ""
implicitWidth: UM.Theme.getSize("favorites_button").width states:
implicitHeight: UM.Theme.getSize("favorites_button").height [
visible: materialSlot.hovered || materialSlot.is_favorite || favorite_button.hovered State
anchors
{
right: materialSlot.right
verticalCenter: materialSlot.verticalCenter
}
onClicked:
{
if (materialSlot.is_favorite)
{ {
CuraApplication.getMaterialManagementModel().removeFavorite(material.root_material_id) name: "favorite"
} when: material !== null && material.is_favorite
else PropertyChanges { target: favoriteIndicator; source: UM.Theme.getIcon("StarFilled"); color: UM.Theme.getColor("primary") }
PropertyChanges { target: favoriteButton; visible: true }
},
State
{ {
CuraApplication.getMaterialManagementModel().addFavorite(material.root_material_id) name: "hovered"
when: hovered
PropertyChanges { target: favoriteButton; visible: true }
} }
} ]
implicitHeight: parent.height
implicitWidth: height
anchors.right: materialSlot.right
visible: false
UM.RecolorImage UM.RecolorImage
{ {
anchors id: favoriteIndicator
anchors.centerIn: parent
width: UM.Theme.getSize("small_button_icon").width
height: UM.Theme.getSize("small_button_icon").height
color: UM.Theme.getColor("text_inactive")
source: UM.Theme.getIcon("Star")
}
MouseArea
{
anchors.fill: parent
onClicked:
{ {
verticalCenter: favorite_button.verticalCenter if (material !== null)
horizontalCenter: favorite_button.horizontalCenter
}
width: UM.Theme.getSize("favorites_button_icon").width
height: UM.Theme.getSize("favorites_button_icon").height
color:
{
if (favorite_button.hovered)
{ {
return UM.Theme.getColor("primary_hover") if (material.is_favorite)
}
else
{
if (materialSlot.is_favorite)
{ {
return UM.Theme.getColor("primary") CuraApplication.getMaterialManagementModel().removeFavorite(material.root_material_id)
} }
else else
{ {
UM.Theme.getColor("text_inactive") CuraApplication.getMaterialManagementModel().addFavorite(material.root_material_id)
} }
} }
} }
source: materialSlot.is_favorite ? UM.Theme.getIcon("StarFilled") : UM.Theme.getIcon("Star")
} }
} }
} }