Clean up code for the toolbox tab button

Removed unused properies and made it use states for it's changing properties.
This makes it a lot easier to read and understand what it's actually doing

CURA-6151
This commit is contained in:
Jaime van Kessel 2019-03-28 13:24:25 +01:00
parent 56f3226ac1
commit 6c26dd38ec

View File

@ -9,14 +9,17 @@ Button
{ {
id: control id: control
property bool active: false property bool active: false
hoverEnabled: true
implicitWidth: UM.Theme.getSize("toolbox_header_tab").width
implicitHeight: UM.Theme.getSize("toolbox_header_tab").height
background: Item background: Item
{ {
implicitWidth: UM.Theme.getSize("toolbox_header_tab").width id: backgroundItem
implicitHeight: UM.Theme.getSize("toolbox_header_tab").height
Rectangle Rectangle
{ {
id: highlight
visible: control.active visible: control.active
color: UM.Theme.getColor("primary") color: UM.Theme.getColor("primary")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -24,28 +27,42 @@ Button
height: UM.Theme.getSize("toolbox_header_highlight").height height: UM.Theme.getSize("toolbox_header_highlight").height
} }
} }
contentItem: Label contentItem: Label
{ {
id: label id: label
text: control.text text: control.text
color: color: UM.Theme.getColor("toolbox_header_button_text_inactive")
{ font: UM.Theme.getFont("medium")
if(control.hovered)
{
return UM.Theme.getColor("toolbox_header_button_text_hovered");
}
if(control.active)
{
return UM.Theme.getColor("toolbox_header_button_text_active");
}
else
{
return UM.Theme.getColor("toolbox_header_button_text_inactive");
}
}
font: control.enabled ? (control.active ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")) : UM.Theme.getFont("default_italic")
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
states:
[
State
{
name: "disabled"
when: !control.enabled
PropertyChanges
{
target: label
font: UM.Theme.getFont("default_italic")
}
},
State
{
name: "active"
when: control.active
PropertyChanges
{
target: label
font: UM.Theme.getFont("medium_bold")
color: UM.Theme.getColor("toolbox_header_button_text_active")
}
}
]
} }