MachineSelector.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.1 as Cura
  7. Cura.ExpandablePopup
  8. {
  9. id: machineSelector
  10. property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasNetworkConnection
  11. property bool isConnectedCloudPrinter: Cura.MachineManager.activeMachineHasCloudConnection
  12. property bool isCloudRegistered: Cura.MachineManager.activeMachineHasCloudRegistration
  13. property bool isGroup: Cura.MachineManager.activeMachineIsGroup
  14. readonly property string connectionStatus: {
  15. if (isNetworkPrinter)
  16. {
  17. return "printer_connected"
  18. }
  19. else if (isConnectedCloudPrinter && Cura.API.connectionStatus.isInternetReachable)
  20. {
  21. return "printer_cloud_connected"
  22. }
  23. else if (isCloudRegistered)
  24. {
  25. return "printer_cloud_not_available"
  26. }
  27. else
  28. {
  29. return ""
  30. }
  31. }
  32. readonly property string connectionStatusMessage: {
  33. if (connectionStatus == "printer_cloud_not_available")
  34. {
  35. if(Cura.API.connectionStatus.isInternetReachable)
  36. {
  37. if (Cura.API.account.isLoggedIn)
  38. {
  39. return catalog.i18nc("@status", "The cloud printer is offline. Please check if the printer is turned on and connected to the internet.")
  40. }
  41. else
  42. {
  43. return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please sign in to connect to the cloud printer.")
  44. }
  45. } else
  46. {
  47. return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please check your internet connection.")
  48. }
  49. }
  50. else
  51. {
  52. return ""
  53. }
  54. }
  55. contentPadding: UM.Theme.getSize("default_lining").width
  56. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  57. UM.I18nCatalog
  58. {
  59. id: catalog
  60. name: "cura"
  61. }
  62. headerItem: Cura.IconWithText
  63. {
  64. text:
  65. {
  66. if (isNetworkPrinter && Cura.MachineManager.activeMachineNetworkGroupName != "")
  67. {
  68. return Cura.MachineManager.activeMachineNetworkGroupName
  69. }
  70. if(Cura.MachineManager.activeMachine != null)
  71. {
  72. return Cura.MachineManager.activeMachine.name
  73. }
  74. return ""
  75. }
  76. source:
  77. {
  78. if (isGroup)
  79. {
  80. return UM.Theme.getIcon("printer_group")
  81. }
  82. else if (isNetworkPrinter || isCloudRegistered)
  83. {
  84. return UM.Theme.getIcon("printer_single")
  85. }
  86. else
  87. {
  88. return ""
  89. }
  90. }
  91. font: UM.Theme.getFont("medium")
  92. iconColor: UM.Theme.getColor("machine_selector_printer_icon")
  93. iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0
  94. UM.RecolorImage
  95. {
  96. id: connectionStatusImage
  97. anchors
  98. {
  99. bottom: parent.bottom
  100. left: parent.left
  101. leftMargin: UM.Theme.getSize("thick_margin").width
  102. }
  103. source: UM.Theme.getIcon(connectionStatus)
  104. width: UM.Theme.getSize("printer_status_icon").width
  105. height: UM.Theme.getSize("printer_status_icon").height
  106. color: connectionStatus == "printer_cloud_not_available" ? UM.Theme.getColor("cloud_unavailable") : UM.Theme.getColor("primary")
  107. visible: isNetworkPrinter || isCloudRegistered
  108. // Make a themable circle in the background so we can change it in other themes
  109. Rectangle
  110. {
  111. id: iconBackground
  112. anchors.centerIn: parent
  113. // Make it a bit bigger so there is an outline
  114. width: parent.width + 2 * UM.Theme.getSize("default_lining").width
  115. height: parent.height + 2 * UM.Theme.getSize("default_lining").height
  116. radius: Math.round(width / 2)
  117. color: UM.Theme.getColor("main_background")
  118. z: parent.z - 1
  119. }
  120. }
  121. MouseArea // Connection status tooltip hover area
  122. {
  123. id: connectionStatusTooltipHoverArea
  124. anchors.fill: parent
  125. hoverEnabled: connectionStatusMessage !== ""
  126. acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
  127. onEntered:
  128. {
  129. machineSelector.mouseArea.entered() // we want both this and the outer area to be entered
  130. tooltip.show()
  131. }
  132. onExited: { tooltip.hide() }
  133. }
  134. Cura.ToolTip
  135. {
  136. id: tooltip
  137. width: 250 * screenScaleFactor
  138. tooltipText: connectionStatusMessage
  139. arrowSize: UM.Theme.getSize("button_tooltip_arrow").width
  140. x: connectionStatusImage.x - UM.Theme.getSize("narrow_margin").width
  141. y: connectionStatusImage.y + connectionStatusImage.height + UM.Theme.getSize("narrow_margin").height
  142. z: popup.z + 1
  143. targetPoint: Qt.point(
  144. connectionStatusImage.x + Math.round(connectionStatusImage.width / 2),
  145. connectionStatusImage.y
  146. )
  147. }
  148. }
  149. contentItem: Item
  150. {
  151. id: popup
  152. width: UM.Theme.getSize("machine_selector_widget_content").width
  153. ScrollView
  154. {
  155. id: scroll
  156. width: parent.width
  157. clip: true
  158. leftPadding: UM.Theme.getSize("default_lining").width
  159. rightPadding: UM.Theme.getSize("default_lining").width
  160. MachineSelectorList
  161. {
  162. id: machineSelectorList
  163. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  164. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  165. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  166. // We use an extra property here, since we only want to to be informed about the content size changes.
  167. onContentHeightChanged:
  168. {
  169. scroll.height = Math.min(contentHeight, maximumHeight)
  170. popup.height = scroll.height + buttonRow.height
  171. }
  172. Component.onCompleted:
  173. {
  174. scroll.height = Math.min(contentHeight, maximumHeight)
  175. popup.height = scroll.height + buttonRow.height
  176. }
  177. }
  178. }
  179. Rectangle
  180. {
  181. id: separator
  182. anchors.top: scroll.bottom
  183. width: parent.width
  184. height: UM.Theme.getSize("default_lining").height
  185. color: UM.Theme.getColor("lining")
  186. }
  187. Row
  188. {
  189. id: buttonRow
  190. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  191. anchors.top: separator.top
  192. anchors.horizontalCenter: parent.horizontalCenter
  193. padding: UM.Theme.getSize("default_margin").width
  194. spacing: UM.Theme.getSize("default_margin").width
  195. Cura.SecondaryButton
  196. {
  197. id: addPrinterButton
  198. leftPadding: UM.Theme.getSize("default_margin").width
  199. rightPadding: UM.Theme.getSize("default_margin").width
  200. text: catalog.i18nc("@button", "Add printer")
  201. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  202. // padding of the component and half the spacing because of the space between buttons.
  203. maximumWidth: UM.Theme.getSize("machine_selector_widget_content").width / 2 - parent.padding - leftPadding - parent.spacing / 2
  204. onClicked:
  205. {
  206. toggleContent()
  207. Cura.Actions.addMachine.trigger()
  208. }
  209. }
  210. Cura.SecondaryButton
  211. {
  212. id: managePrinterButton
  213. leftPadding: UM.Theme.getSize("default_margin").width
  214. rightPadding: UM.Theme.getSize("default_margin").width
  215. text: catalog.i18nc("@button", "Manage printers")
  216. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  217. // padding of the component and half the spacing because of the space between buttons.
  218. maximumWidth: UM.Theme.getSize("machine_selector_widget_content").width / 2 - parent.padding - rightPadding - parent.spacing / 2
  219. onClicked:
  220. {
  221. toggleContent()
  222. Cura.Actions.configureMachines.trigger()
  223. }
  224. }
  225. }
  226. }
  227. }