ProfilesPage.qml 8.1 KB

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