SidebarHeader.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  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. import "Menus"
  9. Column
  10. {
  11. id: base;
  12. property int currentExtruderIndex: ExtruderManager.activeExtruderIndex;
  13. property bool currentExtruderVisible: extrudersList.visible;
  14. spacing: Math.floor(UM.Theme.getSize("sidebar_margin").width * 0.9)
  15. signal showTooltip(Item item, point location, string text)
  16. signal hideTooltip()
  17. Item
  18. {
  19. anchors
  20. {
  21. left: parent.left
  22. right: parent.right
  23. }
  24. visible: extruderSelectionRow.visible
  25. height: UM.Theme.getSize("default_lining").height
  26. width: height
  27. }
  28. Item
  29. {
  30. id: extruderSelectionRow
  31. width: parent.width
  32. height: Math.floor(UM.Theme.getSize("sidebar_tabs").height * 2 / 3)
  33. visible: machineExtruderCount.properties.value > 1 && !sidebar.monitoringPrint
  34. anchors
  35. {
  36. left: parent.left
  37. leftMargin: Math.floor(UM.Theme.getSize("sidebar_margin").width * 0.7)
  38. right: parent.right
  39. rightMargin: Math.floor(UM.Theme.getSize("sidebar_margin").width * 0.7)
  40. topMargin: UM.Theme.getSize("sidebar_margin").height
  41. }
  42. ListView
  43. {
  44. id: extrudersList
  45. property var index: 0
  46. height: UM.Theme.getSize("sidebar_header_mode_tabs").height
  47. width: Math.floor(parent.width)
  48. boundsBehavior: Flickable.StopAtBounds
  49. anchors
  50. {
  51. left: parent.left
  52. leftMargin: Math.floor(UM.Theme.getSize("default_margin").width / 2)
  53. right: parent.right
  54. rightMargin: Math.floor(UM.Theme.getSize("default_margin").width / 2)
  55. verticalCenter: parent.verticalCenter
  56. }
  57. ExclusiveGroup { id: extruderMenuGroup; }
  58. orientation: ListView.Horizontal
  59. model: Cura.ExtrudersModel { id: extrudersModel; addGlobal: false }
  60. Connections
  61. {
  62. target: Cura.MachineManager
  63. onGlobalContainerChanged: forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  64. }
  65. delegate: Button
  66. {
  67. height: ListView.view.height
  68. width: ListView.view.width / extrudersModel.rowCount()
  69. text: model.name
  70. tooltip: model.name
  71. exclusiveGroup: extruderMenuGroup
  72. checked: base.currentExtruderIndex == index
  73. onClicked:
  74. {
  75. forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  76. ExtruderManager.setActiveExtruderIndex(index);
  77. }
  78. style: ButtonStyle
  79. {
  80. background: Item
  81. {
  82. Rectangle
  83. {
  84. anchors.fill: parent
  85. border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
  86. border.color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") :
  87. control.hovered ? UM.Theme.getColor("action_button_hovered_border") :
  88. UM.Theme.getColor("action_button_border")
  89. color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") :
  90. control.hovered ? UM.Theme.getColor("action_button_hovered") :
  91. UM.Theme.getColor("action_button")
  92. Behavior on color { ColorAnimation { duration: 50; } }
  93. }
  94. Item
  95. {
  96. id: extruderButtonFace
  97. anchors.centerIn: parent
  98. width: {
  99. var extruderTextWidth = extruderStaticText.visible ? extruderStaticText.width : 0;
  100. var iconWidth = extruderIconItem.width;
  101. return Math.floor(extruderTextWidth + iconWidth + UM.Theme.getSize("default_margin").width / 2);
  102. }
  103. // Static text "Extruder"
  104. Label
  105. {
  106. id: extruderStaticText
  107. anchors.verticalCenter: parent.verticalCenter
  108. anchors.left: parent.left
  109. color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_text") :
  110. control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
  111. UM.Theme.getColor("action_button_text")
  112. font: UM.Theme.getFont("large_nonbold")
  113. text: catalog.i18nc("@label", "Extruder")
  114. visible: width < (control.width - extruderIconItem.width - UM.Theme.getSize("default_margin").width)
  115. elide: Text.ElideRight
  116. }
  117. // Everthing for the extruder icon
  118. Item
  119. {
  120. id: extruderIconItem
  121. anchors.verticalCenter: parent.verticalCenter
  122. anchors.right: parent.right
  123. property var sizeToUse:
  124. {
  125. var minimumWidth = control.width < UM.Theme.getSize("button").width ? control.width : UM.Theme.getSize("button").width;
  126. var minimumHeight = control.height < UM.Theme.getSize("button").height ? control.height : UM.Theme.getSize("button").height;
  127. var minimumSize = minimumWidth < minimumHeight ? minimumWidth : minimumHeight;
  128. minimumSize -= Math.floor(UM.Theme.getSize("default_margin").width / 2);
  129. return minimumSize;
  130. }
  131. width: sizeToUse
  132. height: sizeToUse
  133. UM.RecolorImage {
  134. id: mainCircle
  135. anchors.fill: parent
  136. sourceSize.width: parent.width
  137. sourceSize.height: parent.width
  138. source: UM.Theme.getIcon("extruder_button")
  139. color: extruderNumberText.color
  140. }
  141. Label
  142. {
  143. id: extruderNumberText
  144. anchors.centerIn: parent
  145. text: index + 1;
  146. color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_text") :
  147. control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
  148. UM.Theme.getColor("action_button_text")
  149. font: UM.Theme.getFont("default_bold")
  150. }
  151. // Material colour circle
  152. // Only draw the filling colour of the material inside the SVG border.
  153. Rectangle
  154. {
  155. anchors
  156. {
  157. right: parent.right
  158. top: parent.top
  159. rightMargin: parent.sizeToUse * 0.01
  160. topMargin: parent.sizeToUse * 0.05
  161. }
  162. color: model.color
  163. width: parent.width * 0.35
  164. height: parent.height * 0.35
  165. radius: width / 2
  166. border.width: 1
  167. border.color: UM.Theme.getColor("extruder_button_material_border")
  168. opacity: !control.checked ? 0.6 : 1.0
  169. }
  170. }
  171. }
  172. }
  173. label: Item {}
  174. }
  175. }
  176. }
  177. }
  178. Item
  179. {
  180. id: variantRowSpacer
  181. height: UM.Theme.getSize("sidebar_margin").height / 4
  182. width: height
  183. visible: !extruderSelectionRow.visible
  184. }
  185. // Material Row
  186. Item
  187. {
  188. id: materialRow
  189. height: UM.Theme.getSize("sidebar_setup").height
  190. visible: Cura.MachineManager.hasMaterials && !sidebar.monitoringPrint && !sidebar.hideSettings
  191. anchors
  192. {
  193. left: parent.left
  194. leftMargin: UM.Theme.getSize("sidebar_margin").width
  195. right: parent.right
  196. rightMargin: UM.Theme.getSize("sidebar_margin").width
  197. }
  198. Label
  199. {
  200. id: materialLabel
  201. text: catalog.i18nc("@label","Material");
  202. width: Math.floor(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  203. font: UM.Theme.getFont("default");
  204. color: UM.Theme.getColor("text");
  205. }
  206. ToolButton
  207. {
  208. id: materialSelection
  209. text: Cura.MachineManager.activeMaterialName
  210. tooltip: Cura.MachineManager.activeMaterialName
  211. visible: Cura.MachineManager.hasMaterials
  212. enabled: !extrudersList.visible || base.currentExtruderIndex > -1
  213. height: UM.Theme.getSize("setting_control").height
  214. width: parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width
  215. anchors.right: parent.right
  216. style: UM.Theme.styles.sidebar_header_button
  217. activeFocusOnPress: true;
  218. menu: MaterialMenu {
  219. extruderIndex: base.currentExtruderIndex
  220. }
  221. property var valueError: !isMaterialSupported()
  222. property var valueWarning: ! Cura.MachineManager.isActiveQualitySupported
  223. function isMaterialSupported () {
  224. return Cura.ContainerManager.getContainerMetaDataEntry(Cura.MachineManager.activeMaterialId, "compatible") == "True"
  225. }
  226. }
  227. }
  228. //Variant row
  229. Item
  230. {
  231. id: variantRow
  232. height: UM.Theme.getSize("sidebar_setup").height
  233. visible: Cura.MachineManager.hasVariants && !sidebar.monitoringPrint && !sidebar.hideSettings
  234. anchors
  235. {
  236. left: parent.left
  237. leftMargin: UM.Theme.getSize("sidebar_margin").width
  238. right: parent.right
  239. rightMargin: UM.Theme.getSize("sidebar_margin").width
  240. }
  241. Label
  242. {
  243. id: variantLabel
  244. text: Cura.MachineManager.activeDefinitionVariantsName;
  245. width: Math.floor(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  246. font: UM.Theme.getFont("default");
  247. color: UM.Theme.getColor("text");
  248. }
  249. ToolButton {
  250. id: variantSelection
  251. text: Cura.MachineManager.activeVariantName
  252. tooltip: Cura.MachineManager.activeVariantName;
  253. visible: Cura.MachineManager.hasVariants
  254. height: UM.Theme.getSize("setting_control").height
  255. width: Math.floor(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width)
  256. anchors.right: parent.right
  257. style: UM.Theme.styles.sidebar_header_button
  258. activeFocusOnPress: true;
  259. menu: NozzleMenu { extruderIndex: base.currentExtruderIndex }
  260. }
  261. }
  262. // Material info row
  263. Item
  264. {
  265. id: materialInfoRow
  266. height: Math.floor(UM.Theme.getSize("sidebar_setup").height / 2)
  267. visible: (Cura.MachineManager.hasVariants || Cura.MachineManager.hasMaterials) && !sidebar.monitoringPrint && !sidebar.hideSettings
  268. anchors
  269. {
  270. left: parent.left
  271. leftMargin: UM.Theme.getSize("sidebar_margin").width
  272. right: parent.right
  273. rightMargin: UM.Theme.getSize("sidebar_margin").width
  274. }
  275. Item {
  276. height: UM.Theme.getSize("sidebar_setup").height
  277. anchors.right: parent.right
  278. width: Math.floor(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width)
  279. UM.RecolorImage {
  280. id: warningImage
  281. anchors.right: materialInfoLabel.left
  282. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  283. anchors.verticalCenter: parent.Bottom
  284. source: UM.Theme.getIcon("warning")
  285. width: UM.Theme.getSize("section_icon").width
  286. height: UM.Theme.getSize("section_icon").height
  287. color: UM.Theme.getColor("material_compatibility_warning")
  288. visible: !Cura.MachineManager.isCurrentSetupSupported
  289. }
  290. Label {
  291. id: materialInfoLabel
  292. wrapMode: Text.WordWrap
  293. text: catalog.i18nc("@label", "<a href='%1'>Check material compatibility</a>")
  294. font: UM.Theme.getFont("default")
  295. color: UM.Theme.getColor("text")
  296. linkColor: UM.Theme.getColor("text_link")
  297. verticalAlignment: Text.AlignTop
  298. anchors.top: parent.top
  299. anchors.right: parent.right
  300. anchors.bottom: parent.bottom
  301. MouseArea {
  302. anchors.fill: parent
  303. hoverEnabled: true
  304. onClicked: {
  305. // open the material URL with web browser
  306. var version = UM.Application.version;
  307. var machineName = Cura.MachineManager.activeMachine.definition.id;
  308. var url = "https://ultimaker.com/materialcompatibility/" + version + "/" + machineName;
  309. Qt.openUrlExternally(url);
  310. }
  311. onEntered: {
  312. var content = catalog.i18nc("@tooltip", "Click to check the material compatibility on Ultimaker.com.");
  313. base.showTooltip(
  314. materialInfoRow,
  315. Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0),
  316. catalog.i18nc("@tooltip", content)
  317. );
  318. }
  319. onExited: base.hideTooltip();
  320. }
  321. }
  322. }
  323. }
  324. UM.SettingPropertyProvider
  325. {
  326. id: machineExtruderCount
  327. containerStackId: Cura.MachineManager.activeMachineId
  328. key: "machine_extruder_count"
  329. watchedProperties: [ "value" ]
  330. storeIndex: 0
  331. }
  332. UM.I18nCatalog { id: catalog; name:"cura" }
  333. }