MonitorButton.qml 8.2 KB

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