DiscardOrKeepProfileChangesDialog.qml 6.9 KB

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