RecommendedSupportSelector.qml 12 KB

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