RecommendedInfillDensitySelector.qml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.15
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. //
  8. // Infill
  9. //
  10. Item
  11. {
  12. id: infillRow
  13. height: childrenRect.height
  14. property real labelColumnWidth: Math.round(width / 3)
  15. // Create a binding to update the icon when the infill density changes
  16. Binding
  17. {
  18. target: infillRowTitle
  19. property: "source"
  20. value:
  21. {
  22. var density = parseInt(infillDensity.properties.value)
  23. if (parseInt(infillSteps.properties.value) != 0)
  24. {
  25. return UM.Theme.getIcon("InfillGradual")
  26. }
  27. if (density <= 0)
  28. {
  29. return UM.Theme.getIcon("Infill0")
  30. }
  31. if (density < 40)
  32. {
  33. return UM.Theme.getIcon("Infill3")
  34. }
  35. if (density < 90)
  36. {
  37. return UM.Theme.getIcon("Infill2")
  38. }
  39. return UM.Theme.getIcon("Infill100")
  40. }
  41. }
  42. // We use a binding to make sure that after manually setting infillSlider.value it is still bound to the property provider
  43. Binding
  44. {
  45. target: infillSlider
  46. property: "value"
  47. value: parseInt(infillDensity.properties.value)
  48. }
  49. // Here are the elements that are shown in the left column
  50. Cura.IconWithText
  51. {
  52. id: infillRowTitle
  53. anchors.top: parent.top
  54. anchors.left: parent.left
  55. source: UM.Theme.getIcon("Infill1")
  56. text: catalog.i18nc("@label", "Infill") + " (%)"
  57. font: UM.Theme.getFont("medium")
  58. width: labelColumnWidth
  59. iconSize: UM.Theme.getSize("medium_button_icon").width
  60. }
  61. Item
  62. {
  63. id: infillSliderContainer
  64. height: childrenRect.height
  65. anchors
  66. {
  67. left: infillRowTitle.right
  68. right: parent.right
  69. verticalCenter: infillRowTitle.verticalCenter
  70. }
  71. Slider
  72. {
  73. id: infillSlider
  74. width: parent.width
  75. height: UM.Theme.getSize("print_setup_slider_handle").height // The handle is the widest element of the slider
  76. from: 0
  77. to: 100
  78. stepSize: 1
  79. // disable slider when gradual support is enabled
  80. enabled: parseInt(infillSteps.properties.value) == 0
  81. // set initial value from stack
  82. value: parseInt(infillDensity.properties.value)
  83. //Draw line
  84. background: Rectangle
  85. {
  86. id: backgroundLine
  87. height: UM.Theme.getSize("print_setup_slider_groove").height
  88. width: infillSlider.width - UM.Theme.getSize("print_setup_slider_handle").width
  89. anchors.horizontalCenter: parent.horizontalCenter
  90. anchors.verticalCenter: parent.verticalCenter
  91. color: infillSlider.enabled ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
  92. Repeater
  93. {
  94. id: repeater
  95. anchors.fill: parent
  96. model: infillSlider.to / infillSlider.stepSize + 1
  97. Rectangle
  98. {
  99. color: infillSlider.enabled ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
  100. implicitWidth: UM.Theme.getSize("print_setup_slider_tickmarks").width
  101. implicitHeight: UM.Theme.getSize("print_setup_slider_tickmarks").height
  102. anchors.verticalCenter: parent.verticalCenter
  103. // Do not use Math.round otherwise the tickmarks won't be aligned
  104. x: ((handleButton.width / 2) - (backgroundLine.implicitWidth / 2) + (index * ((repeater.width - handleButton.width) / (repeater.count-1))))
  105. radius: Math.round(backgroundLine.implicitWidth / 2)
  106. visible: (index % 10) == 0 // Only show steps of 10%
  107. UM.Label
  108. {
  109. text: index
  110. visible: (index % 20) == 0 // Only show steps of 20%
  111. anchors.horizontalCenter: parent.horizontalCenter
  112. y: UM.Theme.getSize("thin_margin").height
  113. renderType: Text.NativeRendering
  114. color: UM.Theme.getColor("quality_slider_available")
  115. }
  116. }
  117. }
  118. }
  119. handle: Rectangle
  120. {
  121. id: handleButton
  122. x: infillSlider.leftPadding + infillSlider.visualPosition * (infillSlider.availableWidth - width)
  123. y: infillSlider.topPadding + infillSlider.availableHeight / 2 - height / 2
  124. color: infillSlider.enabled ? UM.Theme.getColor("primary") : UM.Theme.getColor("quality_slider_unavailable")
  125. implicitWidth: UM.Theme.getSize("print_setup_slider_handle").width
  126. implicitHeight: implicitWidth
  127. radius: Math.round(implicitWidth / 2)
  128. border.color: UM.Theme.getColor("slider_groove_fill")
  129. border.width: UM.Theme.getSize("default_lining").height
  130. }
  131. Connections
  132. {
  133. target: infillSlider
  134. function onValueChanged()
  135. {
  136. // Don't round the value if it's already the same
  137. if (parseInt(infillDensity.properties.value) == infillSlider.value)
  138. {
  139. return
  140. }
  141. // Round the slider value to the nearest multiple of 10 (simulate step size of 10)
  142. var roundedSliderValue = Math.round(infillSlider.value / 10) * 10
  143. // Update the slider value to represent the rounded value
  144. infillSlider.value = roundedSliderValue
  145. // Update value only if the Recommended mode is Active,
  146. // Otherwise if I change the value in the Custom mode the Recommended view will try to repeat
  147. // same operation
  148. const active_mode = UM.Preferences.getValue("cura/active_mode")
  149. if (active_mode == 0 || active_mode == "simple")
  150. {
  151. Cura.MachineManager.setSettingForAllExtruders("infill_sparse_density", "value", roundedSliderValue)
  152. Cura.MachineManager.resetSettingForAllExtruders("infill_line_distance")
  153. }
  154. }
  155. }
  156. }
  157. }
  158. // Gradual Support Infill Checkbox
  159. UM.CheckBox
  160. {
  161. id: enableGradualInfillCheckBox
  162. property alias _hovered: enableGradualInfillMouseArea.containsMouse
  163. anchors.top: infillSliderContainer.bottom
  164. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  165. anchors.left: infillSliderContainer.left
  166. text: catalog.i18nc("@label", "Gradual infill")
  167. enabled: recommendedPrintSetup.settingsEnabled
  168. visible: infillSteps.properties.enabled == "True"
  169. checked: parseInt(infillSteps.properties.value) > 0
  170. MouseArea
  171. {
  172. id: enableGradualInfillMouseArea
  173. anchors.fill: parent
  174. hoverEnabled: true
  175. enabled: true
  176. property var previousInfillDensity: parseInt(infillDensity.properties.value)
  177. onClicked:
  178. {
  179. // Set to 90% only when enabling gradual infill
  180. var newInfillDensity;
  181. if (parseInt(infillSteps.properties.value) == 0)
  182. {
  183. previousInfillDensity = parseInt(infillDensity.properties.value)
  184. newInfillDensity = 90
  185. } else {
  186. newInfillDensity = previousInfillDensity
  187. }
  188. Cura.MachineManager.setSettingForAllExtruders("infill_sparse_density", "value", String(newInfillDensity))
  189. var infill_steps_value = 0
  190. if (parseInt(infillSteps.properties.value) == 0)
  191. {
  192. infill_steps_value = 5
  193. }
  194. Cura.MachineManager.setSettingForAllExtruders("gradual_infill_steps", "value", infill_steps_value)
  195. }
  196. onEntered: base.showTooltip(enableGradualInfillCheckBox, Qt.point(-infillSliderContainer.x - UM.Theme.getSize("thick_margin").width, 0),
  197. catalog.i18nc("@label", "Gradual infill will gradually increase the amount of infill towards the top."))
  198. onExited: base.hideTooltip()
  199. }
  200. }
  201. UM.SettingPropertyProvider
  202. {
  203. id: infillDensity
  204. containerStackId: Cura.MachineManager.activeStackId
  205. key: "infill_sparse_density"
  206. watchedProperties: [ "value" ]
  207. storeIndex: 0
  208. }
  209. UM.SettingPropertyProvider
  210. {
  211. id: infillSteps
  212. containerStackId: Cura.MachineManager.activeStackId
  213. key: "gradual_infill_steps"
  214. watchedProperties: ["value", "enabled"]
  215. storeIndex: 0
  216. }
  217. }