QualitiesWithIntentMenu.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.6 as Cura
  7. Popup
  8. {
  9. id: popup
  10. implicitWidth: 400
  11. property var dataModel: Cura.IntentCategoryModel {}
  12. property int defaultMargin: UM.Theme.getSize("default_margin").width
  13. property color backgroundColor: UM.Theme.getColor("main_background")
  14. property color borderColor: UM.Theme.getColor("lining")
  15. topPadding: UM.Theme.getSize("narrow_margin").height
  16. rightPadding: UM.Theme.getSize("default_lining").width
  17. leftPadding: UM.Theme.getSize("default_lining").width
  18. padding: 0
  19. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  20. background: Cura.RoundedRectangle
  21. {
  22. color: backgroundColor
  23. border.width: UM.Theme.getSize("default_lining").width
  24. border.color: borderColor
  25. cornerSide: Cura.RoundedRectangle.Direction.Down
  26. }
  27. ButtonGroup
  28. {
  29. id: buttonGroup
  30. exclusive: true
  31. onClicked: popup.visible = false
  32. }
  33. contentItem: Column
  34. {
  35. // This repeater adds the intent labels
  36. ScrollView
  37. {
  38. id: qualityListScrollView
  39. property real maximumHeight: screenScaleFactor * 400
  40. contentHeight: dataColumn.height
  41. height: Math.min(contentHeight, maximumHeight)
  42. width: parent.width
  43. clip: true
  44. ScrollBar.vertical: UM.ScrollBar
  45. {
  46. id: qualityListScrollBar
  47. parent: qualityListScrollView
  48. anchors
  49. {
  50. top: parent.top
  51. right: parent.right
  52. bottom: parent.bottom
  53. }
  54. }
  55. Column
  56. {
  57. id: dataColumn
  58. width: qualityListScrollView.width - qualityListScrollBar.width
  59. Repeater
  60. {
  61. model: dataModel
  62. delegate: Item
  63. {
  64. // We need to set it like that, otherwise we'd have to set the sub model with model: model.qualities
  65. // Which obviously won't work due to naming conflicts.
  66. property variant subItemModel: model.qualities
  67. height: childrenRect.height
  68. width: dataColumn.width
  69. UM.Label
  70. {
  71. id: headerLabel
  72. text: model.name
  73. color: UM.Theme.getColor("text_inactive")
  74. width: parent.width
  75. height: visible ? contentHeight: 0
  76. visible: qualitiesList.visibleChildren.length > 0
  77. anchors.left: parent.left
  78. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  79. MouseArea // tooltip hover area
  80. {
  81. anchors.fill: parent
  82. hoverEnabled: true
  83. enabled: model.description !== undefined
  84. acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
  85. onEntered:
  86. {
  87. base.showTooltip(
  88. headerLabel,
  89. Qt.point(- UM.Theme.getSize("default_margin").width, 0),
  90. model.description
  91. )
  92. }
  93. onExited: base.hideTooltip()
  94. }
  95. }
  96. Column
  97. {
  98. id: qualitiesList
  99. anchors.top: headerLabel.bottom
  100. anchors.left: parent.left
  101. anchors.right: parent.right
  102. // Add the qualities that belong to the intent
  103. Repeater
  104. {
  105. visible: false
  106. model: subItemModel
  107. MenuButton
  108. {
  109. id: button
  110. onClicked: Cura.IntentManager.selectIntent(model.intent_category, model.quality_type)
  111. width: parent.width
  112. checkable: true
  113. visible: model.available
  114. text: model.name + " - " + model.layer_height + " mm"
  115. leftPadding: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("narrow_margin").width
  116. checked:
  117. {
  118. if (Cura.MachineManager.hasCustomQuality)
  119. {
  120. // When user created profile is active, no quality tickbox should be active.
  121. return false;
  122. }
  123. return Cura.MachineManager.activeQualityType == model.quality_type && Cura.MachineManager.activeIntentCategory == model.intent_category;
  124. }
  125. ButtonGroup.group: buttonGroup
  126. }
  127. }
  128. }
  129. }
  130. }
  131. //Another "intent category" for custom profiles.
  132. Item
  133. {
  134. height: childrenRect.height
  135. width: dataColumn.width
  136. UM.Label
  137. {
  138. id: customProfileHeader
  139. text: catalog.i18nc("@label:header", "Custom profiles")
  140. height: visible ? contentHeight: 0
  141. enabled: false
  142. visible: profilesList.visibleChildren.length > 1
  143. anchors.left: parent.left
  144. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  145. color: UM.Theme.getColor("text_inactive")
  146. }
  147. Column
  148. {
  149. id: profilesList
  150. anchors
  151. {
  152. top: customProfileHeader.bottom
  153. left: parent.left
  154. right: parent.right
  155. }
  156. //We set it by means of a binding, since then we can use the
  157. //"when" condition, which we need to prevent a binding loop.
  158. Binding
  159. {
  160. target: parent
  161. property: "height"
  162. value: parent.childrenRect.height
  163. when: parent.visibleChildren.length > 1
  164. }
  165. //Add all the custom profiles.
  166. Repeater
  167. {
  168. model: Cura.CustomQualityProfilesDropDownMenuModel
  169. MenuButton
  170. {
  171. onClicked: Cura.MachineManager.setQualityChangesGroup(model.quality_changes_group)
  172. width: parent.width
  173. checkable: true
  174. visible: model.available
  175. text: model.name
  176. leftPadding: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("narrow_margin").width
  177. checked:
  178. {
  179. var active_quality_group = Cura.MachineManager.activeQualityChangesGroup
  180. if (active_quality_group != null)
  181. {
  182. return active_quality_group.name == model.quality_changes_group.name
  183. }
  184. return false
  185. }
  186. ButtonGroup.group: buttonGroup
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. Rectangle
  194. {
  195. height: UM.Theme.getSize("default_lining").height
  196. anchors.left: parent.left
  197. anchors.right: parent.right
  198. color: borderColor
  199. }
  200. MenuButton
  201. {
  202. labelText: Cura.Actions.addProfile.text
  203. anchors.left: parent.left
  204. anchors.right: parent.right
  205. enabled: Cura.Actions.addProfile.enabled
  206. onClicked:
  207. {
  208. Cura.Actions.addProfile.trigger()
  209. popup.visible = false
  210. }
  211. }
  212. MenuButton
  213. {
  214. labelText: Cura.Actions.updateProfile.text
  215. anchors.left: parent.left
  216. anchors.right: parent.right
  217. enabled: Cura.Actions.updateProfile.enabled
  218. onClicked:
  219. {
  220. popup.visible = false
  221. Cura.Actions.updateProfile.trigger()
  222. }
  223. }
  224. MenuButton
  225. {
  226. text: catalog.i18nc("@action:button", "Discard current changes")
  227. anchors.left: parent.left
  228. anchors.right: parent.right
  229. enabled: Cura.MachineManager.hasUserSettings
  230. onClicked:
  231. {
  232. popup.visible = false
  233. Cura.ContainerManager.clearUserContainers()
  234. }
  235. }
  236. Rectangle
  237. {
  238. height: UM.Theme.getSize("default_lining").width
  239. anchors.left: parent.left
  240. anchors.right: parent.right
  241. color: borderColor
  242. }
  243. MenuButton
  244. {
  245. id: manageProfilesButton
  246. text: Cura.Actions.manageProfiles.text
  247. anchors
  248. {
  249. left: parent.left
  250. right: parent.right
  251. }
  252. height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height
  253. contentItem: Item
  254. {
  255. width: parent.width
  256. height: childrenRect.height
  257. UM.Label
  258. {
  259. id: textLabel
  260. text: manageProfilesButton.text
  261. height: contentHeight
  262. }
  263. UM.Label
  264. {
  265. id: shortcutLabel
  266. text: Cura.Actions.manageProfiles.shortcut
  267. color: UM.Theme.getColor("text_lighter")
  268. height: contentHeight
  269. anchors.right: parent.right
  270. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  271. }
  272. }
  273. onClicked:
  274. {
  275. popup.visible = false
  276. Cura.Actions.manageProfiles.trigger()
  277. }
  278. }
  279. // spacer
  280. Item
  281. {
  282. width: 2
  283. height: UM.Theme.getSize("default_radius").width
  284. }
  285. }
  286. }