MachineSelector.qml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // Copyright (c) 2022 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.5 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. function getConnectionStatusMessage() {
  33. if (connectionStatus == "printer_cloud_not_available")
  34. {
  35. if(Cura.API.connectionStatus.isInternetReachable)
  36. {
  37. if (Cura.API.account.isLoggedIn)
  38. {
  39. if (Cura.MachineManager.activeMachineIsLinkedToCurrentAccount)
  40. {
  41. return catalog.i18nc("@status", "The cloud printer is offline. Please check if the printer is turned on and connected to the internet.")
  42. }
  43. else
  44. {
  45. return catalog.i18nc("@status", "This printer is not linked to your account. Please visit the Ultimaker Digital Factory to establish a connection.")
  46. }
  47. }
  48. else
  49. {
  50. return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please sign in to connect to the cloud printer.")
  51. }
  52. } else
  53. {
  54. return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please check your internet connection.")
  55. }
  56. }
  57. else
  58. {
  59. return ""
  60. }
  61. }
  62. contentPadding: UM.Theme.getSize("default_lining").width
  63. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  64. UM.I18nCatalog
  65. {
  66. id: catalog
  67. name: "cura"
  68. }
  69. headerItem: Cura.IconWithText
  70. {
  71. text:
  72. {
  73. if (isNetworkPrinter && Cura.MachineManager.activeMachineNetworkGroupName != "")
  74. {
  75. return Cura.MachineManager.activeMachineNetworkGroupName
  76. }
  77. if(Cura.MachineManager.activeMachine != null)
  78. {
  79. return Cura.MachineManager.activeMachine.name
  80. }
  81. return ""
  82. }
  83. source:
  84. {
  85. if (isGroup)
  86. {
  87. return UM.Theme.getIcon("PrinterTriple", "medium")
  88. }
  89. else if (isNetworkPrinter || isCloudRegistered)
  90. {
  91. return UM.Theme.getIcon("Printer", "medium")
  92. }
  93. else
  94. {
  95. return ""
  96. }
  97. }
  98. font: UM.Theme.getFont("medium")
  99. iconColor: UM.Theme.getColor("machine_selector_printer_icon")
  100. iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0
  101. UM.ColorImage
  102. {
  103. id: connectionStatusImage
  104. anchors
  105. {
  106. bottom: parent.bottom
  107. bottomMargin: - Math.round(height * 1 / 6)
  108. left: parent.left
  109. leftMargin: iconSize - Math.round(width * 5 / 6)
  110. }
  111. source:
  112. {
  113. if (connectionStatus == "printer_connected")
  114. {
  115. return UM.Theme.getIcon("CheckBlueBG", "low")
  116. }
  117. else if (connectionStatus == "printer_cloud_connected" || connectionStatus == "printer_cloud_not_available")
  118. {
  119. return UM.Theme.getIcon("CloudBadge", "low")
  120. }
  121. else
  122. {
  123. return ""
  124. }
  125. }
  126. width: UM.Theme.getSize("printer_status_icon").width
  127. height: UM.Theme.getSize("printer_status_icon").height
  128. color: connectionStatus == "printer_cloud_not_available" ? UM.Theme.getColor("cloud_unavailable") : UM.Theme.getColor("primary")
  129. visible: isNetworkPrinter || isCloudRegistered
  130. // Make a themable circle in the background so we can change it in other themes
  131. Rectangle
  132. {
  133. id: iconBackground
  134. anchors.centerIn: parent
  135. width: parent.width - 1.5 //1.5 pixels smaller, (at least sqrt(2), regardless of screen pixel scale) so that the circle doesn't show up behind the icon due to anti-aliasing.
  136. height: parent.height - 1.5
  137. radius: width / 2
  138. color: UM.Theme.getColor("connection_badge_background")
  139. z: parent.z - 1
  140. }
  141. }
  142. MouseArea // Connection status tooltip hover area
  143. {
  144. id: connectionStatusTooltipHoverArea
  145. anchors.fill: parent
  146. hoverEnabled: getConnectionStatusMessage() !== ""
  147. acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
  148. onEntered:
  149. {
  150. machineSelector.mouseArea.entered() // we want both this and the outer area to be entered
  151. tooltip.tooltipText = getConnectionStatusMessage()
  152. tooltip.show()
  153. }
  154. onExited: { tooltip.hide() }
  155. }
  156. UM.ToolTip
  157. {
  158. id: tooltip
  159. width: 250 * screenScaleFactor
  160. tooltipText: getConnectionStatusMessage()
  161. arrowSize: UM.Theme.getSize("button_tooltip_arrow").width
  162. x: connectionStatusImage.x - UM.Theme.getSize("narrow_margin").width
  163. y: connectionStatusImage.y + connectionStatusImage.height + UM.Theme.getSize("narrow_margin").height
  164. z: popup.z + 1
  165. targetPoint: Qt.point(
  166. connectionStatusImage.x + Math.round(connectionStatusImage.width / 2),
  167. connectionStatusImage.y
  168. )
  169. }
  170. }
  171. contentItem: Item
  172. {
  173. id: popup
  174. implicitWidth: Math.max(machineSelector.width, UM.Theme.getSize("machine_selector_widget_content").width)
  175. implicitHeight: Math.min(machineSelectorList.contentHeight + separator.height + buttonRow.height, UM.Theme.getSize("machine_selector_widget_content").height) //Maximum height is the theme entry.
  176. MachineSelectorList
  177. {
  178. id: machineSelectorList
  179. anchors
  180. {
  181. left: parent.left
  182. leftMargin: UM.Theme.getSize("default_lining").width
  183. right: parent.right
  184. rightMargin: UM.Theme.getSize("default_lining").width
  185. top: parent.top
  186. bottom: separator.top
  187. }
  188. clip: true
  189. }
  190. Rectangle
  191. {
  192. id: separator
  193. anchors.bottom: buttonRow.top
  194. width: parent.width
  195. height: UM.Theme.getSize("default_lining").height
  196. color: UM.Theme.getColor("lining")
  197. }
  198. Row
  199. {
  200. id: buttonRow
  201. anchors.bottom: parent.bottom
  202. anchors.left: parent.left
  203. anchors.right: parent.right
  204. padding: UM.Theme.getSize("default_margin").width
  205. spacing: UM.Theme.getSize("default_margin").width
  206. Cura.SecondaryButton
  207. {
  208. id: addPrinterButton
  209. leftPadding: UM.Theme.getSize("default_margin").width
  210. rightPadding: UM.Theme.getSize("default_margin").width
  211. text: catalog.i18nc("@button", "Add printer")
  212. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  213. // padding of the component and half the spacing because of the space between buttons.
  214. fixedWidthMode: true
  215. width: buttonRow.width / 2 - leftPadding * 1.5
  216. onClicked:
  217. {
  218. toggleContent()
  219. Cura.Actions.addMachine.trigger()
  220. }
  221. }
  222. Cura.SecondaryButton
  223. {
  224. id: managePrinterButton
  225. leftPadding: UM.Theme.getSize("default_margin").width
  226. rightPadding: UM.Theme.getSize("default_margin").width
  227. text: catalog.i18nc("@button", "Manage printers")
  228. fixedWidthMode: true
  229. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  230. // padding of the component and half the spacing because of the space between buttons.
  231. width: buttonRow.width / 2 - rightPadding * 1.5
  232. onClicked:
  233. {
  234. toggleContent()
  235. Cura.Actions.configureMachines.trigger()
  236. }
  237. }
  238. }
  239. }
  240. }