MachineSelector.qml 5.6 KB

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