SidebarHeader.qml 16 KB

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