MaterialsBrandSection.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. // An expandable list of materials. Includes both the header (this file) and the items (brandMaterialList)
  9. Column
  10. {
  11. id: brand_section
  12. property string sectionName: ""
  13. property var elementsModel // This can be a MaterialTypesModel or GenericMaterialsModel or FavoriteMaterialsModel
  14. property bool hasMaterialTypes: true // It indicates whether it has material types or not
  15. property bool expanded: materialList.expandedBrands.indexOf(sectionName) !== -1
  16. width: parent.width
  17. Cura.CategoryButton
  18. {
  19. width: parent.width
  20. labelText: sectionName
  21. height: UM.Theme.getSize("preferences_page_list_item").height
  22. labelFont: UM.Theme.getFont("default_bold")
  23. expanded: brand_section.expanded
  24. onClicked:
  25. {
  26. const i = materialList.expandedBrands.indexOf(sectionName);
  27. if (i !== -1)
  28. {
  29. materialList.expandedBrands.splice(i, 1); // remove
  30. }
  31. else
  32. {
  33. materialList.expandedBrands.push(sectionName); // add
  34. }
  35. UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";"));
  36. }
  37. }
  38. Column
  39. {
  40. id: brandMaterialList
  41. width: parent.width
  42. visible: brand_section.expanded
  43. Repeater
  44. {
  45. model: elementsModel
  46. delegate: Loader
  47. {
  48. width: parent.width
  49. property var element: model
  50. sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
  51. }
  52. }
  53. }
  54. Component
  55. {
  56. id: materialsTypeSection
  57. MaterialsTypeSection
  58. {
  59. materialType: element
  60. indented: true
  61. }
  62. }
  63. Component
  64. {
  65. id: materialSlot
  66. MaterialsSlot
  67. {
  68. material: element
  69. }
  70. }
  71. Connections
  72. {
  73. target: UM.Preferences
  74. function onPreferenceChanged(preference)
  75. {
  76. if (preference !== "cura/expanded_types" && preference !== "cura/expanded_brands")
  77. {
  78. return;
  79. }
  80. brand_section.expanded = materialList.expandedBrands.indexOf(sectionName) !== -1;
  81. }
  82. }
  83. }