MonitorButton.qml 11 KB

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