ProfilesPage.qml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. addText: catalog.i18nc("@label", "Duplicate")
  13. model: UM.InstanceContainersModel
  14. {
  15. filter:
  16. {
  17. var result = { "type": "quality" };
  18. if(Cura.MachineManager.filterQualityByMachine)
  19. {
  20. result.definition = Cura.MachineManager.activeDefinitionId;
  21. if(Cura.MachineManager.hasMaterials)
  22. {
  23. result.material = Cura.MachineManager.activeMaterialId;
  24. }
  25. }
  26. else
  27. {
  28. result.definition = "fdmprinter"
  29. }
  30. return result
  31. }
  32. }
  33. activeId: Cura.MachineManager.activeQualityId
  34. activeIndex: {
  35. for(var i = 0; i < model.rowCount(); i++) {
  36. if (model.getItem(i).id == Cura.MachineManager.activeQualityId) {
  37. return i;
  38. }
  39. }
  40. return -1;
  41. }
  42. onActivateObject: Cura.MachineManager.setActiveQuality(currentItem.id)
  43. onAddObject: {
  44. var selectedContainer;
  45. if (objectList.currentIndex == 0) {
  46. // Current settings
  47. selectedContainer = Cura.MachineManager.convertUserContainerToQuality();
  48. } else {
  49. selectedContainer = Cura.MachineManager.duplicateContainer(base.currentItem.id);
  50. }
  51. base.selectContainer(selectedContainer);
  52. renameDialog.removeWhenRejected = true;
  53. renameDialog.open();
  54. renameDialog.selectText();
  55. }
  56. onRemoveObject: confirmDialog.open();
  57. onRenameObject: { renameDialog.removeWhenRejected = false; renameDialog.open(); renameDialog.selectText(); }
  58. activateEnabled: currentItem != null ? currentItem.id != Cura.MachineManager.activeQualityId : false;
  59. addEnabled: currentItem != null;
  60. removeEnabled: currentItem != null ? !currentItem.metadata.read_only : false;
  61. renameEnabled: currentItem != null ? !currentItem.metadata.read_only : false;
  62. scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
  63. signal showProfileNameDialog()
  64. onShowProfileNameDialog: { renameDialog.removeWhenRejected = true; renameDialog.open(); renameDialog.selectText(); }
  65. signal selectContainer(string id)
  66. onSelectContainer: {
  67. objectList.currentIndex = objectList.model.find("id", id);
  68. }
  69. Item {
  70. visible: base.currentItem != null
  71. anchors.fill: parent
  72. Label {
  73. id: profileName
  74. text: base.currentItem ? base.currentItem.name : ""
  75. font: UM.Theme.getFont("large")
  76. width: parent.width
  77. elide: Text.ElideRight
  78. }
  79. ScrollView {
  80. anchors.left: parent.left
  81. anchors.top: profileName.bottom
  82. anchors.topMargin: UM.Theme.getSize("default_margin").height
  83. anchors.right: parent.right
  84. anchors.bottom: parent.bottom
  85. Column
  86. {
  87. spacing: UM.Theme.getSize("default_margin").height
  88. Row
  89. {
  90. visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
  91. Button
  92. {
  93. text: {
  94. var profileName = Cura.MachineManager.activeQualityName;
  95. profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
  96. return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
  97. }
  98. enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
  99. onClicked: Cura.MachineManager.updateUserContainerToQuality()
  100. }
  101. Button
  102. {
  103. text: catalog.i18nc("@action:button", "Discard changes");
  104. enabled: Cura.MachineManager.hasUserSettings
  105. onClicked: Cura.MachineManager.clearUserSettings();
  106. }
  107. }
  108. Grid
  109. {
  110. id: containerGrid
  111. columns: 2
  112. spacing: UM.Theme.getSize("default_margin").width
  113. Label {
  114. text: base.currentItem == null ? "" :
  115. base.currentItem.id == -1 ? catalog.i18nc("@label", "Based on") : catalog.i18nc("@label", "Profile type")
  116. }
  117. Label {
  118. text: base.currentItem == null ? "" :
  119. base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName:
  120. base.currentItem.metadata.read_only ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
  121. }
  122. Column {
  123. Repeater {
  124. model: base.currentItem ? base.currentItem.settings : null
  125. Label {
  126. text: modelData.name.toString();
  127. elide: Text.ElideMiddle;
  128. }
  129. }
  130. }
  131. Column {
  132. Repeater {
  133. model: base.currentItem ? base.currentItem.settings : null
  134. Label { text: modelData.value.toString(); }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. buttons: Row {
  142. Button
  143. {
  144. text: catalog.i18nc("@action:button", "Import");
  145. iconName: "document-import";
  146. onClicked: importDialog.open();
  147. }
  148. Button
  149. {
  150. text: catalog.i18nc("@action:button", "Export")
  151. iconName: "document-export"
  152. onClicked: exportDialog.open()
  153. enabled: currentItem != null
  154. }
  155. }
  156. Item
  157. {
  158. UM.I18nCatalog { id: catalog; name: "uranium"; }
  159. UM.ConfirmRemoveDialog
  160. {
  161. id: confirmDialog;
  162. object: base.currentItem != null ? base.currentItem.name : "";
  163. onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id);
  164. }
  165. UM.RenameDialog
  166. {
  167. id: renameDialog;
  168. object: base.currentItem != null ? base.currentItem.name : "";
  169. property bool removeWhenRejected: false;
  170. onAccepted: base.model.rename(base.currentItem.id, newName.trim());
  171. onRejected: {
  172. if(removeWhenRejected) {
  173. base.model.removeProfile(base.currentItem.name)
  174. }
  175. }
  176. }
  177. MessageDialog
  178. {
  179. id: messageDialog
  180. title: catalog.i18nc("@window:title", "Import Profile");
  181. standardButtons: StandardButton.Ok
  182. modality: Qt.ApplicationModal
  183. }
  184. FileDialog
  185. {
  186. id: importDialog;
  187. title: catalog.i18nc("@title:window", "Import Profile");
  188. selectExisting: true;
  189. nameFilters: base.model.getFileNameFiltersRead()
  190. folder: base.model.getDefaultPath()
  191. onAccepted:
  192. {
  193. var result = base.model.importProfile(fileUrl)
  194. messageDialog.text = result.message
  195. if(result.status == "ok")
  196. {
  197. messageDialog.icon = StandardIcon.Information
  198. }
  199. else if(result.status == "duplicate")
  200. {
  201. messageDialog.icon = StandardIcon.Warning
  202. }
  203. else
  204. {
  205. messageDialog.icon = StandardIcon.Critical
  206. }
  207. messageDialog.open()
  208. }
  209. }
  210. FileDialog
  211. {
  212. id: exportDialog;
  213. title: catalog.i18nc("@title:window", "Export Profile");
  214. selectExisting: false;
  215. nameFilters: base.model.getFileNameFiltersWrite()
  216. folder: base.model.getDefaultPath()
  217. onAccepted:
  218. {
  219. var result = base.model.exportProfile(base.currentItem.id, base.currentItem.name, fileUrl, selectedNameFilter)
  220. if(result && result.status == "error")
  221. {
  222. messageDialog.icon = StandardIcon.Critical
  223. messageDialog.text = result.message
  224. messageDialog.open()
  225. }
  226. // else pop-up Message thing from python code
  227. }
  228. }
  229. }
  230. }