ProfilesPage.qml 12 KB

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