DiscardOrKeepProfileChangesDialog.qml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Copyright (c) 2020 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Dialogs 1.2
  6. import QtQuick.Window 2.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. UM.Dialog
  10. {
  11. id: base
  12. title: catalog.i18nc("@title:window", "Discard or Keep changes")
  13. minimumWidth: UM.Theme.getSize("popup_dialog").width
  14. minimumHeight: UM.Theme.getSize("popup_dialog").height
  15. property var changesModel: Cura.UserChangesModel{ id: userChangesModel}
  16. onVisibilityChanged:
  17. {
  18. if(visible)
  19. {
  20. changesModel.forceUpdate()
  21. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  22. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  23. {
  24. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  25. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  26. {
  27. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  28. break;
  29. }
  30. }
  31. }
  32. }
  33. Row
  34. {
  35. id: infoTextRow
  36. height: childrenRect.height
  37. anchors.margins: UM.Theme.getSize("default_margin").width
  38. anchors.left: parent.left
  39. anchors.right: parent.right
  40. anchors.top: parent.top
  41. spacing: UM.Theme.getSize("default_margin").width
  42. UM.I18nCatalog
  43. {
  44. id: catalog;
  45. name: "cura"
  46. }
  47. Label
  48. {
  49. text: catalog.i18nc("@text:window, %1 is a profile name", "You have customized some profile settings.\nWould you like to Keep these changed settings after switching profiles?\nAlternatively, you can discard the changes to load the defaults from '%1'.").arg(Cura.MachineManager.activeQualityDisplayNameMap["main"])
  50. anchors.margins: UM.Theme.getSize("default_margin").width
  51. wrapMode: Text.WordWrap
  52. }
  53. }
  54. Item
  55. {
  56. anchors.margins: UM.Theme.getSize("default_margin").width
  57. anchors.top: infoTextRow.bottom
  58. anchors.bottom: optionRow.top
  59. anchors.left: parent.left
  60. anchors.right: parent.right
  61. TableView
  62. {
  63. anchors.fill: parent
  64. height: base.height - 150
  65. id: tableView
  66. Component
  67. {
  68. id: labelDelegate
  69. Label
  70. {
  71. property var extruder_name: userChangesModel.getItem(styleData.row).extruder
  72. anchors.left: parent.left
  73. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  74. anchors.right: parent.right
  75. elide: Text.ElideRight
  76. font: UM.Theme.getFont("system")
  77. text:
  78. {
  79. var result = styleData.value
  80. if (extruder_name != "")
  81. {
  82. result += " (" + extruder_name + ")"
  83. }
  84. return result
  85. }
  86. }
  87. }
  88. Component
  89. {
  90. id: defaultDelegate
  91. Label
  92. {
  93. text: styleData.value
  94. font: UM.Theme.getFont("system")
  95. }
  96. }
  97. TableViewColumn
  98. {
  99. role: "label"
  100. title: catalog.i18nc("@title:column", "Profile settings")
  101. delegate: labelDelegate
  102. width: (tableView.width * 0.4) | 0
  103. }
  104. TableViewColumn
  105. {
  106. role: "original_value"
  107. title: Cura.MachineManager.activeQualityDisplayNameMap["main"]
  108. width: (tableView.width * 0.3) | 0
  109. delegate: defaultDelegate
  110. }
  111. TableViewColumn
  112. {
  113. role: "user_value"
  114. title: catalog.i18nc("@title:column", "Current changes")
  115. width: (tableView.width * 0.3) | 0
  116. }
  117. section.property: "category"
  118. section.delegate: Label
  119. {
  120. text: section
  121. font.bold: true
  122. }
  123. model: userChangesModel
  124. }
  125. }
  126. Item
  127. {
  128. id: optionRow
  129. anchors.bottom: buttonsRow.top
  130. anchors.right: parent.right
  131. anchors.left: parent.left
  132. anchors.margins: UM.Theme.getSize("default_margin").width
  133. height: childrenRect.height
  134. ComboBox
  135. {
  136. id: discardOrKeepProfileChangesDropDownButton
  137. width: 300
  138. model: ListModel
  139. {
  140. id: discardOrKeepProfileListModel
  141. Component.onCompleted: {
  142. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  143. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  144. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  145. }
  146. }
  147. onActivated:
  148. {
  149. var code = model.get(index).code;
  150. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  151. if (code == "always_keep") {
  152. keepButton.enabled = true;
  153. discardButton.enabled = false;
  154. }
  155. else if (code == "always_discard") {
  156. keepButton.enabled = false;
  157. discardButton.enabled = true;
  158. }
  159. else {
  160. keepButton.enabled = true;
  161. discardButton.enabled = true;
  162. }
  163. }
  164. }
  165. }
  166. Item
  167. {
  168. id: buttonsRow
  169. anchors.bottom: parent.bottom
  170. anchors.right: parent.right
  171. anchors.left: parent.left
  172. anchors.margins: UM.Theme.getSize("default_margin").width
  173. height: childrenRect.height
  174. Button
  175. {
  176. id: discardButton
  177. text: catalog.i18nc("@action:button", "Discard changes");
  178. anchors.right: parent.right
  179. onClicked:
  180. {
  181. CuraApplication.discardOrKeepProfileChangesClosed("discard")
  182. base.hide()
  183. }
  184. isDefault: true
  185. }
  186. Button
  187. {
  188. id: keepButton
  189. text: catalog.i18nc("@action:button", "Keep changes");
  190. anchors.right: discardButton.left
  191. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  192. onClicked:
  193. {
  194. CuraApplication.discardOrKeepProfileChangesClosed("keep")
  195. base.hide()
  196. }
  197. }
  198. }
  199. }