RecommendedSupportSelector.qml 13 KB

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