CustomPrintSetup.qml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //Copyright (c) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.6 as Cura
  8. import ".."
  9. Item
  10. {
  11. id: customPrintSetup
  12. property real padding: UM.Theme.getSize("default_margin").width
  13. property bool multipleExtruders: extrudersModel.count > 1
  14. property var extrudersModel: CuraApplication.getExtrudersModel()
  15. Item
  16. {
  17. id: intent
  18. height: childrenRect.height
  19. anchors
  20. {
  21. top: parent.top
  22. topMargin: UM.Theme.getSize("default_margin").height
  23. left: parent.left
  24. leftMargin: parent.padding
  25. right: parent.right
  26. rightMargin: parent.padding
  27. }
  28. UM.Label
  29. {
  30. id: profileLabel
  31. anchors
  32. {
  33. top: parent.top
  34. bottom: parent.bottom
  35. left: parent.left
  36. right: intentSelection.left
  37. }
  38. text: catalog.i18nc("@label", "Profile")
  39. font: UM.Theme.getFont("medium")
  40. }
  41. Button
  42. {
  43. id: intentSelection
  44. onClicked: menu.opened ? menu.close() : menu.open()
  45. anchors.right: parent.right
  46. width: UM.Theme.getSize("print_setup_big_item").width
  47. height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height
  48. hoverEnabled: true
  49. contentItem: RowLayout
  50. {
  51. spacing: 0
  52. anchors.left: parent.left
  53. anchors.right: customisedSettings.left
  54. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  55. UM.Label
  56. {
  57. id: textLabel
  58. text: Cura.MachineManager.activeQualityDisplayNameMap["main"]
  59. Layout.margins: 0
  60. Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row.
  61. height: contentHeight
  62. elide: Text.ElideRight
  63. wrapMode: Text.NoWrap
  64. }
  65. UM.Label
  66. {
  67. text: activeQualityDetailText()
  68. color: UM.Theme.getColor("text_detail")
  69. Layout.margins: 0
  70. Layout.fillWidth: true
  71. height: contentHeight
  72. elide: Text.ElideRight
  73. wrapMode: Text.NoWrap
  74. function activeQualityDetailText()
  75. {
  76. var resultMap = Cura.MachineManager.activeQualityDisplayNameMap
  77. var resultSuffix = resultMap["suffix"]
  78. var result = ""
  79. if (Cura.MachineManager.isActiveQualityExperimental)
  80. {
  81. resultSuffix += " (Experimental)"
  82. }
  83. if (Cura.MachineManager.isActiveQualitySupported)
  84. {
  85. if (Cura.MachineManager.activeQualityLayerHeight > 0)
  86. {
  87. if (resultSuffix)
  88. {
  89. result += " - " + resultSuffix
  90. }
  91. result += " - "
  92. result += Cura.MachineManager.activeQualityLayerHeight + "mm"
  93. }
  94. }
  95. return result
  96. }
  97. }
  98. }
  99. background: UM.UnderlineBackground
  100. {
  101. id: backgroundItem
  102. liningColor: intentSelection.hovered ? UM.Theme.getColor("text_field_border_hovered") : UM.Theme.getColor("border_field_light")
  103. }
  104. UM.SimpleButton
  105. {
  106. id: customisedSettings
  107. visible: Cura.MachineManager.hasUserSettings
  108. width: UM.Theme.getSize("print_setup_icon").width
  109. height: UM.Theme.getSize("print_setup_icon").height
  110. anchors.verticalCenter: parent.verticalCenter
  111. anchors.right: downArrow.left
  112. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  113. color: hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button");
  114. iconSource: UM.Theme.getIcon("StarFilled")
  115. onClicked:
  116. {
  117. forceActiveFocus();
  118. Cura.Actions.manageProfiles.trigger()
  119. }
  120. onEntered:
  121. {
  122. var content = catalog.i18nc("@tooltip", "Some setting/override values are different from the values stored in the profile.\n\nClick to open the profile manager.")
  123. base.showTooltip(intent, Qt.point(-UM.Theme.getSize("default_margin").width, 0), content)
  124. }
  125. onExited: base.hideTooltip()
  126. }
  127. UM.ColorImage
  128. {
  129. id: downArrow
  130. source: UM.Theme.getIcon("ChevronSingleDown")
  131. width: UM.Theme.getSize("standard_arrow").width
  132. height: UM.Theme.getSize("standard_arrow").height
  133. anchors
  134. {
  135. right: parent.right
  136. verticalCenter: parent.verticalCenter
  137. rightMargin: UM.Theme.getSize("default_margin").width
  138. }
  139. color: UM.Theme.getColor("setting_control_button")
  140. }
  141. }
  142. QualitiesWithIntentMenu
  143. {
  144. id: menu
  145. y: intentSelection.y + intentSelection.height
  146. x: intentSelection.x
  147. width: intentSelection.width
  148. }
  149. }
  150. UM.TabRow
  151. {
  152. id: tabBar
  153. visible: multipleExtruders // The tab row is only visible when there are more than 1 extruder
  154. anchors
  155. {
  156. top: intent.bottom
  157. topMargin: UM.Theme.getSize("default_margin").height
  158. left: parent.left
  159. leftMargin: parent.padding
  160. right: parent.right
  161. rightMargin: parent.padding
  162. }
  163. Repeater
  164. {
  165. id: repeater
  166. model: extrudersModel
  167. delegate: UM.TabRowButton
  168. {
  169. checked: model.index == 0
  170. contentItem: Item
  171. {
  172. Cura.ExtruderIcon
  173. {
  174. anchors.centerIn: parent
  175. materialColor: model.color
  176. extruderEnabled: model.enabled
  177. iconVariant: "default"
  178. }
  179. }
  180. onClicked:
  181. {
  182. Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
  183. }
  184. }
  185. }
  186. //When active extruder changes for some other reason, switch tabs.
  187. //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
  188. //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
  189. Connections
  190. {
  191. target: Cura.ExtruderManager
  192. function onActiveExtruderChanged()
  193. {
  194. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  195. }
  196. }
  197. //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
  198. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
  199. //Therefore we need to change it back to what it was: The active extruder index.
  200. Connections
  201. {
  202. target: repeater.model
  203. function onModelChanged()
  204. {
  205. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
  206. }
  207. }
  208. }
  209. Rectangle
  210. {
  211. anchors
  212. {
  213. top: tabBar.visible ? tabBar.bottom : intent.bottom
  214. topMargin: -UM.Theme.getSize("default_lining").width
  215. left: parent.left
  216. leftMargin: parent.padding
  217. right: parent.right
  218. rightMargin: parent.padding
  219. bottom: parent.bottom
  220. }
  221. z: tabBar.z - 1
  222. // Don't show the border when only one extruder
  223. border.color: tabBar.visible ? UM.Theme.getColor("lining") : "transparent"
  224. border.width: UM.Theme.getSize("default_lining").width
  225. color: UM.Theme.getColor("main_background")
  226. Cura.SettingView
  227. {
  228. anchors
  229. {
  230. fill: parent
  231. topMargin: UM.Theme.getSize("default_margin").height
  232. leftMargin: UM.Theme.getSize("default_margin").width
  233. // Small space for the scrollbar
  234. rightMargin: UM.Theme.getSize("narrow_margin").width
  235. // Compensate for the negative margin in the parent
  236. bottomMargin: UM.Theme.getSize("default_lining").width
  237. }
  238. }
  239. }
  240. }