PrintSetupSelector.qml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 2.0
  5. import QtQuick.Layouts 1.3
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. import "Menus"
  9. import "Menus/ConfigurationMenu"
  10. Cura.ExpandableComponent
  11. {
  12. id: base
  13. property int currentModeIndex: -1
  14. property bool hideSettings: PrintInformation.preSliced
  15. property string enabledText: catalog.i18nc("@label:Should be short", "On")
  16. property string disabledText: catalog.i18nc("@label:Should be short", "Off")
  17. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
  18. signal showTooltip(Item item, point location, string text)
  19. signal hideTooltip()
  20. implicitWidth: 200
  21. height: childrenRect.height
  22. iconSource: UM.Theme.getIcon("pencil")
  23. onCurrentModeIndexChanged: UM.Preferences.setValue("cura/active_mode", currentModeIndex)
  24. UM.I18nCatalog
  25. {
  26. id: catalog
  27. name: "cura"
  28. }
  29. Timer
  30. {
  31. id: tooltipDelayTimer
  32. interval: 500
  33. repeat: false
  34. property var item
  35. property string text
  36. onTriggered: base.showTooltip(base, {x: 0, y: item.y}, text)
  37. }
  38. headerItem: RowLayout
  39. {
  40. anchors.fill: parent
  41. IconWithText
  42. {
  43. source: UM.Theme.getIcon("category_layer_height")
  44. text: Cura.MachineManager.activeQualityOrQualityChangesName + " " + layerHeight.properties.value + "mm"
  45. UM.SettingPropertyProvider
  46. {
  47. id: layerHeight
  48. containerStackId: Cura.MachineManager.activeStackId
  49. key: "layer_height"
  50. watchedProperties: ["value"]
  51. }
  52. }
  53. IconWithText
  54. {
  55. source: UM.Theme.getIcon("category_infill")
  56. text: parseInt(infillDensity.properties.value) + "%"
  57. UM.SettingPropertyProvider
  58. {
  59. id: infillDensity
  60. containerStackId: Cura.MachineManager.activeStackId
  61. key: "infill_sparse_density"
  62. watchedProperties: ["value"]
  63. }
  64. }
  65. IconWithText
  66. {
  67. source: UM.Theme.getIcon("category_support")
  68. text: supportEnabled.properties.value == "True" ? enabledText : disabledText
  69. UM.SettingPropertyProvider
  70. {
  71. id: supportEnabled
  72. containerStack: Cura.MachineManager.activeMachine
  73. key: "support_enable"
  74. watchedProperties: ["value"]
  75. }
  76. }
  77. IconWithText
  78. {
  79. source: UM.Theme.getIcon("category_adhesion")
  80. text: platformAdhesionType.properties.value != "skirt" && platformAdhesionType.properties.value != "none" ? enabledText : disabledText
  81. UM.SettingPropertyProvider
  82. {
  83. id: platformAdhesionType
  84. containerStack: Cura.MachineManager.activeMachine
  85. key: "adhesion_type"
  86. watchedProperties: [ "value"]
  87. }
  88. }
  89. }
  90. popupItem: Item
  91. {
  92. height: settingsModeSelection.height + sidebarContents.height + 2 * UM.Theme.getSize("default_margin").height
  93. width: UM.Theme.getSize("print_setup_widget").width
  94. ListView
  95. {
  96. // Settings mode selection toggle
  97. id: settingsModeSelection
  98. model: modesListModel
  99. height: UM.Theme.getSize("print_setup_mode_toggle").height
  100. visible: !hideSettings
  101. anchors
  102. {
  103. right: parent.right
  104. left: parent.left
  105. margins: UM.Theme.getSize("thick_margin").width
  106. }
  107. ButtonGroup
  108. {
  109. id: modeMenuGroup
  110. }
  111. delegate: Button
  112. {
  113. id: control
  114. height: settingsModeSelection.height
  115. width: Math.round(parent.width / 2)
  116. anchors.left: parent.left
  117. anchors.leftMargin: model.index * Math.round(settingsModeSelection.width / 2)
  118. anchors.verticalCenter: parent.verticalCenter
  119. ButtonGroup.group: modeMenuGroup
  120. checkable: true
  121. checked: base.currentModeIndex == index
  122. onClicked: base.currentModeIndex = index
  123. onHoveredChanged:
  124. {
  125. if (hovered)
  126. {
  127. tooltipDelayTimer.item = settingsModeSelection
  128. tooltipDelayTimer.text = model.tooltipText
  129. tooltipDelayTimer.start()
  130. }
  131. else
  132. {
  133. tooltipDelayTimer.stop()
  134. base.hideTooltip()
  135. }
  136. }
  137. background: Rectangle
  138. {
  139. border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
  140. border.color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") : control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  141. // For some reason, QtQuick decided to use the color of the background property as text color for the contentItem, so here it is
  142. color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") : control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  143. }
  144. contentItem: Label
  145. {
  146. text: model.text
  147. font: UM.Theme.getFont("default")
  148. horizontalAlignment: Text.AlignHCenter
  149. verticalAlignment: Text.AlignVCenter
  150. renderType: Text.NativeRendering
  151. elide: Text.ElideRight
  152. color:
  153. {
  154. if(control.pressed)
  155. {
  156. return UM.Theme.getColor("action_button_active_text")
  157. }
  158. else if(control.hovered)
  159. {
  160. return UM.Theme.getColor("action_button_hovered_text")
  161. }
  162. return UM.Theme.getColor("action_button_text")
  163. }
  164. }
  165. }
  166. }
  167. Item
  168. {
  169. id: sidebarContents
  170. anchors.top: settingsModeSelection.bottom
  171. anchors.topMargin: UM.Theme.getSize("thick_margin").height
  172. anchors.left: parent.left
  173. anchors.right: parent.right
  174. height: UM.Theme.getSize("print_setup_widget").height
  175. visible: !hideSettings
  176. // We load both of them at once (instead of using a loader) because the advanced sidebar can take
  177. // quite some time to load. So in this case we sacrifice memory for speed.
  178. SidebarAdvanced
  179. {
  180. anchors.fill: parent
  181. visible: currentModeIndex == 1
  182. onShowTooltip: base.showTooltip(item, location, text)
  183. onHideTooltip: base.hideTooltip()
  184. }
  185. SidebarSimple
  186. {
  187. anchors.fill: parent
  188. visible: currentModeIndex != 1
  189. onShowTooltip: base.showTooltip(item, location, text)
  190. onHideTooltip: base.hideTooltip()
  191. }
  192. }
  193. // Setting mode: Recommended or Custom
  194. ListModel
  195. {
  196. id: modesListModel
  197. }
  198. Component.onCompleted:
  199. {
  200. modesListModel.append({
  201. text: catalog.i18nc("@title:tab", "Recommended"),
  202. tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Recommended Print Setup")).arg(catalog.i18nc("@tooltip", "Print with the recommended settings for the selected printer, material and quality."))
  203. })
  204. modesListModel.append({
  205. text: catalog.i18nc("@title:tab", "Custom"),
  206. tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Custom Print Setup")).arg(catalog.i18nc("@tooltip", "Print with finegrained control over every last bit of the slicing process."))
  207. })
  208. var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
  209. if(index != null && !isNaN(index))
  210. {
  211. currentModeIndex = index
  212. }
  213. else
  214. {
  215. currentModeIndex = 0
  216. }
  217. }
  218. }
  219. }