SidebarHeader.qml 16 KB

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