RecommendedSupportSelector.qml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. // Enable support
  10. //
  11. Item
  12. {
  13. id: enableSupportRow
  14. height: childrenRect.height
  15. property real labelColumnWidth: Math.round(width / 3)
  16. Cura.IconWithText
  17. {
  18. id: enableSupportRowTitle
  19. anchors.top: parent.top
  20. anchors.left: parent.left
  21. visible: enableSupportCheckBox.visible
  22. source: UM.Theme.getIcon("category_support")
  23. text: catalog.i18nc("@label", "Support")
  24. font: UM.Theme.getFont("medium")
  25. width: labelColumnWidth
  26. }
  27. Item
  28. {
  29. id: enableSupportContainer
  30. height: enableSupportCheckBox.height
  31. anchors
  32. {
  33. left: enableSupportRowTitle.right
  34. right: parent.right
  35. verticalCenter: enableSupportRowTitle.verticalCenter
  36. }
  37. CheckBox
  38. {
  39. id: enableSupportCheckBox
  40. anchors.verticalCenter: parent.verticalCenter
  41. property alias _hovered: enableSupportMouseArea.containsMouse
  42. style: UM.Theme.styles.checkbox
  43. enabled: recommendedPrintSetup.settingsEnabled
  44. visible: supportEnabled.properties.enabled == "True"
  45. checked: supportEnabled.properties.value == "True"
  46. MouseArea
  47. {
  48. id: enableSupportMouseArea
  49. anchors.fill: parent
  50. hoverEnabled: true
  51. onClicked: supportEnabled.setPropertyValue("value", supportEnabled.properties.value != "True")
  52. onEntered:
  53. {
  54. base.showTooltip(enableSupportCheckBox, Qt.point(-enableSupportContainer.x - UM.Theme.getSize("thick_margin").width, 0),
  55. catalog.i18nc("@label", "Generate structures to support parts of the model which have overhangs. Without these structures, such parts would collapse during printing."))
  56. }
  57. onExited: base.hideTooltip()
  58. }
  59. }
  60. ComboBox
  61. {
  62. id: supportExtruderCombobox
  63. height: UM.Theme.getSize("print_setup_big_item").height
  64. anchors
  65. {
  66. left: enableSupportCheckBox.right
  67. right: parent.right
  68. leftMargin: UM.Theme.getSize("thick_margin").width
  69. rightMargin: UM.Theme.getSize("thick_margin").width
  70. verticalCenter: parent.verticalCenter
  71. }
  72. style: UM.Theme.styles.combobox_color
  73. enabled: recommendedPrintSetup.settingsEnabled
  74. visible: enableSupportCheckBox.visible && (supportEnabled.properties.value == "True") && (extrudersEnabledCount.properties.value > 1)
  75. textRole: "text" // this solves that the combobox isn't populated in the first time Cura is started
  76. model: extruderModel
  77. property alias _hovered: supportExtruderMouseArea.containsMouse
  78. property string color_override: "" // for manually setting values
  79. property string color: // is evaluated automatically, but the first time is before extruderModel being filled
  80. {
  81. var current_extruder = extruderModel.get(currentIndex)
  82. color_override = ""
  83. if (current_extruder === undefined) return ""
  84. return (current_extruder.color) ? current_extruder.color : ""
  85. }
  86. currentIndex:
  87. {
  88. if (supportExtruderNr.properties == null)
  89. {
  90. return Cura.MachineManager.defaultExtruderPosition
  91. }
  92. else
  93. {
  94. var extruder = parseInt(supportExtruderNr.properties.value)
  95. if ( extruder === -1)
  96. {
  97. return Cura.MachineManager.defaultExtruderPosition
  98. }
  99. return extruder;
  100. }
  101. }
  102. onActivated: supportExtruderNr.setPropertyValue("value", String(index))
  103. MouseArea
  104. {
  105. id: supportExtruderMouseArea
  106. anchors.fill: parent
  107. hoverEnabled: true
  108. enabled: recommendedPrintSetup.settingsEnabled
  109. acceptedButtons: Qt.NoButton
  110. onEntered:
  111. {
  112. base.showTooltip(supportExtruderCombobox, Qt.point(-enableSupportContainer.x - supportExtruderCombobox.x - UM.Theme.getSize("thick_margin").width, 0),
  113. catalog.i18nc("@label", "Select which extruder to use for support. This will build up supporting structures below the model to prevent the model from sagging or printing in mid air."));
  114. }
  115. onExited: base.hideTooltip()
  116. }
  117. function updateCurrentColor()
  118. {
  119. var current_extruder = extruderModel.get(currentIndex)
  120. if (current_extruder !== undefined)
  121. {
  122. supportExtruderCombobox.color_override = current_extruder.color
  123. }
  124. }
  125. }
  126. }
  127. ListModel
  128. {
  129. id: extruderModel
  130. Component.onCompleted: populateExtruderModel()
  131. }
  132. //: Model used to populate the extrudelModel
  133. property var extruders: CuraApplication.getExtrudersModel()
  134. Connections
  135. {
  136. target: extruders
  137. onModelChanged: populateExtruderModel()
  138. }
  139. UM.SettingPropertyProvider
  140. {
  141. id: supportEnabled
  142. containerStack: Cura.MachineManager.activeMachine
  143. key: "support_enable"
  144. watchedProperties: [ "value", "enabled", "description" ]
  145. storeIndex: 0
  146. }
  147. UM.SettingPropertyProvider
  148. {
  149. id: supportExtruderNr
  150. containerStack: Cura.MachineManager.activeMachine
  151. key: "support_extruder_nr"
  152. watchedProperties: [ "value" ]
  153. storeIndex: 0
  154. }
  155. UM.SettingPropertyProvider
  156. {
  157. id: machineExtruderCount
  158. containerStack: Cura.MachineManager.activeMachine
  159. key: "machine_extruder_count"
  160. watchedProperties: ["value"]
  161. storeIndex: 0
  162. }
  163. function populateExtruderModel()
  164. {
  165. extruderModel.clear()
  166. for (var extruderNumber = 0; extruderNumber < extruders.rowCount(); extruderNumber++)
  167. {
  168. extruderModel.append({
  169. text: extruders.getItem(extruderNumber).name,
  170. color: extruders.getItem(extruderNumber).color
  171. })
  172. }
  173. supportExtruderCombobox.updateCurrentColor()
  174. }
  175. }