SidebarHeader.qml 24 KB

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