MonitorButton.qml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.Dialogs 1.1
  7. import QtQuick.Layouts 1.1
  8. import UM 1.1 as UM
  9. import Cura 1.0 as Cura
  10. Item
  11. {
  12. id: base;
  13. UM.I18nCatalog { id: catalog; name:"cura"}
  14. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  15. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  16. property real progress: printerConnected ? Cura.MachineManager.printerOutputDevices[0].progress : 0
  17. property int backendState: UM.Backend.state
  18. property bool showProgress: {
  19. // determine if we need to show the progress bar + percentage
  20. if(!printerConnected || !printerAcceptsCommands) {
  21. return false;
  22. }
  23. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  24. {
  25. case "printing":
  26. case "paused":
  27. case "pausing":
  28. case "resuming":
  29. return true;
  30. case "pre_print": // heating, etc.
  31. case "wait_cleanup":
  32. case "offline":
  33. case "abort": // note sure if this jobState actually occurs in the wild
  34. case "error": // after clicking abort you apparently get "error"
  35. case "ready": // ready to print or getting ready
  36. case "": // ready to print or getting ready
  37. default:
  38. return false;
  39. }
  40. }
  41. property variant statusColor:
  42. {
  43. if(!printerConnected || !printerAcceptsCommands)
  44. return UM.Theme.getColor("text");
  45. switch(Cura.MachineManager.printerOutputDevices[0].printerState)
  46. {
  47. case "maintenance":
  48. return UM.Theme.getColor("status_busy");
  49. case "error":
  50. return UM.Theme.getColor("status_stopped");
  51. }
  52. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  53. {
  54. case "printing":
  55. case "pre_print":
  56. case "wait_cleanup":
  57. case "pausing":
  58. case "resuming":
  59. return UM.Theme.getColor("status_busy");
  60. case "ready":
  61. case "":
  62. return UM.Theme.getColor("status_ready");
  63. case "paused":
  64. return UM.Theme.getColor("status_paused");
  65. case "error":
  66. return UM.Theme.getColor("status_stopped");
  67. case "offline":
  68. return UM.Theme.getColor("status_offline");
  69. default:
  70. return UM.Theme.getColor("text");
  71. }
  72. }
  73. property bool activity: CuraApplication.platformActivity;
  74. property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
  75. property string fileBaseName
  76. property string statusText:
  77. {
  78. if(!printerConnected)
  79. return catalog.i18nc("@label:MonitorStatus", "Not connected to a printer");
  80. if(!printerAcceptsCommands)
  81. return catalog.i18nc("@label:MonitorStatus", "Printer does not accept commands");
  82. var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
  83. if(printerOutputDevice.printerState == "maintenance")
  84. {
  85. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  86. }
  87. switch(printerOutputDevice.jobState)
  88. {
  89. case "offline":
  90. return catalog.i18nc("@label:MonitorStatus", "Lost connection with the printer");
  91. case "printing":
  92. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  93. //TODO: Add text for case "pausing".
  94. case "paused":
  95. return catalog.i18nc("@label:MonitorStatus", "Paused");
  96. //TODO: Add text for case "resuming".
  97. case "pre_print":
  98. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  99. case "wait_cleanup":
  100. return catalog.i18nc("@label:MonitorStatus", "Please remove the print");
  101. case "error":
  102. return printerOutputDevice.errorText;
  103. default:
  104. return " ";
  105. }
  106. }
  107. Label
  108. {
  109. id: statusLabel
  110. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  111. anchors.top: parent.top
  112. anchors.left: parent.left
  113. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  114. color: base.statusColor
  115. font: UM.Theme.getFont("large")
  116. text: statusText
  117. }
  118. Label
  119. {
  120. id: percentageLabel
  121. anchors.top: parent.top
  122. anchors.right: progressBar.right
  123. color: base.statusColor
  124. font: UM.Theme.getFont("large")
  125. text: Math.round(progress) + "%"
  126. visible: showProgress
  127. }
  128. ProgressBar
  129. {
  130. id: progressBar;
  131. minimumValue: 0;
  132. maximumValue: 100;
  133. value: 0;
  134. //Doing this in an explicit binding since the implicit binding breaks on occasion.
  135. Binding
  136. {
  137. target: progressBar;
  138. property: "value";
  139. value: base.progress;
  140. }
  141. visible: showProgress;
  142. indeterminate:
  143. {
  144. if(!printerConnected)
  145. {
  146. return false;
  147. }
  148. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  149. {
  150. case "pausing":
  151. case "resuming":
  152. return true;
  153. default:
  154. return false;
  155. }
  156. }
  157. style: UM.Theme.styles.progressbar;
  158. property string backgroundColor: UM.Theme.getColor("progressbar_background");
  159. property string controlColor: base.statusColor;
  160. width: parent.width - 2 * UM.Theme.getSize("default_margin").width;
  161. height: UM.Theme.getSize("progressbar").height;
  162. anchors.top: statusLabel.bottom;
  163. anchors.topMargin: UM.Theme.getSize("default_margin").height / 4;
  164. anchors.left: parent.left;
  165. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  166. }
  167. Row {
  168. id: buttonsRow
  169. height: abortButton.height
  170. anchors.top: progressBar.bottom
  171. anchors.topMargin: UM.Theme.getSize("default_margin").height
  172. anchors.right: parent.right
  173. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  174. spacing: UM.Theme.getSize("default_margin").width
  175. Row {
  176. id: additionalComponentsRow
  177. spacing: UM.Theme.getSize("default_margin").width
  178. }
  179. Connections {
  180. target: Printer
  181. onAdditionalComponentsChanged:
  182. {
  183. if(areaId == "monitorButtons") {
  184. for (var component in CuraApplication.additionalComponents["monitorButtons"]) {
  185. CuraApplication.additionalComponents["monitorButtons"][component].parent = additionalComponentsRow
  186. }
  187. }
  188. }
  189. }
  190. Button
  191. {
  192. id: pauseResumeButton
  193. height: UM.Theme.getSize("save_button_save_to_button").height
  194. property bool userClicked: false
  195. property string lastJobState: ""
  196. visible: printerConnected
  197. enabled: (!userClicked) && printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  198. (["paused", "printing"].indexOf(Cura.MachineManager.printerOutputDevices[0].jobState) >= 0)
  199. text: {
  200. var result = "";
  201. if (!printerConnected)
  202. {
  203. return "";
  204. }
  205. var jobState = Cura.MachineManager.printerOutputDevices[0].jobState;
  206. if (jobState == "paused")
  207. {
  208. return catalog.i18nc("@label:", "Resume");
  209. }
  210. else
  211. {
  212. return catalog.i18nc("@label:", "Pause");
  213. }
  214. }
  215. onClicked:
  216. {
  217. var current_job_state = Cura.MachineManager.printerOutputDevices[0].jobState
  218. if(current_job_state == "paused")
  219. {
  220. Cura.MachineManager.printerOutputDevices[0].setJobState("print");
  221. }
  222. else if(current_job_state == "printing")
  223. {
  224. Cura.MachineManager.printerOutputDevices[0].setJobState("pause");
  225. }
  226. }
  227. style: UM.Theme.styles.sidebar_action_button
  228. }
  229. Button
  230. {
  231. id: abortButton
  232. visible: printerConnected
  233. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  234. (["paused", "printing", "pre_print"].indexOf(Cura.MachineManager.printerOutputDevices[0].jobState) >= 0)
  235. height: UM.Theme.getSize("save_button_save_to_button").height
  236. text: catalog.i18nc("@label:", "Abort Print")
  237. onClicked: confirmationDialog.visible = true
  238. style: UM.Theme.styles.sidebar_action_button
  239. }
  240. MessageDialog
  241. {
  242. id: confirmationDialog
  243. title: catalog.i18nc("@window:title", "Abort print")
  244. icon: StandardIcon.Warning
  245. text: catalog.i18nc("@label", "Are you sure you want to abort the print?")
  246. standardButtons: StandardButton.Yes | StandardButton.No
  247. Component.onCompleted: visible = false
  248. onYes: Cura.MachineManager.printerOutputDevices[0].setJobState("abort")
  249. }
  250. }
  251. }