MachineSelector.qml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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: 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.horizontalCenter: parent.horizontalCenter
  203. padding: UM.Theme.getSize("default_margin").width
  204. spacing: UM.Theme.getSize("default_margin").width
  205. Cura.SecondaryButton
  206. {
  207. id: addPrinterButton
  208. leftPadding: UM.Theme.getSize("default_margin").width
  209. rightPadding: UM.Theme.getSize("default_margin").width
  210. text: catalog.i18nc("@button", "Add printer")
  211. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  212. // padding of the component and half the spacing because of the space between buttons.
  213. fixedWidthMode: true
  214. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  215. onClicked:
  216. {
  217. toggleContent()
  218. Cura.Actions.addMachine.trigger()
  219. }
  220. }
  221. Cura.SecondaryButton
  222. {
  223. id: managePrinterButton
  224. leftPadding: UM.Theme.getSize("default_margin").width
  225. rightPadding: UM.Theme.getSize("default_margin").width
  226. text: catalog.i18nc("@button", "Manage printers")
  227. fixedWidthMode: true
  228. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  229. // padding of the component and half the spacing because of the space between buttons.
  230. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  231. onClicked:
  232. {
  233. toggleContent()
  234. Cura.Actions.configureMachines.trigger()
  235. }
  236. }
  237. }
  238. }
  239. }