MaterialsPage.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.Layouts 1.3
  6. import QtQuick.Dialogs 1.2
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. id: base
  12. property QtObject materialManager: CuraApplication.getMaterialManager()
  13. // Keep PreferencesDialog happy
  14. property var resetEnabled: false
  15. property var currentItem: null
  16. property var hasCurrentItem: base.currentItem != null
  17. property var isCurrentItemActivated:
  18. {
  19. if (!hasCurrentItem)
  20. {
  21. return false
  22. }
  23. const extruder_position = Cura.ExtruderManager.activeExtruderIndex
  24. const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position]
  25. return base.currentItem.root_material_id == root_material_id
  26. }
  27. property string newRootMaterialIdToSwitchTo: ""
  28. property bool toActivateNewMaterial: false
  29. property var extruder_position: Cura.ExtruderManager.activeExtruderIndex
  30. property var active_root_material_id: Cura.MachineManager.currentRootMaterialId[extruder_position]
  31. UM.I18nCatalog
  32. {
  33. id: catalog
  34. name: "cura"
  35. }
  36. // When loaded, try to select the active material in the tree
  37. Component.onCompleted: materialListView.expandActiveMaterial(active_root_material_id)
  38. // Every time the selected item has changed, notify to the details panel
  39. onCurrentItemChanged: materialDetailsPanel.currentItem = currentItem
  40. // Main layout
  41. Label
  42. {
  43. id: titleLabel
  44. anchors
  45. {
  46. top: parent.top
  47. left: parent.left
  48. right: parent.right
  49. margins: 5 * screenScaleFactor
  50. }
  51. font.pointSize: 18
  52. text: catalog.i18nc("@title:tab", "Materials")
  53. }
  54. // Button Row
  55. Row
  56. {
  57. id: buttonRow
  58. anchors
  59. {
  60. left: parent.left
  61. right: parent.right
  62. top: titleLabel.bottom
  63. }
  64. height: childrenRect.height
  65. // Activate button
  66. Button
  67. {
  68. text: catalog.i18nc("@action:button", "Activate")
  69. iconName: "list-activate"
  70. enabled: !isCurrentItemActivated
  71. onClicked:
  72. {
  73. forceActiveFocus()
  74. const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
  75. Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node);
  76. }
  77. }
  78. // Create button
  79. Button
  80. {
  81. text: catalog.i18nc("@action:button", "Create")
  82. iconName: "list-add"
  83. onClicked:
  84. {
  85. forceActiveFocus();
  86. base.newRootMaterialIdToSwitchTo = base.materialManager.createMaterial();
  87. base.toActivateNewMaterial = true;
  88. }
  89. }
  90. // Duplicate button
  91. Button
  92. {
  93. text: catalog.i18nc("@action:button", "Duplicate");
  94. iconName: "list-add"
  95. enabled: base.hasCurrentItem
  96. onClicked:
  97. {
  98. forceActiveFocus();
  99. base.newRootMaterialIdToSwitchTo = base.materialManager.duplicateMaterial(base.currentItem.container_node);
  100. base.toActivateNewMaterial = true;
  101. }
  102. }
  103. // Remove button
  104. Button
  105. {
  106. text: catalog.i18nc("@action:button", "Remove")
  107. iconName: "list-remove"
  108. enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated
  109. onClicked:
  110. {
  111. forceActiveFocus();
  112. confirmRemoveMaterialDialog.open();
  113. }
  114. }
  115. // Import button
  116. Button
  117. {
  118. text: catalog.i18nc("@action:button", "Import")
  119. iconName: "document-import"
  120. onClicked:
  121. {
  122. forceActiveFocus();
  123. importMaterialDialog.open();
  124. }
  125. visible: true
  126. }
  127. // Export button
  128. Button
  129. {
  130. text: catalog.i18nc("@action:button", "Export")
  131. iconName: "document-export"
  132. onClicked:
  133. {
  134. forceActiveFocus();
  135. exportMaterialDialog.open();
  136. }
  137. enabled: base.hasCurrentItem
  138. }
  139. }
  140. Item {
  141. id: contentsItem
  142. anchors
  143. {
  144. top: titleLabel.bottom
  145. left: parent.left
  146. right: parent.right
  147. bottom: parent.bottom
  148. margins: 5 * screenScaleFactor
  149. bottomMargin: 0
  150. }
  151. clip: true
  152. }
  153. Item
  154. {
  155. anchors
  156. {
  157. top: buttonRow.bottom
  158. topMargin: UM.Theme.getSize("default_margin").height
  159. left: parent.left
  160. right: parent.right
  161. bottom: parent.bottom
  162. }
  163. SystemPalette { id: palette }
  164. Label
  165. {
  166. id: captionLabel
  167. anchors
  168. {
  169. top: parent.top
  170. left: parent.left
  171. }
  172. visible: text != ""
  173. text:
  174. {
  175. var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachineName;
  176. if (Cura.MachineManager.hasVariants)
  177. {
  178. caption += ", " + Cura.MachineManager.activeDefinitionVariantsName + ": " + Cura.MachineManager.activeVariantName;
  179. }
  180. return caption;
  181. }
  182. width: materialScrollView.width
  183. elide: Text.ElideRight
  184. }
  185. ScrollView
  186. {
  187. id: materialScrollView
  188. anchors
  189. {
  190. top: captionLabel.visible ? captionLabel.bottom : parent.top
  191. topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
  192. bottom: parent.bottom
  193. left: parent.left
  194. }
  195. Rectangle
  196. {
  197. parent: viewport
  198. anchors.fill: parent
  199. color: palette.light
  200. }
  201. width: true ? (parent.width * 0.4) | 0 : parent.width
  202. frameVisible: true
  203. verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
  204. MaterialsList
  205. {
  206. id: materialListView
  207. }
  208. }
  209. MaterialsDetailsPanel
  210. {
  211. id: materialDetailsPanel
  212. anchors
  213. {
  214. left: materialScrollView.right
  215. leftMargin: UM.Theme.getSize("default_margin").width
  216. top: parent.top
  217. bottom: parent.bottom
  218. right: parent.right
  219. }
  220. }
  221. }
  222. // Dialogs
  223. MessageDialog
  224. {
  225. id: confirmRemoveMaterialDialog
  226. icon: StandardIcon.Question;
  227. title: catalog.i18nc("@title:window", "Confirm Remove")
  228. text: catalog.i18nc("@label (%1 is object name)", "Are you sure you wish to remove %1? This cannot be undone!").arg(base.currentItem.name)
  229. standardButtons: StandardButton.Yes | StandardButton.No
  230. modality: Qt.ApplicationModal
  231. onYes:
  232. {
  233. base.materialManager.removeMaterial(base.currentItem.container_node);
  234. }
  235. }
  236. FileDialog
  237. {
  238. id: importMaterialDialog
  239. title: catalog.i18nc("@title:window", "Import Material")
  240. selectExisting: true
  241. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  242. folder: CuraApplication.getDefaultPath("dialog_material_path")
  243. onAccepted:
  244. {
  245. var result = Cura.ContainerManager.importMaterialContainer(fileUrl);
  246. messageDialog.title = catalog.i18nc("@title:window", "Import Material");
  247. messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
  248. if (result.status == "success")
  249. {
  250. messageDialog.icon = StandardIcon.Information;
  251. messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully imported material <filename>%1</filename>").arg(fileUrl);
  252. }
  253. else if (result.status == "duplicate")
  254. {
  255. messageDialog.icon = StandardIcon.Warning;
  256. }
  257. else
  258. {
  259. messageDialog.icon = StandardIcon.Critical;
  260. }
  261. messageDialog.open();
  262. CuraApplication.setDefaultPath("dialog_material_path", folder);
  263. }
  264. }
  265. FileDialog
  266. {
  267. id: exportMaterialDialog
  268. title: catalog.i18nc("@title:window", "Export Material")
  269. selectExisting: false
  270. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  271. folder: CuraApplication.getDefaultPath("dialog_material_path")
  272. onAccepted:
  273. {
  274. var result = Cura.ContainerManager.exportContainer(base.currentItem.root_material_id, selectedNameFilter, fileUrl);
  275. messageDialog.title = catalog.i18nc("@title:window", "Export Material");
  276. if (result.status == "error")
  277. {
  278. messageDialog.icon = StandardIcon.Critical;
  279. messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> and <message>!", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
  280. messageDialog.open();
  281. }
  282. else if (result.status == "success")
  283. {
  284. messageDialog.icon = StandardIcon.Information;
  285. messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully exported material to <filename>%1</filename>").arg(result.path);
  286. messageDialog.open();
  287. }
  288. CuraApplication.setDefaultPath("dialog_material_path", folder);
  289. }
  290. }
  291. MessageDialog
  292. {
  293. id: messageDialog
  294. }
  295. }