MaterialsList.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. width: materialScrollView.width - 17
  14. height: childrenRect.height
  15. // Children
  16. UM.I18nCatalog { id: catalog; name: "cura"; }
  17. Cura.MaterialBrandsModel { id: materialsModel }
  18. Cura.FavoriteMaterialsModel { id: favoriteMaterialsModel }
  19. Cura.GenericMaterialsModel { id: genericMaterialsModel }
  20. property var currentType: null
  21. property var currentBrand: null
  22. property var expandedBrands: UM.Preferences.getValue("cura/expanded_brands").split(";")
  23. property var expandedTypes: UM.Preferences.getValue("cura/expanded_types").split(";")
  24. function expandActiveMaterial(search_root_id)
  25. {
  26. for (var n = 0; n < genericMaterialsModel.rowCount(); n++)
  27. {
  28. var material = genericMaterialsModel.getItem(n);
  29. if (material.root_material_id == search_root_id)
  30. {
  31. if (materialList.expandedBrands.indexOf("Generic") == -1)
  32. {
  33. materialList.expandedBrands.push("Generic");
  34. materialList.currentBrand = "Generic"
  35. }
  36. }
  37. }
  38. for (var i = 0; i < materialsModel.rowCount(); i++)
  39. {
  40. var brand = materialsModel.getItem(i);
  41. var types_model = brand.material_types;
  42. for (var j = 0; j < types_model.rowCount(); j++)
  43. {
  44. var type = types_model.getItem(j);
  45. var colors_model = type.colors;
  46. for (var k = 0; k < colors_model.rowCount(); k++)
  47. {
  48. var material = colors_model.getItem(k);
  49. if (material.root_material_id == search_root_id)
  50. {
  51. if (materialList.expandedBrands.indexOf(brand.name) == -1)
  52. {
  53. materialList.expandedBrands.push(brand.name);
  54. materialList.currentBrand = brand.name
  55. }
  56. if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1)
  57. {
  58. materialList.expandedTypes.push(brand.name + "_" + type.name)
  59. materialList.currentType = brand.name + "_" + type.name
  60. }
  61. }
  62. }
  63. }
  64. }
  65. UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";"));
  66. UM.Preferences.setValue("cura/expanded_types", materialList.expandedTypes.join(";"));
  67. }
  68. // Connections
  69. // {
  70. // target: materialsModel
  71. // onItemsChanged:
  72. // {
  73. // var currentItemId = base.hasCurrentItem ? base.currentItem.root_material_id : ""
  74. // var position = Cura.ExtruderManager.activeExtruderIndex
  75. // console.log("!!!!!!!!!!!!!!!!!!! on items changed:", base.newRootMaterialIdToSwitchTo)
  76. //
  77. // // try to pick the currently selected item; it may have been moved
  78. // if (base.newRootMaterialIdToSwitchTo == "")
  79. // {
  80. // console.log("material id is empty, setting to ", currentItemId)
  81. // base.newRootMaterialIdToSwitchTo = currentItemId
  82. // }
  83. //
  84. // console.log("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", materialsModel.rowCount())
  85. // for (var brand_idx = 0; brand_idx < materialsModel.rowCount(); ++brand_idx)
  86. // {
  87. // var brand = materialsModel.getItem(brand_idx)
  88. // console.log(item.root_material_id, "=", base.newRootMaterialIdToSwitchTo)
  89. //
  90. // for (var type_idx = 0; type_idx < brand.material_types.rowCount(); ++type_idx)
  91. // {
  92. // var type = brand.material_types.getItem(type_idx)
  93. // if (type.root_material_id == base.newRootMaterialIdToSwitchTo)
  94. // {
  95. // // Switch to the newly created profile if needed
  96. // base.currentItem = item
  97. // // materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex)
  98. // // if (base.toActivateNewMaterial)
  99. // // {
  100. // // Cura.MachineManager.setMaterial(position, item.container_node)
  101. // // }
  102. // base.newRootMaterialIdToSwitchTo = ""
  103. // base.toActivateNewMaterial = false
  104. // return
  105. // }
  106. // }
  107. // }
  108. //
  109. // // If the new id can't be found, then do nothing
  110. //// materialListView.currentIndex = 0
  111. //// materialListView.activateDetailsWithIndex(materialListView.currentIndex)
  112. //// if (base.toActivateNewMaterial)
  113. //// {
  114. //// Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node)
  115. //// }
  116. // base.newRootMaterialIdToSwitchTo = ""
  117. // base.toActivateNewMaterial = false
  118. // }
  119. // }
  120. Column
  121. {
  122. Rectangle
  123. {
  124. property var expanded: true
  125. id: favorites_section
  126. height: childrenRect.height
  127. width: materialList.width
  128. Rectangle
  129. {
  130. id: favorites_header_background
  131. color: UM.Theme.getColor("favorites_header_bar")
  132. anchors.fill: favorites_header
  133. }
  134. Row
  135. {
  136. id: favorites_header
  137. Label
  138. {
  139. id: favorites_name
  140. text: "Favorites"
  141. height: UM.Theme.getSize("favorites_row").height
  142. width: materialList.width - UM.Theme.getSize("favorites_button").width
  143. verticalAlignment: Text.AlignVCenter
  144. leftPadding: 4
  145. }
  146. Button
  147. {
  148. text: ""
  149. implicitWidth: UM.Theme.getSize("favorites_button").width
  150. implicitHeight: UM.Theme.getSize("favorites_button").height
  151. UM.RecolorImage {
  152. anchors
  153. {
  154. verticalCenter: parent.verticalCenter
  155. horizontalCenter: parent.horizontalCenter
  156. }
  157. width: UM.Theme.getSize("standard_arrow").width
  158. height: UM.Theme.getSize("standard_arrow").height
  159. sourceSize.width: width
  160. sourceSize.height: height
  161. color: "black"
  162. source: favorites_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  163. }
  164. style: ButtonStyle
  165. {
  166. background: Rectangle
  167. {
  168. anchors.fill: parent
  169. color: "transparent"
  170. }
  171. }
  172. }
  173. }
  174. MouseArea
  175. {
  176. anchors.fill: favorites_header
  177. onPressed:
  178. {
  179. favorites_section.expanded = !favorites_section.expanded
  180. }
  181. }
  182. Column
  183. {
  184. anchors.top: favorites_header.bottom
  185. anchors.left: parent.left
  186. width: materialList.width
  187. height: favorites_section.expanded ? childrenRect.height : 0
  188. visible: favorites_section.expanded
  189. Repeater
  190. {
  191. model: favoriteMaterialsModel
  192. delegate: MaterialsSlot {
  193. material: model
  194. }
  195. }
  196. }
  197. }
  198. Rectangle
  199. {
  200. property var expanded: materialList.expandedBrands.indexOf("Generic") > -1
  201. id: generic_section
  202. height: childrenRect.height
  203. width: materialList.width
  204. Rectangle
  205. {
  206. id: generic_header_background
  207. color: UM.Theme.getColor("favorites_header_bar")
  208. anchors.fill: generic_header
  209. }
  210. Row
  211. {
  212. id: generic_header
  213. Label
  214. {
  215. id: generic_name
  216. text: "Generic"
  217. height: UM.Theme.getSize("favorites_row").height
  218. width: materialList.width - UM.Theme.getSize("favorites_button").width
  219. verticalAlignment: Text.AlignVCenter
  220. leftPadding: 4
  221. }
  222. Button
  223. {
  224. text: ""
  225. implicitWidth: UM.Theme.getSize("favorites_button").width
  226. implicitHeight: UM.Theme.getSize("favorites_button").height
  227. UM.RecolorImage {
  228. anchors
  229. {
  230. verticalCenter: parent.verticalCenter
  231. horizontalCenter: parent.horizontalCenter
  232. }
  233. width: UM.Theme.getSize("standard_arrow").width
  234. height: UM.Theme.getSize("standard_arrow").height
  235. sourceSize.width: width
  236. sourceSize.height: height
  237. color: "black"
  238. source: generic_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  239. }
  240. style: ButtonStyle
  241. {
  242. background: Rectangle
  243. {
  244. anchors.fill: parent
  245. color: "transparent"
  246. }
  247. }
  248. }
  249. }
  250. MouseArea
  251. {
  252. anchors.fill: generic_header
  253. onPressed:
  254. {
  255. const index = materialList.expandedBrands.indexOf("Generic")
  256. if (index > -1)
  257. {
  258. // Remove it
  259. materialList.expandedBrands.splice(index, 1)
  260. generic_section.expanded = false
  261. }
  262. else
  263. {
  264. // Add it
  265. materialList.expandedBrands.push("Generic")
  266. generic_section.expanded = true
  267. }
  268. }
  269. }
  270. Column
  271. {
  272. anchors.top: generic_header.bottom
  273. width: materialList.width
  274. anchors.left: parent.left
  275. height: generic_section.expanded ? childrenRect.height : 0
  276. visible: generic_section.expanded
  277. Repeater
  278. {
  279. model: genericMaterialsModel
  280. delegate: MaterialsSlot
  281. {
  282. material: model
  283. }
  284. }
  285. }
  286. }
  287. Repeater
  288. {
  289. id: brand_list
  290. model: materialsModel
  291. delegate: MaterialsBrandSection {}
  292. }
  293. }
  294. }