RecommendedInfillDensitySelector.qml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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("gradual")
  27. }
  28. if (density <= 0)
  29. {
  30. return UM.Theme.getIcon("hollow")
  31. }
  32. if (density < 40)
  33. {
  34. return UM.Theme.getIcon("sparse")
  35. }
  36. if (density < 90)
  37. {
  38. return UM.Theme.getIcon("dense")
  39. }
  40. return UM.Theme.getIcon("solid")
  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("category_infill")
  57. text: catalog.i18nc("@label", "Infill") + " (%)"
  58. font: UM.Theme.getFont("medium")
  59. width: labelColumnWidth
  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. minimumValue: 0
  77. maximumValue: 100
  78. stepSize: 1
  79. tickmarksEnabled: true
  80. // disable slider when gradual support is enabled
  81. enabled: parseInt(infillSteps.properties.value) == 0
  82. // set initial value from stack
  83. value: parseInt(infillDensity.properties.value)
  84. style: SliderStyle
  85. {
  86. //Draw line
  87. groove: Item
  88. {
  89. Rectangle
  90. {
  91. height: UM.Theme.getSize("print_setup_slider_groove").height
  92. width: control.width - UM.Theme.getSize("print_setup_slider_handle").width
  93. anchors.horizontalCenter: parent.horizontalCenter
  94. anchors.verticalCenter: parent.verticalCenter
  95. color: control.enabled ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
  96. }
  97. }
  98. handle: Rectangle
  99. {
  100. id: handleButton
  101. color: control.enabled ? UM.Theme.getColor("primary") : UM.Theme.getColor("quality_slider_unavailable")
  102. implicitWidth: UM.Theme.getSize("print_setup_slider_handle").width
  103. implicitHeight: implicitWidth
  104. radius: Math.round(implicitWidth / 2)
  105. }
  106. tickmarks: Repeater
  107. {
  108. id: repeater
  109. model: control.maximumValue / control.stepSize + 1
  110. Rectangle
  111. {
  112. color: control.enabled ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
  113. implicitWidth: UM.Theme.getSize("print_setup_slider_tickmarks").width
  114. implicitHeight: UM.Theme.getSize("print_setup_slider_tickmarks").height
  115. anchors.verticalCenter: parent.verticalCenter
  116. // Do not use Math.round otherwise the tickmarks won't be aligned
  117. x: ((styleData.handleWidth / 2) - (implicitWidth / 2) + (index * ((repeater.width - styleData.handleWidth) / (repeater.count-1))))
  118. radius: Math.round(implicitWidth / 2)
  119. visible: (index % 10) == 0 // Only show steps of 10%
  120. Label
  121. {
  122. text: index
  123. font: UM.Theme.getFont("default")
  124. visible: (index % 20) == 0 // Only show steps of 20%
  125. anchors.horizontalCenter: parent.horizontalCenter
  126. y: UM.Theme.getSize("thin_margin").height
  127. renderType: Text.NativeRendering
  128. color: UM.Theme.getColor("quality_slider_available")
  129. }
  130. }
  131. }
  132. }
  133. onValueChanged:
  134. {
  135. // Don't round the value if it's already the same
  136. if (parseInt(infillDensity.properties.value) == infillSlider.value)
  137. {
  138. return
  139. }
  140. // Round the slider value to the nearest multiple of 10 (simulate step size of 10)
  141. var roundedSliderValue = Math.round(infillSlider.value / 10) * 10
  142. // Update the slider value to represent the rounded value
  143. infillSlider.value = roundedSliderValue
  144. // Update value only if the Recomended mode is Active,
  145. // Otherwise if I change the value in the Custom mode the Recomended view will try to repeat
  146. // same operation
  147. var active_mode = UM.Preferences.getValue("cura/active_mode")
  148. if (active_mode == 0 || active_mode == "simple")
  149. {
  150. Cura.MachineManager.setSettingForAllExtruders("infill_sparse_density", "value", roundedSliderValue)
  151. Cura.MachineManager.resetSettingForAllExtruders("infill_line_distance")
  152. }
  153. }
  154. }
  155. }
  156. // Gradual Support Infill Checkbox
  157. CheckBox
  158. {
  159. id: enableGradualInfillCheckBox
  160. property alias _hovered: enableGradualInfillMouseArea.containsMouse
  161. anchors.top: infillSliderContainer.bottom
  162. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  163. anchors.left: infillSliderContainer.left
  164. text: catalog.i18nc("@label", "Gradual infill")
  165. style: UM.Theme.styles.checkbox
  166. enabled: recommendedPrintSetup.settingsEnabled
  167. visible: infillSteps.properties.enabled == "True"
  168. checked: parseInt(infillSteps.properties.value) > 0
  169. MouseArea
  170. {
  171. id: enableGradualInfillMouseArea
  172. anchors.fill: parent
  173. hoverEnabled: true
  174. enabled: true
  175. property var previousInfillDensity: parseInt(infillDensity.properties.value)
  176. onClicked:
  177. {
  178. // Set to 90% only when enabling gradual infill
  179. var newInfillDensity;
  180. if (parseInt(infillSteps.properties.value) == 0)
  181. {
  182. previousInfillDensity = parseInt(infillDensity.properties.value)
  183. newInfillDensity = 90
  184. } else {
  185. newInfillDensity = previousInfillDensity
  186. }
  187. Cura.MachineManager.setSettingForAllExtruders("infill_sparse_density", "value", String(newInfillDensity))
  188. var infill_steps_value = 0
  189. if (parseInt(infillSteps.properties.value) == 0)
  190. {
  191. infill_steps_value = 5
  192. }
  193. Cura.MachineManager.setSettingForAllExtruders("gradual_infill_steps", "value", infill_steps_value)
  194. }
  195. onEntered: base.showTooltip(enableGradualInfillCheckBox, Qt.point(-infillSliderContainer.x - UM.Theme.getSize("thick_margin").width, 0),
  196. catalog.i18nc("@label", "Gradual infill will gradually increase the amount of infill towards the top."))
  197. onExited: base.hideTooltip()
  198. }
  199. }
  200. UM.SettingPropertyProvider
  201. {
  202. id: infillDensity
  203. containerStackId: Cura.MachineManager.activeStackId
  204. key: "infill_sparse_density"
  205. watchedProperties: [ "value" ]
  206. storeIndex: 0
  207. }
  208. UM.SettingPropertyProvider
  209. {
  210. id: infillSteps
  211. containerStackId: Cura.MachineManager.activeStackId
  212. key: "gradual_infill_steps"
  213. watchedProperties: ["value", "enabled"]
  214. storeIndex: 0
  215. }
  216. }