MachineSelector.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Copyright (c) 2018 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.3
  5. import UM 1.2 as UM
  6. import Cura 1.0 as Cura
  7. Cura.ExpandablePopup
  8. {
  9. id: machineSelector
  10. property var outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  11. property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasRemoteConnection
  12. property bool isCloudPrinter: machineSelector.outputDevice.connectionType == Cura.PrinterOutputDevice.CloudConnection
  13. property bool isPrinterConnected: Cura.MachineManager.printerConnected
  14. contentPadding: UM.Theme.getSize("default_lining").width
  15. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  16. UM.I18nCatalog
  17. {
  18. id: catalog
  19. name: "cura"
  20. }
  21. headerItem: Cura.IconWithText
  22. {
  23. text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
  24. source:
  25. {
  26. if (isNetworkPrinter)
  27. {
  28. if (machineSelector.outputDevice != null && machineSelector.outputDevice.clusterSize > 1)
  29. {
  30. return UM.Theme.getIcon("printer_group")
  31. }
  32. return UM.Theme.getIcon("printer_single")
  33. }
  34. return ""
  35. }
  36. font: UM.Theme.getFont("medium")
  37. iconColor: UM.Theme.getColor("machine_selector_printer_icon")
  38. iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0
  39. UM.RecolorImage
  40. {
  41. anchors
  42. {
  43. bottom: parent.bottom
  44. left: parent.left
  45. leftMargin: UM.Theme.getSize("thick_margin").width
  46. }
  47. source: machineSelector.isCloudPrinter ? UM.Theme.getIcon("printer_connected") : UM.Theme.getIcon("printer_connected")
  48. width: UM.Theme.getSize("printer_status_icon").width
  49. height: UM.Theme.getSize("printer_status_icon").height
  50. color: UM.Theme.getColor("primary")
  51. visible: isNetworkPrinter && isPrinterConnected
  52. // Make a themable circle in the background so we can change it in other themes
  53. Rectangle
  54. {
  55. id: iconBackground
  56. anchors.centerIn: parent
  57. // Make it a bit bigger so there is an outline
  58. width: parent.width + 2 * UM.Theme.getSize("default_lining").width
  59. height: parent.height + 2 * UM.Theme.getSize("default_lining").height
  60. radius: Math.round(width / 2)
  61. color: UM.Theme.getColor("main_background")
  62. z: parent.z - 1
  63. }
  64. }
  65. }
  66. contentItem: Item
  67. {
  68. id: popup
  69. width: UM.Theme.getSize("machine_selector_widget_content").width
  70. ScrollView
  71. {
  72. id: scroll
  73. width: parent.width
  74. clip: true
  75. leftPadding: UM.Theme.getSize("default_lining").width
  76. rightPadding: UM.Theme.getSize("default_lining").width
  77. MachineSelectorList
  78. {
  79. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  80. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  81. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  82. onHeightChanged:
  83. {
  84. scroll.height = Math.min(height, maximumHeight)
  85. popup.height = scroll.height + buttonRow.height
  86. }
  87. Component.onCompleted:
  88. {
  89. scroll.height = Math.min(height, maximumHeight)
  90. popup.height = scroll.height + buttonRow.height
  91. }
  92. }
  93. }
  94. Rectangle
  95. {
  96. id: separator
  97. anchors.top: scroll.bottom
  98. width: parent.width
  99. height: UM.Theme.getSize("default_lining").height
  100. color: UM.Theme.getColor("lining")
  101. }
  102. Row
  103. {
  104. id: buttonRow
  105. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  106. anchors.top: separator.top
  107. anchors.horizontalCenter: parent.horizontalCenter
  108. padding: UM.Theme.getSize("default_margin").width
  109. spacing: UM.Theme.getSize("default_margin").width
  110. Cura.SecondaryButton
  111. {
  112. leftPadding: UM.Theme.getSize("default_margin").width
  113. rightPadding: UM.Theme.getSize("default_margin").width
  114. text: catalog.i18nc("@button", "Add printer")
  115. onClicked:
  116. {
  117. toggleContent()
  118. Cura.Actions.addMachine.trigger()
  119. }
  120. }
  121. Cura.SecondaryButton
  122. {
  123. leftPadding: UM.Theme.getSize("default_margin").width
  124. rightPadding: UM.Theme.getSize("default_margin").width
  125. text: catalog.i18nc("@button", "Manage printers")
  126. onClicked:
  127. {
  128. toggleContent()
  129. Cura.Actions.configureMachines.trigger()
  130. }
  131. }
  132. }
  133. }
  134. }