Sidebar.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. Connections
  15. {
  16. target: Printer
  17. onShowPrintMonitor:
  18. {
  19. base.monitoringPrint = show;
  20. showSettings.checked = !show;
  21. showMonitor.checked = show;
  22. }
  23. }
  24. // Is there an output device for this printer?
  25. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  26. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  27. color: UM.Theme.getColor("sidebar");
  28. UM.I18nCatalog { id: catalog; name:"cura"}
  29. function showTooltip(item, position, text)
  30. {
  31. tooltip.text = text;
  32. position = item.mapToItem(base, position.x, position.y);
  33. tooltip.show(position);
  34. }
  35. function hideTooltip()
  36. {
  37. tooltip.hide();
  38. }
  39. function strPadLeft(string, pad, length) {
  40. return (new Array(length + 1).join(pad) + string).slice(-length);
  41. }
  42. function getPrettyTime(time)
  43. {
  44. var hours = Math.floor(time / 3600)
  45. time -= hours * 3600
  46. var minutes = Math.floor(time / 60);
  47. time -= minutes * 60
  48. var seconds = Math.floor(time);
  49. var finalTime = strPadLeft(hours, "0", 2) + ':' + strPadLeft(minutes,'0',2)+ ':' + strPadLeft(seconds,'0',2);
  50. return finalTime;
  51. }
  52. MouseArea
  53. {
  54. anchors.fill: parent
  55. acceptedButtons: Qt.AllButtons;
  56. onWheel:
  57. {
  58. wheel.accepted = true;
  59. }
  60. }
  61. // Mode selection buttons for changing between Setting & Monitor print mode
  62. Rectangle
  63. {
  64. id: sidebarHeaderBar
  65. anchors.left: parent.left
  66. anchors.right: parent.right
  67. height: childrenRect.height
  68. color: UM.Theme.getColor("sidebar_header_bar")
  69. Row
  70. {
  71. anchors.left: parent.left
  72. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  73. anchors.right: parent.right
  74. Button
  75. {
  76. id: showSettings
  77. width: (parent.width - UM.Theme.getSize("default_margin").width) / 2
  78. height: UM.Theme.getSize("sidebar_header").height
  79. onClicked: monitoringPrint = false
  80. iconSource: UM.Theme.getIcon("tab_settings");
  81. checkable: true
  82. checked: !monitoringPrint
  83. exclusiveGroup: sidebarHeaderBarGroup
  84. style: UM.Theme.styles.sidebar_header_tab
  85. }
  86. Button
  87. {
  88. id: showMonitor
  89. width: (parent.width - UM.Theme.getSize("default_margin").width) / 2
  90. height: UM.Theme.getSize("sidebar_header").height
  91. onClicked: monitoringPrint = true
  92. iconSource: {
  93. if(!printerConnected)
  94. return UM.Theme.getIcon("tab_monitor");
  95. else if(!printerAcceptsCommands)
  96. return UM.Theme.getIcon("tab_monitor_unknown");
  97. if(Cura.MachineManager.printerOutputDevices[0].printerState == "maintenance")
  98. {
  99. return UM.Theme.getIcon("tab_monitor_busy");
  100. }
  101. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  102. {
  103. case "printing":
  104. case "pre_print":
  105. case "wait_cleanup":
  106. return UM.Theme.getIcon("tab_monitor_busy");
  107. case "ready":
  108. case "":
  109. return UM.Theme.getIcon("tab_monitor_connected")
  110. case "paused":
  111. return UM.Theme.getIcon("tab_monitor_paused")
  112. case "error":
  113. return UM.Theme.getIcon("tab_monitor_stopped")
  114. case "offline":
  115. return UM.Theme.getIcon("tab_monitor_offline")
  116. default:
  117. return UM.Theme.getIcon("tab_monitor")
  118. }
  119. }
  120. checkable: true
  121. checked: monitoringPrint
  122. exclusiveGroup: sidebarHeaderBarGroup
  123. style: UM.Theme.styles.sidebar_header_tab
  124. }
  125. ExclusiveGroup { id: sidebarHeaderBarGroup }
  126. }
  127. }
  128. SidebarHeader {
  129. id: header
  130. width: parent.width
  131. anchors.top: sidebarHeaderBar.bottom
  132. anchors.topMargin: UM.Theme.getSize("default_margin").height
  133. onShowTooltip: base.showTooltip(item, location, text)
  134. onHideTooltip: base.hideTooltip()
  135. }
  136. Rectangle {
  137. id: headerSeparator
  138. width: parent.width
  139. height: UM.Theme.getSize("sidebar_lining").height
  140. color: UM.Theme.getColor("sidebar_lining")
  141. anchors.top: header.bottom
  142. anchors.topMargin: UM.Theme.getSize("default_margin").height
  143. }
  144. currentModeIndex:
  145. {
  146. var index = parseInt(UM.Preferences.getValue("cura/active_mode"))
  147. if(index)
  148. {
  149. return index;
  150. }
  151. return 0;
  152. }
  153. onCurrentModeIndexChanged:
  154. {
  155. UM.Preferences.setValue("cura/active_mode", currentModeIndex);
  156. if(modesListModel.count > base.currentModeIndex)
  157. {
  158. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "replace": true });
  159. }
  160. }
  161. Label {
  162. id: settingsModeLabel
  163. text: catalog.i18nc("@label:listbox", "Print Setup");
  164. anchors.left: parent.left
  165. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  166. anchors.top: headerSeparator.bottom
  167. anchors.topMargin: UM.Theme.getSize("default_margin").height
  168. width: parent.width * 0.45 - 2 * UM.Theme.getSize("default_margin").width
  169. font: UM.Theme.getFont("large")
  170. color: UM.Theme.getColor("text")
  171. visible: !monitoringPrint
  172. elide: Text.ElideRight
  173. }
  174. Rectangle {
  175. id: settingsModeSelection
  176. width: parent.width * 0.55
  177. height: UM.Theme.getSize("sidebar_header_mode_toggle").height
  178. anchors.right: parent.right
  179. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  180. anchors.top: headerSeparator.bottom
  181. anchors.topMargin: UM.Theme.getSize("default_margin").height
  182. visible: !monitoringPrint
  183. Component{
  184. id: wizardDelegate
  185. Button {
  186. height: settingsModeSelection.height
  187. anchors.left: parent.left
  188. anchors.leftMargin: model.index * (settingsModeSelection.width / 2)
  189. anchors.verticalCenter: parent.verticalCenter
  190. width: parent.width / 2
  191. text: model.text
  192. exclusiveGroup: modeMenuGroup;
  193. checkable: true;
  194. checked: base.currentModeIndex == index
  195. onClicked: base.currentModeIndex = index
  196. style: ButtonStyle {
  197. background: Rectangle {
  198. border.width: UM.Theme.getSize("default_lining").width
  199. border.color: control.checked ? UM.Theme.getColor("toggle_checked_border") :
  200. control.pressed ? UM.Theme.getColor("toggle_active_border") :
  201. control.hovered ? UM.Theme.getColor("toggle_hovered_border") : UM.Theme.getColor("toggle_unchecked_border")
  202. color: control.checked ? UM.Theme.getColor("toggle_checked") :
  203. control.pressed ? UM.Theme.getColor("toggle_active") :
  204. control.hovered ? UM.Theme.getColor("toggle_hovered") : UM.Theme.getColor("toggle_unchecked")
  205. Behavior on color { ColorAnimation { duration: 50; } }
  206. Label {
  207. anchors.centerIn: parent
  208. color: control.checked ? UM.Theme.getColor("toggle_checked_text") :
  209. control.pressed ? UM.Theme.getColor("toggle_active_text") :
  210. control.hovered ? UM.Theme.getColor("toggle_hovered_text") : UM.Theme.getColor("toggle_unchecked_text")
  211. font: UM.Theme.getFont("default")
  212. text: control.text;
  213. }
  214. }
  215. label: Item { }
  216. }
  217. }
  218. }
  219. ExclusiveGroup { id: modeMenuGroup; }
  220. ListView{
  221. id: modesList
  222. property var index: 0
  223. model: modesListModel
  224. delegate: wizardDelegate
  225. anchors.top: parent.top
  226. anchors.left: parent.left
  227. width: parent.width
  228. }
  229. }
  230. Label {
  231. id: monitorLabel
  232. text: catalog.i18nc("@label","Printer Monitor");
  233. anchors.left: parent.left
  234. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  235. anchors.top: headerSeparator.bottom
  236. anchors.topMargin: UM.Theme.getSize("default_margin").height
  237. width: parent.width * 0.45
  238. font: UM.Theme.getFont("large")
  239. color: UM.Theme.getColor("text")
  240. visible: monitoringPrint
  241. }
  242. StackView
  243. {
  244. id: sidebarContents
  245. anchors.bottom: footerSeparator.top
  246. anchors.top: settingsModeSelection.bottom
  247. anchors.topMargin: UM.Theme.getSize("default_margin").height
  248. anchors.left: base.left
  249. anchors.right: base.right
  250. visible: !monitoringPrint
  251. delegate: StackViewDelegate
  252. {
  253. function transitionFinished(properties)
  254. {
  255. properties.exitItem.opacity = 1
  256. }
  257. pushTransition: StackViewTransition
  258. {
  259. PropertyAnimation
  260. {
  261. target: enterItem
  262. property: "opacity"
  263. from: 0
  264. to: 1
  265. duration: 100
  266. }
  267. PropertyAnimation
  268. {
  269. target: exitItem
  270. property: "opacity"
  271. from: 1
  272. to: 0
  273. duration: 100
  274. }
  275. }
  276. }
  277. }
  278. Loader
  279. {
  280. anchors.bottom: footerSeparator.top
  281. anchors.top: monitorLabel.bottom
  282. anchors.topMargin: UM.Theme.getSize("default_margin").height
  283. anchors.left: base.left
  284. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  285. anchors.right: base.right
  286. source: monitoringPrint ? "PrintMonitor.qml": "SidebarContents.qml"
  287. }
  288. Rectangle
  289. {
  290. id: footerSeparator
  291. width: parent.width
  292. height: UM.Theme.getSize("sidebar_lining").height
  293. color: UM.Theme.getColor("sidebar_lining")
  294. anchors.bottom: saveButton.top
  295. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  296. }
  297. SaveButton
  298. {
  299. id: saveButton
  300. implicitWidth: base.width
  301. implicitHeight: totalHeight
  302. anchors.bottom: parent.bottom
  303. visible: !monitoringPrint
  304. }
  305. MonitorButton
  306. {
  307. id: monitorButton
  308. implicitWidth: base.width
  309. implicitHeight: totalHeight
  310. anchors.bottom: parent.bottom
  311. visible: monitoringPrint
  312. }
  313. SidebarTooltip
  314. {
  315. id: tooltip;
  316. }
  317. ListModel
  318. {
  319. id: modesListModel;
  320. }
  321. SidebarSimple
  322. {
  323. id: sidebarSimple;
  324. visible: false;
  325. onShowTooltip: base.showTooltip(item, location, text)
  326. onHideTooltip: base.hideTooltip()
  327. }
  328. SidebarAdvanced
  329. {
  330. id: sidebarAdvanced;
  331. visible: false;
  332. onShowTooltip: base.showTooltip(item, location, text)
  333. onHideTooltip: base.hideTooltip()
  334. }
  335. Component.onCompleted:
  336. {
  337. modesListModel.append({ text: catalog.i18nc("@title:tab", "Simple"), item: sidebarSimple })
  338. modesListModel.append({ text: catalog.i18nc("@title:tab", "Advanced"), item: sidebarAdvanced })
  339. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "immediate": true });
  340. }
  341. UM.SettingPropertyProvider
  342. {
  343. id: machineExtruderCount
  344. containerStackId: Cura.MachineManager.activeMachineId
  345. key: "machine_extruder_count"
  346. watchedProperties: [ "value" ]
  347. storeIndex: 0
  348. }
  349. UM.SettingPropertyProvider
  350. {
  351. id: machineHeatedBed
  352. containerStackId: Cura.MachineManager.activeMachineId
  353. key: "machine_heated_bed"
  354. watchedProperties: [ "value" ]
  355. storeIndex: 0
  356. }
  357. }