From fae5e2cffd196feaf50e5ab128839a04f0d66bca Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Mon, 28 Jun 2021 14:53:50 +0200 Subject: [PATCH] Adjust the text of the material according to the size of the window Now, when the size of the Cura window changes and the configurationSelector gets resized, instead of eliding the material text it will now change as follows: * If it fits, display "Brand, Color, and Type" of material (e.g. Ultimaker Black PLA) * If "Brand, Color, and Type" doesn't fit, change it to "Color and Type" of material (e.g. Black PLA) * If "Color Type" doesn't fit either, display only the type (e.g. PLA) * If "Type" doesn't fit, elide it CURA-8013 --- cura/Machines/Models/ExtrudersModel.py | 8 ++- .../ConfigurationMenu/ConfigurationMenu.qml | 50 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cura/Machines/Models/ExtrudersModel.py b/cura/Machines/Models/ExtrudersModel.py index 98865ed37e..e979a1e848 100644 --- a/cura/Machines/Models/ExtrudersModel.py +++ b/cura/Machines/Models/ExtrudersModel.py @@ -53,6 +53,9 @@ class ExtrudersModel(ListModel): EnabledRole = Qt.UserRole + 11 """Is the extruder enabled?""" + MaterialTypeRole = Qt.UserRole + 12 + """The type of the material (e.g. PLA, ABS, PETG, etc.).""" + defaultColors = ["#ffc924", "#86ec21", "#22eeee", "#245bff", "#9124ff", "#ff24c8"] """List of colours to display if there is no material or the material has no known colour. """ @@ -75,6 +78,7 @@ class ExtrudersModel(ListModel): self.addRoleName(self.StackRole, "stack") self.addRoleName(self.MaterialBrandRole, "material_brand") self.addRoleName(self.ColorNameRole, "color_name") + self.addRoleName(self.MaterialTypeRole, "material_type") self._update_extruder_timer = QTimer() self._update_extruder_timer.setInterval(100) self._update_extruder_timer.setSingleShot(True) @@ -193,7 +197,8 @@ class ExtrudersModel(ListModel): "variant": extruder.variant.getName() if extruder.variant else "", # e.g. print core "stack": extruder, "material_brand": material_brand, - "color_name": color_name + "color_name": color_name, + "material_type": extruder.material.getMetaDataEntry("material") if extruder.material else "", } items.append(item) @@ -218,6 +223,7 @@ class ExtrudersModel(ListModel): "stack": None, "material_brand": "", "color_name": "", + "material_type": "", } items.append(item) if self._items != items: diff --git a/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml b/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml index d388bd7a7e..6f9f30e7e6 100644 --- a/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml +++ b/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml @@ -63,9 +63,9 @@ Cura.ExpandablePopup // Label for the brand of the material Label { - id: typeAndBrandNameLabel + id: materialBrandColorTypeLabel - text: model.material_brand + " " + model.material + text: model.material_brand == model.color_name ? model.color_name + " " + model.material_type : model.material_brand + " " + model.color_name + " " + model.material_type elide: Text.ElideRight font: UM.Theme.getFont("default") color: UM.Theme.getColor("text") @@ -79,6 +79,50 @@ Cura.ExpandablePopup right: parent.right rightMargin: UM.Theme.getSize("default_margin").width } + visible: !truncated + } + + Label + { + id: materialColorTypeLabel + + text: model.color_name + " " + model.material_type + elide: Text.ElideRight + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text") + renderType: Text.NativeRendering + + anchors + { + top: extruderIcon.top + left: extruderIcon.right + leftMargin: UM.Theme.getSize("default_margin").width + right: parent.right + rightMargin: UM.Theme.getSize("default_margin").width + } + + visible: !materialBrandColorTypeLabel.visible && !truncated + } + + Label + { + id: materialTypeLabel + + text: model.material_type + elide: Text.ElideRight + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text") + renderType: Text.NativeRendering + + anchors + { + top: extruderIcon.top + left: extruderIcon.right + leftMargin: UM.Theme.getSize("default_margin").width + right: parent.right + rightMargin: UM.Theme.getSize("default_margin").width + } + visible: !materialBrandColorTypeLabel.visible && !materialColorTypeLabel.visible } // Label that shows the name of the variant Label @@ -97,7 +141,7 @@ Cura.ExpandablePopup { left: extruderIcon.right leftMargin: UM.Theme.getSize("default_margin").width - top: typeAndBrandNameLabel.bottom + top: materialBrandColorTypeLabel.bottom right: parent.right rightMargin: UM.Theme.getSize("default_margin").width }