ProfilesPage.qml 12 KB

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