MonitorButton.qml 7.6 KB

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