ProfilesPage.qml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. Row {
  80. id: currentSettingsActions
  81. visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
  82. anchors.left: parent.left
  83. anchors.top: profileName.bottom
  84. anchors.topMargin: UM.Theme.getSize("default_margin").height
  85. Button
  86. {
  87. text: {
  88. var profileName = Cura.MachineManager.activeQualityName;
  89. profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
  90. return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
  91. }
  92. enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
  93. onClicked: Cura.MachineManager.updateUserContainerToQuality()
  94. }
  95. Button
  96. {
  97. text: catalog.i18nc("@action:button", "Discard changes");
  98. enabled: Cura.MachineManager.hasUserSettings
  99. onClicked: Cura.MachineManager.clearUserSettings();
  100. }
  101. }
  102. ScrollView {
  103. id: scrollView
  104. anchors.left: parent.left
  105. anchors.top: currentSettingsActions.visible ? currentSettingsActions.bottom : profileName.bottom
  106. anchors.topMargin: UM.Theme.getSize("default_margin").height
  107. anchors.right: parent.right
  108. anchors.bottom: parent.bottom
  109. ListView {
  110. model: base.currentItem ? base.currentItem.settings: null
  111. delegate: Row {
  112. spacing: UM.Theme.getSize("default_margin").width
  113. Label {
  114. text: model.label
  115. elide: Text.ElideMiddle
  116. width: scrollView.width / 100 * 40
  117. }
  118. Label {
  119. text: model.value.toString()
  120. }
  121. Label {
  122. text: model.unit
  123. }
  124. }
  125. section.property: "category"
  126. section.criteria: ViewSection.FullString
  127. section.delegate: Label {
  128. text: section
  129. font.bold: true
  130. }
  131. }
  132. }
  133. }
  134. buttons: Row {
  135. Button
  136. {
  137. text: catalog.i18nc("@action:button", "Import");
  138. iconName: "document-import";
  139. onClicked: importDialog.open();
  140. }
  141. Button
  142. {
  143. text: catalog.i18nc("@action:button", "Export")
  144. iconName: "document-export"
  145. onClicked: exportDialog.open()
  146. enabled: currentItem != null
  147. }
  148. }
  149. Item
  150. {
  151. UM.I18nCatalog { id: catalog; name: "uranium"; }
  152. UM.ConfirmRemoveDialog
  153. {
  154. id: confirmDialog
  155. object: base.currentItem != null ? base.currentItem.name : ""
  156. onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id)
  157. }
  158. UM.RenameDialog
  159. {
  160. id: renameDialog;
  161. object: base.currentItem != null ? base.currentItem.name : ""
  162. property bool removeWhenRejected: false
  163. onAccepted: Cura.MachineManager.renameQualityContainer(base.currentItem.id, newName)
  164. onRejected: {
  165. if(removeWhenRejected) {
  166. Cura.MachineManager.removeQualityContainer(base.currentItem.id)
  167. }
  168. }
  169. }
  170. MessageDialog
  171. {
  172. id: messageDialog
  173. title: catalog.i18nc("@window:title", "Import Profile");
  174. standardButtons: StandardButton.Ok
  175. modality: Qt.ApplicationModal
  176. }
  177. FileDialog
  178. {
  179. id: importDialog;
  180. title: catalog.i18nc("@title:window", "Import Profile");
  181. selectExisting: true;
  182. nameFilters: base.model.getFileNameFiltersRead()
  183. folder: base.model.getDefaultPath()
  184. onAccepted:
  185. {
  186. var result = base.model.importProfile(fileUrl)
  187. messageDialog.text = result.message
  188. if(result.status == "ok")
  189. {
  190. messageDialog.icon = StandardIcon.Information
  191. }
  192. else if(result.status == "duplicate")
  193. {
  194. messageDialog.icon = StandardIcon.Warning
  195. }
  196. else
  197. {
  198. messageDialog.icon = StandardIcon.Critical
  199. }
  200. messageDialog.open()
  201. }
  202. }
  203. FileDialog
  204. {
  205. id: exportDialog;
  206. title: catalog.i18nc("@title:window", "Export Profile");
  207. selectExisting: false;
  208. nameFilters: base.model.getFileNameFiltersWrite()
  209. folder: base.model.getDefaultPath()
  210. onAccepted:
  211. {
  212. var result = base.model.exportProfile(base.currentItem.id, fileUrl)
  213. if(result && result.status == "error")
  214. {
  215. messageDialog.icon = StandardIcon.Critical
  216. messageDialog.text = result.message
  217. messageDialog.open()
  218. }
  219. // else pop-up Message thing from python code
  220. }
  221. }
  222. }
  223. }