QualitiesWithIntentMenu.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. // Add the qualities that belong to the intent
  92. Repeater
  93. {
  94. visible: false
  95. model: subItemModel
  96. MenuButton
  97. {
  98. id: button
  99. onClicked: Cura.IntentManager.selectIntent(model.intent_category, model.quality_type)
  100. width: parent.width
  101. checkable: true
  102. visible: model.available
  103. text: model.name + " - " + model.layer_height + " mm"
  104. checked:
  105. {
  106. if (Cura.MachineManager.hasCustomQuality)
  107. {
  108. // When user created profile is active, no quality tickbox should be active.
  109. return false;
  110. }
  111. return Cura.MachineManager.activeQualityType == model.quality_type && Cura.MachineManager.activeIntentCategory == model.intent_category;
  112. }
  113. ButtonGroup.group: buttonGroup
  114. }
  115. }
  116. }
  117. }
  118. }
  119. //Another "intent category" for custom profiles.
  120. Item
  121. {
  122. height: childrenRect.height
  123. width: popup.contentWidth
  124. Label
  125. {
  126. id: customProfileHeader
  127. text: catalog.i18nc("@label:header", "Custom profiles")
  128. renderType: Text.NativeRendering
  129. height: visible ? contentHeight: 0
  130. enabled: false
  131. visible: profilesList.visibleChildren.length > 1
  132. anchors.left: parent.left
  133. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  134. color: UM.Theme.getColor("text_inactive")
  135. }
  136. Column
  137. {
  138. id: profilesList
  139. anchors
  140. {
  141. top: customProfileHeader.bottom
  142. left: parent.left
  143. right: parent.right
  144. }
  145. //We set it by means of a binding, since then we can use the
  146. //"when" condition, which we need to prevent a binding loop.
  147. Binding
  148. {
  149. target: parent
  150. property: "height"
  151. value: parent.childrenRect.height
  152. when: parent.visibleChildren.length > 1
  153. }
  154. //Add all the custom profiles.
  155. Repeater
  156. {
  157. model: Cura.CustomQualityProfilesDropDownMenuModel
  158. MenuButton
  159. {
  160. onClicked: Cura.MachineManager.setQualityChangesGroup(model.quality_changes_group)
  161. width: parent.width
  162. checkable: true
  163. visible: model.available
  164. text: model.name
  165. checked:
  166. {
  167. var active_quality_group = Cura.MachineManager.activeQualityChangesGroup
  168. if (active_quality_group != null)
  169. {
  170. return active_quality_group.name == model.quality_changes_group.name
  171. }
  172. return false
  173. }
  174. ButtonGroup.group: buttonGroup
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. Rectangle
  182. {
  183. height: UM.Theme.getSize("default_lining").height
  184. anchors.left: parent.left
  185. anchors.right: parent.right
  186. color: borderColor
  187. }
  188. MenuButton
  189. {
  190. labelText: Cura.Actions.addProfile.text
  191. anchors.left: parent.left
  192. anchors.right: parent.right
  193. enabled: Cura.Actions.addProfile.enabled
  194. onClicked:
  195. {
  196. Cura.Actions.addProfile.trigger()
  197. popup.visible = false
  198. }
  199. }
  200. MenuButton
  201. {
  202. labelText: Cura.Actions.updateProfile.text
  203. anchors.left: parent.left
  204. anchors.right: parent.right
  205. enabled: Cura.Actions.updateProfile.enabled
  206. onClicked:
  207. {
  208. popup.visible = false
  209. Cura.Actions.updateProfile.trigger()
  210. }
  211. }
  212. MenuButton
  213. {
  214. text: catalog.i18nc("@action:button", "Discard current changes")
  215. anchors.left: parent.left
  216. anchors.right: parent.right
  217. enabled: Cura.MachineManager.hasUserSettings
  218. onClicked:
  219. {
  220. popup.visible = false
  221. Cura.ContainerManager.clearUserContainers()
  222. }
  223. }
  224. Rectangle
  225. {
  226. height: UM.Theme.getSize("default_lining").width
  227. anchors.left: parent.left
  228. anchors.right: parent.right
  229. color: borderColor
  230. }
  231. MenuButton
  232. {
  233. id: manageProfilesButton
  234. text: Cura.Actions.manageProfiles.text
  235. anchors
  236. {
  237. left: parent.left
  238. right: parent.right
  239. }
  240. height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height
  241. contentItem: Item
  242. {
  243. width: parent.width
  244. height: childrenRect.height
  245. Label
  246. {
  247. id: textLabel
  248. text: manageProfilesButton.text
  249. height: contentHeight
  250. anchors.left: parent.left
  251. anchors.leftMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("narrow_margin").width
  252. verticalAlignment: Text.AlignVCenter
  253. renderType: Text.NativeRendering
  254. font: UM.Theme.getFont("default")
  255. color: UM.Theme.getColor("text")
  256. }
  257. Label
  258. {
  259. id: shortcutLabel
  260. text: Cura.Actions.manageProfiles.shortcut
  261. height: contentHeight
  262. anchors.right: parent.right
  263. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  264. verticalAlignment: Text.AlignVCenter
  265. renderType: Text.NativeRendering
  266. font: UM.Theme.getFont("default")
  267. color: UM.Theme.getColor("text")
  268. }
  269. }
  270. onClicked:
  271. {
  272. popup.visible = false
  273. Cura.Actions.manageProfiles.trigger()
  274. }
  275. }
  276. // spacer
  277. Item
  278. {
  279. width: 2
  280. height: UM.Theme.getSize("default_radius").width
  281. }
  282. }
  283. }