CustomConfigurationSelector.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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.1
  5. import QtQuick.Controls.Styles 1.1
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. Rectangle
  9. {
  10. implicitWidth: parent.width
  11. implicitHeight: parent.height
  12. id: base
  13. color: UM.Theme.getColor("main_background")
  14. // Height has an extra 2x margin for the top & bottom margin.
  15. height: childrenRect.height + 2 * UM.Theme.getSize("default_margin").width
  16. Cura.ExtrudersModel { id: extrudersModel }
  17. ListView
  18. {
  19. // Horizontal list that shows the extruders
  20. id: extrudersList
  21. visible: extrudersModel.items.length > 1
  22. property var index: 0
  23. height: UM.Theme.getSize("configuration_selector_mode_tabs").height
  24. boundsBehavior: Flickable.StopAtBounds
  25. anchors
  26. {
  27. left: parent.left
  28. right: parent.right
  29. top: parent.top
  30. margins: UM.Theme.getSize("thick_margin").width
  31. }
  32. ExclusiveGroup { id: extruderMenuGroup }
  33. orientation: ListView.Horizontal
  34. model: extrudersModel
  35. Connections
  36. {
  37. target: Cura.MachineManager
  38. onGlobalContainerChanged: forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  39. }
  40. delegate: Button
  41. {
  42. height: parent.height
  43. width: Math.round(ListView.view.width / extrudersModel.rowCount())
  44. text: model.name
  45. tooltip: model.name
  46. exclusiveGroup: extruderMenuGroup
  47. checked: Cura.ExtruderManager.activeExtruderIndex == index
  48. property bool extruder_enabled: true
  49. MouseArea // TODO; This really should be fixed. It makes absolutely no sense to have a button AND a mouse area.
  50. {
  51. anchors.fill: parent
  52. acceptedButtons: Qt.LeftButton | Qt.RightButton
  53. onClicked:
  54. {
  55. switch (mouse.button)
  56. {
  57. case Qt.LeftButton:
  58. extruder_enabled = Cura.MachineManager.getExtruder(model.index).isEnabled
  59. if (extruder_enabled)
  60. {
  61. forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  62. Cura.ExtruderManager.setActiveExtruderIndex(index)
  63. }
  64. break
  65. case Qt.RightButton:
  66. extruder_enabled = Cura.MachineManager.getExtruder(model.index).isEnabled
  67. extruderMenu.popup()
  68. break
  69. }
  70. }
  71. }
  72. Menu
  73. {
  74. id: extruderMenu
  75. MenuItem
  76. {
  77. text: catalog.i18nc("@action:inmenu", "Enable Extruder")
  78. onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true)
  79. visible: !extruder_enabled // using an intermediate variable prevents an empty popup that occured now and then
  80. }
  81. MenuItem
  82. {
  83. text: catalog.i18nc("@action:inmenu", "Disable Extruder")
  84. onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, false)
  85. visible: extruder_enabled
  86. enabled: Cura.MachineManager.numberExtrudersEnabled > 1
  87. }
  88. }
  89. style: ButtonStyle
  90. {
  91. background: Rectangle
  92. {
  93. anchors.fill: parent
  94. border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
  95. border.color:
  96. {
  97. if (Cura.MachineManager.getExtruder(index).isEnabled)
  98. {
  99. if(control.checked || control.pressed)
  100. {
  101. return UM.Theme.getColor("action_button_active_border")
  102. }
  103. else if (control.hovered)
  104. {
  105. return UM.Theme.getColor("action_button_hovered_border")
  106. }
  107. return UM.Theme.getColor("action_button_border")
  108. }
  109. return UM.Theme.getColor("action_button_disabled_border")
  110. }
  111. color:
  112. {
  113. if (Cura.MachineManager.getExtruder(index).isEnabled)
  114. {
  115. if(control.checked || control.pressed)
  116. {
  117. return UM.Theme.getColor("action_button_active");
  118. }
  119. else if (control.hovered)
  120. {
  121. return UM.Theme.getColor("action_button_hovered")
  122. }
  123. return UM.Theme.getColor("action_button")
  124. }
  125. return UM.Theme.getColor("action_button_disabled")
  126. }
  127. Behavior on color { ColorAnimation { duration: 50; } }
  128. Item
  129. {
  130. id: extruderButtonFace
  131. anchors.centerIn: parent
  132. width: childrenRect.width
  133. Label
  134. {
  135. // Static text that holds the "Extruder" label
  136. id: extruderStaticText
  137. anchors.verticalCenter: parent.verticalCenter
  138. anchors.left: parent.left
  139. color:
  140. {
  141. if (Cura.MachineManager.getExtruder(index).isEnabled)
  142. {
  143. if(control.checked || control.pressed)
  144. {
  145. return UM.Theme.getColor("action_button_active_text");
  146. }
  147. else if (control.hovered)
  148. {
  149. return UM.Theme.getColor("action_button_hovered_text")
  150. }
  151. return UM.Theme.getColor("action_button_text")
  152. }
  153. return UM.Theme.getColor("action_button_disabled_text")
  154. }
  155. font: UM.Theme.getFont("large_nonbold")
  156. text: catalog.i18nc("@label", "Extruder")
  157. visible: width < (control.width - extruderIcon.width - UM.Theme.getSize("default_margin").width)
  158. elide: Text.ElideRight
  159. }
  160. ExtruderIcon
  161. {
  162. // Round icon with the extruder number and material color indicator.
  163. id: extruderIcon
  164. anchors.verticalCenter: parent.verticalCenter
  165. anchors.left: extruderStaticText.right
  166. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  167. width: control.height - Math.round(UM.Theme.getSize("default_margin").width / 2)
  168. height: width
  169. checked: control.checked
  170. materialColor: model.color
  171. textColor: extruderStaticText.color
  172. }
  173. }
  174. }
  175. label: Item {}
  176. }
  177. }
  178. }
  179. Item
  180. {
  181. id: materialRow
  182. height: UM.Theme.getSize("print_setup_item").height
  183. visible: Cura.MachineManager.hasMaterials
  184. anchors
  185. {
  186. left: parent.left
  187. right: parent.right
  188. top: extrudersList.bottom
  189. margins: UM.Theme.getSize("thick_margin").width
  190. }
  191. Label
  192. {
  193. id: materialLabel
  194. text: catalog.i18nc("@label", "Material");
  195. width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  196. height: parent.height
  197. verticalAlignment: Text.AlignVCenter
  198. font: UM.Theme.getFont("default");
  199. color: UM.Theme.getColor("text");
  200. }
  201. ToolButton
  202. {
  203. id: materialSelection
  204. property var activeExtruder: Cura.MachineManager.activeStack
  205. property var hasActiveExtruder: activeExtruder != null
  206. property var currentRootMaterialName: hasActiveExtruder ? activeExtruder.material.name : ""
  207. text: currentRootMaterialName
  208. tooltip: currentRootMaterialName
  209. visible: Cura.MachineManager.hasMaterials
  210. enabled: !extrudersList.visible || Cura.ExtruderManager.activeExtruderIndex > -1
  211. height: UM.Theme.getSize("setting_control").height
  212. width: Math.round(parent.width * 0.7) + UM.Theme.getSize("thick_margin").width
  213. anchors.right: parent.right
  214. style: UM.Theme.styles.sidebar_header_button
  215. activeFocusOnPress: true;
  216. menu: Cura.MaterialMenu
  217. {
  218. extruderIndex: Cura.ExtruderManager.activeExtruderIndex
  219. }
  220. property var valueError: hasActiveExtruder ? Cura.ContainerManager.getContainerMetaDataEntry(activeExtruder.material.id, "compatible", "") != "True" : true
  221. property var valueWarning: ! Cura.MachineManager.isActiveQualitySupported
  222. }
  223. }
  224. Item
  225. {
  226. id: variantRow
  227. height: UM.Theme.getSize("print_setup_item").height
  228. visible: Cura.MachineManager.hasVariants
  229. anchors
  230. {
  231. left: parent.left
  232. right: parent.right
  233. top: materialRow.bottom
  234. margins: UM.Theme.getSize("thick_margin").width
  235. }
  236. Label
  237. {
  238. id: variantLabel
  239. text: Cura.MachineManager.activeDefinitionVariantsName;
  240. width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  241. height: parent.height
  242. verticalAlignment: Text.AlignVCenter
  243. font: UM.Theme.getFont("default");
  244. color: UM.Theme.getColor("text");
  245. }
  246. ToolButton
  247. {
  248. id: variantSelection
  249. text: Cura.MachineManager.activeVariantName
  250. tooltip: Cura.MachineManager.activeVariantName;
  251. visible: Cura.MachineManager.hasVariants
  252. height: UM.Theme.getSize("setting_control").height
  253. width: Math.round(parent.width * 0.7 + UM.Theme.getSize("thick_margin").width)
  254. anchors.right: parent.right
  255. style: UM.Theme.styles.sidebar_header_button
  256. activeFocusOnPress: true;
  257. menu: Cura.NozzleMenu { extruderIndex: Cura.ExtruderManager.activeExtruderIndex }
  258. }
  259. }
  260. Item
  261. {
  262. id: materialCompatibilityLink
  263. height: UM.Theme.getSize("print_setup_item").height
  264. anchors.right: parent.right
  265. anchors.top: variantRow.bottom
  266. anchors.margins: UM.Theme.getSize("thick_margin").width
  267. UM.RecolorImage
  268. {
  269. id: warningImage
  270. anchors.right: materialInfoLabel.left
  271. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  272. source: UM.Theme.getIcon("warning")
  273. width: UM.Theme.getSize("section_icon").width
  274. height: UM.Theme.getSize("section_icon").height
  275. sourceSize.width: width
  276. sourceSize.height: height
  277. color: UM.Theme.getColor("material_compatibility_warning")
  278. visible: !Cura.MachineManager.isCurrentSetupSupported
  279. }
  280. Label
  281. {
  282. id: materialInfoLabel
  283. wrapMode: Text.WordWrap
  284. text: "<a href='%1'>" + catalog.i18nc("@label", "Check compatibility") + "</a>"
  285. font: UM.Theme.getFont("default")
  286. color: UM.Theme.getColor("text")
  287. linkColor: UM.Theme.getColor("text_link")
  288. verticalAlignment: Text.AlignTop
  289. anchors.right: parent.right
  290. MouseArea
  291. {
  292. anchors.fill: parent
  293. onClicked:
  294. {
  295. // open the material URL with web browser
  296. Qt.openUrlExternally("https://ultimaker.com/incoming-links/cura/material-compatibilty");
  297. }
  298. }
  299. }
  300. }
  301. }