Sidebar.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // Copyright (c) 2015 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 QtQuick.Layouts 1.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Rectangle
  10. {
  11. id: base;
  12. property int currentModeIndex;
  13. property bool monitoringPrint: false
  14. // Is there an output device for this printer?
  15. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  16. onPrinterConnectedChanged: populatePrintMonitorModel()
  17. color: UM.Theme.getColor("sidebar");
  18. UM.I18nCatalog { id: catalog; name:"cura"}
  19. function showTooltip(item, position, text)
  20. {
  21. tooltip.text = text;
  22. position = item.mapToItem(base, position.x, position.y);
  23. tooltip.show(position);
  24. }
  25. function hideTooltip()
  26. {
  27. tooltip.hide();
  28. }
  29. function strPadLeft(string, pad, length) {
  30. return (new Array(length + 1).join(pad) + string).slice(-length);
  31. }
  32. function getPrettyTime(time)
  33. {
  34. var hours = Math.floor(time / 3600)
  35. time -= hours * 3600
  36. var minutes = Math.floor(time / 60);
  37. time -= minutes * 60
  38. var seconds = Math.floor(time);
  39. var finalTime = strPadLeft(hours, "0", 2) + ':' + strPadLeft(minutes,'0',2)+ ':' + strPadLeft(seconds,'0',2);
  40. return finalTime;
  41. }
  42. MouseArea
  43. {
  44. anchors.fill: parent
  45. acceptedButtons: Qt.AllButtons;
  46. onWheel:
  47. {
  48. wheel.accepted = true;
  49. }
  50. }
  51. // Mode selection buttons for changing between Setting & Monitor print mode
  52. Rectangle
  53. {
  54. id: sidebarHeaderBar
  55. anchors.left: parent.left
  56. anchors.right: parent.right
  57. height: childrenRect.height
  58. color: UM.Theme.getColor("sidebar_header_bar")
  59. Row
  60. {
  61. anchors.left: parent.left
  62. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  63. anchors.right: parent.right
  64. Button
  65. {
  66. width: (parent.width - UM.Theme.getSize("default_margin").width) / 2
  67. height: UM.Theme.getSize("sidebar_header").height
  68. onClicked: monitoringPrint = false
  69. iconSource: UM.Theme.getIcon("tab_settings");
  70. checkable: true
  71. checked: true
  72. exclusiveGroup: sidebarHeaderBarGroup
  73. style: UM.Theme.styles.sidebar_header_tab
  74. }
  75. Button
  76. {
  77. width: (parent.width - UM.Theme.getSize("default_margin").width) / 2
  78. height: UM.Theme.getSize("sidebar_header").height
  79. onClicked: monitoringPrint = true
  80. iconSource: {
  81. if(!printerConnected)
  82. {
  83. return UM.Theme.getIcon("tab_monitor")
  84. } else if(Cura.MachineManager.printerOutputDevices[0].jobState == "paused")
  85. {
  86. return UM.Theme.getIcon("tab_monitor_paused")
  87. } else if (Cura.MachineManager.printerOutputDevices[0].jobState != "error")
  88. {
  89. return UM.Theme.getIcon("tab_monitor_connected")
  90. }
  91. }
  92. checkable: true
  93. exclusiveGroup: sidebarHeaderBarGroup
  94. style: UM.Theme.styles.sidebar_header_tab
  95. }
  96. ExclusiveGroup { id: sidebarHeaderBarGroup }
  97. }
  98. }
  99. SidebarHeader {
  100. id: header
  101. width: parent.width
  102. height: totalHeightHeader
  103. anchors.top: sidebarHeaderBar.bottom
  104. anchors.topMargin: UM.Theme.getSize("default_margin").height
  105. onShowTooltip: base.showTooltip(item, location, text)
  106. onHideTooltip: base.hideTooltip()
  107. }
  108. Rectangle {
  109. id: headerSeparator
  110. width: parent.width
  111. height: UM.Theme.getSize("sidebar_lining").height
  112. color: UM.Theme.getColor("sidebar_lining")
  113. anchors.top: header.bottom
  114. anchors.topMargin: UM.Theme.getSize("default_margin").height
  115. }
  116. currentModeIndex:
  117. {
  118. var index = parseInt(UM.Preferences.getValue("cura/active_mode"))
  119. if(index)
  120. {
  121. return index;
  122. }
  123. return 0;
  124. }
  125. onCurrentModeIndexChanged:
  126. {
  127. UM.Preferences.setValue("cura/active_mode", currentModeIndex);
  128. if(modesListModel.count > base.currentModeIndex)
  129. {
  130. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "replace": true });
  131. }
  132. }
  133. Label {
  134. id: settingsModeLabel
  135. text: catalog.i18nc("@label:listbox","Print Setup");
  136. anchors.left: parent.left
  137. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  138. anchors.top: headerSeparator.bottom
  139. anchors.topMargin: UM.Theme.getSize("default_margin").height
  140. width: parent.width/100*45
  141. font: UM.Theme.getFont("large")
  142. color: UM.Theme.getColor("text")
  143. visible: !monitoringPrint
  144. }
  145. Rectangle {
  146. id: settingsModeSelection
  147. width: parent.width/100*55
  148. height: UM.Theme.getSize("sidebar_header_mode_toggle").height
  149. anchors.right: parent.right
  150. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  151. anchors.top: headerSeparator.bottom
  152. anchors.topMargin: UM.Theme.getSize("default_margin").height
  153. visible: !monitoringPrint
  154. Component{
  155. id: wizardDelegate
  156. Button {
  157. height: settingsModeSelection.height
  158. anchors.left: parent.left
  159. anchors.leftMargin: model.index * (settingsModeSelection.width / 2)
  160. anchors.verticalCenter: parent.verticalCenter
  161. width: parent.width / 2
  162. text: model.text
  163. exclusiveGroup: modeMenuGroup;
  164. checkable: true;
  165. checked: base.currentModeIndex == index
  166. onClicked: base.currentModeIndex = index
  167. style: ButtonStyle {
  168. background: Rectangle {
  169. border.width: UM.Theme.getSize("default_lining").width
  170. border.color: control.checked ? UM.Theme.getColor("toggle_checked_border") :
  171. control.pressed ? UM.Theme.getColor("toggle_active_border") :
  172. control.hovered ? UM.Theme.getColor("toggle_hovered_border") : UM.Theme.getColor("toggle_unchecked_border")
  173. color: control.checked ? UM.Theme.getColor("toggle_checked") :
  174. control.pressed ? UM.Theme.getColor("toggle_active") :
  175. control.hovered ? UM.Theme.getColor("toggle_hovered") : UM.Theme.getColor("toggle_unchecked")
  176. Behavior on color { ColorAnimation { duration: 50; } }
  177. Label {
  178. anchors.centerIn: parent
  179. color: control.checked ? UM.Theme.getColor("toggle_checked_text") :
  180. control.pressed ? UM.Theme.getColor("toggle_active_text") :
  181. control.hovered ? UM.Theme.getColor("toggle_hovered_text") : UM.Theme.getColor("toggle_unchecked_text")
  182. font: UM.Theme.getFont("default")
  183. text: control.text;
  184. }
  185. }
  186. label: Item { }
  187. }
  188. }
  189. }
  190. ExclusiveGroup { id: modeMenuGroup; }
  191. ListView{
  192. id: modesList
  193. property var index: 0
  194. model: modesListModel
  195. delegate: wizardDelegate
  196. anchors.top: parent.top
  197. anchors.left: parent.left
  198. width: parent.width
  199. }
  200. }
  201. Label {
  202. id: monitorLabel
  203. text: catalog.i18nc("@label","Printer Monitor");
  204. anchors.left: parent.left
  205. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  206. anchors.top: headerSeparator.bottom
  207. anchors.topMargin: UM.Theme.getSize("default_margin").height
  208. width: parent.width/100*45
  209. font: UM.Theme.getFont("large")
  210. color: UM.Theme.getColor("text")
  211. visible: monitoringPrint
  212. }
  213. StackView
  214. {
  215. id: sidebarContents
  216. anchors.bottom: footerSeparator.top
  217. anchors.top: settingsModeSelection.bottom
  218. anchors.topMargin: UM.Theme.getSize("default_margin").height
  219. anchors.left: base.left
  220. anchors.right: base.right
  221. visible: !monitoringPrint
  222. delegate: StackViewDelegate
  223. {
  224. function transitionFinished(properties)
  225. {
  226. properties.exitItem.opacity = 1
  227. }
  228. pushTransition: StackViewTransition
  229. {
  230. PropertyAnimation
  231. {
  232. target: enterItem
  233. property: "opacity"
  234. from: 0
  235. to: 1
  236. duration: 100
  237. }
  238. PropertyAnimation
  239. {
  240. target: exitItem
  241. property: "opacity"
  242. from: 1
  243. to: 0
  244. duration: 100
  245. }
  246. }
  247. }
  248. }
  249. // Item that shows the print monitor properties
  250. Column
  251. {
  252. id: printMonitor
  253. anchors.bottom: footerSeparator.top
  254. anchors.top: monitorLabel.bottom
  255. anchors.topMargin: UM.Theme.getSize("default_margin").height
  256. anchors.left: base.left
  257. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  258. anchors.right: base.right
  259. visible: monitoringPrint
  260. Loader
  261. {
  262. sourceComponent: monitorSection
  263. property string label: catalog.i18nc("@label", "Temperatures")
  264. }
  265. Repeater
  266. {
  267. model: machineExtruderCount.properties.value
  268. delegate: Loader
  269. {
  270. sourceComponent: monitorItem
  271. property string label: machineExtruderCount.properties.value > 1 ? catalog.i18nc("@label", "Hotend Temperature %1").arg(index + 1) : catalog.i18nc("@label", "Hotend Temperature")
  272. property string value: printerConnected ? Math.round(Cura.MachineManager.printerOutputDevices[0].hotendTemperatures[index]) + "°C" : ""
  273. }
  274. }
  275. Repeater
  276. {
  277. model: machineHeatedBed.properties.value == "True" ? 1 : 0
  278. delegate: Loader
  279. {
  280. sourceComponent: monitorItem
  281. property string label: catalog.i18nc("@label", "Bed Temperature")
  282. property string value: printerConnected ? Math.round(Cura.MachineManager.printerOutputDevices[0].bedTemperature) + "°C" : ""
  283. }
  284. }
  285. Loader
  286. {
  287. sourceComponent: monitorSection
  288. property string label: catalog.i18nc("@label", "Active print")
  289. }
  290. Loader
  291. {
  292. sourceComponent: monitorItem
  293. property string label: catalog.i18nc("@label", "Job Name")
  294. property string value: printerConnected ? Cura.MachineManager.printerOutputDevices[0].jobName : ""
  295. }
  296. Loader
  297. {
  298. sourceComponent: monitorItem
  299. property string label: catalog.i18nc("@label", "Printing Time")
  300. property string value: printerConnected ? getPrettyTime(Cura.MachineManager.printerOutputDevices[0].timeTotal) : ""
  301. }
  302. Loader
  303. {
  304. sourceComponent: monitorItem
  305. property string label: catalog.i18nc("@label", "Estimated time left")
  306. property string value: printerConnected ? getPrettyTime(Cura.MachineManager.printerOutputDevices[0].timeTotal - Cura.MachineManager.printerOutputDevices[0].timeElapsed) : ""
  307. }
  308. Loader
  309. {
  310. sourceComponent: monitorItem
  311. property string label: catalog.i18nc("@label", "Current Layer")
  312. property string value: printerConnected ? "0" : ""
  313. }
  314. Component
  315. {
  316. id: monitorItem
  317. Row
  318. {
  319. Label
  320. {
  321. text: label
  322. color: UM.Theme.getColor("setting_control_text");
  323. font: UM.Theme.getFont("default");
  324. width: base.width * 0.4
  325. elide: Text.ElideRight;
  326. }
  327. Label
  328. {
  329. text: value
  330. color: UM.Theme.getColor("setting_control_text");
  331. font: UM.Theme.getFont("default");
  332. }
  333. }
  334. }
  335. Component
  336. {
  337. id: monitorSection
  338. Rectangle
  339. {
  340. color: UM.Theme.getColor("setting_category")
  341. width: base.width - 2 * UM.Theme.getSize("default_margin").width
  342. height: UM.Theme.getSize("section").height
  343. Label
  344. {
  345. anchors.verticalCenter: parent.verticalCenter
  346. anchors.left: parent.left
  347. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  348. text: label
  349. font: UM.Theme.getFont("setting_category")
  350. color: UM.Theme.getColor("setting_category_text")
  351. }
  352. }
  353. }
  354. }
  355. Rectangle
  356. {
  357. id: footerSeparator
  358. width: parent.width
  359. height: UM.Theme.getSize("sidebar_lining").height
  360. color: UM.Theme.getColor("sidebar_lining")
  361. anchors.bottom: saveButton.top
  362. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  363. }
  364. SaveButton
  365. {
  366. id: saveButton
  367. implicitWidth: base.width
  368. implicitHeight: totalHeight
  369. anchors.bottom: parent.bottom
  370. visible: !monitoringPrint
  371. }
  372. MonitorButton
  373. {
  374. id: monitorButton
  375. implicitWidth: base.width
  376. implicitHeight: totalHeight
  377. anchors.bottom: parent.bottom
  378. visible: monitoringPrint
  379. }
  380. SidebarTooltip
  381. {
  382. id: tooltip;
  383. }
  384. ListModel
  385. {
  386. id: modesListModel;
  387. }
  388. SidebarSimple
  389. {
  390. id: sidebarSimple;
  391. visible: false;
  392. onShowTooltip: base.showTooltip(item, location, text)
  393. onHideTooltip: base.hideTooltip()
  394. }
  395. SidebarAdvanced
  396. {
  397. id: sidebarAdvanced;
  398. visible: false;
  399. onShowTooltip: base.showTooltip(item, location, text)
  400. onHideTooltip: base.hideTooltip()
  401. }
  402. Component.onCompleted:
  403. {
  404. modesListModel.append({ text: catalog.i18nc("@title:tab", "Simple"), item: sidebarSimple })
  405. modesListModel.append({ text: catalog.i18nc("@title:tab", "Advanced"), item: sidebarAdvanced })
  406. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "immediate": true });
  407. }
  408. UM.SettingPropertyProvider
  409. {
  410. id: machineExtruderCount
  411. containerStackId: Cura.MachineManager.activeMachineId
  412. key: "machine_extruder_count"
  413. watchedProperties: [ "value" ]
  414. storeIndex: 0
  415. }
  416. UM.SettingPropertyProvider
  417. {
  418. id: machineHeatedBed
  419. containerStackId: Cura.MachineManager.activeMachineId
  420. key: "machine_heated_bed"
  421. watchedProperties: [ "value" ]
  422. storeIndex: 0
  423. }
  424. }