CustomPrintSetup.qml 9.4 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. // Anchoring to the right makes much more sense here, but for some reason this component compresses from the right
  46. // and then expands from the left afterwards. This pushes it left by profileWarningReset.width
  47. // The solution is to anchor from the other direction so this does not happen.
  48. anchors.left: parent.left
  49. // This leftMargin gives us the same spacing as anchoring to the right on profileWarningReset
  50. anchors.leftMargin: parent.width - UM.Theme.getSize("print_setup_big_item").width
  51. width: profileWarningReset.visible ? UM.Theme.getSize("print_setup_big_item").width - profileWarningReset.width - UM.Theme.getSize("default_margin").width : UM.Theme.getSize("print_setup_big_item").width
  52. height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height
  53. hoverEnabled: true
  54. contentItem: RowLayout
  55. {
  56. spacing: 0
  57. anchors.left: parent.left
  58. anchors.right: customisedSettings.left
  59. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  60. UM.Label
  61. {
  62. id: textLabel
  63. text: Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - ")
  64. Layout.margins: 0
  65. Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row.
  66. height: contentHeight
  67. elide: Text.ElideRight
  68. wrapMode: Text.NoWrap
  69. }
  70. UM.Label
  71. {
  72. text:
  73. {
  74. const string_parts = Cura.MachineManager.activeQualityDisplayNameTailStringParts;
  75. if (string_parts.length === 0)
  76. {
  77. return "";
  78. }
  79. else
  80. {
  81. ` - ${string_parts.join(" - ")}`
  82. }
  83. }
  84. color: UM.Theme.getColor("text_detail")
  85. Layout.margins: 0
  86. Layout.fillWidth: true
  87. height: contentHeight
  88. elide: Text.ElideRight
  89. wrapMode: Text.NoWrap
  90. }
  91. }
  92. background: UM.UnderlineBackground
  93. {
  94. id: backgroundItem
  95. liningColor: intentSelection.hovered ? UM.Theme.getColor("text_field_border_hovered") : UM.Theme.getColor("border_field_light")
  96. }
  97. UM.SimpleButton
  98. {
  99. id: customisedSettings
  100. visible: Cura.MachineManager.hasUserSettings
  101. width: UM.Theme.getSize("print_setup_icon").width
  102. height: UM.Theme.getSize("print_setup_icon").height
  103. anchors.verticalCenter: parent.verticalCenter
  104. anchors.right: downArrow.left
  105. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  106. color: hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button");
  107. iconSource: UM.Theme.getIcon("StarFilled")
  108. onClicked:
  109. {
  110. forceActiveFocus();
  111. Cura.Actions.manageProfiles.trigger()
  112. }
  113. onEntered:
  114. {
  115. 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.")
  116. base.showTooltip(intent, Qt.point(-UM.Theme.getSize("default_margin").width, 0), content)
  117. }
  118. onExited: base.hideTooltip()
  119. }
  120. UM.ColorImage
  121. {
  122. id: downArrow
  123. source: UM.Theme.getIcon("ChevronSingleDown")
  124. width: UM.Theme.getSize("standard_arrow").width
  125. height: UM.Theme.getSize("standard_arrow").height
  126. anchors
  127. {
  128. right: parent.right
  129. verticalCenter: parent.verticalCenter
  130. rightMargin: UM.Theme.getSize("default_margin").width
  131. }
  132. color: UM.Theme.getColor("setting_control_button")
  133. }
  134. }
  135. ProfileWarningReset
  136. {
  137. id: profileWarningReset
  138. width: childrenRect.width
  139. anchors.right: parent.right
  140. anchors.verticalCenter: parent.verticalCenter
  141. fullWarning: false
  142. }
  143. QualitiesWithIntentMenu
  144. {
  145. id: menu
  146. y: intentSelection.y + intentSelection.height
  147. x: intentSelection.x
  148. width: intentSelection.width
  149. }
  150. }
  151. UM.TabRow
  152. {
  153. id: tabBar
  154. visible: multipleExtruders // The tab row is only visible when there are more than 1 extruder
  155. anchors
  156. {
  157. top: intent.bottom
  158. topMargin: UM.Theme.getSize("default_margin").height
  159. left: parent.left
  160. leftMargin: parent.padding
  161. right: parent.right
  162. rightMargin: parent.padding
  163. }
  164. Repeater
  165. {
  166. id: repeater
  167. model: extrudersModel
  168. delegate: UM.TabRowButton
  169. {
  170. checked: model.index == 0
  171. contentItem: Item
  172. {
  173. Cura.ExtruderIcon
  174. {
  175. anchors.centerIn: parent
  176. materialColor: model.color
  177. extruderEnabled: model.enabled
  178. iconVariant: "default"
  179. }
  180. }
  181. onClicked:
  182. {
  183. Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
  184. }
  185. }
  186. }
  187. //When active extruder changes for some other reason, switch tabs.
  188. //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
  189. //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
  190. Connections
  191. {
  192. target: Cura.ExtruderManager
  193. function onActiveExtruderChanged()
  194. {
  195. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  196. }
  197. }
  198. //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
  199. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
  200. //Therefore we need to change it back to what it was: The active extruder index.
  201. Connections
  202. {
  203. target: repeater.model
  204. function onModelChanged()
  205. {
  206. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
  207. }
  208. }
  209. }
  210. Rectangle
  211. {
  212. anchors
  213. {
  214. top: tabBar.visible ? tabBar.bottom : intent.bottom
  215. topMargin: -UM.Theme.getSize("default_lining").width
  216. left: parent.left
  217. leftMargin: parent.padding
  218. right: parent.right
  219. rightMargin: parent.padding
  220. bottom: parent.bottom
  221. }
  222. z: tabBar.z - 1
  223. // Don't show the border when only one extruder
  224. border.color: tabBar.visible ? UM.Theme.getColor("lining") : "transparent"
  225. border.width: UM.Theme.getSize("default_lining").width
  226. color: UM.Theme.getColor("main_background")
  227. Cura.SettingView
  228. {
  229. anchors
  230. {
  231. fill: parent
  232. topMargin: UM.Theme.getSize("default_margin").height
  233. leftMargin: UM.Theme.getSize("default_margin").width
  234. // Small space for the scrollbar
  235. rightMargin: UM.Theme.getSize("narrow_margin").width
  236. // Compensate for the negative margin in the parent
  237. bottomMargin: UM.Theme.getSize("default_lining").width
  238. }
  239. }
  240. }
  241. }