MaterialsTypeSection.qml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.4
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. Column
  9. {
  10. id: material_type_section
  11. property var materialType: null
  12. property string materialBrand: materialType !== null ? materialType.brand : ""
  13. property string materialName: materialType !== null ? materialType.name : ""
  14. property bool expanded: materialList.expandedTypes.indexOf(`${materialBrand}_${materialName}`) !== -1
  15. property var colorsModel: materialType !== null ? materialType.colors : null
  16. property alias indented: categoryButton.indented
  17. width: parent.width
  18. Cura.CategoryButton
  19. {
  20. id: categoryButton
  21. width: parent.width
  22. height: UM.Theme.getSize("preferences_page_list_item").height
  23. labelText: materialName
  24. labelFont: UM.Theme.getFont("default")
  25. expanded: material_type_section.expanded
  26. onClicked:
  27. {
  28. const identifier = `${materialBrand}_${materialName}`;
  29. const i = materialList.expandedTypes.indexOf(identifier);
  30. if (i !== -1)
  31. {
  32. materialList.expandedTypes.splice(i, 1); // remove
  33. }
  34. else
  35. {
  36. materialList.expandedTypes.push(identifier); // add
  37. }
  38. UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";"));
  39. }
  40. }
  41. Column
  42. {
  43. visible: material_type_section.expanded
  44. width: parent.width
  45. Repeater
  46. {
  47. model: colorsModel
  48. delegate: MaterialsSlot
  49. {
  50. material: model
  51. }
  52. }
  53. }
  54. Connections
  55. {
  56. target: UM.Preferences
  57. function onPreferenceChanged(preference)
  58. {
  59. if (preference !== "cura/expanded_types" && preference !== "cura/expanded_brands")
  60. {
  61. return;
  62. }
  63. material_type_section.expanded = materialList.expandedTypes.indexOf(`${materialBrand}_${materialName}`) !== -1;
  64. }
  65. }
  66. }