Bit of QML cleanup

This commit is contained in:
Jaime van Kessel 2018-11-05 16:26:35 +01:00
parent 406dd68aa4
commit 8106df1ae2
2 changed files with 454 additions and 470 deletions

View file

@ -9,32 +9,21 @@ import QtQuick.Controls.Styles 1.1
import UM 1.0 as UM
import Cura 1.0 as Cura
Item
Rectangle
{
id: base
width:
color: UM.Theme.getColor("tool_panel_background")
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
width: UM.Theme.getSize("layerview_menu_size").width
height:
{
if (UM.SimulationView.compatibilityMode)
{
return UM.Theme.getSize("layerview_menu_size_compatibility").width;
}
else
{
return UM.Theme.getSize("layerview_menu_size").width;
}
}
height: {
if (viewSettings.collapsed)
{
if (UM.SimulationView.compatibilityMode)
{
return UM.Theme.getSize("layerview_menu_size_compatibility_collapsed").height;
}
return UM.Theme.getSize("layerview_menu_size_collapsed").height;
}
else if (UM.SimulationView.compatibilityMode)
{
return UM.Theme.getSize("layerview_menu_size_compatibility").height;
return UM.Theme.getSize("layerview_menu_size_collapsed").height
}
else if (UM.Preferences.getValue("layerview/layer_view_type") == 0)
{
@ -45,6 +34,7 @@ Item
return UM.Theme.getSize("layerview_menu_size").height + UM.SimulationView.extruderCount * (UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("layerview_row_spacing").height)
}
}
Behavior on height { NumberAnimation { duration: 100 } }
property var buttonTarget:
@ -57,26 +47,34 @@ Item
return Qt.point(0,0)
}
Rectangle
Connections
{
id: layerViewMenu
anchors.right: parent.right
anchors.top: parent.top
width: parent.width
height: parent.height
clip: true
z: layerSlider.z - 1
color: UM.Theme.getColor("tool_panel_background")
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
target: UM.Preferences
onPreferenceChanged:
{
layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type")
layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex)
viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|")
viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves")
viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers")
viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin")
viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill")
viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers")
viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count")
}
}
Button
{
id: collapseButton
anchors.top: parent.top
anchors.topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2)
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
anchors
{
top: parent.top
topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2)
right: parent.right
rightMargin: UM.Theme.getSize("default_margin").width
}
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
@ -108,7 +106,8 @@ Item
property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers")
property bool show_skin: UM.Preferences.getValue("layerview/show_skin")
property bool show_infill: UM.Preferences.getValue("layerview/show_infill")
// if we are in compatibility mode, we only show the "line type"
// If we are in compatibility mode, we only show the "line type"
property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1
property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3
property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2
@ -116,12 +115,14 @@ Item
property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers")
property int top_layer_count: UM.Preferences.getValue("view/top_layer_count")
anchors.top: parent.top
anchors.topMargin: UM.Theme.getSize("default_margin").height
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
anchors
{
top: parent.top
left: parent.left
right: parent.right
margins: UM.Theme.getSize("default_margin").height
}
spacing: UM.Theme.getSize("layerview_row_spacing").height
Label
@ -180,7 +181,7 @@ Item
function updateLegends(type_id)
{
// update visibility of legends
// Update the visibility of the legends.
viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1);
viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3);
viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2);
@ -199,43 +200,33 @@ Item
width: parent.width
}
Item
Item // Spacer
{
height: Math.round(UM.Theme.getSize("default_margin").width / 2)
width: width
}
Connections
{
target: UM.Preferences
onPreferenceChanged:
{
layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type")
layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex)
viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|")
viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves")
viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers")
viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin")
viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill")
viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers")
viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count")
}
}
Repeater
{
model: Cura.ExtrudersModel{}
CheckBox
{
id: extrudersModelCheckBox
checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == ""
height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
width: parent.width
visible: !UM.SimulationView.compatibilityMode
enabled: index < 4
onClicked:
{
viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0
UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|"));
}
visible: !UM.SimulationView.compatibilityMode
enabled: index + 1 <= 4
style: UM.Theme.styles.checkbox
Rectangle
{
anchors.verticalCenter: parent.verticalCenter
@ -246,23 +237,24 @@ Item
radius: Math.round(width / 2)
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
visible: !viewSettings.show_legend & !viewSettings.show_gradient
visible: !viewSettings.show_legend && !viewSettings.show_gradient
}
height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
width: parent.width
style: UM.Theme.styles.checkbox
Label
{
text: model.name
elide: Text.ElideRight
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
anchors.verticalCenter: parent.verticalCenter
anchors.left: extrudersModelCheckBox.left
anchors.right: extrudersModelCheckBox.right
anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2
anchors
{
verticalCenter: parent.verticalCenter
left: extrudersModelCheckBox.left
right: extrudersModelCheckBox.right
leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
rightMargin: UM.Theme.getSize("default_margin").width * 2
}
}
}
}
@ -305,10 +297,12 @@ Item
{
id: legendModelCheckBox
checked: model.initialValue
onClicked:
{
UM.Preferences.setValue(model.preference, checked);
}
onClicked: UM.Preferences.setValue(model.preference, checked)
height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
width: parent.width
style: UM.Theme.styles.checkbox
Rectangle
{
anchors.verticalCenter: parent.verticalCenter
@ -320,9 +314,7 @@ Item
border.color: UM.Theme.getColor("lining")
visible: viewSettings.show_legend
}
height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
width: parent.width
style: UM.Theme.styles.checkbox
Label
{
text: label
@ -341,21 +333,16 @@ Item
CheckBox
{
checked: viewSettings.only_show_top_layers
onClicked:
{
UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
}
onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
text: catalog.i18nc("@label", "Only Show Top Layers")
visible: UM.SimulationView.compatibilityMode
style: UM.Theme.styles.checkbox
}
CheckBox
{
checked: viewSettings.top_layer_count == 5
onClicked:
{
UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
}
onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top")
visible: UM.SimulationView.compatibilityMode
style: UM.Theme.styles.checkbox
@ -384,21 +371,25 @@ Item
text: label
visible: viewSettings.show_legend
id: typesLegendModelLabel
Rectangle
{
anchors.verticalCenter: parent.verticalCenter
anchors.right: typesLegendModelLabel.right
width: UM.Theme.getSize("layerview_legend_size").width
height: UM.Theme.getSize("layerview_legend_size").height
color: UM.Theme.getColor(model.colorId)
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
visible: viewSettings.show_legend
}
height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
width: parent.width
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
Rectangle
{
anchors.verticalCenter: parent.verticalCenter
anchors.right: typesLegendModelLabel.right
width: UM.Theme.getSize("layerview_legend_size").width
height: UM.Theme.getSize("layerview_legend_size").height
color: UM.Theme.getColor(model.colorId)
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
}
}
}
@ -412,12 +403,7 @@ Item
Label
{
text: minText()
anchors.left: parent.left
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
function minText()
text:
{
if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
{
@ -434,17 +420,14 @@ Item
}
return catalog.i18nc("@label","min")
}
anchors.left: parent.left
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
}
Label
{
text: unitsText()
anchors.horizontalCenter: parent.horizontalCenter
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
function unitsText()
{
text: {
if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
{
// Feedrate selected
@ -460,17 +443,15 @@ Item
}
return ""
}
anchors.horizontalCenter: parent.horizontalCenter
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
}
Label
{
text: maxText()
anchors.right: parent.right
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
function maxText()
{
text: {
if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
{
// Feedrate selected
@ -486,6 +467,10 @@ Item
}
return catalog.i18nc("@label","max")
}
anchors.right: parent.right
color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default")
}
}
@ -535,8 +520,10 @@ Item
anchors.left: parent.right
height: parent.width
width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining")
transform: Rotation {origin.x: 0; origin.y: 0; angle: 90}
gradient: Gradient
{
@ -568,7 +555,6 @@ Item
}
}
}
}
FontMetrics
{

View file

@ -452,8 +452,6 @@
"layerview_menu_size": [15, 20],
"layerview_menu_size_material_color_mode": [15, 16],
"layerview_menu_size_collapsed": [15, 6],
"layerview_menu_size_compatibility": [22, 22.0],
"layerview_menu_size_compatibility_collapsed": [15, 3.5],
"layerview_legend_size": [1.0, 1.0],
"layerview_row": [11.0, 1.5],
"layerview_row_spacing": [0.0, 0.5],