MachineSelector.qml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. 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.RecolorImage
  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. Cura.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. width: UM.Theme.getSize("machine_selector_widget_content").width
  175. ScrollView
  176. {
  177. id: scroll
  178. width: parent.width
  179. clip: true
  180. leftPadding: UM.Theme.getSize("default_lining").width
  181. rightPadding: UM.Theme.getSize("default_lining").width
  182. MachineSelectorList
  183. {
  184. id: machineSelectorList
  185. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  186. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  187. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  188. // We use an extra property here, since we only want to to be informed about the content size changes.
  189. onContentHeightChanged:
  190. {
  191. scroll.height = Math.min(contentHeight, maximumHeight)
  192. popup.height = scroll.height + buttonRow.height
  193. }
  194. Component.onCompleted:
  195. {
  196. scroll.height = Math.min(contentHeight, maximumHeight)
  197. popup.height = scroll.height + buttonRow.height
  198. }
  199. }
  200. }
  201. Rectangle
  202. {
  203. id: separator
  204. anchors.top: scroll.bottom
  205. width: parent.width
  206. height: UM.Theme.getSize("default_lining").height
  207. color: UM.Theme.getColor("lining")
  208. }
  209. Row
  210. {
  211. id: buttonRow
  212. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  213. anchors.top: separator.top
  214. anchors.horizontalCenter: parent.horizontalCenter
  215. padding: UM.Theme.getSize("default_margin").width
  216. spacing: UM.Theme.getSize("default_margin").width
  217. Cura.SecondaryButton
  218. {
  219. id: addPrinterButton
  220. leftPadding: UM.Theme.getSize("default_margin").width
  221. rightPadding: UM.Theme.getSize("default_margin").width
  222. text: catalog.i18nc("@button", "Add printer")
  223. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  224. // padding of the component and half the spacing because of the space between buttons.
  225. fixedWidthMode: true
  226. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  227. onClicked:
  228. {
  229. toggleContent()
  230. Cura.Actions.addMachine.trigger()
  231. }
  232. }
  233. Cura.SecondaryButton
  234. {
  235. id: managePrinterButton
  236. leftPadding: UM.Theme.getSize("default_margin").width
  237. rightPadding: UM.Theme.getSize("default_margin").width
  238. text: catalog.i18nc("@button", "Manage printers")
  239. fixedWidthMode: true
  240. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  241. // padding of the component and half the spacing because of the space between buttons.
  242. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  243. onClicked:
  244. {
  245. toggleContent()
  246. Cura.Actions.configureMachines.trigger()
  247. }
  248. }
  249. }
  250. }
  251. }