AddNetworkOrLocalPrinterContent.qml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 UM 1.3 as UM
  6. import Cura 1.1 as Cura
  7. //
  8. // This component contains the content for the "Add a printer" (network) page of the welcome on-boarding process.
  9. //
  10. Item
  11. {
  12. UM.I18nCatalog { id: catalog; name: "cura" }
  13. Label
  14. {
  15. id: titleLabel
  16. anchors.top: parent.top
  17. anchors.horizontalCenter: parent.horizontalCenter
  18. horizontalAlignment: Text.AlignHCenter
  19. text: catalog.i18nc("@label", "Add a printer")
  20. color: UM.Theme.getColor("primary_button")
  21. font: UM.Theme.getFont("huge")
  22. renderType: Text.NativeRendering
  23. }
  24. DropDownWidget
  25. {
  26. id: addNetworkPrinterDropDown
  27. anchors.top: titleLabel.bottom
  28. anchors.left: parent.left
  29. anchors.right: parent.right
  30. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  31. title: catalog.i18nc("@label", "Add a networked printer")
  32. contentShown: true // by default expand the network printer list
  33. onClicked:
  34. {
  35. addLocalPrinterDropDown.contentShown = !contentShown
  36. }
  37. contentComponent: networkPrinterListComponent
  38. Component
  39. {
  40. id: networkPrinterListComponent
  41. AddNetworkPrinterScrollView
  42. {
  43. id: networkPrinterScrollView
  44. maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll.
  45. onRefreshButtonClicked:
  46. {
  47. UM.OutputDeviceManager.startDiscovery()
  48. }
  49. onAddByIpButtonClicked:
  50. {
  51. base.goToPage("add_printer_by_ip")
  52. }
  53. onAddCloudPrinterButtonClicked:
  54. {
  55. base.goToPage("add_cloud_printers")
  56. if (!Cura.API.account.isLoggedIn)
  57. {
  58. Cura.API.account.login()
  59. }
  60. else
  61. {
  62. Qt.openUrlExternally("https://mycloud.ultimaker.com/")
  63. }
  64. }
  65. }
  66. }
  67. }
  68. DropDownWidget
  69. {
  70. id: addLocalPrinterDropDown
  71. anchors.top: addNetworkPrinterDropDown.bottom
  72. anchors.left: parent.left
  73. anchors.right: parent.right
  74. anchors.topMargin: UM.Theme.getSize("default_margin").height
  75. title: catalog.i18nc("@label", "Add a non-networked printer")
  76. onClicked:
  77. {
  78. addNetworkPrinterDropDown.contentShown = !contentShown
  79. }
  80. contentComponent: localPrinterListComponent
  81. Component
  82. {
  83. id: localPrinterListComponent
  84. AddLocalPrinterScrollView
  85. {
  86. id: localPrinterView
  87. property int childrenHeight: backButton.y - addLocalPrinterDropDown.y - UM.Theme.getSize("expandable_component_content_header").height - UM.Theme.getSize("default_margin").height
  88. onChildrenHeightChanged:
  89. {
  90. addLocalPrinterDropDown.children[1].height = childrenHeight
  91. }
  92. }
  93. }
  94. }
  95. // This "Back" button only shows in the "Add Machine" dialog, which has "previous_page_button_text" set to "Cancel"
  96. Cura.SecondaryButton
  97. {
  98. id: backButton
  99. anchors.left: parent.left
  100. anchors.bottom: parent.bottom
  101. visible: base.currentItem.previous_page_button_text ? true : false
  102. text: base.currentItem.previous_page_button_text ? base.currentItem.previous_page_button_text : ""
  103. onClicked:
  104. {
  105. base.endWizard()
  106. }
  107. }
  108. Cura.PrimaryButton
  109. {
  110. id: nextButton
  111. anchors.right: parent.right
  112. anchors.bottom: parent.bottom
  113. enabled:
  114. {
  115. // If the network printer dropdown is expanded, make sure that there is a selected item
  116. if (addNetworkPrinterDropDown.contentShown)
  117. {
  118. return addNetworkPrinterDropDown.contentItem.currentItem != null
  119. }
  120. else
  121. {
  122. // Printer name cannot be empty
  123. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  124. const isPrinterNameValid = addLocalPrinterDropDown.contentItem.isPrinterNameValid
  125. return localPrinterItem != null && isPrinterNameValid
  126. }
  127. }
  128. text: base.currentItem.next_page_button_text
  129. onClicked:
  130. {
  131. // Create a network printer or a local printer according to the selection
  132. if (addNetworkPrinterDropDown.contentShown)
  133. {
  134. // Create a network printer
  135. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  136. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  137. // If we have created a machine, end the wizard (since this is the last page)
  138. base.endWizard()
  139. }
  140. else
  141. {
  142. // Create a local printer
  143. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  144. const printerName = addLocalPrinterDropDown.contentItem.printerName
  145. if(Cura.MachineManager.addMachine(localPrinterItem.id, printerName))
  146. {
  147. base.showNextPage()
  148. }
  149. }
  150. }
  151. }
  152. }