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
This commit is contained in:
Konstantinos Karmas 2021-06-28 14:53:50 +02:00
parent bbfa93c9a7
commit fae5e2cffd
2 changed files with 54 additions and 4 deletions

View file

@ -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: