MaterialsPage.qml 11 KB

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