MonitorButton.qml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 real progress: printerConnected ? Cura.MachineManager.printerOutputDevices[0].progress : 0;
  15. property int backendState: UM.Backend.state;
  16. property variant statusColor:
  17. {
  18. if(!printerConnected)
  19. return UM.Theme.getColor("status_offline")
  20. else if(Cura.MachineManager.printerOutputDevices[0].jobState == "printing" || Cura.MachineManager.printerOutputDevices[0].jobState == "pre_print" || Cura.MachineManager.printerOutputDevices[0].jobState == "wait_cleanup" )
  21. return UM.Theme.getColor("status_busy")
  22. else if(Cura.MachineManager.printerOutputDevices[0].jobState == "ready" || Cura.MachineManager.printerOutputDevices[0].jobState == "")
  23. return UM.Theme.getColor("status_ready")
  24. else if(Cura.MachineManager.printerOutputDevices[0].jobState == "paused")
  25. return UM.Theme.getColor("status_paused")
  26. else if (Cura.MachineManager.printerOutputDevices[0].jobState == "error")
  27. return UM.Theme.getColor("status_stopped")
  28. else if (Cura.MachineManager.printerOutputDevices[0].jobState == "offline")
  29. return UM.Theme.getColor("status_offline")
  30. else
  31. return UM.Theme.getColor("text")
  32. }
  33. property bool activity: Printer.getPlatformActivity;
  34. property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
  35. property string fileBaseName
  36. property string statusText:
  37. {
  38. if(!printerConnected)
  39. {
  40. return catalog.i18nc("@label:MonitorStatus", "Not connected to a printer")
  41. }
  42. var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
  43. if(printerOutputDevice.jobState == "offline")
  44. {
  45. return catalog.i18nc("@label:MonitorStatus", "Lost connection with the printer")
  46. } else if(printerOutputDevice.jobState == "printing")
  47. {
  48. return catalog.i18nc("@label:MonitorStatus", "Printing...")
  49. } else if(printerOutputDevice.jobState == "paused")
  50. {
  51. return catalog.i18nc("@label:MonitorStatus", "Paused")
  52. }
  53. else if(printerOutputDevice.jobState == "pre_print")
  54. {
  55. return catalog.i18nc("@label:MonitorStatus", "Preparing...")
  56. }
  57. else if(printerOutputDevice.jobState == "wait_cleanup")
  58. {
  59. return catalog.i18nc("@label:MonitorStatus", "Please remove the print")
  60. }
  61. else if(printerOutputDevice.jobState == "error")
  62. {
  63. return printerOutputDevice.errorText
  64. }
  65. else
  66. {
  67. return " "
  68. }
  69. }
  70. Label
  71. {
  72. id: statusLabel
  73. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  74. anchors.top: parent.top
  75. anchors.left: parent.left
  76. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  77. color: base.statusColor
  78. font: UM.Theme.getFont("large")
  79. text: statusText;
  80. }
  81. Label
  82. {
  83. id: percentageLabel
  84. anchors.top: parent.top
  85. anchors.right: progressBar.right
  86. color: base.statusColor
  87. font: UM.Theme.getFont("large")
  88. text: Math.round(progress) + "%";
  89. visible: printerConnected
  90. }
  91. Rectangle
  92. {
  93. id: progressBar
  94. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  95. height: UM.Theme.getSize("progressbar").height
  96. anchors.top: statusLabel.bottom
  97. anchors.topMargin: UM.Theme.getSize("default_margin").height / 4
  98. anchors.left: parent.left
  99. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  100. radius: UM.Theme.getSize("progressbar_radius").width
  101. color: UM.Theme.getColor("progressbar_background")
  102. Rectangle
  103. {
  104. width: Math.max(parent.width * base.progress / 100)
  105. height: parent.height
  106. color: base.statusColor
  107. radius: UM.Theme.getSize("progressbar_radius").width
  108. }
  109. }
  110. Button
  111. {
  112. id: abortButton
  113. visible: printerConnected
  114. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  115. (Cura.MachineManager.printerOutputDevices[0].jobState == "paused" || Cura.MachineManager.printerOutputDevices[0].jobState == "printing")
  116. height: UM.Theme.getSize("save_button_save_to_button").height
  117. anchors.top: progressBar.bottom
  118. anchors.topMargin: UM.Theme.getSize("default_margin").height
  119. anchors.right: parent.right
  120. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  121. text: catalog.i18nc("@label:", "Abort Print")
  122. onClicked: { Cura.MachineManager.printerOutputDevices[0].setJobState("abort") }
  123. style: ButtonStyle
  124. {
  125. background: Rectangle
  126. {
  127. border.width: UM.Theme.getSize("default_lining").width
  128. border.color: !control.enabled ? UM.Theme.getColor("action_button_disabled_border") :
  129. control.pressed ? UM.Theme.getColor("action_button_active_border") :
  130. control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  131. color: !control.enabled ? UM.Theme.getColor("action_button_disabled") :
  132. control.pressed ? UM.Theme.getColor("action_button_active") :
  133. control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  134. Behavior on color { ColorAnimation { duration: 50; } }
  135. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  136. Label
  137. {
  138. id: actualLabel
  139. anchors.centerIn: parent
  140. color: !control.enabled ? UM.Theme.getColor("action_button_disabled_text") :
  141. control.pressed ? UM.Theme.getColor("action_button_active_text") :
  142. control.hovered ? UM.Theme.getColor("action_button_hovered_text") : UM.Theme.getColor("action_button_text")
  143. font: UM.Theme.getFont("action_button")
  144. text: control.text;
  145. }
  146. }
  147. label: Item { }
  148. }
  149. }
  150. Button
  151. {
  152. id: pauseButton
  153. visible: printerConnected
  154. enabled: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands &&
  155. (Cura.MachineManager.printerOutputDevices[0].jobState == "paused" || Cura.MachineManager.printerOutputDevices[0].jobState == "printing")
  156. height: UM.Theme.getSize("save_button_save_to_button").height
  157. anchors.top: progressBar.bottom
  158. anchors.topMargin: UM.Theme.getSize("default_margin").height
  159. anchors.right: abortButton.left
  160. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  161. text: printerConnected ? Cura.MachineManager.printerOutputDevices[0].jobState == "paused" ? catalog.i18nc("@label:", "Resume") : catalog.i18nc("@label:", "Pause") : ""
  162. onClicked: { Cura.MachineManager.printerOutputDevices[0].jobState == "paused" ? Cura.MachineManager.printerOutputDevices[0].setJobState("print") : Cura.MachineManager.printerOutputDevices[0].setJobState("pause") }
  163. style: ButtonStyle
  164. {
  165. background: Rectangle
  166. {
  167. border.width: UM.Theme.getSize("default_lining").width
  168. border.color: !control.enabled ? UM.Theme.getColor("action_button_disabled_border") :
  169. control.pressed ? UM.Theme.getColor("action_button_active_border") :
  170. control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  171. color: !control.enabled ? UM.Theme.getColor("action_button_disabled") :
  172. control.pressed ? UM.Theme.getColor("action_button_active") :
  173. control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  174. Behavior on color { ColorAnimation { duration: 50; } }
  175. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  176. Label
  177. {
  178. id: actualLabel
  179. anchors.centerIn: parent
  180. color: !control.enabled ? UM.Theme.getColor("action_button_disabled_text") :
  181. control.pressed ? UM.Theme.getColor("action_button_active_text") :
  182. control.hovered ? UM.Theme.getColor("action_button_hovered_text") : UM.Theme.getColor("action_button_text")
  183. font: UM.Theme.getFont("action_button")
  184. text: control.text;
  185. }
  186. }
  187. label: Item { }
  188. }
  189. }
  190. }