ProfilesPage.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.8
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Layouts 1.3
  6. import QtQuick.Dialogs 1.2
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. id: base
  12. property var resetEnabled: false // Keep PreferencesDialog happy
  13. property var extrudersModel: Cura.ExtrudersModel{}
  14. UM.I18nCatalog { id: catalog; name: "cura"; }
  15. Cura.QualityManagementModel {
  16. id: qualitiesModel
  17. }
  18. Label {
  19. id: titleLabel
  20. anchors {
  21. top: parent.top
  22. left: parent.left
  23. right: parent.right
  24. margins: 5 * screenScaleFactor
  25. }
  26. font.pointSize: 18
  27. text: catalog.i18nc("@title:tab", "Profiles")
  28. }
  29. property var hasCurrentItem: qualityListView.currentItem != null
  30. property var currentItem: {
  31. var current_index = qualityListView.currentIndex;
  32. return qualitiesModel.getItem(current_index);
  33. }
  34. property var isCurrentItemActivated: {
  35. if (!base.currentItem) {
  36. return false;
  37. }
  38. return base.currentItem.name == Cura.MachineManager.activeQualityOrQualityChangesName;
  39. }
  40. property var canCreateProfile: {
  41. return isCurrentItemActivated && Cura.MachineManager.hasUserSettings;
  42. }
  43. Row // Button Row
  44. {
  45. id: buttonRow
  46. anchors {
  47. left: parent.left
  48. right: parent.right
  49. top: titleLabel.bottom
  50. }
  51. height: childrenRect.height
  52. // Activate button
  53. Button
  54. {
  55. text: catalog.i18nc("@action:button", "Activate")
  56. iconName: "list-activate"
  57. enabled: !isCurrentItemActivated
  58. onClicked: {
  59. if (base.currentItem.is_read_only) {
  60. Cura.MachineManager.setQualityGroup(base.currentItem.quality_group);
  61. } else {
  62. Cura.MachineManager.setQualityChangesGroup(base.currentItem.quality_changes_group);
  63. }
  64. }
  65. }
  66. // Create button
  67. Button
  68. {
  69. text: catalog.i18nc("@label", "Create")
  70. iconName: "list-add"
  71. enabled: base.canCreateProfile && !Cura.MachineManager.stacksHaveErrors
  72. visible: base.canCreateProfile
  73. onClicked: {
  74. newNameDialog.object = base.currentItem != null ? Cura.ContainerManager.makeUniqueName(Cura.MachineManager.activeQualityOrQualityChangesName) : "";
  75. newNameDialog.open();
  76. newNameDialog.selectText();
  77. }
  78. }
  79. // Duplicate button
  80. Button
  81. {
  82. text: catalog.i18nc("@label", "Duplicate")
  83. iconName: "list-add"
  84. enabled: !base.canCreateProfile
  85. visible: !base.canCreateProfile
  86. onClicked: {
  87. // TODO
  88. }
  89. }
  90. // Remove button
  91. Button
  92. {
  93. text: catalog.i18nc("@action:button", "Remove")
  94. iconName: "list-remove"
  95. //enabled: base.currentItem != null ? !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id) : false;
  96. enabled: true // TODO
  97. onClicked: {
  98. // TODO
  99. }
  100. }
  101. // Rename button
  102. Button
  103. {
  104. text: catalog.i18nc("@action:button", "Rename")
  105. iconName: "edit-rename"
  106. //enabled: base.currentItem != null ? !base.currentItem.readOnly : false;
  107. enabled: true // TODO
  108. onClicked: {
  109. // TODO
  110. }
  111. }
  112. // Import button
  113. Button
  114. {
  115. text: catalog.i18nc("@action:button", "Import")
  116. iconName: "document-import"
  117. onClicked: {
  118. // TODO
  119. }
  120. }
  121. // Export button
  122. Button
  123. {
  124. text: catalog.i18nc("@action:button", "Export")
  125. iconName: "document-export"
  126. //enabled: currentItem != null && !base.currentItem.readOnly
  127. enabled: true // TODO
  128. onClicked: {
  129. // TODO
  130. }
  131. }
  132. }
  133. // Dialog to request a name when creating a new profile
  134. UM.RenameDialog
  135. {
  136. title: catalog.i18nc("@title:window", "Create Profile")
  137. id: newNameDialog;
  138. object: "<new name>";
  139. onAccepted:
  140. {
  141. var selectedContainer = Cura.ContainerManager.createQualityChanges(newName);
  142. objectList.currentIndex = -1 //Reset selection.
  143. }
  144. }
  145. Item {
  146. id: contentsItem
  147. anchors {
  148. top: titleLabel.bottom
  149. left: parent.left
  150. right: parent.right
  151. bottom: parent.bottom
  152. margins: 5 * screenScaleFactor
  153. bottomMargin: 0
  154. }
  155. clip: true
  156. }
  157. Item
  158. {
  159. anchors {
  160. top: buttonRow.bottom
  161. topMargin: UM.Theme.getSize("default_margin").height
  162. left: parent.left
  163. right: parent.right
  164. bottom: parent.bottom
  165. }
  166. SystemPalette { id: palette }
  167. Label
  168. {
  169. id: captionLabel
  170. anchors {
  171. top: parent.top
  172. left: parent.left
  173. }
  174. visible: text != ""
  175. text: {
  176. // OLD STUFF
  177. return catalog.i18nc("@label %1 is printer name", "Printer: %1").arg(Cura.MachineManager.activeMachineName);
  178. }
  179. width: profileScrollView.width
  180. elide: Text.ElideRight
  181. }
  182. ScrollView
  183. {
  184. id: profileScrollView
  185. anchors {
  186. top: captionLabel.visible ? captionLabel.bottom : parent.top
  187. topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
  188. bottom: parent.bottom
  189. left: parent.left
  190. }
  191. Rectangle {
  192. parent: viewport
  193. anchors.fill: parent
  194. color: palette.light
  195. }
  196. width: true ? (parent.width * 0.4) | 0 : parent.width
  197. ListView
  198. {
  199. id: qualityListView
  200. model: qualitiesModel
  201. section.property: "is_read_only"
  202. section.delegate: Rectangle
  203. {
  204. height: childrenRect.height
  205. Label
  206. {
  207. anchors.left: parent.left
  208. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  209. text: section == "true" ? catalog.i18nc("@label", "Protected profiles") : catalog.i18nc("@label", "Custom profiles")
  210. font.bold: true
  211. }
  212. }
  213. delegate: Rectangle
  214. {
  215. width: profileScrollView.width
  216. height: childrenRect.height
  217. color: ListView.isCurrentItem ? palette.highlight : (model.index % 2) ? palette.base : palette.alternateBase
  218. Row
  219. {
  220. spacing: (UM.Theme.getSize("default_margin").width / 2) | 0
  221. anchors.left: parent.left
  222. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  223. anchors.right: parent.right
  224. Label
  225. {
  226. width: Math.floor((parent.width * 0.3))
  227. text: model.name
  228. elide: Text.ElideRight
  229. font.italic: { // TODO: make it easier
  230. return model.name == Cura.MachineManager.activeQualityOrQualityChangesName;
  231. }
  232. color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text;
  233. }
  234. }
  235. MouseArea
  236. {
  237. anchors.fill: parent
  238. onClicked: {
  239. parent.ListView.view.currentIndex = model.index;
  240. }
  241. }
  242. }
  243. onCurrentIndexChanged:
  244. {
  245. var model = qualitiesModel.getItem(currentIndex);
  246. // TODO
  247. }
  248. }
  249. }
  250. // details panel on the right
  251. Item
  252. {
  253. id: detailsPanel
  254. anchors {
  255. left: profileScrollView.right
  256. leftMargin: UM.Theme.getSize("default_margin").width
  257. top: parent.top
  258. bottom: parent.bottom
  259. right: parent.right
  260. }
  261. Item
  262. {
  263. anchors.fill: parent
  264. Item // Profile title Label
  265. {
  266. id: profileName
  267. width: parent.width
  268. height: childrenRect.height
  269. Label {
  270. text: base.currentItem.name // TODO
  271. font: UM.Theme.getFont("large")
  272. }
  273. }
  274. Flow {
  275. id: currentSettingsActions
  276. visible: true // TODO //currentItem && currentItem.id == Cura.MachineManager.activeQualityId
  277. anchors.left: parent.left
  278. anchors.right: parent.right
  279. anchors.top: profileName.bottom
  280. anchors.topMargin: UM.Theme.getSize("default_margin").height
  281. Button
  282. {
  283. text: {
  284. return catalog.i18nc("@action:button", "Update profile with current settings/overrides");
  285. }
  286. enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
  287. onClicked: Cura.ContainerManager.updateQualityChanges()
  288. }
  289. Button
  290. {
  291. text: catalog.i18nc("@action:button", "Discard current changes");
  292. enabled: Cura.MachineManager.hasUserSettings
  293. onClicked: Cura.ContainerManager.clearUserContainers();
  294. }
  295. }
  296. Column {
  297. id: profileNotices
  298. anchors.top: currentSettingsActions.visible ? currentSettingsActions.bottom : currentSettingsActions.anchors.top
  299. anchors.topMargin: UM.Theme.getSize("default_margin").height
  300. anchors.left: parent.left
  301. anchors.right: parent.right
  302. spacing: UM.Theme.getSize("default_margin").height
  303. Label {
  304. id: defaultsMessage
  305. visible: false
  306. text: catalog.i18nc("@action:label", "This profile uses the defaults specified by the printer, so it has no settings/overrides in the list below.")
  307. wrapMode: Text.WordWrap
  308. width: parent.width
  309. }
  310. Label {
  311. id: noCurrentSettingsMessage
  312. visible: currentItem && currentItem.id == Cura.MachineManager.activeQualityId && !Cura.MachineManager.hasUserSettings
  313. text: catalog.i18nc("@action:label", "Your current settings match the selected profile.")
  314. wrapMode: Text.WordWrap
  315. width: parent.width
  316. }
  317. }
  318. TabView
  319. {
  320. anchors.left: parent.left
  321. anchors.top: profileNotices.visible ? profileNotices.bottom : profileNotices.anchors.top
  322. anchors.topMargin: UM.Theme.getSize("default_margin").height
  323. anchors.right: parent.right
  324. anchors.bottom: parent.bottom
  325. currentIndex: 0
  326. ProfileTab
  327. {
  328. title: catalog.i18nc("@title:tab", "Global Settings");
  329. quality: base.currentItem;
  330. }
  331. Repeater
  332. {
  333. model: base.extrudersModel
  334. ProfileTab
  335. {
  336. title: model.name;
  337. extruderPosition: model.index;
  338. quality: base.currentItem;
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }