AddNetworkOrLocalPrinterContent.qml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright (c) 2022 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.5 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. UM.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. }
  23. DropDownWidget
  24. {
  25. id: addNetworkPrinterDropDown
  26. anchors.top: titleLabel.bottom
  27. anchors.left: parent.left
  28. anchors.right: parent.right
  29. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  30. title: catalog.i18nc("@label", "Add a networked printer")
  31. contentShown: true // by default expand the network printer list
  32. onClicked:
  33. {
  34. addLocalPrinterDropDown.contentShown = !contentShown
  35. }
  36. contentComponent: networkPrinterListComponent
  37. Component
  38. {
  39. id: networkPrinterListComponent
  40. AddNetworkPrinterScrollView
  41. {
  42. id: networkPrinterScrollView
  43. maxItemCountAtOnce: 9 // show at max 9 items at once, otherwise you need to scroll.
  44. onRefreshButtonClicked:
  45. {
  46. UM.OutputDeviceManager.startDiscovery()
  47. }
  48. onAddByIpButtonClicked:
  49. {
  50. base.goToPage("add_printer_by_ip")
  51. }
  52. onAddCloudPrinterButtonClicked:
  53. {
  54. base.goToPage("add_cloud_printers")
  55. if (!Cura.API.account.isLoggedIn)
  56. {
  57. Cura.API.account.login()
  58. }
  59. }
  60. }
  61. }
  62. }
  63. DropDownWidget
  64. {
  65. id: addLocalPrinterDropDown
  66. anchors.top: addNetworkPrinterDropDown.bottom
  67. anchors.left: parent.left
  68. anchors.right: parent.right
  69. anchors.topMargin: UM.Theme.getSize("default_margin").height
  70. title: catalog.i18nc("@label", "Add a non-networked printer")
  71. onClicked:
  72. {
  73. addNetworkPrinterDropDown.contentShown = !contentShown
  74. }
  75. contentComponent: localPrinterListComponent
  76. Component
  77. {
  78. id: localPrinterListComponent
  79. AddLocalPrinterScrollView
  80. {
  81. id: localPrinterView
  82. height: backButton.y - addLocalPrinterDropDown.y - UM.Theme.getSize("expandable_component_content_header").height - UM.Theme.getSize("default_margin").height
  83. }
  84. }
  85. }
  86. // This "Back" button only shows in the "Add Machine" dialog, which has "previous_page_button_text" set to "Cancel"
  87. Cura.SecondaryButton
  88. {
  89. id: backButton
  90. anchors.left: parent.left
  91. anchors.bottom: parent.bottom
  92. visible: base.currentItem.previous_page_button_text ? true : false
  93. text: base.currentItem.previous_page_button_text ? base.currentItem.previous_page_button_text : ""
  94. onClicked:
  95. {
  96. base.endWizard()
  97. }
  98. }
  99. Cura.PrimaryButton
  100. {
  101. id: nextButton
  102. anchors.right: parent.right
  103. anchors.bottom: parent.bottom
  104. enabled:
  105. {
  106. // If the network printer dropdown is expanded, make sure that there is a selected item
  107. if (addNetworkPrinterDropDown.contentShown)
  108. {
  109. return addNetworkPrinterDropDown.contentItem.currentItem != null
  110. }
  111. else
  112. {
  113. // Printer name cannot be empty
  114. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  115. const isPrinterNameValid = addLocalPrinterDropDown.contentItem.isPrinterNameValid
  116. return localPrinterItem != null && isPrinterNameValid
  117. }
  118. }
  119. text: base.currentItem.next_page_button_text
  120. onClicked:
  121. {
  122. // Create a network printer or a local printer according to the selection
  123. if (addNetworkPrinterDropDown.contentShown)
  124. {
  125. // Create a network printer
  126. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  127. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  128. // After the networked machine has been created, go to the next page
  129. base.showNextPage()
  130. }
  131. else
  132. {
  133. // Create a local printer
  134. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  135. const printerName = addLocalPrinterDropDown.contentItem.printerName
  136. if(Cura.MachineManager.addMachine(localPrinterItem.id, printerName))
  137. {
  138. base.showNextPage()
  139. }
  140. }
  141. }
  142. }
  143. }