RecommendedInfillDensitySelector.qml 9.1 KB

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