MonitorButton.qml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 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 string fileBaseName
  75. property string statusText:
  76. {
  77. if(!printerConnected)
  78. return catalog.i18nc("@label:MonitorStatus", "Not connected to a printer");
  79. if(!printerAcceptsCommands)
  80. return catalog.i18nc("@label:MonitorStatus", "Printer does not accept commands");
  81. var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
  82. if(printerOutputDevice.printerState == "maintenance")
  83. {
  84. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  85. }
  86. switch(printerOutputDevice.jobState)
  87. {
  88. case "offline":
  89. return catalog.i18nc("@label:MonitorStatus", "Lost connection with the printer");
  90. case "printing":
  91. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  92. //TODO: Add text for case "pausing".
  93. case "paused":
  94. return catalog.i18nc("@label:MonitorStatus", "Paused");
  95. //TODO: Add text for case "resuming".
  96. case "pre_print":
  97. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  98. case "wait_cleanup":
  99. return catalog.i18nc("@label:MonitorStatus", "Please remove the print");
  100. case "error":
  101. return printerOutputDevice.errorText;
  102. default:
  103. return " ";
  104. }
  105. }
  106. Label
  107. {
  108. id: statusLabel
  109. width: parent.width - 2 * UM.Theme.getSize("sidebar_margin").width
  110. anchors.top: parent.top
  111. anchors.left: parent.left
  112. anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width
  113. color: base.statusColor
  114. font: UM.Theme.getFont("large")
  115. text: statusText
  116. }
  117. Label
  118. {
  119. id: percentageLabel
  120. anchors.top: parent.top
  121. anchors.right: progressBar.right
  122. color: base.statusColor
  123. font: UM.Theme.getFont("large")
  124. text: Math.round(progress) + "%"
  125. visible: showProgress
  126. }
  127. ProgressBar
  128. {
  129. id: progressBar;
  130. minimumValue: 0;
  131. maximumValue: 100;
  132. value: 0;
  133. //Doing this in an explicit binding since the implicit binding breaks on occasion.
  134. Binding
  135. {
  136. target: progressBar;
  137. property: "value";
  138. value: base.progress;
  139. }
  140. visible: showProgress;
  141. indeterminate:
  142. {
  143. if(!printerConnected)
  144. {
  145. return false;
  146. }
  147. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  148. {
  149. case "pausing":
  150. case "resuming":
  151. return true;
  152. default:
  153. return false;
  154. }
  155. }
  156. style: UM.Theme.styles.progressbar;
  157. property string backgroundColor: UM.Theme.getColor("progressbar_background");
  158. property string controlColor: base.statusColor;
  159. width: parent.width - 2 * UM.Theme.getSize("sidebar_margin").width;
  160. height: UM.Theme.getSize("progressbar").height;
  161. anchors.top: statusLabel.bottom;
  162. anchors.topMargin: UM.Theme.getSize("sidebar_margin").height / 4;
  163. anchors.left: parent.left;
  164. anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width;
  165. }
  166. Row {
  167. id: buttonsRow
  168. height: abortButton.height
  169. anchors.top: progressBar.bottom
  170. anchors.topMargin: UM.Theme.getSize("sidebar_margin").height
  171. anchors.right: parent.right
  172. anchors.rightMargin: UM.Theme.getSize("sidebar_margin").width
  173. spacing: UM.Theme.getSize("default_margin").width
  174. Row {
  175. id: additionalComponentsRow
  176. spacing: UM.Theme.getSize("default_margin").width
  177. }
  178. Connections {
  179. target: Printer
  180. onAdditionalComponentsChanged:
  181. {
  182. if(areaId == "monitorButtons") {
  183. for (var component in CuraApplication.additionalComponents["monitorButtons"]) {
  184. CuraApplication.additionalComponents["monitorButtons"][component].parent = additionalComponentsRow
  185. }
  186. }
  187. }
  188. }
  189. Button
  190. {
  191. id: pauseResumeButton
  192. height: UM.Theme.getSize("save_button_save_to_button").height
  193. property bool userClicked: false
  194. property string lastJobState: ""
  195. visible: printerConnected && Cura.MachineManager.printerOutputDevices[0].canPause
  196. enabled: (!userClicked) && printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  197. (["paused", "printing"].indexOf(Cura.MachineManager.printerOutputDevices[0].jobState) >= 0)
  198. text: {
  199. var result = "";
  200. if (!printerConnected)
  201. {
  202. return "";
  203. }
  204. var jobState = Cura.MachineManager.printerOutputDevices[0].jobState;
  205. if (jobState == "paused")
  206. {
  207. return catalog.i18nc("@label:", "Resume");
  208. }
  209. else
  210. {
  211. return catalog.i18nc("@label:", "Pause");
  212. }
  213. }
  214. onClicked:
  215. {
  216. var current_job_state = Cura.MachineManager.printerOutputDevices[0].jobState
  217. if(current_job_state == "paused")
  218. {
  219. Cura.MachineManager.printerOutputDevices[0].setJobState("print");
  220. }
  221. else if(current_job_state == "printing")
  222. {
  223. Cura.MachineManager.printerOutputDevices[0].setJobState("pause");
  224. }
  225. }
  226. style: UM.Theme.styles.sidebar_action_button
  227. }
  228. Button
  229. {
  230. id: abortButton
  231. visible: printerConnected && Cura.MachineManager.printerOutputDevices[0].canAbort
  232. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  233. (["paused", "printing", "pre_print"].indexOf(Cura.MachineManager.printerOutputDevices[0].jobState) >= 0)
  234. height: UM.Theme.getSize("save_button_save_to_button").height
  235. text: catalog.i18nc("@label:", "Abort Print")
  236. onClicked: confirmationDialog.visible = true
  237. style: UM.Theme.styles.sidebar_action_button
  238. }
  239. MessageDialog
  240. {
  241. id: confirmationDialog
  242. title: catalog.i18nc("@window:title", "Abort print")
  243. icon: StandardIcon.Warning
  244. text: catalog.i18nc("@label", "Are you sure you want to abort the print?")
  245. standardButtons: StandardButton.Yes | StandardButton.No
  246. Component.onCompleted: visible = false
  247. onYes: Cura.MachineManager.printerOutputDevices[0].setJobState("abort")
  248. }
  249. }
  250. }