CustomPrintSetup.qml 8.5 KB

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