MaterialsList.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium 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. Item
  11. {
  12. id: materialList
  13. UM.I18nCatalog { id: catalog; name: "cura"; }
  14. Cura.BrandMaterialsModel { id: materialsModel }
  15. Cura.GenericMaterialsModel { id: genericMaterialsModel }
  16. width: materialScrollView.width - 20
  17. height: childrenRect.height
  18. Column
  19. {
  20. Rectangle
  21. {
  22. height: 23
  23. width: materialList.width
  24. Label
  25. {
  26. text: "Generic"
  27. }
  28. }
  29. Repeater
  30. {
  31. model: genericMaterialsModel
  32. delegate: Rectangle
  33. {
  34. height: 23
  35. width: materialList.width
  36. color: "green"
  37. Label
  38. {
  39. text: model.name
  40. }
  41. }
  42. }
  43. Repeater
  44. {
  45. id: brand_list
  46. model: materialsModel
  47. delegate: Rectangle
  48. {
  49. id: brand_section
  50. property var expanded: true
  51. property var types_model: model.materials
  52. height: childrenRect.height
  53. width: parent.width
  54. Rectangle
  55. {
  56. id: brand_header_background
  57. color: "grey"
  58. anchors.fill: brand_header
  59. }
  60. Row
  61. {
  62. id: brand_header
  63. width: parent.width
  64. Label
  65. {
  66. id: brand_name
  67. text: model.name
  68. height: 24
  69. width: parent.width - 24
  70. verticalAlignment: Text.AlignVCenter
  71. leftPadding: 4
  72. }
  73. Button
  74. {
  75. text: ""
  76. implicitWidth: 24
  77. implicitHeight: 24
  78. UM.RecolorImage {
  79. anchors
  80. {
  81. verticalCenter: parent.verticalCenter
  82. horizontalCenter: parent.horizontalCenter
  83. }
  84. width: UM.Theme.getSize("standard_arrow").width
  85. height: UM.Theme.getSize("standard_arrow").height
  86. sourceSize.width: width
  87. sourceSize.height: height
  88. color: "black"
  89. source: brand_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  90. }
  91. style: ButtonStyle
  92. {
  93. background: Rectangle
  94. {
  95. anchors.fill: parent
  96. color: "transparent"
  97. }
  98. }
  99. }
  100. }
  101. MouseArea
  102. {
  103. anchors.fill: brand_header
  104. onPressed:
  105. {
  106. brand_section.expanded = !brand_section.expanded
  107. }
  108. }
  109. Column
  110. {
  111. anchors.top: brand_header.bottom
  112. width: parent.width - leftPadding
  113. anchors.left: parent.left
  114. leftPadding: 8
  115. height: brand_section.expanded ? childrenRect.height : 0
  116. visible: brand_section.expanded
  117. Repeater
  118. {
  119. model: types_model
  120. delegate: Rectangle
  121. {
  122. id: material_type_section
  123. property var expanded: true
  124. property var colors_model: model.colors
  125. height: childrenRect.height
  126. width: parent.width
  127. Rectangle
  128. {
  129. id: material_type_header_background
  130. color: "grey"
  131. anchors.bottom: material_type_header.bottom
  132. height: 1
  133. width: parent.width
  134. }
  135. Row
  136. {
  137. id: material_type_header
  138. width: parent.width
  139. Label
  140. {
  141. text: model.name
  142. height: 24
  143. width: parent.width - 24
  144. id: material_type_name
  145. verticalAlignment: Text.AlignVCenter
  146. }
  147. Button
  148. {
  149. text: ""
  150. implicitWidth: 24
  151. implicitHeight: 24
  152. UM.RecolorImage {
  153. anchors
  154. {
  155. verticalCenter: parent.verticalCenter
  156. horizontalCenter: parent.horizontalCenter
  157. }
  158. width: UM.Theme.getSize("standard_arrow").width
  159. height: UM.Theme.getSize("standard_arrow").height
  160. sourceSize.width: width
  161. sourceSize.height: height
  162. color: "black"
  163. source: material_type_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  164. }
  165. style: ButtonStyle
  166. {
  167. background: Rectangle
  168. {
  169. anchors.fill: parent
  170. color: "transparent"
  171. }
  172. }
  173. }
  174. }
  175. MouseArea
  176. {
  177. anchors.fill: material_type_header
  178. onPressed:
  179. {
  180. material_type_section.expanded = !material_type_section.expanded
  181. }
  182. }
  183. Column
  184. {
  185. height: material_type_section.expanded ? childrenRect.height : 0
  186. visible: material_type_section.expanded
  187. width: parent.width - leftPadding
  188. anchors.top: material_type_header.bottom
  189. leftPadding: 8
  190. anchors.left: parent.left
  191. Repeater
  192. {
  193. model: colors_model
  194. delegate: Rectangle
  195. {
  196. height: 24
  197. width: parent.width
  198. // color: "green"
  199. Row
  200. {
  201. height: parent.height
  202. width: parent.width
  203. Rectangle
  204. {
  205. id: swatch
  206. color: model.color_code
  207. border.width: 1
  208. border.color: "black"
  209. width: 14
  210. height: 14
  211. anchors.verticalCenter: parent.verticalCenter
  212. }
  213. Label
  214. {
  215. text: model.name
  216. verticalAlignment: Text.AlignVCenter
  217. height: 24
  218. anchors.left: swatch.right
  219. anchors.verticalCenter: parent.verticalCenter
  220. anchors.leftMargin: 4
  221. }
  222. MouseArea
  223. {
  224. anchors.fill: parent
  225. onClicked:
  226. {
  227. print(model.guid)
  228. }
  229. }
  230. Button
  231. {
  232. text: "+"
  233. implicitWidth: 24
  234. implicitHeight: 24
  235. anchors.right: parent.right
  236. anchors.verticalCenter: parent.verticalCenter
  237. onClicked:
  238. {
  239. if (model.is_favorite) {
  240. base.materialManager.removeFavorite(model.root_material_id)
  241. model.is_favorite = false
  242. return
  243. }
  244. base.materialManager.addFavorite(model.root_material_id)
  245. model.is_favorite = true
  246. return
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }