MonitorButton.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. // Copyright (c) 2016 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.1 as UM
  8. import Cura 1.0 as Cura
  9. Rectangle
  10. {
  11. id: base;
  12. UM.I18nCatalog { id: catalog; name:"cura"}
  13. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  14. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  15. property real progress: printerConnected ? Cura.MachineManager.printerOutputDevices[0].progress : 0
  16. property int backendState: UM.Backend.state
  17. property bool showProgress: {
  18. // determine if we need to show the progress bar + percentage
  19. if(!printerConnected || !printerAcceptsCommands)
  20. return false;
  21. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  22. {
  23. case "printing":
  24. case "pre_print": // heating, etc.
  25. case "paused":
  26. return true;
  27. case "wait_cleanup":
  28. case "ready": // nut sure if this occurs, "" seems to be the ready state.
  29. case "offline":
  30. case "abort": // note sure if this jobState actually occurs in the wild
  31. case "error": // after clicking abort you apparently get "error"
  32. case "": // ready to print
  33. default:
  34. return false;
  35. }
  36. }
  37. property variant statusColor:
  38. {
  39. if(!printerConnected || !printerAcceptsCommands)
  40. return UM.Theme.getColor("text");
  41. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  42. {
  43. case "printing":
  44. case "pre_print":
  45. case "wait_cleanup":
  46. return UM.Theme.getColor("status_busy");
  47. case "ready":
  48. case "":
  49. return UM.Theme.getColor("status_ready");
  50. case "paused":
  51. return UM.Theme.getColor("status_paused");
  52. case "error":
  53. return UM.Theme.getColor("status_stopped");
  54. case "offline":
  55. return UM.Theme.getColor("status_offline");
  56. default:
  57. return UM.Theme.getColor("text");
  58. }
  59. }
  60. property bool activity: Printer.getPlatformActivity;
  61. property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
  62. property string fileBaseName
  63. property string statusText:
  64. {
  65. if(!printerConnected)
  66. return catalog.i18nc("@label:MonitorStatus", "Not connected to a printer");
  67. if(!printerAcceptsCommands)
  68. return catalog.i18nc("@label:MonitorStatus", "Printer does not accept commands");
  69. var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
  70. switch(printerOutputDevice.jobState)
  71. {
  72. case "offline":
  73. return catalog.i18nc("@label:MonitorStatus", "Lost connection with the printer");
  74. case "printing":
  75. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  76. case "paused":
  77. return catalog.i18nc("@label:MonitorStatus", "Paused");
  78. case "pre_print":
  79. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  80. case "wait_cleanup":
  81. return catalog.i18nc("@label:MonitorStatus", "Please remove the print");
  82. case "error":
  83. return printerOutputDevice.errorText;
  84. default:
  85. return " ";
  86. }
  87. }
  88. Label
  89. {
  90. id: statusLabel
  91. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  92. anchors.top: parent.top
  93. anchors.left: parent.left
  94. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  95. color: base.statusColor
  96. font: UM.Theme.getFont("large")
  97. text: statusText
  98. }
  99. Label
  100. {
  101. id: percentageLabel
  102. anchors.top: parent.top
  103. anchors.right: progressBar.right
  104. color: base.statusColor
  105. font: UM.Theme.getFont("large")
  106. text: Math.round(progress) + "%"
  107. visible: showProgress
  108. }
  109. Rectangle
  110. {
  111. id: progressBar
  112. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  113. height: UM.Theme.getSize("progressbar").height
  114. anchors.top: statusLabel.bottom
  115. anchors.topMargin: UM.Theme.getSize("default_margin").height / 4
  116. anchors.left: parent.left
  117. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  118. radius: UM.Theme.getSize("progressbar_radius").width
  119. color: UM.Theme.getColor("progressbar_background")
  120. visible: showProgress
  121. Rectangle
  122. {
  123. width: Math.max(parent.width * base.progress / 100)
  124. height: parent.height
  125. color: base.statusColor
  126. radius: UM.Theme.getSize("progressbar_radius").width
  127. }
  128. }
  129. Button
  130. {
  131. id: abortButton
  132. visible: printerConnected
  133. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  134. (Cura.MachineManager.printerOutputDevices[0].jobState == "paused" || Cura.MachineManager.printerOutputDevices[0].jobState == "printing")
  135. height: UM.Theme.getSize("save_button_save_to_button").height
  136. anchors.top: progressBar.bottom
  137. anchors.topMargin: UM.Theme.getSize("default_margin").height
  138. anchors.right: parent.right
  139. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  140. text: catalog.i18nc("@label:", "Abort Print");
  141. onClicked: Cura.MachineManager.printerOutputDevices[0].setJobState("abort");
  142. style: ButtonStyle
  143. {
  144. background: Rectangle
  145. {
  146. border.width: UM.Theme.getSize("default_lining").width
  147. border.color:
  148. {
  149. if(!control.enabled)
  150. return UM.Theme.getColor("action_button_disabled_border");
  151. else if(control.pressed)
  152. return UM.Theme.getColor("action_button_active_border");
  153. else if(control.hovered)
  154. return UM.Theme.getColor("action_button_hovered_border");
  155. else
  156. return UM.Theme.getColor("action_button_border");
  157. }
  158. color:
  159. {
  160. if(!control.enabled)
  161. return UM.Theme.getColor("action_button_disabled");
  162. else if(control.pressed)
  163. return UM.Theme.getColor("action_button_active");
  164. else if(control.hovered)
  165. return UM.Theme.getColor("action_button_hovered");
  166. else
  167. return UM.Theme.getColor("action_button");
  168. }
  169. Behavior on color { ColorAnimation { duration: 50; } }
  170. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  171. Label
  172. {
  173. id: actualLabel
  174. anchors.centerIn: parent
  175. color:
  176. {
  177. if(!control.enabled)
  178. return UM.Theme.getColor("action_button_disabled_text");
  179. else if(control.pressed)
  180. return UM.Theme.getColor("action_button_active_text");
  181. else if(control.hovered)
  182. return UM.Theme.getColor("action_button_hovered_text");
  183. else
  184. return UM.Theme.getColor("action_button_text");
  185. }
  186. font: UM.Theme.getFont("action_button")
  187. text: control.text;
  188. }
  189. }
  190. label: Item { }
  191. }
  192. }
  193. Button
  194. {
  195. id: pauseResumeButton
  196. height: UM.Theme.getSize("save_button_save_to_button").height
  197. anchors.top: progressBar.bottom
  198. anchors.topMargin: UM.Theme.getSize("default_margin").height
  199. anchors.right: abortButton.left
  200. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  201. visible: printerConnected
  202. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  203. (Cura.MachineManager.printerOutputDevices[0].jobState == "paused" || Cura.MachineManager.printerOutputDevices[0].jobState == "printing")
  204. property bool userClicked: false
  205. text: {
  206. var result = "";
  207. if (!printerConnected) {
  208. return "";
  209. }
  210. if (Cura.MachineManager.printerOutputDevices[0].jobState == "paused")
  211. {
  212. if (userClicked) {
  213. result = catalog.i18nc("@label:", "Resuming...");
  214. } else {
  215. result = catalog.i18nc("@label:", "Resume");
  216. }
  217. } else {
  218. if (userClicked) {
  219. result = catalog.i18nc("@label:", "Pausing...");
  220. } else {
  221. result = catalog.i18nc("@label:", "Pause");
  222. }
  223. }
  224. userClicked = false;
  225. return result;
  226. }
  227. onClicked: {
  228. var newJobState = Cura.MachineManager.printerOutputDevices[0].jobState == "paused" ? "print" : "pause";
  229. Cura.MachineManager.printerOutputDevices[0].setJobState(newJobState);
  230. userClicked = true;
  231. }
  232. style: ButtonStyle
  233. {
  234. background: Rectangle
  235. {
  236. border.width: UM.Theme.getSize("default_lining").width
  237. border.color:
  238. {
  239. if(!control.enabled)
  240. return UM.Theme.getColor("action_button_disabled_border");
  241. else if(control.pressed)
  242. return UM.Theme.getColor("action_button_active_border");
  243. else if(control.hovered)
  244. return UM.Theme.getColor("action_button_hovered_border");
  245. else
  246. return UM.Theme.getColor("action_button_border");
  247. }
  248. color:
  249. {
  250. if(!control.enabled)
  251. return UM.Theme.getColor("action_button_disabled");
  252. else if(control.pressed)
  253. return UM.Theme.getColor("action_button_active");
  254. else if(control.hovered)
  255. return UM.Theme.getColor("action_button_hovered");
  256. else
  257. return UM.Theme.getColor("action_button");
  258. }
  259. Behavior on color { ColorAnimation { duration: 50; } }
  260. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  261. Label
  262. {
  263. id: actualLabel
  264. anchors.centerIn: parent
  265. color:
  266. {
  267. if(!control.enabled)
  268. return UM.Theme.getColor("action_button_disabled_text");
  269. else if(control.pressed)
  270. return UM.Theme.getColor("action_button_active_text");
  271. else if(control.hovered)
  272. return UM.Theme.getColor("action_button_hovered_text");
  273. else
  274. return UM.Theme.getColor("action_button_text");
  275. }
  276. font: UM.Theme.getFont("action_button")
  277. text: control.text
  278. }
  279. }
  280. label: Item { }
  281. }
  282. }
  283. }