MonitorButton.qml 9.6 KB

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