MachineSelector.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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("printer_group")
  88. }
  89. else if (isNetworkPrinter || isCloudRegistered)
  90. {
  91. return UM.Theme.getIcon("printer_single")
  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. left: parent.left
  108. leftMargin: UM.Theme.getSize("thick_margin").width
  109. }
  110. source: UM.Theme.getIcon(connectionStatus)
  111. width: UM.Theme.getSize("printer_status_icon").width
  112. height: UM.Theme.getSize("printer_status_icon").height
  113. color: connectionStatus == "printer_cloud_not_available" ? UM.Theme.getColor("cloud_unavailable") : UM.Theme.getColor("primary")
  114. visible: isNetworkPrinter || isCloudRegistered
  115. // Make a themable circle in the background so we can change it in other themes
  116. Rectangle
  117. {
  118. id: iconBackground
  119. anchors.centerIn: parent
  120. // Make it a bit bigger so there is an outline
  121. width: parent.width + 2 * UM.Theme.getSize("default_lining").width
  122. height: parent.height + 2 * UM.Theme.getSize("default_lining").height
  123. radius: Math.round(width / 2)
  124. color: UM.Theme.getColor("main_background")
  125. z: parent.z - 1
  126. }
  127. }
  128. MouseArea // Connection status tooltip hover area
  129. {
  130. id: connectionStatusTooltipHoverArea
  131. anchors.fill: parent
  132. hoverEnabled: getConnectionStatusMessage() !== ""
  133. acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
  134. onEntered:
  135. {
  136. machineSelector.mouseArea.entered() // we want both this and the outer area to be entered
  137. tooltip.tooltipText = getConnectionStatusMessage()
  138. tooltip.show()
  139. }
  140. onExited: { tooltip.hide() }
  141. }
  142. Cura.ToolTip
  143. {
  144. id: tooltip
  145. width: 250 * screenScaleFactor
  146. tooltipText: getConnectionStatusMessage()
  147. arrowSize: UM.Theme.getSize("button_tooltip_arrow").width
  148. x: connectionStatusImage.x - UM.Theme.getSize("narrow_margin").width
  149. y: connectionStatusImage.y + connectionStatusImage.height + UM.Theme.getSize("narrow_margin").height
  150. z: popup.z + 1
  151. targetPoint: Qt.point(
  152. connectionStatusImage.x + Math.round(connectionStatusImage.width / 2),
  153. connectionStatusImage.y
  154. )
  155. }
  156. }
  157. contentItem: Item
  158. {
  159. id: popup
  160. width: UM.Theme.getSize("machine_selector_widget_content").width
  161. ScrollView
  162. {
  163. id: scroll
  164. width: parent.width
  165. clip: true
  166. leftPadding: UM.Theme.getSize("default_lining").width
  167. rightPadding: UM.Theme.getSize("default_lining").width
  168. MachineSelectorList
  169. {
  170. id: machineSelectorList
  171. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  172. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  173. property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
  174. // We use an extra property here, since we only want to to be informed about the content size changes.
  175. onContentHeightChanged:
  176. {
  177. scroll.height = Math.min(contentHeight, maximumHeight)
  178. popup.height = scroll.height + buttonRow.height
  179. }
  180. Component.onCompleted:
  181. {
  182. scroll.height = Math.min(contentHeight, maximumHeight)
  183. popup.height = scroll.height + buttonRow.height
  184. }
  185. }
  186. }
  187. Rectangle
  188. {
  189. id: separator
  190. anchors.top: scroll.bottom
  191. width: parent.width
  192. height: UM.Theme.getSize("default_lining").height
  193. color: UM.Theme.getColor("lining")
  194. }
  195. Row
  196. {
  197. id: buttonRow
  198. // The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
  199. anchors.top: separator.top
  200. anchors.horizontalCenter: parent.horizontalCenter
  201. padding: UM.Theme.getSize("default_margin").width
  202. spacing: UM.Theme.getSize("default_margin").width
  203. Cura.SecondaryButton
  204. {
  205. id: addPrinterButton
  206. leftPadding: UM.Theme.getSize("default_margin").width
  207. rightPadding: UM.Theme.getSize("default_margin").width
  208. text: catalog.i18nc("@button", "Add printer")
  209. // The maximum width of the button is half of the total space, minus the padding of the parent, the left
  210. // padding of the component and half the spacing because of the space between buttons.
  211. fixedWidthMode: true
  212. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  213. onClicked:
  214. {
  215. toggleContent()
  216. Cura.Actions.addMachine.trigger()
  217. }
  218. }
  219. Cura.SecondaryButton
  220. {
  221. id: managePrinterButton
  222. leftPadding: UM.Theme.getSize("default_margin").width
  223. rightPadding: UM.Theme.getSize("default_margin").width
  224. text: catalog.i18nc("@button", "Manage printers")
  225. fixedWidthMode: true
  226. // The maximum width of the button is half of the total space, minus the padding of the parent, the right
  227. // padding of the component and half the spacing because of the space between buttons.
  228. width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
  229. onClicked:
  230. {
  231. toggleContent()
  232. Cura.Actions.configureMachines.trigger()
  233. }
  234. }
  235. }
  236. }
  237. }