SidebarHeader.qml 24 KB

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