MachineSelector.qml 6.7 KB

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