RecommendedSupportSelector.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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.0 as Cura
  7. //
  8. // Enable support
  9. //
  10. Item
  11. {
  12. id: enableSupportRow
  13. height: UM.Theme.getSize("print_setup_big_item").height
  14. property real labelColumnWidth: Math.round(width / 3)
  15. Item
  16. {
  17. id: enableSupportContainer
  18. width: labelColumnWidth + enableSupportCheckBox.width
  19. anchors
  20. {
  21. left: parent.left
  22. top: parent.top
  23. bottom: parent.bottom
  24. rightMargin: UM.Theme.getSize("thick_margin").width
  25. }
  26. Cura.IconWithText
  27. {
  28. id: enableSupportRowTitle
  29. anchors.left: parent.left
  30. visible: enableSupportCheckBox.visible
  31. source: UM.Theme.getIcon("Support")
  32. text: catalog.i18nc("@label", "Support")
  33. font: UM.Theme.getFont("medium")
  34. width: labelColumnWidth
  35. iconSize: UM.Theme.getSize("medium_button_icon").width
  36. tooltipText: catalog.i18nc("@label", "Generate structures to support parts of the model which have overhangs. Without these structures, such parts would collapse during printing.")
  37. }
  38. UM.CheckBox
  39. {
  40. id: enableSupportCheckBox
  41. anchors.verticalCenter: parent.verticalCenter
  42. anchors.left: enableSupportRowTitle.right
  43. property alias _hovered: enableSupportMouseArea.containsMouse
  44. enabled: recommendedPrintSetup.settingsEnabled
  45. visible: supportEnabled.properties.enabled == "True"
  46. checked: supportEnabled.properties.value == "True"
  47. MouseArea
  48. {
  49. id: enableSupportMouseArea
  50. anchors.fill: parent
  51. hoverEnabled: true
  52. // propagateComposedEvents used on supportToolTipMouseArea does not work with Controls Components.
  53. // It only works with other MouseAreas, so this is required
  54. onClicked: supportEnabled.setPropertyValue("value", supportEnabled.properties.value != "True")
  55. }
  56. }
  57. MouseArea
  58. {
  59. id: supportToolTipMouseArea
  60. anchors.fill: parent
  61. propagateComposedEvents: true
  62. hoverEnabled: true
  63. onEntered: base.showTooltip(enableSupportContainer, Qt.point(-enableSupportContainer.x - UM.Theme.getSize("thick_margin").width, 0),
  64. catalog.i18nc("@label", "Generate structures to support parts of the model which have overhangs. Without these structures, such parts would collapse during printing."))
  65. onExited: base.hideTooltip()
  66. }
  67. }
  68. ComboBox
  69. {
  70. id: supportExtruderCombobox
  71. height: UM.Theme.getSize("print_setup_big_item").height
  72. anchors
  73. {
  74. left: enableSupportContainer.right
  75. right: parent.right
  76. leftMargin: UM.Theme.getSize("default_margin").width
  77. rightMargin: UM.Theme.getSize("thick_margin").width
  78. verticalCenter: parent.verticalCenter
  79. }
  80. enabled: recommendedPrintSetup.settingsEnabled
  81. visible: enableSupportCheckBox.visible && (supportEnabled.properties.value == "True") && (extrudersEnabledCount.properties.value > 1)
  82. textRole: "name" // this solves that the combobox isn't populated in the first time Cura is started
  83. model: extruderModel
  84. // knowing the extruder position, try to find the item index in the model
  85. function getIndexByPosition(position)
  86. {
  87. var itemIndex = -1 // if position is not found, return -1
  88. for (var item_index in model.items)
  89. {
  90. var item = model.getItem(item_index)
  91. if (item.index == position)
  92. {
  93. itemIndex = item_index
  94. break
  95. }
  96. }
  97. return itemIndex
  98. }
  99. onActivated:
  100. {
  101. if (model.getItem(index).enabled)
  102. {
  103. forceActiveFocus();
  104. supportExtruderNr.setPropertyValue("value", model.getItem(index).index);
  105. } else
  106. {
  107. currentIndex = supportExtruderNr.properties.value; // keep the old value
  108. }
  109. }
  110. currentIndex: (supportExtruderNr.properties.value !== undefined) ? supportExtruderNr.properties.value : 0
  111. property string color: "#fff"
  112. Connections
  113. {
  114. target: extruderModel
  115. function onModelChanged()
  116. {
  117. var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
  118. if (maybeColor)
  119. {
  120. supportExtruderCombobox.color = maybeColor
  121. }
  122. }
  123. }
  124. onCurrentIndexChanged:
  125. {
  126. var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
  127. if(maybeColor)
  128. {
  129. supportExtruderCombobox.color = maybeColor
  130. }
  131. }
  132. Binding
  133. {
  134. target: supportExtruderCombobox
  135. property: "currentIndex"
  136. value: supportExtruderCombobox.getIndexByPosition(supportExtruderNr.properties.value)
  137. // Sometimes when the value is already changed, the model is still being built.
  138. // The when clause ensures that the current index is not updated when this happens.
  139. when: supportExtruderCombobox.model.count > 0
  140. }
  141. indicator: UM.ColorImage
  142. {
  143. id: downArrow
  144. x: supportExtruderCombobox.width - width - supportExtruderCombobox.rightPadding
  145. y: supportExtruderCombobox.topPadding + Math.round((supportExtruderCombobox.availableHeight - height) / 2)
  146. source: UM.Theme.getIcon("ChevronSingleDown")
  147. width: UM.Theme.getSize("standard_arrow").width
  148. height: UM.Theme.getSize("standard_arrow").height
  149. color: UM.Theme.getColor("setting_control_button")
  150. }
  151. background: Rectangle
  152. {
  153. color:
  154. {
  155. if (!enabled)
  156. {
  157. return UM.Theme.getColor("setting_control_disabled")
  158. }
  159. if (supportExtruderCombobox.hovered || base.activeFocus)
  160. {
  161. return UM.Theme.getColor("setting_control_highlight")
  162. }
  163. return UM.Theme.getColor("setting_control")
  164. }
  165. radius: UM.Theme.getSize("setting_control_radius").width
  166. border.width: UM.Theme.getSize("default_lining").width
  167. border.color:
  168. {
  169. if (!enabled)
  170. {
  171. return UM.Theme.getColor("setting_control_disabled_border")
  172. }
  173. if (supportExtruderCombobox.hovered || supportExtruderCombobox.activeFocus)
  174. {
  175. return UM.Theme.getColor("setting_control_border_highlight")
  176. }
  177. return UM.Theme.getColor("setting_control_border")
  178. }
  179. }
  180. contentItem: UM.Label
  181. {
  182. anchors.verticalCenter: parent.verticalCenter
  183. anchors.left: parent.left
  184. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  185. anchors.right: downArrow.left
  186. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  187. text: supportExtruderCombobox.currentText
  188. textFormat: Text.PlainText
  189. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  190. elide: Text.ElideLeft
  191. background: Rectangle
  192. {
  193. id: swatch
  194. height: Math.round(parent.height / 2)
  195. width: height
  196. radius: Math.round(width / 2)
  197. anchors.right: parent.right
  198. anchors.verticalCenter: parent.verticalCenter
  199. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  200. color: supportExtruderCombobox.color
  201. }
  202. }
  203. popup: Popup
  204. {
  205. y: supportExtruderCombobox.height - UM.Theme.getSize("default_lining").height
  206. width: supportExtruderCombobox.width
  207. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  208. padding: UM.Theme.getSize("default_lining").width
  209. contentItem: ListView
  210. {
  211. implicitHeight: contentHeight
  212. ScrollBar.vertical: UM.ScrollBar {}
  213. clip: true
  214. model: supportExtruderCombobox.popup.visible ? supportExtruderCombobox.delegateModel : null
  215. currentIndex: supportExtruderCombobox.highlightedIndex
  216. }
  217. background: Rectangle
  218. {
  219. color: UM.Theme.getColor("setting_control")
  220. border.color: UM.Theme.getColor("setting_control_border")
  221. }
  222. }
  223. delegate: ItemDelegate
  224. {
  225. width: supportExtruderCombobox.width - 2 * UM.Theme.getSize("default_lining").width
  226. height: supportExtruderCombobox.height
  227. highlighted: supportExtruderCombobox.highlightedIndex == index
  228. contentItem: UM.Label
  229. {
  230. anchors.fill: parent
  231. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  232. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  233. text: model.name
  234. color: model.enabled ? UM.Theme.getColor("setting_control_text"): UM.Theme.getColor("action_button_disabled_text")
  235. elide: Text.ElideRight
  236. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  237. background: Rectangle
  238. {
  239. id: swatch
  240. height: Math.round(parent.height / 2)
  241. width: height
  242. radius: Math.round(width / 2)
  243. anchors.right: parent.right
  244. anchors.verticalCenter: parent.verticalCenter
  245. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  246. color: supportExtruderCombobox.model.getItem(index).color
  247. }
  248. }
  249. background: Rectangle
  250. {
  251. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  252. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  253. }
  254. }
  255. }
  256. property var extruderModel: CuraApplication.getExtrudersModel()
  257. UM.SettingPropertyProvider
  258. {
  259. id: supportEnabled
  260. containerStack: Cura.MachineManager.activeMachine
  261. key: "support_enable"
  262. watchedProperties: [ "value", "enabled", "description" ]
  263. storeIndex: 0
  264. }
  265. UM.SettingPropertyProvider
  266. {
  267. id: supportExtruderNr
  268. containerStack: Cura.MachineManager.activeMachine
  269. key: "support_extruder_nr"
  270. watchedProperties: [ "value" ]
  271. storeIndex: 0
  272. }
  273. UM.SettingPropertyProvider
  274. {
  275. id: machineExtruderCount
  276. containerStack: Cura.MachineManager.activeMachine
  277. key: "machine_extruder_count"
  278. watchedProperties: ["value"]
  279. storeIndex: 0
  280. }
  281. }