RecommendedSupportSelector.qml 12 KB

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