RecommendedSupportSelector.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Copyright (c) 2018 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
  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: supportExtruderCombobox.color = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
  114. Binding
  115. {
  116. target: supportExtruderCombobox
  117. property: "currentIndex"
  118. value: supportExtruderCombobox.getIndexByPosition(supportExtruderNr.properties.value)
  119. // Sometimes when the value is already changed, the model is still being built.
  120. // The when clause ensures that the current index is not updated when this happens.
  121. when: supportExtruderCombobox.model.count > 0
  122. }
  123. indicator: UM.RecolorImage
  124. {
  125. id: downArrow
  126. x: supportExtruderCombobox.width - width - supportExtruderCombobox.rightPadding
  127. y: supportExtruderCombobox.topPadding + Math.round((supportExtruderCombobox.availableHeight - height) / 2)
  128. source: UM.Theme.getIcon("arrow_bottom")
  129. width: UM.Theme.getSize("standard_arrow").width
  130. height: UM.Theme.getSize("standard_arrow").height
  131. sourceSize.width: width + 5 * screenScaleFactor
  132. sourceSize.height: width + 5 * screenScaleFactor
  133. color: UM.Theme.getColor("setting_control_button")
  134. }
  135. background: Rectangle
  136. {
  137. color:
  138. {
  139. if (!enabled)
  140. {
  141. return UM.Theme.getColor("setting_control_disabled")
  142. }
  143. if (supportExtruderCombobox.hovered || base.activeFocus)
  144. {
  145. return UM.Theme.getColor("setting_control_highlight")
  146. }
  147. return UM.Theme.getColor("setting_control")
  148. }
  149. radius: UM.Theme.getSize("setting_control_radius").width
  150. border.width: UM.Theme.getSize("default_lining").width
  151. border.color:
  152. {
  153. if (!enabled)
  154. {
  155. return UM.Theme.getColor("setting_control_disabled_border")
  156. }
  157. if (supportExtruderCombobox.hovered || supportExtruderCombobox.activeFocus)
  158. {
  159. return UM.Theme.getColor("setting_control_border_highlight")
  160. }
  161. return UM.Theme.getColor("setting_control_border")
  162. }
  163. }
  164. contentItem: Controls2.Label
  165. {
  166. anchors.verticalCenter: parent.verticalCenter
  167. anchors.left: parent.left
  168. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  169. anchors.right: downArrow.left
  170. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  171. text: supportExtruderCombobox.currentText
  172. textFormat: Text.PlainText
  173. renderType: Text.NativeRendering
  174. font: UM.Theme.getFont("default")
  175. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  176. elide: Text.ElideLeft
  177. verticalAlignment: Text.AlignVCenter
  178. background: UM.RecolorImage
  179. {
  180. id: swatch
  181. height: Math.round(parent.height / 2)
  182. width: height
  183. anchors.right: parent.right
  184. anchors.verticalCenter: parent.verticalCenter
  185. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  186. sourceSize.width: width
  187. sourceSize.height: height
  188. source: UM.Theme.getIcon("extruder_button")
  189. color: supportExtruderCombobox.color
  190. }
  191. }
  192. popup: Controls2.Popup
  193. {
  194. y: supportExtruderCombobox.height - UM.Theme.getSize("default_lining").height
  195. width: supportExtruderCombobox.width
  196. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  197. padding: UM.Theme.getSize("default_lining").width
  198. contentItem: ListView
  199. {
  200. clip: true
  201. implicitHeight: contentHeight
  202. model: supportExtruderCombobox.popup.visible ? supportExtruderCombobox.delegateModel : null
  203. currentIndex: supportExtruderCombobox.highlightedIndex
  204. Controls2.ScrollIndicator.vertical: Controls2.ScrollIndicator { }
  205. }
  206. background: Rectangle
  207. {
  208. color: UM.Theme.getColor("setting_control")
  209. border.color: UM.Theme.getColor("setting_control_border")
  210. }
  211. }
  212. delegate: Controls2.ItemDelegate
  213. {
  214. width: supportExtruderCombobox.width - 2 * UM.Theme.getSize("default_lining").width
  215. height: supportExtruderCombobox.height
  216. highlighted: supportExtruderCombobox.highlightedIndex == index
  217. contentItem: Controls2.Label
  218. {
  219. anchors.fill: parent
  220. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  221. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  222. text: model.name
  223. renderType: Text.NativeRendering
  224. color:
  225. {
  226. if (model.enabled)
  227. {
  228. UM.Theme.getColor("setting_control_text")
  229. }
  230. else
  231. {
  232. UM.Theme.getColor("action_button_disabled_text");
  233. }
  234. }
  235. font: UM.Theme.getFont("default")
  236. elide: Text.ElideRight
  237. verticalAlignment: Text.AlignVCenter
  238. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  239. background: UM.RecolorImage
  240. {
  241. id: swatch
  242. height: Math.round(parent.height / 2)
  243. width: height
  244. anchors.right: parent.right
  245. anchors.verticalCenter: parent.verticalCenter
  246. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  247. sourceSize.width: width
  248. sourceSize.height: height
  249. source: UM.Theme.getIcon("extruder_button")
  250. color: supportExtruderCombobox.model.getItem(index).color
  251. }
  252. }
  253. background: Rectangle
  254. {
  255. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  256. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  257. }
  258. }
  259. }
  260. }
  261. property var extruderModel: CuraApplication.getExtrudersModel()
  262. UM.SettingPropertyProvider
  263. {
  264. id: supportEnabled
  265. containerStack: Cura.MachineManager.activeMachine
  266. key: "support_enable"
  267. watchedProperties: [ "value", "enabled", "description" ]
  268. storeIndex: 0
  269. }
  270. UM.SettingPropertyProvider
  271. {
  272. id: supportExtruderNr
  273. containerStack: Cura.MachineManager.activeMachine
  274. key: "support_extruder_nr"
  275. watchedProperties: [ "value" ]
  276. storeIndex: 0
  277. }
  278. UM.SettingPropertyProvider
  279. {
  280. id: machineExtruderCount
  281. containerStack: Cura.MachineManager.activeMachine
  282. key: "machine_extruder_count"
  283. watchedProperties: ["value"]
  284. storeIndex: 0
  285. }
  286. }