Sidebar.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. onCurrentModeIndexChanged:
  145. {
  146. UM.Preferences.setValue("cura/active_mode", currentModeIndex);
  147. if(modesListModel.count > base.currentModeIndex)
  148. {
  149. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "replace": true });
  150. }
  151. }
  152. Label {
  153. id: settingsModeLabel
  154. text: catalog.i18nc("@label:listbox", "Print Setup");
  155. anchors.left: parent.left
  156. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  157. anchors.top: headerSeparator.bottom
  158. anchors.topMargin: UM.Theme.getSize("default_margin").height
  159. width: parent.width * 0.45 - 2 * UM.Theme.getSize("default_margin").width
  160. font: UM.Theme.getFont("large")
  161. color: UM.Theme.getColor("text")
  162. visible: !monitoringPrint
  163. elide: Text.ElideRight
  164. }
  165. Rectangle {
  166. id: settingsModeSelection
  167. width: parent.width * 0.55
  168. height: UM.Theme.getSize("sidebar_header_mode_toggle").height
  169. anchors.right: parent.right
  170. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  171. anchors.top: headerSeparator.bottom
  172. anchors.topMargin: UM.Theme.getSize("default_margin").height
  173. visible: !monitoringPrint
  174. Component{
  175. id: wizardDelegate
  176. Button {
  177. height: settingsModeSelection.height
  178. anchors.left: parent.left
  179. anchors.leftMargin: model.index * (settingsModeSelection.width / 2)
  180. anchors.verticalCenter: parent.verticalCenter
  181. width: 0.5 * parent.width - (model.showFilterButton ? toggleFilterButton.width : 0)
  182. text: model.text
  183. exclusiveGroup: modeMenuGroup;
  184. checkable: true;
  185. checked: base.currentModeIndex == index
  186. onClicked: base.currentModeIndex = index
  187. style: ButtonStyle {
  188. background: Rectangle {
  189. border.width: UM.Theme.getSize("default_lining").width
  190. border.color: control.checked ? UM.Theme.getColor("toggle_checked_border") :
  191. control.pressed ? UM.Theme.getColor("toggle_active_border") :
  192. control.hovered ? UM.Theme.getColor("toggle_hovered_border") : UM.Theme.getColor("toggle_unchecked_border")
  193. color: control.checked ? UM.Theme.getColor("toggle_checked") :
  194. control.pressed ? UM.Theme.getColor("toggle_active") :
  195. control.hovered ? UM.Theme.getColor("toggle_hovered") : UM.Theme.getColor("toggle_unchecked")
  196. Behavior on color { ColorAnimation { duration: 50; } }
  197. Label {
  198. anchors.centerIn: parent
  199. color: control.checked ? UM.Theme.getColor("toggle_checked_text") :
  200. control.pressed ? UM.Theme.getColor("toggle_active_text") :
  201. control.hovered ? UM.Theme.getColor("toggle_hovered_text") : UM.Theme.getColor("toggle_unchecked_text")
  202. font: UM.Theme.getFont("default")
  203. text: control.text;
  204. }
  205. }
  206. label: Item { }
  207. }
  208. }
  209. }
  210. ExclusiveGroup { id: modeMenuGroup; }
  211. ListView{
  212. id: modesList
  213. property var index: 0
  214. model: modesListModel
  215. delegate: wizardDelegate
  216. anchors.top: parent.top
  217. anchors.left: parent.left
  218. width: parent.width
  219. }
  220. }
  221. Button
  222. {
  223. id: toggleFilterButton
  224. anchors.right: parent.right
  225. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  226. anchors.top: headerSeparator.bottom
  227. anchors.topMargin: UM.Theme.getSize("default_margin").height
  228. height: settingsModeSelection.height
  229. width: visible ? height : 0
  230. visible: !monitoringPrint && modesListModel.get(base.currentModeIndex) != undefined && modesListModel.get(base.currentModeIndex).showFilterButton
  231. opacity: visible ? 1 : 0
  232. onClicked: sidebarContents.currentItem.toggleFilterField()
  233. style: ButtonStyle
  234. {
  235. background: Rectangle
  236. {
  237. border.width: UM.Theme.getSize("default_lining").width
  238. border.color: UM.Theme.getColor("toggle_checked_border")
  239. color: visible ? UM.Theme.getColor("toggle_checked") : UM.Theme.getColor("toggle_hovered")
  240. Behavior on color { ColorAnimation { duration: 50; } }
  241. }
  242. label: UM.RecolorImage
  243. {
  244. anchors.verticalCenter: parent.verticalCenter
  245. anchors.right: parent.right
  246. anchors.rightMargin: UM.Theme.getSize("default_margin").width / 2
  247. source: UM.Theme.getIcon("search")
  248. color: UM.Theme.getColor("toggle_checked_text")
  249. }
  250. }
  251. }
  252. Label {
  253. id: monitorLabel
  254. text: catalog.i18nc("@label","Printer Monitor");
  255. anchors.left: parent.left
  256. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  257. anchors.top: headerSeparator.bottom
  258. anchors.topMargin: UM.Theme.getSize("default_margin").height
  259. width: parent.width * 0.45
  260. font: UM.Theme.getFont("large")
  261. color: UM.Theme.getColor("text")
  262. visible: monitoringPrint
  263. }
  264. StackView
  265. {
  266. id: sidebarContents
  267. anchors.bottom: footerSeparator.top
  268. anchors.top: settingsModeSelection.bottom
  269. anchors.topMargin: UM.Theme.getSize("default_margin").height
  270. anchors.left: base.left
  271. anchors.right: base.right
  272. visible: !monitoringPrint
  273. delegate: StackViewDelegate
  274. {
  275. function transitionFinished(properties)
  276. {
  277. properties.exitItem.opacity = 1
  278. }
  279. pushTransition: StackViewTransition
  280. {
  281. PropertyAnimation
  282. {
  283. target: enterItem
  284. property: "opacity"
  285. from: 0
  286. to: 1
  287. duration: 100
  288. }
  289. PropertyAnimation
  290. {
  291. target: exitItem
  292. property: "opacity"
  293. from: 1
  294. to: 0
  295. duration: 100
  296. }
  297. }
  298. }
  299. }
  300. Loader
  301. {
  302. anchors.bottom: footerSeparator.top
  303. anchors.top: monitorLabel.bottom
  304. anchors.topMargin: UM.Theme.getSize("default_margin").height
  305. anchors.left: base.left
  306. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  307. anchors.right: base.right
  308. source: monitoringPrint ? "PrintMonitor.qml": "SidebarContents.qml"
  309. }
  310. Rectangle
  311. {
  312. id: footerSeparator
  313. width: parent.width
  314. height: UM.Theme.getSize("sidebar_lining").height
  315. color: UM.Theme.getColor("sidebar_lining")
  316. anchors.bottom: saveButton.top
  317. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  318. }
  319. SaveButton
  320. {
  321. id: saveButton
  322. implicitWidth: base.width
  323. implicitHeight: totalHeight
  324. anchors.bottom: parent.bottom
  325. visible: !monitoringPrint
  326. }
  327. MonitorButton
  328. {
  329. id: monitorButton
  330. implicitWidth: base.width
  331. implicitHeight: totalHeight
  332. anchors.bottom: parent.bottom
  333. visible: monitoringPrint
  334. }
  335. SidebarTooltip
  336. {
  337. id: tooltip;
  338. }
  339. ListModel
  340. {
  341. id: modesListModel;
  342. }
  343. SidebarSimple
  344. {
  345. id: sidebarSimple;
  346. visible: false;
  347. onShowTooltip: base.showTooltip(item, location, text)
  348. onHideTooltip: base.hideTooltip()
  349. }
  350. SidebarAdvanced
  351. {
  352. id: sidebarAdvanced;
  353. visible: false;
  354. onShowTooltip: base.showTooltip(item, location, text)
  355. onHideTooltip: base.hideTooltip()
  356. }
  357. Component.onCompleted:
  358. {
  359. modesListModel.append({ text: catalog.i18nc("@title:tab", "Recommended"), item: sidebarSimple, showFilterButton: false })
  360. modesListModel.append({ text: catalog.i18nc("@title:tab", "Custom"), item: sidebarAdvanced, showFilterButton: true })
  361. sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "immediate": true });
  362. var index = parseInt(UM.Preferences.getValue("cura/active_mode"))
  363. if(index)
  364. {
  365. currentModeIndex = index;
  366. }
  367. }
  368. UM.SettingPropertyProvider
  369. {
  370. id: machineExtruderCount
  371. containerStackId: Cura.MachineManager.activeMachineId
  372. key: "machine_extruder_count"
  373. watchedProperties: [ "value" ]
  374. storeIndex: 0
  375. }
  376. UM.SettingPropertyProvider
  377. {
  378. id: machineHeatedBed
  379. containerStackId: Cura.MachineManager.activeMachineId
  380. key: "machine_heated_bed"
  381. watchedProperties: [ "value" ]
  382. storeIndex: 0
  383. }
  384. }