MonitorSidebar.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Layouts 1.3
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. import "Menus"
  9. import "Menus/ConfigurationMenu"
  10. Rectangle
  11. {
  12. id: base
  13. property int currentModeIndex
  14. property bool hideSettings: PrintInformation.preSliced
  15. property bool hideView: Cura.MachineManager.activeMachineName == ""
  16. // Is there an output device for this printer?
  17. property bool isNetworkPrinter: Cura.MachineManager.activeMachineNetworkKey != ""
  18. property bool printerConnected: Cura.MachineManager.printerConnected
  19. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  20. property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  21. property variant printDuration: PrintInformation.currentPrintTime
  22. property variant printMaterialLengths: PrintInformation.materialLengths
  23. property variant printMaterialWeights: PrintInformation.materialWeights
  24. property variant printMaterialCosts: PrintInformation.materialCosts
  25. property variant printMaterialNames: PrintInformation.materialNames
  26. color: UM.Theme.getColor("main_background")
  27. UM.I18nCatalog { id: catalog; name: "cura"}
  28. Timer {
  29. id: tooltipDelayTimer
  30. interval: 500
  31. repeat: false
  32. property var item
  33. property string text
  34. onTriggered:
  35. {
  36. base.showTooltip(base, {x: 0, y: item.y}, text);
  37. }
  38. }
  39. function showTooltip(item, position, text)
  40. {
  41. tooltip.text = text;
  42. position = item.mapToItem(base, position.x - UM.Theme.getSize("default_arrow").width, position.y);
  43. tooltip.show(position);
  44. }
  45. function hideTooltip()
  46. {
  47. tooltip.hide();
  48. }
  49. function strPadLeft(string, pad, length) {
  50. return (new Array(length + 1).join(pad) + string).slice(-length);
  51. }
  52. function getPrettyTime(time)
  53. {
  54. var hours = Math.floor(time / 3600)
  55. time -= hours * 3600
  56. var minutes = Math.floor(time / 60);
  57. time -= minutes * 60
  58. var seconds = Math.floor(time);
  59. var finalTime = strPadLeft(hours, "0", 2) + ":" + strPadLeft(minutes, "0", 2) + ":" + strPadLeft(seconds, "0", 2);
  60. return finalTime;
  61. }
  62. MouseArea
  63. {
  64. anchors.fill: parent
  65. acceptedButtons: Qt.AllButtons
  66. onWheel:
  67. {
  68. wheel.accepted = true;
  69. }
  70. }
  71. MachineSelector
  72. {
  73. id: machineSelection
  74. width: base.width - configSelection.width - separator.width
  75. height: UM.Theme.getSize("stage_menu").height
  76. anchors.top: base.top
  77. anchors.left: parent.left
  78. }
  79. Rectangle
  80. {
  81. id: separator
  82. visible: configSelection.visible
  83. width: visible ? Math.round(UM.Theme.getSize("thick_lining").height / 2) : 0
  84. height: UM.Theme.getSize("stage_menu").height
  85. color: UM.Theme.getColor("thick_lining")
  86. anchors.left: machineSelection.right
  87. }
  88. CustomConfigurationSelector
  89. {
  90. id: configSelection
  91. visible: isNetworkPrinter && printerConnected
  92. width: visible ? Math.round(base.width * 0.15) : 0
  93. height: UM.Theme.getSize("stage_menu").height
  94. anchors.top: base.top
  95. anchors.right: parent.right
  96. }
  97. Loader
  98. {
  99. id: controlItem
  100. anchors.bottom: footerSeparator.top
  101. anchors.top: machineSelection.bottom
  102. anchors.left: base.left
  103. anchors.right: base.right
  104. sourceComponent:
  105. {
  106. if(connectedPrinter != null)
  107. {
  108. if(connectedPrinter.controlItem != null)
  109. {
  110. return connectedPrinter.controlItem
  111. }
  112. }
  113. return null
  114. }
  115. }
  116. Loader
  117. {
  118. anchors.bottom: footerSeparator.top
  119. anchors.top: machineSelection.bottom
  120. anchors.left: base.left
  121. anchors.right: base.right
  122. source:
  123. {
  124. if(controlItem.sourceComponent == null)
  125. {
  126. return "PrintMonitor.qml"
  127. }
  128. else
  129. {
  130. return ""
  131. }
  132. }
  133. }
  134. Rectangle
  135. {
  136. id: footerSeparator
  137. width: parent.width
  138. height: UM.Theme.getSize("wide_lining").height
  139. color: UM.Theme.getColor("wide_lining")
  140. anchors.bottom: monitorButton.top
  141. anchors.bottomMargin: UM.Theme.getSize("thick_margin").height
  142. }
  143. // MonitorButton is actually the bottom footer panel.
  144. MonitorButton
  145. {
  146. id: monitorButton
  147. implicitWidth: base.width
  148. anchors.bottom: parent.bottom
  149. }
  150. PrintSetupTooltip
  151. {
  152. id: tooltip
  153. }
  154. UM.SettingPropertyProvider
  155. {
  156. id: machineExtruderCount
  157. containerStack: Cura.MachineManager.activeMachine
  158. key: "machine_extruder_count"
  159. watchedProperties: [ "value" ]
  160. storeIndex: 0
  161. }
  162. UM.SettingPropertyProvider
  163. {
  164. id: machineHeatedBed
  165. containerStack: Cura.MachineManager.activeMachine
  166. key: "machine_heated_bed"
  167. watchedProperties: [ "value" ]
  168. storeIndex: 0
  169. }
  170. // Make the ConfigurationSelector react when the global container changes, otherwise if Cura is not connected to the printer,
  171. // switching printers make no reaction
  172. Connections
  173. {
  174. target: Cura.MachineManager
  175. onGlobalContainerChanged:
  176. {
  177. base.isNetworkPrinter = Cura.MachineManager.activeMachineNetworkKey != ""
  178. base.printerConnected = Cura.MachineManager.printerOutputDevices.length != 0
  179. }
  180. }
  181. }