RecommendedInfillDensitySelector.qml 8.7 KB

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