ProfilesPage.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.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.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.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: (currentItem.id == Cura.MachineManager.activeQualityId) ? [base.currentItem.id, Cura.MachineManager.activeUserProfileId] : [base.currentItem.id] }
  176. delegate: Row {
  177. property variant setting: model
  178. spacing: UM.Theme.getSize("default_margin").width/2
  179. Label {
  180. text: model.label
  181. elide: Text.ElideMiddle
  182. width: scrollView.width / 100 * 40
  183. }
  184. Repeater {
  185. model: setting.values.length
  186. Label {
  187. text: setting.values[index].toString()
  188. width: scrollView.width / 100 * 15
  189. elide: Text.ElideRight
  190. font.strikeout: index < setting.values.length - 1 && setting.values[index + 1] != ""
  191. opacity: font.strikeout ? 0.5 : 1
  192. }
  193. }
  194. Label {
  195. text: model.unit
  196. }
  197. }
  198. header: Row {
  199. visible: currentItem.id == Cura.MachineManager.activeQualityId
  200. spacing: UM.Theme.getSize("default_margin").width
  201. Label {
  202. text: catalog.i18nc("@action:label", "Profile:")
  203. width: scrollView.width / 100 * 55
  204. horizontalAlignment: Text.AlignRight
  205. font.bold: true
  206. }
  207. Label {
  208. text: catalog.i18nc("@action:label", "Current:")
  209. visible: currentItem.id == Cura.MachineManager.activeQualityId
  210. font.bold: true
  211. }
  212. }
  213. section.property: "category"
  214. section.criteria: ViewSection.FullString
  215. section.delegate: Label {
  216. text: section
  217. font.bold: true
  218. }
  219. }
  220. }
  221. }
  222. Item
  223. {
  224. UM.I18nCatalog { id: catalog; name: "uranium"; }
  225. UM.ConfirmRemoveDialog
  226. {
  227. id: confirmDialog
  228. object: base.currentItem != null ? base.currentItem.name : ""
  229. onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id)
  230. }
  231. UM.RenameDialog
  232. {
  233. id: renameDialog;
  234. object: base.currentItem != null ? base.currentItem.name : ""
  235. property bool removeWhenRejected: false
  236. onAccepted: Cura.MachineManager.renameQualityContainer(base.currentItem.id, newName)
  237. onRejected: {
  238. if(removeWhenRejected) {
  239. Cura.MachineManager.removeQualityContainer(base.currentItem.id)
  240. }
  241. }
  242. }
  243. MessageDialog
  244. {
  245. id: messageDialog
  246. title: catalog.i18nc("@window:title", "Import Profile");
  247. standardButtons: StandardButton.Ok
  248. modality: Qt.ApplicationModal
  249. }
  250. FileDialog
  251. {
  252. id: importDialog;
  253. title: catalog.i18nc("@title:window", "Import Profile");
  254. selectExisting: true;
  255. nameFilters: base.model.getFileNameFilters("profile_reader")
  256. folder: base.model.getDefaultPath()
  257. onAccepted:
  258. {
  259. var result = base.model.importProfile(fileUrl)
  260. messageDialog.text = result.message
  261. if(result.status == "ok")
  262. {
  263. messageDialog.icon = StandardIcon.Information
  264. }
  265. else if(result.status == "duplicate")
  266. {
  267. messageDialog.icon = StandardIcon.Warning
  268. }
  269. else
  270. {
  271. messageDialog.icon = StandardIcon.Critical
  272. }
  273. messageDialog.open()
  274. }
  275. }
  276. FileDialog
  277. {
  278. id: exportDialog;
  279. title: catalog.i18nc("@title:window", "Export Profile");
  280. selectExisting: false;
  281. nameFilters: base.model.getFileNameFilters("profile_writer")
  282. folder: base.model.getDefaultPath()
  283. onAccepted:
  284. {
  285. var result = base.model.exportProfile(base.currentItem.id, fileUrl, selectedNameFilter)
  286. if(result && result.status == "error")
  287. {
  288. messageDialog.icon = StandardIcon.Critical
  289. messageDialog.text = result.message
  290. messageDialog.open()
  291. }
  292. // else pop-up Message thing from python code
  293. }
  294. }
  295. }
  296. }