RecommendedSupportSelector.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. supportExtruderCombobox.color = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
  111. }
  112. }
  113. onCurrentIndexChanged:
  114. {
  115. var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
  116. if(maybeColor)
  117. {
  118. supportExtruderCombobox.color = maybeColor
  119. }
  120. }
  121. Binding
  122. {
  123. target: supportExtruderCombobox
  124. property: "currentIndex"
  125. value: supportExtruderCombobox.getIndexByPosition(supportExtruderNr.properties.value)
  126. // Sometimes when the value is already changed, the model is still being built.
  127. // The when clause ensures that the current index is not updated when this happens.
  128. when: supportExtruderCombobox.model.count > 0
  129. }
  130. indicator: UM.RecolorImage
  131. {
  132. id: downArrow
  133. x: supportExtruderCombobox.width - width - supportExtruderCombobox.rightPadding
  134. y: supportExtruderCombobox.topPadding + Math.round((supportExtruderCombobox.availableHeight - height) / 2)
  135. source: UM.Theme.getIcon("arrow_bottom")
  136. width: UM.Theme.getSize("standard_arrow").width
  137. height: UM.Theme.getSize("standard_arrow").height
  138. sourceSize.width: width + 5 * screenScaleFactor
  139. sourceSize.height: width + 5 * screenScaleFactor
  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: Controls2.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. renderType: Text.NativeRendering
  181. font: UM.Theme.getFont("default")
  182. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  183. elide: Text.ElideLeft
  184. verticalAlignment: Text.AlignVCenter
  185. background: UM.RecolorImage
  186. {
  187. id: swatch
  188. height: Math.round(parent.height / 2)
  189. width: height
  190. anchors.right: parent.right
  191. anchors.verticalCenter: parent.verticalCenter
  192. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  193. sourceSize.width: width
  194. sourceSize.height: height
  195. source: UM.Theme.getIcon("extruder_button")
  196. color: supportExtruderCombobox.color
  197. }
  198. }
  199. popup: Controls2.Popup
  200. {
  201. y: supportExtruderCombobox.height - UM.Theme.getSize("default_lining").height
  202. width: supportExtruderCombobox.width
  203. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  204. padding: UM.Theme.getSize("default_lining").width
  205. contentItem: ListView
  206. {
  207. clip: true
  208. implicitHeight: contentHeight
  209. model: supportExtruderCombobox.popup.visible ? supportExtruderCombobox.delegateModel : null
  210. currentIndex: supportExtruderCombobox.highlightedIndex
  211. Controls2.ScrollIndicator.vertical: Controls2.ScrollIndicator { }
  212. }
  213. background: Rectangle
  214. {
  215. color: UM.Theme.getColor("setting_control")
  216. border.color: UM.Theme.getColor("setting_control_border")
  217. }
  218. }
  219. delegate: Controls2.ItemDelegate
  220. {
  221. width: supportExtruderCombobox.width - 2 * UM.Theme.getSize("default_lining").width
  222. height: supportExtruderCombobox.height
  223. highlighted: supportExtruderCombobox.highlightedIndex == index
  224. contentItem: Controls2.Label
  225. {
  226. anchors.fill: parent
  227. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  228. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  229. text: model.name
  230. renderType: Text.NativeRendering
  231. color:
  232. {
  233. if (model.enabled)
  234. {
  235. UM.Theme.getColor("setting_control_text")
  236. }
  237. else
  238. {
  239. UM.Theme.getColor("action_button_disabled_text");
  240. }
  241. }
  242. font: UM.Theme.getFont("default")
  243. elide: Text.ElideRight
  244. verticalAlignment: Text.AlignVCenter
  245. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  246. background: UM.RecolorImage
  247. {
  248. id: swatch
  249. height: Math.round(parent.height / 2)
  250. width: height
  251. anchors.right: parent.right
  252. anchors.verticalCenter: parent.verticalCenter
  253. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  254. sourceSize.width: width
  255. sourceSize.height: height
  256. source: UM.Theme.getIcon("extruder_button")
  257. color: supportExtruderCombobox.model.getItem(index).color
  258. }
  259. }
  260. background: Rectangle
  261. {
  262. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  263. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  264. }
  265. }
  266. }
  267. }
  268. property var extruderModel: CuraApplication.getExtrudersModel()
  269. UM.SettingPropertyProvider
  270. {
  271. id: supportEnabled
  272. containerStack: Cura.MachineManager.activeMachine
  273. key: "support_enable"
  274. watchedProperties: [ "value", "enabled", "description" ]
  275. storeIndex: 0
  276. }
  277. UM.SettingPropertyProvider
  278. {
  279. id: supportExtruderNr
  280. containerStack: Cura.MachineManager.activeMachine
  281. key: "support_extruder_nr"
  282. watchedProperties: [ "value" ]
  283. storeIndex: 0
  284. }
  285. UM.SettingPropertyProvider
  286. {
  287. id: machineExtruderCount
  288. containerStack: Cura.MachineManager.activeMachine
  289. key: "machine_extruder_count"
  290. watchedProperties: ["value"]
  291. storeIndex: 0
  292. }
  293. }