QualitiesWithIntentMenu.qml 12 KB

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