MaterialsBrandSection.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import QtQuick.Dialogs 1.2
  8. import UM 1.2 as UM
  9. import Cura 1.0 as Cura
  10. // An expandable list of materials. Includes both the header (this file) and the items (brandMaterialList)
  11. Item
  12. {
  13. id: brand_section
  14. property var sectionName: ""
  15. property var elementsModel // This can be a MaterialTypesModel or GenericMaterialsModel or FavoriteMaterialsModel
  16. property var hasMaterialTypes: true // It indicates whether it has material types or not
  17. property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1
  18. height: childrenRect.height
  19. width: parent.width
  20. Rectangle
  21. {
  22. id: brand_header_background
  23. color:
  24. {
  25. if(!expanded && sectionName == materialList.currentBrand)
  26. {
  27. return UM.Theme.getColor("favorites_row_selected")
  28. }
  29. else
  30. {
  31. return UM.Theme.getColor("favorites_header_bar")
  32. }
  33. }
  34. anchors.fill: brand_header
  35. }
  36. Row
  37. {
  38. id: brand_header
  39. width: parent.width
  40. Label
  41. {
  42. id: brand_name
  43. text: sectionName
  44. height: UM.Theme.getSize("favorites_row").height
  45. width: parent.width - UM.Theme.getSize("favorites_button").width
  46. verticalAlignment: Text.AlignVCenter
  47. leftPadding: (UM.Theme.getSize("default_margin").width / 2) | 0
  48. }
  49. Item
  50. {
  51. implicitWidth: UM.Theme.getSize("favorites_button").width
  52. implicitHeight: UM.Theme.getSize("favorites_button").height
  53. UM.RecolorImage
  54. {
  55. anchors
  56. {
  57. verticalCenter: parent.verticalCenter
  58. horizontalCenter: parent.horizontalCenter
  59. }
  60. width: UM.Theme.getSize("standard_arrow").width
  61. height: UM.Theme.getSize("standard_arrow").height
  62. color: "black"
  63. source: brand_section.expanded ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleLeft")
  64. }
  65. }
  66. }
  67. MouseArea
  68. {
  69. anchors.fill: brand_header
  70. onPressed:
  71. {
  72. const i = materialList.expandedBrands.indexOf(sectionName)
  73. if (i > -1)
  74. {
  75. // Remove it
  76. materialList.expandedBrands.splice(i, 1)
  77. brand_section.expanded = false
  78. }
  79. else
  80. {
  81. // Add it
  82. materialList.expandedBrands.push(sectionName)
  83. brand_section.expanded = true
  84. }
  85. UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";"));
  86. }
  87. }
  88. Column
  89. {
  90. id: brandMaterialList
  91. anchors.top: brand_header.bottom
  92. width: parent.width
  93. anchors.left: parent ? parent.left : undefined
  94. height: brand_section.expanded ? childrenRect.height : 0
  95. visible: brand_section.expanded
  96. Repeater
  97. {
  98. model: elementsModel
  99. delegate: Loader
  100. {
  101. id: loader
  102. width: parent ? parent.width : 0
  103. property var element: model
  104. sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
  105. }
  106. }
  107. }
  108. Component
  109. {
  110. id: materialsTypeSection
  111. MaterialsTypeSection
  112. {
  113. materialType: element
  114. }
  115. }
  116. Component
  117. {
  118. id: materialSlot
  119. MaterialsSlot
  120. {
  121. material: element
  122. }
  123. }
  124. Connections
  125. {
  126. target: UM.Preferences
  127. function onPreferenceChanged(preference)
  128. {
  129. if (preference !== "cura/expanded_types" && preference !== "cura/expanded_brands")
  130. {
  131. return;
  132. }
  133. expanded = materialList.expandedBrands.indexOf(sectionName) > -1
  134. }
  135. }
  136. }