MachineSelector.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 bool isNetworkPrinter: Cura.MachineManager.activeMachineHasRemoteConnection
  11. property bool isPrinterConnected: Cura.MachineManager.printerConnected
  12. property var outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  13. contentPadding: UM.Theme.getSize("default_lining").width
  14. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  15. UM.I18nCatalog
  16. {
  17. id: catalog
  18. name: "cura"
  19. }
  20. headerItem: Cura.IconWithText
  21. {
  22. text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
  23. source:
  24. {
  25. if (isNetworkPrinter)
  26. {
  27. if (machineSelector.outputDevice != null && machineSelector.outputDevice.clusterSize > 1)
  28. {
  29. return UM.Theme.getIcon("printer_group")
  30. }
  31. return UM.Theme.getIcon("printer_single")
  32. }
  33. return ""
  34. }
  35. font: UM.Theme.getFont("medium")
  36. iconColor: UM.Theme.getColor("machine_selector_printer_icon")
  37. iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0
  38. UM.RecolorImage
  39. {
  40. anchors
  41. {
  42. bottom: parent.bottom
  43. left: parent.left
  44. leftMargin: UM.Theme.getSize("thick_margin").width
  45. }
  46. source: UM.Theme.getIcon("printer_connected")
  47. width: UM.Theme.getSize("printer_status_icon").width
  48. height: UM.Theme.getSize("printer_status_icon").height
  49. color: UM.Theme.getColor("primary")
  50. visible: isNetworkPrinter && isPrinterConnected
  51. // Make a themable circle in the background so we can change it in other themes
  52. Rectangle
  53. {
  54. id: iconBackground
  55. anchors.centerIn: parent
  56. // Make it a bit bigger so there is an outline
  57. width: parent.width + 2 * UM.Theme.getSize("default_lining").width
  58. height: parent.height + 2 * UM.Theme.getSize("default_lining").height
  59. radius: Math.round(width / 2)
  60. color: UM.Theme.getColor("main_background")
  61. z: parent.z - 1
  62. }
  63. }
  64. }
  65. contentItem: Item
  66. {
  67. id: popup
  68. width: UM.Theme.getSize("machine_selector_widget_content").width
  69. ScrollView
  70. {
  71. id: scroll
  72. width: parent.width
  73. clip: true
  74. leftPadding: UM.Theme.getSize("default_lining").width
  75. rightPadding: UM.Theme.getSize("default_lining").width
  76. MachineSelectorList
  77. {
  78. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  79. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  80. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  81. // We use an extra property here, since we only want to to be informed about the content size changes.
  82. onContentHeightChanged:
  83. {
  84. scroll.height = Math.min(contentHeight, maximumHeight)
  85. popup.height = scroll.height + buttonRow.height
  86. }
  87. Component.onCompleted:
  88. {
  89. scroll.height = Math.min(contentHeight, 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. }