AddCloudPrintersView.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Layouts 1.3
  6. import UM 1.3 as UM
  7. import Cura 1.7 as Cura
  8. //
  9. // This component gets activated when the user presses the "Add cloud printers" button from the "Add a Printer" page.
  10. // It contains a busy indicator that remains active until the user logs in and adds a cloud printer in his/her account.
  11. // Once a cloud printer is added in mycloud.ultimaker.com, Cura discovers it (in a time window of 30 sec) and displays
  12. // the newly added printers in this page.
  13. //
  14. Item
  15. {
  16. UM.I18nCatalog { id: catalog; name: "cura" }
  17. property bool searchingForCloudPrinters: true
  18. property var discoveredCloudPrintersModel: CuraApplication.getDiscoveredCloudPrintersModel()
  19. // The area where either the discoveredCloudPrintersScrollView or the busyIndicator will be displayed
  20. Item
  21. {
  22. id: cloudPrintersContent
  23. width: parent.width
  24. height: parent.height
  25. anchors
  26. {
  27. top: parent.top
  28. left: parent.left
  29. leftMargin: UM.Theme.getSize("default_margin").width
  30. right: parent.right
  31. bottom: finishButton.top
  32. bottomMargin: UM.Theme.getSize("default_margin").height
  33. }
  34. Label
  35. {
  36. id: titleLabel
  37. anchors.top: parent.top
  38. anchors.horizontalCenter: parent.horizontalCenter
  39. horizontalAlignment: Text.AlignHCenter
  40. text: catalog.i18nc("@label", "Add a Cloud printer")
  41. color: UM.Theme.getColor("primary_button")
  42. font: UM.Theme.getFont("huge")
  43. renderType: Text.NativeRendering
  44. }
  45. // Component that contains a busy indicator and a message, while it waits for Cura to discover a cloud printer
  46. Item
  47. {
  48. id: waitingContent
  49. width: parent.width
  50. height: childrenRect.height
  51. anchors.verticalCenter: parent.verticalCenter
  52. anchors.horizontalCenter: parent.horizontalCenter
  53. BusyIndicator
  54. {
  55. id: waitingIndicator
  56. anchors.horizontalCenter: parent.horizontalCenter
  57. running: searchingForCloudPrinters
  58. palette.dark: UM.Theme.getColor("text")
  59. }
  60. Label
  61. {
  62. id: waitingLabel
  63. anchors.top: waitingIndicator.bottom
  64. anchors.horizontalCenter: parent.horizontalCenter
  65. horizontalAlignment: Text.AlignHCenter
  66. text: catalog.i18nc("@label", "Waiting for Cloud response")
  67. font: UM.Theme.getFont("large")
  68. renderType: Text.NativeRendering
  69. color: UM.Theme.getColor("text")
  70. }
  71. Label
  72. {
  73. id: noPrintersFoundLabel
  74. anchors.top: waitingLabel.bottom
  75. anchors.topMargin: 2 * UM.Theme.getSize("wide_margin").height
  76. anchors.horizontalCenter: parent.horizontalCenter
  77. horizontalAlignment: Text.AlignHCenter
  78. text: catalog.i18nc("@label", "No printers found in your account?")
  79. font: UM.Theme.getFont("medium")
  80. color: UM.Theme.getColor("text")
  81. }
  82. Label
  83. {
  84. text: "Sign in with a different account"
  85. anchors.top: noPrintersFoundLabel.bottom
  86. anchors.horizontalCenter: parent.horizontalCenter
  87. font: UM.Theme.getFont("medium")
  88. color: UM.Theme.getColor("text_link")
  89. MouseArea {
  90. anchors.fill: parent;
  91. onClicked: Cura.API.account.login(true)
  92. hoverEnabled: true
  93. onEntered:
  94. {
  95. parent.font.underline = true
  96. }
  97. onExited:
  98. {
  99. parent.font.underline = false
  100. }
  101. }
  102. }
  103. visible: discoveredCloudPrintersModel.count == 0
  104. }
  105. // Label displayed when a new cloud printer is discovered
  106. Label
  107. {
  108. anchors.top: titleLabel.bottom
  109. anchors.topMargin: 2 * UM.Theme.getSize("default_margin").height
  110. id: cloudPrintersAddedTitle
  111. font: UM.Theme.getFont("medium")
  112. text: catalog.i18nc("@label", "The following printers in your account have been added in Cura:")
  113. height: contentHeight + 2 * UM.Theme.getSize("default_margin").height
  114. visible: discoveredCloudPrintersModel.count > 0
  115. color: UM.Theme.getColor("text")
  116. }
  117. // The scrollView that contains the list of newly discovered Ultimaker Cloud printers. Visible only when
  118. // there is at least a new cloud printer.
  119. ScrollView
  120. {
  121. id: discoveredCloudPrintersScrollView
  122. width: parent.width
  123. clip : true
  124. ScrollBar.horizontal.policy: ScrollBar.AsNeeded
  125. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  126. visible: discoveredCloudPrintersModel.count > 0
  127. anchors
  128. {
  129. top: cloudPrintersAddedTitle.bottom
  130. topMargin: UM.Theme.getSize("default_margin").height
  131. left: parent.left
  132. leftMargin: UM.Theme.getSize("default_margin").width
  133. right: parent.right
  134. bottom: parent.bottom
  135. }
  136. Column
  137. {
  138. id: discoveredPrintersColumn
  139. spacing: 2 * UM.Theme.getSize("default_margin").height
  140. Repeater
  141. {
  142. id: discoveredCloudPrintersRepeater
  143. model: discoveredCloudPrintersModel
  144. delegate: Item
  145. {
  146. width: discoveredCloudPrintersScrollView.width
  147. height: contentColumn.height
  148. Column
  149. {
  150. id: contentColumn
  151. Label
  152. {
  153. id: cloudPrinterNameLabel
  154. leftPadding: UM.Theme.getSize("default_margin").width
  155. text: model.name
  156. font: UM.Theme.getFont("large_bold")
  157. color: UM.Theme.getColor("text")
  158. elide: Text.ElideRight
  159. }
  160. Label
  161. {
  162. id: cloudPrinterTypeLabel
  163. leftPadding: 2 * UM.Theme.getSize("default_margin").width
  164. topPadding: UM.Theme.getSize("thin_margin").height
  165. text: {"Type: " + model.machine_type}
  166. font: UM.Theme.getFont("medium")
  167. color: UM.Theme.getColor("text")
  168. elide: Text.ElideRight
  169. }
  170. Label
  171. {
  172. id: cloudPrinterFirmwareVersionLabel
  173. leftPadding: 2 * UM.Theme.getSize("default_margin").width
  174. text: {"Firmware version: " + model.firmware_version}
  175. font: UM.Theme.getFont("medium")
  176. color: UM.Theme.getColor("text")
  177. elide: Text.ElideRight
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. Cura.SecondaryButton
  186. {
  187. id: backButton
  188. anchors.left: parent.left
  189. anchors.bottom: parent.bottom
  190. text: catalog.i18nc("@button", "Add printer manually")
  191. onClicked:
  192. {
  193. discoveredCloudPrintersModel.clear()
  194. base.showPreviousPage()
  195. }
  196. visible: discoveredCloudPrintersModel.count == 0
  197. }
  198. Cura.PrimaryButton
  199. {
  200. id: finishButton
  201. anchors.right: parent.right
  202. anchors.bottom: parent.bottom
  203. text: catalog.i18nc("@button", "Finish")
  204. onClicked:
  205. {
  206. discoveredCloudPrintersModel.clear()
  207. base.showNextPage()
  208. }
  209. enabled: !waitingContent.visible
  210. }
  211. }