MonitorButton.qml 8.4 KB

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