MaterialsPage.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.8
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Layouts 1.3
  6. import QtQuick.Dialogs 1.3
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. id: base
  12. property var resetEnabled: false // Keep PreferencesDialog happy
  13. UM.I18nCatalog { id: catalog; name: "cura"; }
  14. Cura.NewMaterialsModel {
  15. id: materialsModel
  16. }
  17. Label {
  18. id: titleLabel
  19. anchors {
  20. top: parent.top
  21. left: parent.left
  22. right: parent.right
  23. margins: 5 * screenScaleFactor
  24. }
  25. font.pointSize: 18
  26. text: catalog.i18nc("@title:tab", "Materials")
  27. }
  28. property var hasCurrentItem: materialListView.currentItem != null
  29. property var currentItem: {
  30. var current_index = materialListView.currentIndex;
  31. return materialsModel.getItem(current_index);
  32. }
  33. property var isCurrentItemActivated: {
  34. const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
  35. const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
  36. return base.currentItem.root_material_id == root_material_id;
  37. }
  38. Row // Button Row
  39. {
  40. id: buttonRow
  41. anchors {
  42. left: parent.left
  43. right: parent.right
  44. top: titleLabel.bottom
  45. }
  46. height: childrenRect.height
  47. // Activate button
  48. Button {
  49. text: catalog.i18nc("@action:button", "Activate")
  50. iconName: "list-activate"
  51. enabled: !isCurrentItemActivated
  52. onClicked: {
  53. forceActiveFocus()
  54. const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
  55. Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node);
  56. }
  57. }
  58. // Create button
  59. Button {
  60. text: catalog.i18nc("@action:button", "Create")
  61. iconName: "list-add"
  62. onClicked: {
  63. forceActiveFocus()
  64. // TODO
  65. }
  66. }
  67. // Duplicate button
  68. Button {
  69. text: catalog.i18nc("@action:button", "Duplicate");
  70. iconName: "list-add"
  71. enabled: base.hasCurrentItem
  72. onClicked: {
  73. forceActiveFocus();
  74. Cura.ContainerManager.duplicateMaterial(base.currentItem.container_node);
  75. }
  76. }
  77. // Remove button
  78. Button {
  79. text: catalog.i18nc("@action:button", "Remove")
  80. iconName: "list-remove"
  81. enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated
  82. onClicked: {
  83. forceActiveFocus();
  84. confirmRemoveMaterialDialog.open();
  85. }
  86. }
  87. // Import button
  88. Button {
  89. text: catalog.i18nc("@action:button", "Import")
  90. iconName: "document-import"
  91. onClicked: {
  92. forceActiveFocus()
  93. // TODO
  94. }
  95. visible: true
  96. }
  97. // Export button
  98. Button {
  99. text: catalog.i18nc("@action:button", "Export")
  100. iconName: "document-export"
  101. onClicked: {
  102. forceActiveFocus()
  103. // TODO
  104. }
  105. enabled: currentItem != null
  106. }
  107. }
  108. MessageDialog
  109. {
  110. id: confirmRemoveMaterialDialog
  111. icon: StandardIcon.Question;
  112. title: catalog.i18nc("@title:window", "Confirm Remove")
  113. text: catalog.i18nc("@label (%1 is object name)", "Are you sure you wish to remove %1? This cannot be undone!").arg(base.currentItem.name)
  114. standardButtons: StandardButton.Yes | StandardButton.No
  115. modality: Qt.ApplicationModal
  116. onYes:
  117. {
  118. Cura.ContainerManager.removeMaterial(base.currentItem.container_node);
  119. // reset current item to the first if available
  120. materialListView.currentIndex = 0;
  121. }
  122. }
  123. Item {
  124. id: contentsItem
  125. anchors {
  126. top: titleLabel.bottom
  127. left: parent.left
  128. right: parent.right
  129. bottom: parent.bottom
  130. margins: 5 * screenScaleFactor
  131. bottomMargin: 0
  132. }
  133. clip: true
  134. }
  135. Item
  136. {
  137. anchors {
  138. top: buttonRow.bottom
  139. topMargin: UM.Theme.getSize("default_margin").height
  140. left: parent.left
  141. right: parent.right
  142. bottom: parent.bottom
  143. }
  144. SystemPalette { id: palette }
  145. Label
  146. {
  147. id: captionLabel
  148. anchors {
  149. top: parent.top
  150. left: parent.left
  151. }
  152. visible: text != ""
  153. text: {
  154. // OLD STUFF
  155. var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachineName;
  156. if (Cura.MachineManager.hasVariants)
  157. {
  158. caption += ", " + Cura.MachineManager.activeDefinitionVariantsName + ": " + Cura.MachineManager.activeVariantName;
  159. }
  160. return caption;
  161. }
  162. width: materialScrollView.width
  163. elide: Text.ElideRight
  164. }
  165. ScrollView
  166. {
  167. id: materialScrollView
  168. anchors {
  169. top: captionLabel.visible ? captionLabel.bottom : parent.top
  170. topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
  171. bottom: parent.bottom
  172. left: parent.left
  173. }
  174. Rectangle {
  175. parent: viewport
  176. anchors.fill: parent
  177. color: palette.light
  178. }
  179. width: true ? (parent.width * 0.4) | 0 : parent.width
  180. ListView
  181. {
  182. id: materialListView
  183. model: materialsModel
  184. section.property: "brand"
  185. section.criteria: ViewSection.FullString
  186. section.delegate: Rectangle
  187. {
  188. width: materialScrollView.width
  189. height: childrenRect.height
  190. color: palette.light
  191. Label
  192. {
  193. anchors.left: parent.left
  194. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  195. text: section
  196. font.bold: true
  197. color: palette.text
  198. }
  199. }
  200. delegate: Rectangle
  201. {
  202. width: materialScrollView.width
  203. height: childrenRect.height
  204. color: ListView.isCurrentItem ? palette.highlight : (model.index % 2) ? palette.base : palette.alternateBase
  205. Row
  206. {
  207. spacing: (UM.Theme.getSize("default_margin").width / 2) | 0
  208. anchors.left: parent.left
  209. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  210. anchors.right: parent.right
  211. Rectangle
  212. {
  213. width: Math.floor(parent.height * 0.8)
  214. height: Math.floor(parent.height * 0.8)
  215. color: model.color_code
  216. border.color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text;
  217. anchors.verticalCenter: parent.verticalCenter
  218. }
  219. Label
  220. {
  221. width: Math.floor((parent.width * 0.3))
  222. text: model.material
  223. elide: Text.ElideRight
  224. font.italic: { // TODO: make it easier
  225. const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
  226. const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
  227. return model.root_material_id == root_material_id
  228. }
  229. color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text;
  230. }
  231. Label
  232. {
  233. text: (model.name != model.material) ? model.name : ""
  234. elide: Text.ElideRight
  235. font.italic: { // TODO: make it easier
  236. const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
  237. const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
  238. return model.root_material_id == root_material_id;
  239. }
  240. color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text;
  241. }
  242. }
  243. MouseArea
  244. {
  245. anchors.fill: parent
  246. onClicked: {
  247. parent.ListView.view.currentIndex = model.index;
  248. }
  249. }
  250. }
  251. onCurrentIndexChanged:
  252. {
  253. var model = materialsModel.getItem(currentIndex);
  254. materialDetailsView.containerId = model.container_id;
  255. materialDetailsView.currentMaterialNode = model.container_node;
  256. detailsPanel.updateMaterialPropertiesObject();
  257. }
  258. }
  259. }
  260. Item
  261. {
  262. id: detailsPanel
  263. anchors {
  264. left: materialScrollView.right
  265. leftMargin: UM.Theme.getSize("default_margin").width
  266. top: parent.top
  267. bottom: parent.bottom
  268. right: parent.right
  269. }
  270. function updateMaterialPropertiesObject()
  271. {
  272. var currentItem = materialsModel.getItem(materialListView.currentIndex);
  273. materialProperties.name = currentItem.name;
  274. materialProperties.guid = currentItem.guid;
  275. materialProperties.brand = currentItem.brand ? currentItem.brand : "Unknown";
  276. materialProperties.material = currentItem.material ? currentItem.material : "Unknown";
  277. materialProperties.color_name = currentItem.color_name ? currentItem.color_name : "Yellow";
  278. materialProperties.color_code = currentItem.color_code ? currentItem.color_code : "yellow";
  279. materialProperties.description = currentItem.description ? currentItem.description : "";
  280. materialProperties.adhesion_info = currentItem.adhesion_info ? currentItem.adhesion_info : "";
  281. if(currentItem.properties != undefined && currentItem.properties != null)
  282. {
  283. materialProperties.density = currentItem.density ? currentItem.density : 0.0;
  284. materialProperties.diameter = currentItem.diameter ? currentItem.diameter : 0.0;
  285. materialProperties.approximate_diameter = currentItem.approximate_diameter ? currentItem.approximate_diameter : "0";
  286. }
  287. else
  288. {
  289. materialProperties.density = 0.0;
  290. materialProperties.diameter = 0.0;
  291. materialProperties.approximate_diameter = "0";
  292. }
  293. }
  294. Item
  295. {
  296. anchors.fill: parent
  297. Item // Material title Label
  298. {
  299. id: profileName
  300. width: parent.width
  301. height: childrenRect.height
  302. Label {
  303. text: materialProperties.name
  304. font: UM.Theme.getFont("large")
  305. }
  306. }
  307. MaterialView // Material detailed information view below the title Label
  308. {
  309. id: materialDetailsView
  310. anchors
  311. {
  312. left: parent.left
  313. right: parent.right
  314. top: profileName.bottom
  315. topMargin: UM.Theme.getSize("default_margin").height
  316. bottom: parent.bottom
  317. }
  318. editingEnabled: base.currentItem != null && !base.currentItem.is_read_only
  319. properties: materialProperties
  320. containerId: base.currentItem != null ? base.currentItem.id : ""
  321. currentMaterialNode: base.currentItem
  322. property alias pane: base
  323. }
  324. QtObject
  325. {
  326. id: materialProperties
  327. property string guid: "00000000-0000-0000-0000-000000000000"
  328. property string name: "Unknown";
  329. property string profile_type: "Unknown";
  330. property string brand: "Unknown";
  331. property string material: "Unknown"; // This needs to be named as "material" to be consistent with
  332. // the material container's metadata entry
  333. property string color_name: "Yellow";
  334. property color color_code: "yellow";
  335. property real density: 0.0;
  336. property real diameter: 0.0;
  337. property string approximate_diameter: "0";
  338. property real spool_cost: 0.0;
  339. property real spool_weight: 0.0;
  340. property real spool_length: 0.0;
  341. property real cost_per_meter: 0.0;
  342. property string description: "";
  343. property string adhesion_info: "";
  344. }
  345. }
  346. }
  347. }
  348. }