MachineSelector.qml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.activeMachineHasNetworkConnection
  11. property bool isCloudPrinter: Cura.MachineManager.activeMachineHasCloudConnection
  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. id: machineSelectorList
  103. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  104. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  105. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  106. // We use an extra property here, since we only want to to be informed about the content size changes.
  107. onContentHeightChanged:
  108. {
  109. scroll.height = Math.min(contentHeight, maximumHeight)
  110. popup.height = scroll.height + buttonRow.height
  111. }
  112. Component.onCompleted:
  113. {
  114. scroll.height = Math.min(contentHeight, maximumHeight)
  115. popup.height = scroll.height + buttonRow.height
  116. }
  117. }
  118. }
  119. Rectangle
  120. {
  121. id: separator
  122. anchors.top: scroll.bottom
  123. width: parent.width
  124. height: UM.Theme.getSize("default_lining").height
  125. color: UM.Theme.getColor("lining")
  126. }
  127. Row
  128. {
  129. id: buttonRow
  130. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  131. anchors.top: separator.top
  132. anchors.horizontalCenter: parent.horizontalCenter
  133. padding: UM.Theme.getSize("default_margin").width
  134. spacing: UM.Theme.getSize("default_margin").width
  135. Cura.SecondaryButton
  136. {
  137. id: addPrinterButton
  138. leftPadding: UM.Theme.getSize("default_margin").width
  139. rightPadding: UM.Theme.getSize("default_margin").width
  140. text: catalog.i18nc("@button", "Add printer")
  141. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  142. // padding of the component and half the spacing because of the space between buttons.
  143. maximumWidth: UM.Theme.getSize("machine_selector_widget_content").width / 2 - parent.padding - leftPadding - parent.spacing / 2
  144. onClicked:
  145. {
  146. toggleContent()
  147. Cura.Actions.addMachine.trigger()
  148. }
  149. }
  150. Cura.SecondaryButton
  151. {
  152. id: managePrinterButton
  153. leftPadding: UM.Theme.getSize("default_margin").width
  154. rightPadding: UM.Theme.getSize("default_margin").width
  155. text: catalog.i18nc("@button", "Manage printers")
  156. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  157. // padding of the component and half the spacing because of the space between buttons.
  158. maximumWidth: UM.Theme.getSize("machine_selector_widget_content").width / 2 - parent.padding - rightPadding - parent.spacing / 2
  159. onClicked:
  160. {
  161. toggleContent()
  162. Cura.Actions.configureMachines.trigger()
  163. }
  164. }
  165. }
  166. }
  167. }