Cura/resources/qml/Widgets/CheckBox.qml
j.delarago 171da643d5 I'm replacing all CheckBox in Cura with this CheckBox except ones that use the old "style" tag (Not in scope). This should make the design consistent everywhere and easier to update.
Moved set width and height from top level into "indicator" since this was causing the label to be cut off.

Swapped out setting_control_radius for checkbox_radius since these are different now.

Updated the UM.RecolorImage to work with tri state checkboxes so this can replace the Checkbox in SettingVisiblityPage.qml.
2022-01-21 18:06:31 +01:00

114 lines
3.5 KiB
QML

// Copyright (c) 2020 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.3 as UM
import Cura 1.1 as Cura
//
// Checkbox with Cura styling.
//
CheckBox
{
id: control
hoverEnabled: true
indicator: Rectangle
{
height: UM.Theme.getSize("checkbox").height
width: UM.Theme.getSize("checkbox").width
anchors.verticalCenter: parent.verticalCenter
color:
{
if (!control.enabled)
{
return UM.Theme.getColor("setting_control_disabled")
}
if (control.hovered || control.activeFocus)
{
return UM.Theme.getColor("setting_control_highlight")
}
return UM.Theme.getColor("setting_control")
}
radius: UM.Theme.getSize("checkbox_radius").width
border.width: UM.Theme.getSize("default_lining").width
border.color:
{
if (!enabled)
{
return UM.Theme.getColor("setting_control_disabled_border")
}
if (control.hovered || control.activeFocus)
{
return UM.Theme.getColor("setting_control_border_highlight")
}
return UM.Theme.getColor("setting_control_border")
}
UM.RecolorImage
{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
height:
{
switch(control.checkState)
{
case Qt.Checked: return UM.Theme.getSize("checkbox_mark").height
case Qt.PartiallyChecked: return UM.Theme.getSize("checkbox_square").height
default: UM.Theme.getSize("checkbox_mark").height
}
}
width: height
sourceSize.height: height
color:
{
switch(control.checkState)
{
case Qt.Checked: return !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("checkbox_mark")
case Qt.PartiallyChecked: return !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("checkbox_square")
default: return !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("checkbox_mark")
}
}
source:
{
switch (control.checkState)
{
case Qt.Checked: return UM.Theme.getIcon("EmptyCheck", "low")
case Qt.PartiallyChecked: return UM.Theme.getIcon("CheckBoxFill", "low")
default: return UM.Theme.getIcon("EmptyCheck", "low")
}
}
opacity:
{
switch (control.checkState)
{
case Qt.Checked: return 1;
case Qt.PartiallyChecked: return 1;
default: 0;
}
}
Behavior on opacity { NumberAnimation { duration: 100; } }
}
}
contentItem: Label
{
id: textLabel
anchors.left: control.indicator.right
leftPadding: UM.Theme.getSize("checkbox_label_padding").width
text: control.text
font: control.font
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
}
}