ProfilesPage.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Dialogs 1.2
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. UM.ManagementPage
  9. {
  10. id: base;
  11. title: catalog.i18nc("@title:tab", "Profiles");
  12. property var extrudersModel: Cura.ExtrudersModel{}
  13. //Cura.ExtrudersModel { id: extrudersModel}
  14. model: UM.InstanceContainersModel
  15. {
  16. filter:
  17. {
  18. var result = { "type": "quality*", "extruder": null };
  19. if(Cura.MachineManager.filterQualityByMachine)
  20. {
  21. result.definition = Cura.MachineManager.activeDefinitionId;
  22. if(Cura.MachineManager.hasMaterials)
  23. {
  24. result.material = Cura.MachineManager.allActiveMaterialIds[Cura.MachineManager.activeMachineId];
  25. }
  26. }
  27. else
  28. {
  29. result.definition = "fdmprinter"
  30. }
  31. return result
  32. }
  33. }
  34. section.property: "readOnly"
  35. section.delegate: Rectangle
  36. {
  37. height: childrenRect.height;
  38. Label
  39. {
  40. anchors.left: parent.left;
  41. anchors.leftMargin: UM.Theme.getSize("default_lining").width;
  42. text: section == "true" ? catalog.i18nc("@label", "Protected profiles") : catalog.i18nc("@label", "Custom profiles")
  43. font.bold: true
  44. }
  45. }
  46. activeId: Cura.MachineManager.activeQualityId
  47. activeIndex: {
  48. for(var i = 0; i < model.rowCount(); i++) {
  49. if (model.getItem(i).id == Cura.MachineManager.activeQualityId) {
  50. return i;
  51. }
  52. }
  53. return -1;
  54. }
  55. function canCreateProfile() {
  56. return base.currentItem && (base.currentItem.id == Cura.MachineManager.activeQualityId) && Cura.MachineManager.hasUserSettings;
  57. }
  58. buttons: [
  59. Button
  60. {
  61. text: catalog.i18nc("@action:button", "Activate");
  62. iconName: "list-activate";
  63. enabled: base.currentItem != null ? base.currentItem.id != Cura.MachineManager.activeQualityId : false;
  64. onClicked: Cura.MachineManager.setActiveQuality(base.currentItem.id)
  65. },
  66. // Create button
  67. Button
  68. {
  69. text: catalog.i18nc("@label", "Create")
  70. enabled: base.canCreateProfile()
  71. visible: base.canCreateProfile()
  72. iconName: "list-add";
  73. onClicked:
  74. {
  75. newNameDialog.object = base.currentItem != null ? base.currentItem.name : "";
  76. newNameDialog.open();
  77. newNameDialog.selectText();
  78. }
  79. },
  80. // Duplicate button
  81. Button
  82. {
  83. text: catalog.i18nc("@label", "Duplicate")
  84. enabled: ! base.canCreateProfile()
  85. visible: ! base.canCreateProfile()
  86. iconName: "list-add";
  87. onClicked:
  88. {
  89. newDuplicateNameDialog.object = base.currentItem.name;
  90. newDuplicateNameDialog.open();
  91. newDuplicateNameDialog.selectText();
  92. }
  93. },
  94. Button
  95. {
  96. text: catalog.i18nc("@action:button", "Remove");
  97. iconName: "list-remove";
  98. enabled: base.currentItem != null ? !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id) : false;
  99. onClicked: confirmDialog.open();
  100. },
  101. Button
  102. {
  103. text: catalog.i18nc("@action:button", "Rename");
  104. iconName: "edit-rename";
  105. enabled: base.currentItem != null ? !base.currentItem.readOnly : false;
  106. onClicked:
  107. {
  108. renameDialog.open();
  109. renameDialog.selectText();
  110. }
  111. },
  112. Button
  113. {
  114. text: catalog.i18nc("@action:button", "Import");
  115. iconName: "document-import";
  116. onClicked: importDialog.open();
  117. },
  118. Button
  119. {
  120. text: catalog.i18nc("@action:button", "Export")
  121. iconName: "document-export"
  122. onClicked: exportDialog.open()
  123. enabled: currentItem != null
  124. }
  125. ]
  126. scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
  127. signal showProfileNameDialog()
  128. onShowProfileNameDialog:
  129. {
  130. renameDialog.removeWhenRejected = true;
  131. renameDialog.open();
  132. renameDialog.selectText();
  133. }
  134. signal selectContainer(string name)
  135. onSelectContainer:
  136. {
  137. objectList.currentIndex = objectList.model.find("name", name);
  138. }
  139. Item {
  140. visible: base.currentItem != null
  141. anchors.fill: parent
  142. Label {
  143. id: profileName
  144. text: base.currentItem ? base.currentItem.name : ""
  145. font: UM.Theme.getFont("large")
  146. width: parent.width
  147. elide: Text.ElideRight
  148. }
  149. Row {
  150. id: currentSettingsActions
  151. visible: currentItem && currentItem.id == Cura.MachineManager.activeQualityId
  152. anchors.left: parent.left
  153. anchors.top: profileName.bottom
  154. anchors.topMargin: UM.Theme.getSize("default_margin").height
  155. Button
  156. {
  157. text: {
  158. return catalog.i18nc("@action:button", "Update profile with current settings");
  159. }
  160. enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
  161. onClicked: Cura.ContainerManager.updateQualityChanges()
  162. }
  163. Button
  164. {
  165. text: catalog.i18nc("@action:button", "Discard current settings");
  166. enabled: Cura.MachineManager.hasUserSettings
  167. onClicked: Cura.ContainerManager.clearUserContainers();
  168. }
  169. }
  170. Column {
  171. id: profileNotices
  172. anchors.top: currentSettingsActions.visible ? currentSettingsActions.bottom : currentSettingsActions.anchors.top
  173. anchors.topMargin: UM.Theme.getSize("default_margin").height
  174. anchors.left: parent.left
  175. anchors.right: parent.right
  176. spacing: UM.Theme.getSize("default_margin").height
  177. Label {
  178. id: defaultsMessage
  179. visible: false
  180. text: catalog.i18nc("@action:label", "This profile uses the defaults specified by the printer, so it has no settings in the list below.")
  181. wrapMode: Text.WordWrap
  182. width: parent.width
  183. }
  184. Label {
  185. id: noCurrentSettingsMessage
  186. visible: currentItem && currentItem.id == Cura.MachineManager.activeQualityId && !Cura.MachineManager.hasUserSettings
  187. text: catalog.i18nc("@action:label", "Your current settings match the selected profile.")
  188. wrapMode: Text.WordWrap
  189. width: parent.width
  190. }
  191. }
  192. TabView
  193. {
  194. anchors.left: parent.left
  195. anchors.top: profileNotices.visible ? profileNotices.bottom : profileNotices.anchors.top
  196. anchors.topMargin: UM.Theme.getSize("default_margin").height
  197. anchors.right: parent.right
  198. anchors.bottom: parent.bottom
  199. ProfileTab
  200. {
  201. title: catalog.i18nc("@title:tab", "Global Settings");
  202. quality: base.currentItem != null ? base.currentItem.id : "";
  203. material: Cura.MachineManager.allActiveMaterialIds[Cura.MachineManager.activeMachineId]
  204. }
  205. Repeater
  206. {
  207. model: base.extrudersModel
  208. ProfileTab
  209. {
  210. title: model.name;
  211. extruderId: model.id;
  212. quality: base.currentItem != null ? base.currentItem.id : "";
  213. material: Cura.MachineManager.allActiveMaterialIds[model.id]
  214. }
  215. }
  216. }
  217. }
  218. Item
  219. {
  220. UM.I18nCatalog { id: catalog; name: "uranium"; }
  221. UM.ConfirmRemoveDialog
  222. {
  223. id: confirmDialog
  224. object: base.currentItem != null ? base.currentItem.name : ""
  225. onYes:
  226. {
  227. var name = base.currentItem.name;
  228. Cura.ContainerManager.removeQualityChanges(name)
  229. if(Cura.MachineManager.activeQualityName == name)
  230. {
  231. Cura.MachineManager.setActiveQuality(base.model.getItem(0).name)
  232. }
  233. objectList.currentIndex = -1 //Reset selection.
  234. }
  235. }
  236. UM.RenameDialog
  237. {
  238. id: renameDialog;
  239. object: base.currentItem != null ? base.currentItem.name : ""
  240. onAccepted:
  241. {
  242. Cura.ContainerManager.renameQualityChanges(base.currentItem.name, newName)
  243. objectList.currentIndex = -1 //Reset selection.
  244. }
  245. }
  246. // Dialog to request a name when creating a new profile
  247. UM.RenameDialog
  248. {
  249. id: newNameDialog;
  250. object: "<new name>";
  251. onAccepted:
  252. {
  253. var selectedContainer = Cura.ContainerManager.createQualityChanges(newName);
  254. base.selectContainer(selectedContainer);
  255. objectList.currentIndex = -1 //Reset selection.
  256. }
  257. }
  258. // Dialog to request a name when duplicating a new profile
  259. UM.RenameDialog
  260. {
  261. id: newDuplicateNameDialog;
  262. object: "<new name>";
  263. onAccepted:
  264. {
  265. var selectedContainer = Cura.ContainerManager.duplicateQualityOrQualityChanges(base.currentItem.name, newName);
  266. base.selectContainer(selectedContainer);
  267. objectList.currentIndex = -1 //Reset selection.
  268. }
  269. }
  270. MessageDialog
  271. {
  272. id: messageDialog
  273. title: catalog.i18nc("@window:title", "Import Profile");
  274. standardButtons: StandardButton.Ok
  275. modality: Qt.ApplicationModal
  276. }
  277. FileDialog
  278. {
  279. id: importDialog;
  280. title: catalog.i18nc("@title:window", "Import Profile");
  281. selectExisting: true;
  282. nameFilters: base.model.getFileNameFilters("profile_reader")
  283. folder: CuraApplication.getDefaultPath("dialog_profile_path")
  284. onAccepted:
  285. {
  286. var result = base.model.importProfile(fileUrl)
  287. messageDialog.text = result.message
  288. if(result.status == "ok")
  289. {
  290. messageDialog.icon = StandardIcon.Information
  291. }
  292. else if(result.status == "duplicate")
  293. {
  294. messageDialog.icon = StandardIcon.Warning
  295. }
  296. else
  297. {
  298. messageDialog.icon = StandardIcon.Critical
  299. }
  300. messageDialog.open()
  301. CuraApplication.setDefaultPath("dialog_profile_path", folder)
  302. }
  303. }
  304. FileDialog
  305. {
  306. id: exportDialog;
  307. title: catalog.i18nc("@title:window", "Export Profile");
  308. selectExisting: false;
  309. nameFilters: base.model.getFileNameFilters("profile_writer")
  310. folder: CuraApplication.getDefaultPath("dialog_profile_path")
  311. onAccepted:
  312. {
  313. var profiles_to_export = [base.currentItem.id]
  314. for(var extruder_nr in base.extrudersModel.items)
  315. {
  316. profiles_to_export.push(ExtruderManager.getQualityChangesIdByExtruderStackId(base.extrudersModel.items[extruder_nr].id))
  317. }
  318. var result = base.model.exportProfile(profiles_to_export, fileUrl, selectedNameFilter)
  319. if(result && result.status == "error")
  320. {
  321. messageDialog.icon = StandardIcon.Critical
  322. messageDialog.text = result.message
  323. messageDialog.open()
  324. }
  325. // else pop-up Message thing from python code
  326. CuraApplication.setDefaultPath("dialog_profile_path", folder)
  327. }
  328. }
  329. }
  330. }