SidebarHeader.qml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. // Copyright (c) 2017 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. import "Menus"
  9. Column
  10. {
  11. id: base;
  12. property int currentExtruderIndex: Cura.ExtruderManager.activeExtruderIndex;
  13. property bool currentExtruderVisible: extrudersList.visible;
  14. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  15. property bool hasManyPrinterTypes: printerConnected ? Cura.MachineManager.printerOutputDevices[0].connectedPrintersTypeCount.length > 1 : false
  16. spacing: Math.round(UM.Theme.getSize("sidebar_margin").width * 0.9)
  17. signal showTooltip(Item item, point location, string text)
  18. signal hideTooltip()
  19. Item
  20. {
  21. id: initialSeparator
  22. anchors
  23. {
  24. left: parent.left
  25. right: parent.right
  26. }
  27. visible: printerTypeSelectionRow.visible || buildplateRow.visible || extruderSelectionRow.visible
  28. height: UM.Theme.getSize("default_lining").height
  29. width: height
  30. }
  31. // Printer Type Row
  32. Item
  33. {
  34. id: printerTypeSelectionRow
  35. height: UM.Theme.getSize("sidebar_setup").height
  36. visible: printerConnected && hasManyPrinterTypes && !sidebar.monitoringPrint && !sidebar.hideSettings
  37. anchors
  38. {
  39. left: parent.left
  40. leftMargin: UM.Theme.getSize("sidebar_margin").width
  41. right: parent.right
  42. rightMargin: UM.Theme.getSize("sidebar_margin").width
  43. }
  44. Label
  45. {
  46. id: configurationLabel
  47. text: catalog.i18nc("@label", "Printer type");
  48. width: Math.round(parent.width * 0.4 - UM.Theme.getSize("default_margin").width)
  49. height: parent.height
  50. verticalAlignment: Text.AlignVCenter
  51. font: UM.Theme.getFont("default");
  52. color: UM.Theme.getColor("text");
  53. }
  54. ToolButton
  55. {
  56. id: printerTypeSelection
  57. text: Cura.MachineManager.activeMachineDefinitionName
  58. tooltip: Cura.MachineManager.activeMachineDefinitionName
  59. height: UM.Theme.getSize("setting_control").height
  60. width: Math.round(parent.width * 0.7) + UM.Theme.getSize("sidebar_margin").width
  61. anchors.right: parent.right
  62. style: UM.Theme.styles.sidebar_header_button
  63. activeFocusOnPress: true;
  64. menu: PrinterTypeMenu { }
  65. }
  66. }
  67. Rectangle {
  68. id: headerSeparator
  69. width: parent.width
  70. visible: printerTypeSelectionRow.visible
  71. height: visible ? UM.Theme.getSize("sidebar_lining").height : 0
  72. color: UM.Theme.getColor("sidebar_lining")
  73. }
  74. // Extruder Row
  75. Item
  76. {
  77. id: extruderSelectionRow
  78. width: parent.width
  79. height: Math.round(UM.Theme.getSize("sidebar_tabs").height * 2 / 3)
  80. visible: machineExtruderCount.properties.value > 1 && !sidebar.monitoringPrint
  81. anchors
  82. {
  83. left: parent.left
  84. leftMargin: Math.round(UM.Theme.getSize("sidebar_margin").width * 0.7)
  85. right: parent.right
  86. rightMargin: Math.round(UM.Theme.getSize("sidebar_margin").width * 0.7)
  87. topMargin: UM.Theme.getSize("sidebar_margin").height
  88. }
  89. ListView
  90. {
  91. id: extrudersList
  92. property var index: 0
  93. height: UM.Theme.getSize("sidebar_header_mode_tabs").height
  94. width: Math.round(parent.width)
  95. boundsBehavior: Flickable.StopAtBounds
  96. anchors
  97. {
  98. left: parent.left
  99. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  100. right: parent.right
  101. rightMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  102. verticalCenter: parent.verticalCenter
  103. }
  104. ExclusiveGroup { id: extruderMenuGroup; }
  105. orientation: ListView.Horizontal
  106. model: Cura.ExtrudersModel { id: extrudersModel; }
  107. Connections
  108. {
  109. target: Cura.MachineManager
  110. onGlobalContainerChanged: forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  111. }
  112. delegate: Button
  113. {
  114. height: ListView.view.height
  115. width: Math.round(ListView.view.width / extrudersModel.rowCount())
  116. text: model.name
  117. tooltip: model.name
  118. exclusiveGroup: extruderMenuGroup
  119. checked: base.currentExtruderIndex == index
  120. property bool extruder_enabled: true
  121. MouseArea
  122. {
  123. anchors.fill: parent
  124. acceptedButtons: Qt.LeftButton | Qt.RightButton
  125. onClicked: {
  126. switch (mouse.button) {
  127. case Qt.LeftButton:
  128. forceActiveFocus(); // Changing focus applies the currently-being-typed values so it can change the displayed setting values.
  129. Cura.ExtruderManager.setActiveExtruderIndex(index);
  130. break;
  131. case Qt.RightButton:
  132. extruder_enabled = Cura.MachineManager.getExtruder(model.index).isEnabled
  133. extruderMenu.popup();
  134. break;
  135. }
  136. }
  137. }
  138. Menu
  139. {
  140. id: extruderMenu
  141. MenuItem {
  142. text: catalog.i18nc("@action:inmenu", "Enable Extruder")
  143. onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true)
  144. visible: !extruder_enabled // using an intermediate variable prevents an empty popup that occured now and then
  145. }
  146. MenuItem {
  147. text: catalog.i18nc("@action:inmenu", "Disable Extruder")
  148. onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, false)
  149. visible: extruder_enabled
  150. enabled: Cura.MachineManager.numberExtrudersEnabled > 1
  151. }
  152. }
  153. style: ButtonStyle
  154. {
  155. background: Item
  156. {
  157. function buttonBackgroundColor(index)
  158. {
  159. var extruder = Cura.MachineManager.getExtruder(index)
  160. if (extruder.isEnabled) {
  161. return (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") :
  162. control.hovered ? UM.Theme.getColor("action_button_hovered") :
  163. UM.Theme.getColor("action_button")
  164. } else {
  165. return UM.Theme.getColor("action_button_disabled")
  166. }
  167. }
  168. function buttonBorderColor(index)
  169. {
  170. var extruder = Cura.MachineManager.getExtruder(index)
  171. if (extruder.isEnabled) {
  172. return (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") :
  173. control.hovered ? UM.Theme.getColor("action_button_hovered_border") :
  174. UM.Theme.getColor("action_button_border")
  175. } else {
  176. return UM.Theme.getColor("action_button_disabled_border")
  177. }
  178. }
  179. function buttonColor(index) {
  180. var extruder = Cura.MachineManager.getExtruder(index);
  181. if (extruder.isEnabled)
  182. {
  183. return (
  184. control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_text") :
  185. control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
  186. UM.Theme.getColor("action_button_text");
  187. } else {
  188. return UM.Theme.getColor("action_button_disabled_text");
  189. }
  190. }
  191. Rectangle
  192. {
  193. anchors.fill: parent
  194. border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
  195. border.color: buttonBorderColor(index)
  196. color: buttonBackgroundColor(index)
  197. Behavior on color { ColorAnimation { duration: 50; } }
  198. }
  199. Item
  200. {
  201. id: extruderButtonFace
  202. anchors.centerIn: parent
  203. width: {
  204. var extruderTextWidth = extruderStaticText.visible ? extruderStaticText.width : 0;
  205. var iconWidth = extruderIconItem.width;
  206. return Math.round(extruderTextWidth + iconWidth + UM.Theme.getSize("default_margin").width / 2);
  207. }
  208. // Static text "Extruder"
  209. Label
  210. {
  211. id: extruderStaticText
  212. anchors.verticalCenter: parent.verticalCenter
  213. anchors.left: parent.left
  214. color: buttonColor(index)
  215. font: UM.Theme.getFont("large_nonbold")
  216. text: catalog.i18nc("@label", "Extruder")
  217. visible: width < (control.width - extruderIconItem.width - UM.Theme.getSize("default_margin").width)
  218. elide: Text.ElideRight
  219. }
  220. // Everthing for the extruder icon
  221. Item
  222. {
  223. id: extruderIconItem
  224. anchors.verticalCenter: parent.verticalCenter
  225. anchors.right: parent.right
  226. property var sizeToUse:
  227. {
  228. var minimumWidth = control.width < UM.Theme.getSize("button").width ? control.width : UM.Theme.getSize("button").width;
  229. var minimumHeight = control.height < UM.Theme.getSize("button").height ? control.height : UM.Theme.getSize("button").height;
  230. var minimumSize = minimumWidth < minimumHeight ? minimumWidth : minimumHeight;
  231. minimumSize -= Math.round(UM.Theme.getSize("default_margin").width / 2);
  232. return minimumSize;
  233. }
  234. width: sizeToUse
  235. height: sizeToUse
  236. UM.RecolorImage {
  237. id: mainCircle
  238. anchors.fill: parent
  239. sourceSize.width: parent.width
  240. sourceSize.height: parent.width
  241. source: UM.Theme.getIcon("extruder_button")
  242. color: extruderNumberText.color
  243. }
  244. Label
  245. {
  246. id: extruderNumberText
  247. anchors.centerIn: parent
  248. text: index + 1;
  249. color: buttonColor(index)
  250. font: UM.Theme.getFont("default_bold")
  251. }
  252. // Material colour circle
  253. // Only draw the filling colour of the material inside the SVG border.
  254. Rectangle
  255. {
  256. id: materialColorCircle
  257. anchors
  258. {
  259. right: parent.right
  260. top: parent.top
  261. rightMargin: Math.round(parent.sizeToUse * 0.01)
  262. topMargin: Math.round(parent.sizeToUse * 0.05)
  263. }
  264. color: model.color
  265. width: Math.round(parent.width * 0.35)
  266. height: Math.round(parent.height * 0.35)
  267. radius: Math.round(width / 2)
  268. border.width: 1
  269. border.color: UM.Theme.getColor("extruder_button_material_border")
  270. opacity: !control.checked ? 0.6 : 1.0
  271. }
  272. }
  273. }
  274. }
  275. label: Item {}
  276. }
  277. }
  278. }
  279. }
  280. Item
  281. {
  282. id: variantRowSpacer
  283. height: Math.round(UM.Theme.getSize("sidebar_margin").height / 4)
  284. width: height
  285. visible: !extruderSelectionRow.visible && !initialSeparator.visible
  286. }
  287. // Material Row
  288. Item
  289. {
  290. id: materialRow
  291. height: UM.Theme.getSize("sidebar_setup").height
  292. visible: Cura.MachineManager.hasMaterials && !sidebar.monitoringPrint && !sidebar.hideSettings
  293. anchors
  294. {
  295. left: parent.left
  296. leftMargin: UM.Theme.getSize("sidebar_margin").width
  297. right: parent.right
  298. rightMargin: UM.Theme.getSize("sidebar_margin").width
  299. }
  300. Label
  301. {
  302. id: materialLabel
  303. text: catalog.i18nc("@label", "Material");
  304. width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  305. height: parent.height
  306. verticalAlignment: Text.AlignVCenter
  307. font: UM.Theme.getFont("default");
  308. color: UM.Theme.getColor("text");
  309. }
  310. ToolButton
  311. {
  312. id: materialSelection
  313. property var activeExtruder: Cura.MachineManager.activeStack
  314. property var hasActiveExtruder: activeExtruder != null
  315. property var currentRootMaterialName: hasActiveExtruder ? activeExtruder.material.name : ""
  316. text: currentRootMaterialName
  317. tooltip: currentRootMaterialName
  318. visible: Cura.MachineManager.hasMaterials
  319. enabled: !extrudersList.visible || base.currentExtruderIndex > -1
  320. height: UM.Theme.getSize("setting_control").height
  321. width: Math.round(parent.width * 0.7) + UM.Theme.getSize("sidebar_margin").width
  322. anchors.right: parent.right
  323. style: UM.Theme.styles.sidebar_header_button
  324. activeFocusOnPress: true;
  325. menu: MaterialMenu {
  326. extruderIndex: base.currentExtruderIndex
  327. }
  328. property var valueError: !isMaterialSupported()
  329. property var valueWarning: ! Cura.MachineManager.isActiveQualitySupported
  330. function isMaterialSupported () {
  331. if (!hasActiveExtruder)
  332. {
  333. return false;
  334. }
  335. return Cura.ContainerManager.getContainerMetaDataEntry(activeExtruder.material.id, "compatible") == "True"
  336. }
  337. }
  338. }
  339. //Variant row
  340. Item
  341. {
  342. id: variantRow
  343. height: UM.Theme.getSize("sidebar_setup").height
  344. visible: Cura.MachineManager.hasVariants && !sidebar.monitoringPrint && !sidebar.hideSettings
  345. anchors
  346. {
  347. left: parent.left
  348. leftMargin: UM.Theme.getSize("sidebar_margin").width
  349. right: parent.right
  350. rightMargin: UM.Theme.getSize("sidebar_margin").width
  351. }
  352. Label
  353. {
  354. id: variantLabel
  355. text: Cura.MachineManager.activeDefinitionVariantsName;
  356. width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  357. height: parent.height
  358. verticalAlignment: Text.AlignVCenter
  359. font: UM.Theme.getFont("default");
  360. color: UM.Theme.getColor("text");
  361. }
  362. ToolButton {
  363. id: variantSelection
  364. text: Cura.MachineManager.activeVariantName
  365. tooltip: Cura.MachineManager.activeVariantName;
  366. visible: Cura.MachineManager.hasVariants
  367. height: UM.Theme.getSize("setting_control").height
  368. width: Math.round(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width)
  369. anchors.right: parent.right
  370. style: UM.Theme.styles.sidebar_header_button
  371. activeFocusOnPress: true;
  372. menu: NozzleMenu { extruderIndex: base.currentExtruderIndex }
  373. }
  374. }
  375. Rectangle {
  376. id: buildplateSeparator
  377. anchors.left: parent.left
  378. anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width
  379. width: parent.width - 2 * UM.Theme.getSize("sidebar_margin").width
  380. visible: buildplateRow.visible
  381. height: visible ? UM.Theme.getSize("sidebar_lining_thin").height : 0
  382. color: UM.Theme.getColor("sidebar_lining")
  383. }
  384. //Buildplate row
  385. Item
  386. {
  387. id: buildplateRow
  388. height: UM.Theme.getSize("sidebar_setup").height
  389. visible: Cura.MachineManager.hasVariantBuildplates && !sidebar.monitoringPrint && !sidebar.hideSettings
  390. anchors
  391. {
  392. left: parent.left
  393. leftMargin: UM.Theme.getSize("sidebar_margin").width
  394. right: parent.right
  395. rightMargin: UM.Theme.getSize("sidebar_margin").width
  396. }
  397. Label
  398. {
  399. id: bulidplateLabel
  400. text: catalog.i18nc("@label", "Build plate");
  401. width: Math.floor(parent.width * 0.45 - UM.Theme.getSize("default_margin").width)
  402. height: parent.height
  403. verticalAlignment: Text.AlignVCenter
  404. font: UM.Theme.getFont("default");
  405. color: UM.Theme.getColor("text");
  406. }
  407. ToolButton {
  408. id: buildplateSelection
  409. text: Cura.MachineManager.activeVariantBuildplateName
  410. tooltip: Cura.MachineManager.activeVariantBuildplateName
  411. visible: Cura.MachineManager.hasVariantBuildplates
  412. height: UM.Theme.getSize("setting_control").height
  413. width: Math.floor(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width)
  414. anchors.right: parent.right
  415. style: UM.Theme.styles.sidebar_header_button
  416. activeFocusOnPress: true;
  417. menu: BuildplateMenu {}
  418. property var valueError: !Cura.MachineManager.variantBuildplateCompatible && !Cura.MachineManager.variantBuildplateUsable
  419. property var valueWarning: Cura.MachineManager.variantBuildplateUsable
  420. }
  421. }
  422. // Material info row
  423. Item
  424. {
  425. id: materialInfoRow
  426. height: Math.round(UM.Theme.getSize("sidebar_setup").height / 2)
  427. visible: (Cura.MachineManager.hasVariants || Cura.MachineManager.hasMaterials) && !sidebar.monitoringPrint && !sidebar.hideSettings
  428. anchors
  429. {
  430. left: parent.left
  431. leftMargin: UM.Theme.getSize("sidebar_margin").width
  432. right: parent.right
  433. rightMargin: UM.Theme.getSize("sidebar_margin").width
  434. }
  435. Item {
  436. height: UM.Theme.getSize("sidebar_setup").height
  437. anchors.right: parent.right
  438. width: Math.round(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width)
  439. UM.RecolorImage {
  440. id: warningImage
  441. anchors.right: materialInfoLabel.left
  442. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  443. anchors.verticalCenter: parent.Bottom
  444. source: UM.Theme.getIcon("warning")
  445. width: UM.Theme.getSize("section_icon").width
  446. height: UM.Theme.getSize("section_icon").height
  447. color: UM.Theme.getColor("material_compatibility_warning")
  448. visible: !Cura.MachineManager.isCurrentSetupSupported
  449. }
  450. Label {
  451. id: materialInfoLabel
  452. wrapMode: Text.WordWrap
  453. text: "<a href='%1'>" + catalog.i18nc("@label", "Check compatibility") + "</a>"
  454. font: UM.Theme.getFont("default")
  455. color: UM.Theme.getColor("text")
  456. linkColor: UM.Theme.getColor("text_link")
  457. verticalAlignment: Text.AlignTop
  458. anchors.top: parent.top
  459. anchors.right: parent.right
  460. anchors.bottom: parent.bottom
  461. MouseArea {
  462. anchors.fill: parent
  463. hoverEnabled: true
  464. onClicked: {
  465. // open the material URL with web browser
  466. var version = UM.Application.version;
  467. var machineName = Cura.MachineManager.activeMachine.definition.id;
  468. var url = "https://ultimaker.com/materialcompatibility/" + version + "/" + machineName + "?utm_source=cura&utm_medium=software&utm_campaign=resources";
  469. Qt.openUrlExternally(url);
  470. }
  471. onEntered: {
  472. var content = catalog.i18nc("@tooltip", "Click to check the material compatibility on Ultimaker.com.");
  473. base.showTooltip(
  474. materialInfoRow,
  475. Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0),
  476. catalog.i18nc("@tooltip", content)
  477. );
  478. }
  479. onExited: base.hideTooltip();
  480. }
  481. }
  482. }
  483. }
  484. UM.SettingPropertyProvider
  485. {
  486. id: machineExtruderCount
  487. containerStackId: Cura.MachineManager.activeMachineId
  488. key: "machine_extruder_count"
  489. watchedProperties: [ "value" ]
  490. storeIndex: 0
  491. }
  492. UM.I18nCatalog { id: catalog; name:"cura" }
  493. }