MonitorButton.qml 7.2 KB

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