style and code improvements for combobox with color swatch

This commit is contained in:
ChrisTerBeke 2017-09-12 12:11:23 +02:00
parent 3f60bc9287
commit 073c2d3335
2 changed files with 20 additions and 45 deletions

View File

@ -331,41 +331,19 @@ Item
{ {
var current_extruder = extruderModel.get(currentIndex); var current_extruder = extruderModel.get(currentIndex);
color_override = ""; color_override = "";
if (current_extruder === undefined) { if (current_extruder === undefined) return ""
return ""; return (current_extruder.color) ? current_extruder.color : "";
}
var model_color = current_extruder.color;
return (model_color) ? model_color : "";
} }
textRole: 'text' // this solves that the combobox isn't populated in the first time Cura is started textRole: "text" // this solves that the combobox isn't populated in the first time Cura is started
anchors.top: enableSupportCheckBox.bottom anchors.top: enableSupportCheckBox.bottom
anchors.topMargin: anchors.topMargin: ((supportEnabled.properties.value === "True") && (machineExtruderCount.properties.value > 1)) ? UM.Theme.getSize("sidebar_margin").height : 0
{
if ((supportEnabled.properties.value == "True") && (machineExtruderCount.properties.value > 1))
{
return UM.Theme.getSize("sidebar_margin").height;
}
else
{
return 0;
}
}
anchors.left: infillCellRight.left anchors.left: infillCellRight.left
width: UM.Theme.getSize("sidebar").width * .55 width: UM.Theme.getSize("sidebar").width * .55
height: height: ((supportEnabled.properties.value == "True") && (machineExtruderCount.properties.value > 1)) ? UM.Theme.getSize("setting_control").height : 0
{
if ((supportEnabled.properties.value == "True") && (machineExtruderCount.properties.value > 1))
{
// default height when control is enabled
return UM.Theme.getSize("setting_control").height;
}
else
{
return 0;
}
}
Behavior on height { NumberAnimation { duration: 100 } } Behavior on height { NumberAnimation { duration: 100 } }
style: UM.Theme.styles.combobox_color style: UM.Theme.styles.combobox_color

View File

@ -610,6 +610,7 @@ QtObject {
property Component combobox: Component { property Component combobox: Component {
ComboBoxStyle { ComboBoxStyle {
background: Rectangle { background: Rectangle {
implicitHeight: Theme.getSize("setting_control").height; implicitHeight: Theme.getSize("setting_control").height;
implicitWidth: Theme.getSize("setting_control").width; implicitWidth: Theme.getSize("setting_control").width;
@ -620,6 +621,7 @@ QtObject {
border.width: Theme.getSize("default_lining").width; border.width: Theme.getSize("default_lining").width;
border.color: (control.hovered || control._hovered) ? Theme.getColor("setting_control_border_highlight") : Theme.getColor("setting_control_border"); border.color: (control.hovered || control._hovered) ? Theme.getColor("setting_control_border_highlight") : Theme.getColor("setting_control_border");
} }
label: Item { label: Item {
Label { Label {
anchors.left: parent.left; anchors.left: parent.left;
@ -656,19 +658,17 @@ QtObject {
// Combobox with items with colored rectangles // Combobox with items with colored rectangles
property Component combobox_color: Component { property Component combobox_color: Component {
ComboBoxStyle ComboBoxStyle {
{
background: Rectangle background: Rectangle {
{
color: !enabled ? UM.Theme.getColor("setting_control_disabled") : (control.hovered || controler._hovered) ? UM.Theme.getColor("setting_control_highlight") : UM.Theme.getColor("setting_control") color: !enabled ? UM.Theme.getColor("setting_control_disabled") : (control.hovered || controler._hovered) ? UM.Theme.getColor("setting_control_highlight") : UM.Theme.getColor("setting_control")
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : (control.hovered || control._hovered) ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border") border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : (control.hovered || control._hovered) ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border")
} }
label: Item label: Item {
{
Label Label {
{
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_lining").width anchors.leftMargin: UM.Theme.getSize("default_lining").width
anchors.right: swatch.left anchors.right: swatch.left
@ -683,28 +683,25 @@ QtObject {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
Rectangle Rectangle {
{
id: swatch id: swatch
height: UM.Theme.getSize("setting_control").height / 2 height: UM.Theme.getSize("setting_control").height / 2
width: height width: height
anchors anchors {
{
right: downArrow.left; right: downArrow.left;
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
margins: UM.Theme.getSize("default_margin").width / 4 margins: UM.Theme.getSize("default_margin").width / 4
} }
border.width: UM.Theme.getSize("default_lining").width * 2 // border.width: UM.Theme.getSize("default_lining").width * 2
border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border") // border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
radius: width / 2 radius: width / 2
color: if (control.color_override != "") {return control.color_override} else {return control.color;} color: if (control.color_override != "") {return control.color_override} else {return control.color;}
} }
UM.RecolorImage UM.RecolorImage {
{
id: downArrow id: downArrow
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2 anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2