RecommendedSupportSelector.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.ColorImage
  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. color: UM.Theme.getColor("setting_control_button")
  141. }
  142. background: Rectangle
  143. {
  144. color:
  145. {
  146. if (!enabled)
  147. {
  148. return UM.Theme.getColor("setting_control_disabled")
  149. }
  150. if (supportExtruderCombobox.hovered || base.activeFocus)
  151. {
  152. return UM.Theme.getColor("setting_control_highlight")
  153. }
  154. return UM.Theme.getColor("setting_control")
  155. }
  156. radius: UM.Theme.getSize("setting_control_radius").width
  157. border.width: UM.Theme.getSize("default_lining").width
  158. border.color:
  159. {
  160. if (!enabled)
  161. {
  162. return UM.Theme.getColor("setting_control_disabled_border")
  163. }
  164. if (supportExtruderCombobox.hovered || supportExtruderCombobox.activeFocus)
  165. {
  166. return UM.Theme.getColor("setting_control_border_highlight")
  167. }
  168. return UM.Theme.getColor("setting_control_border")
  169. }
  170. }
  171. contentItem: UM.Label
  172. {
  173. anchors.verticalCenter: parent.verticalCenter
  174. anchors.left: parent.left
  175. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  176. anchors.right: downArrow.left
  177. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  178. text: supportExtruderCombobox.currentText
  179. textFormat: Text.PlainText
  180. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  181. elide: Text.ElideLeft
  182. background: Rectangle
  183. {
  184. id: swatch
  185. height: Math.round(parent.height / 2)
  186. width: height
  187. radius: Math.round(width / 2)
  188. anchors.right: parent.right
  189. anchors.verticalCenter: parent.verticalCenter
  190. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  191. color: supportExtruderCombobox.color
  192. }
  193. }
  194. popup: Popup
  195. {
  196. y: supportExtruderCombobox.height - UM.Theme.getSize("default_lining").height
  197. width: supportExtruderCombobox.width
  198. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  199. padding: UM.Theme.getSize("default_lining").width
  200. contentItem: ListView
  201. {
  202. implicitHeight: contentHeight
  203. ScrollBar.vertical: UM.ScrollBar {}
  204. clip: true
  205. model: supportExtruderCombobox.popup.visible ? supportExtruderCombobox.delegateModel : null
  206. currentIndex: supportExtruderCombobox.highlightedIndex
  207. }
  208. background: Rectangle
  209. {
  210. color: UM.Theme.getColor("setting_control")
  211. border.color: UM.Theme.getColor("setting_control_border")
  212. }
  213. }
  214. delegate: ItemDelegate
  215. {
  216. width: supportExtruderCombobox.width - 2 * UM.Theme.getSize("default_lining").width
  217. height: supportExtruderCombobox.height
  218. highlighted: supportExtruderCombobox.highlightedIndex == index
  219. contentItem: UM.Label
  220. {
  221. anchors.fill: parent
  222. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  223. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  224. text: model.name
  225. color: model.enabled ? UM.Theme.getColor("setting_control_text"): UM.Theme.getColor("action_button_disabled_text")
  226. elide: Text.ElideRight
  227. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  228. background: Rectangle
  229. {
  230. id: swatch
  231. height: Math.round(parent.height / 2)
  232. width: height
  233. radius: Math.round(width / 2)
  234. anchors.right: parent.right
  235. anchors.verticalCenter: parent.verticalCenter
  236. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  237. color: supportExtruderCombobox.model.getItem(index).color
  238. }
  239. }
  240. background: Rectangle
  241. {
  242. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  243. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  244. }
  245. }
  246. }
  247. }
  248. property var extruderModel: CuraApplication.getExtrudersModel()
  249. UM.SettingPropertyProvider
  250. {
  251. id: supportEnabled
  252. containerStack: Cura.MachineManager.activeMachine
  253. key: "support_enable"
  254. watchedProperties: [ "value", "enabled", "description" ]
  255. storeIndex: 0
  256. }
  257. UM.SettingPropertyProvider
  258. {
  259. id: supportExtruderNr
  260. containerStack: Cura.MachineManager.activeMachine
  261. key: "support_extruder_nr"
  262. watchedProperties: [ "value" ]
  263. storeIndex: 0
  264. }
  265. UM.SettingPropertyProvider
  266. {
  267. id: machineExtruderCount
  268. containerStack: Cura.MachineManager.activeMachine
  269. key: "machine_extruder_count"
  270. watchedProperties: ["value"]
  271. storeIndex: 0
  272. }
  273. }