QualitiesWithIntentMenu.qml 12 KB

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