From 073c2d3335d91c2c8427340efcb39829edb330c1 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Tue, 12 Sep 2017 12:11:23 +0200 Subject: [PATCH] style and code improvements for combobox with color swatch --- resources/qml/SidebarSimple.qml | 36 +++++--------------------- resources/themes/cura-light/styles.qml | 29 ++++++++++----------- 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/resources/qml/SidebarSimple.qml b/resources/qml/SidebarSimple.qml index bd2c7ab3b7..c2c1562fbb 100644 --- a/resources/qml/SidebarSimple.qml +++ b/resources/qml/SidebarSimple.qml @@ -331,41 +331,19 @@ Item { var current_extruder = extruderModel.get(currentIndex); color_override = ""; - if (current_extruder === undefined) { - return ""; - } - var model_color = current_extruder.color; - return (model_color) ? model_color : ""; + if (current_extruder === undefined) return "" + return (current_extruder.color) ? current_extruder.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.topMargin: - { - if ((supportEnabled.properties.value == "True") && (machineExtruderCount.properties.value > 1)) - { - return UM.Theme.getSize("sidebar_margin").height; - } - else - { - return 0; - } - } + anchors.topMargin: ((supportEnabled.properties.value === "True") && (machineExtruderCount.properties.value > 1)) ? UM.Theme.getSize("sidebar_margin").height : 0 anchors.left: infillCellRight.left + width: UM.Theme.getSize("sidebar").width * .55 - height: - { - 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; - } - } + height: ((supportEnabled.properties.value == "True") && (machineExtruderCount.properties.value > 1)) ? UM.Theme.getSize("setting_control").height : 0 + Behavior on height { NumberAnimation { duration: 100 } } style: UM.Theme.styles.combobox_color diff --git a/resources/themes/cura-light/styles.qml b/resources/themes/cura-light/styles.qml index 049c2b547c..a2b36569fb 100755 --- a/resources/themes/cura-light/styles.qml +++ b/resources/themes/cura-light/styles.qml @@ -610,6 +610,7 @@ QtObject { property Component combobox: Component { ComboBoxStyle { + background: Rectangle { implicitHeight: Theme.getSize("setting_control").height; implicitWidth: Theme.getSize("setting_control").width; @@ -620,6 +621,7 @@ QtObject { border.width: Theme.getSize("default_lining").width; border.color: (control.hovered || control._hovered) ? Theme.getColor("setting_control_border_highlight") : Theme.getColor("setting_control_border"); } + label: Item { Label { anchors.left: parent.left; @@ -656,19 +658,17 @@ QtObject { // Combobox with items with colored rectangles property Component combobox_color: Component { - ComboBoxStyle - { - background: Rectangle - { + ComboBoxStyle { + + 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") 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") } - label: Item - { - Label - { + label: Item { + + Label { anchors.left: parent.left anchors.leftMargin: UM.Theme.getSize("default_lining").width anchors.right: swatch.left @@ -683,28 +683,25 @@ QtObject { verticalAlignment: Text.AlignVCenter } - Rectangle - { + Rectangle { id: swatch height: UM.Theme.getSize("setting_control").height / 2 width: height - anchors - { + anchors { right: downArrow.left; verticalCenter: parent.verticalCenter margins: UM.Theme.getSize("default_margin").width / 4 } - 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.width: UM.Theme.getSize("default_lining").width * 2 +// border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border") radius: width / 2 color: if (control.color_override != "") {return control.color_override} else {return control.color;} } - UM.RecolorImage - { + UM.RecolorImage { id: downArrow anchors.right: parent.right anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2