MonitorSidebar.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  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("sidebar")
  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. MachineSelection
  72. {
  73. id: machineSelection
  74. width: base.width - configSelection.width - separator.width
  75. height: UM.Theme.getSize("sidebar_header").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("sidebar_lining_thin").height / 2) : 0
  84. height: UM.Theme.getSize("sidebar_header").height
  85. color: UM.Theme.getColor("sidebar_lining_thin")
  86. anchors.left: machineSelection.right
  87. }
  88. ConfigurationSelection
  89. {
  90. id: configSelection
  91. visible: isNetworkPrinter && printerConnected
  92. width: visible ? Math.round(base.width * 0.15) : 0
  93. height: UM.Theme.getSize("sidebar_header").height
  94. anchors.top: base.top
  95. anchors.right: parent.right
  96. panelWidth: base.width
  97. }
  98. Loader
  99. {
  100. id: controlItem
  101. anchors.bottom: footerSeparator.top
  102. anchors.top: machineSelection.bottom
  103. anchors.left: base.left
  104. anchors.right: base.right
  105. sourceComponent:
  106. {
  107. if(connectedPrinter != null)
  108. {
  109. if(connectedPrinter.controlItem != null)
  110. {
  111. return connectedPrinter.controlItem
  112. }
  113. }
  114. return null
  115. }
  116. }
  117. Loader
  118. {
  119. anchors.bottom: footerSeparator.top
  120. anchors.top: machineSelection.bottom
  121. anchors.left: base.left
  122. anchors.right: base.right
  123. source:
  124. {
  125. if(controlItem.sourceComponent == null)
  126. {
  127. return "PrintMonitor.qml"
  128. }
  129. else
  130. {
  131. return ""
  132. }
  133. }
  134. }
  135. Rectangle
  136. {
  137. id: footerSeparator
  138. width: parent.width
  139. height: UM.Theme.getSize("sidebar_lining").height
  140. color: UM.Theme.getColor("sidebar_lining")
  141. anchors.bottom: monitorButton.top
  142. anchors.bottomMargin: UM.Theme.getSize("sidebar_margin").height
  143. }
  144. // MonitorButton is actually the bottom footer panel.
  145. MonitorButton
  146. {
  147. id: monitorButton
  148. implicitWidth: base.width
  149. anchors.bottom: parent.bottom
  150. }
  151. SidebarTooltip
  152. {
  153. id: tooltip
  154. }
  155. UM.SettingPropertyProvider
  156. {
  157. id: machineExtruderCount
  158. containerStackId: Cura.MachineManager.activeMachineId
  159. key: "machine_extruder_count"
  160. watchedProperties: [ "value" ]
  161. storeIndex: 0
  162. }
  163. UM.SettingPropertyProvider
  164. {
  165. id: machineHeatedBed
  166. containerStackId: Cura.MachineManager.activeMachineId
  167. key: "machine_heated_bed"
  168. watchedProperties: [ "value" ]
  169. storeIndex: 0
  170. }
  171. // Make the ConfigurationSelector react when the global container changes, otherwise if Cura is not connected to the printer,
  172. // switching printers make no reaction
  173. Connections
  174. {
  175. target: Cura.MachineManager
  176. onGlobalContainerChanged:
  177. {
  178. base.isNetworkPrinter = Cura.MachineManager.activeMachineNetworkKey != ""
  179. base.printerConnected = Cura.MachineManager.printerOutputDevices.length != 0
  180. }
  181. }
  182. }