MachineSelector.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.activeMachineHasActiveNetworkConnection
  11. property bool isCloudPrinter: Cura.MachineManager.activeMachineHasActiveCloudConnection
  12. property bool isGroup: Cura.MachineManager.activeMachineIsGroup
  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:
  23. {
  24. if (isNetworkPrinter && Cura.MachineManager.activeMachineNetworkGroupName != "")
  25. {
  26. return Cura.MachineManager.activeMachineNetworkGroupName
  27. }
  28. return Cura.MachineManager.activeMachineName
  29. }
  30. source:
  31. {
  32. if (isGroup)
  33. {
  34. return UM.Theme.getIcon("printer_group")
  35. }
  36. else if (isNetworkPrinter || isCloudPrinter)
  37. {
  38. return UM.Theme.getIcon("printer_single")
  39. }
  40. else
  41. {
  42. return ""
  43. }
  44. }
  45. font: UM.Theme.getFont("medium")
  46. iconColor: UM.Theme.getColor("machine_selector_printer_icon")
  47. iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0
  48. UM.RecolorImage
  49. {
  50. anchors
  51. {
  52. bottom: parent.bottom
  53. left: parent.left
  54. leftMargin: UM.Theme.getSize("thick_margin").width
  55. }
  56. source:
  57. {
  58. if (isNetworkPrinter)
  59. {
  60. return UM.Theme.getIcon("printer_connected")
  61. }
  62. else if (isCloudPrinter)
  63. {
  64. return UM.Theme.getIcon("printer_cloud_connected")
  65. }
  66. else
  67. {
  68. return ""
  69. }
  70. }
  71. width: UM.Theme.getSize("printer_status_icon").width
  72. height: UM.Theme.getSize("printer_status_icon").height
  73. color: UM.Theme.getColor("primary")
  74. visible: isNetworkPrinter || isCloudPrinter
  75. // Make a themable circle in the background so we can change it in other themes
  76. Rectangle
  77. {
  78. id: iconBackground
  79. anchors.centerIn: parent
  80. // Make it a bit bigger so there is an outline
  81. width: parent.width + 2 * UM.Theme.getSize("default_lining").width
  82. height: parent.height + 2 * UM.Theme.getSize("default_lining").height
  83. radius: Math.round(width / 2)
  84. color: UM.Theme.getColor("main_background")
  85. z: parent.z - 1
  86. }
  87. }
  88. }
  89. contentItem: Item
  90. {
  91. id: popup
  92. width: UM.Theme.getSize("machine_selector_widget_content").width
  93. ScrollView
  94. {
  95. id: scroll
  96. width: parent.width
  97. clip: true
  98. leftPadding: UM.Theme.getSize("default_lining").width
  99. rightPadding: UM.Theme.getSize("default_lining").width
  100. MachineSelectorList
  101. {
  102. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  103. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  104. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  105. // We use an extra property here, since we only want to to be informed about the content size changes.
  106. onContentHeightChanged:
  107. {
  108. scroll.height = Math.min(contentHeight, maximumHeight)
  109. popup.height = scroll.height + buttonRow.height
  110. }
  111. Component.onCompleted:
  112. {
  113. scroll.height = Math.min(contentHeight, maximumHeight)
  114. popup.height = scroll.height + buttonRow.height
  115. }
  116. }
  117. }
  118. Rectangle
  119. {
  120. id: separator
  121. anchors.top: scroll.bottom
  122. width: parent.width
  123. height: UM.Theme.getSize("default_lining").height
  124. color: UM.Theme.getColor("lining")
  125. }
  126. Row
  127. {
  128. id: buttonRow
  129. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  130. anchors.top: separator.top
  131. anchors.horizontalCenter: parent.horizontalCenter
  132. padding: UM.Theme.getSize("default_margin").width
  133. spacing: UM.Theme.getSize("default_margin").width
  134. Cura.SecondaryButton
  135. {
  136. leftPadding: UM.Theme.getSize("default_margin").width
  137. rightPadding: UM.Theme.getSize("default_margin").width
  138. text: catalog.i18nc("@button", "Add printer")
  139. onClicked:
  140. {
  141. toggleContent()
  142. Cura.Actions.addMachine.trigger()
  143. }
  144. }
  145. Cura.SecondaryButton
  146. {
  147. leftPadding: UM.Theme.getSize("default_margin").width
  148. rightPadding: UM.Theme.getSize("default_margin").width
  149. text: catalog.i18nc("@button", "Manage printers")
  150. onClicked:
  151. {
  152. toggleContent()
  153. Cura.Actions.configureMachines.trigger()
  154. }
  155. }
  156. }
  157. }
  158. }