AddNetworkOrLocalPrinterContent.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. if (contentShown)
  36. {
  37. addLocalPrinterDropDown.contentShown = false
  38. }
  39. }
  40. contentComponent: networkPrinterListComponent
  41. Component
  42. {
  43. id: networkPrinterListComponent
  44. AddNetworkPrinterScrollView
  45. {
  46. id: networkPrinterScrollView
  47. maxItemCountAtOnce: 6 // show at max 6 items at once, otherwise you need to scroll.
  48. onRefreshButtonClicked:
  49. {
  50. UM.OutputDeviceManager.startDiscovery()
  51. }
  52. onAddByIpButtonClicked:
  53. {
  54. base.goToPage("add_printer_by_ip")
  55. }
  56. }
  57. }
  58. }
  59. DropDownWidget
  60. {
  61. id: addLocalPrinterDropDown
  62. anchors.top: addNetworkPrinterDropDown.bottom
  63. anchors.left: parent.left
  64. anchors.right: parent.right
  65. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  66. title: catalog.i18nc("@label", "Add a non-networked printer")
  67. onClicked:
  68. {
  69. if (contentShown)
  70. {
  71. addNetworkPrinterDropDown.contentShown = false
  72. }
  73. }
  74. contentComponent: localPrinterListComponent
  75. Component
  76. {
  77. id: localPrinterListComponent
  78. AddLocalPrinterScrollView
  79. {
  80. id: localPrinterView
  81. }
  82. }
  83. }
  84. Cura.PrimaryButton
  85. {
  86. id: nextButton
  87. anchors.right: parent.right
  88. anchors.bottom: parent.bottom
  89. enabled:
  90. {
  91. // If the network printer dropdown is expanded, make sure that there is a selected item
  92. if (addNetworkPrinterDropDown.contentShown)
  93. {
  94. return addNetworkPrinterDropDown.contentItem.currentItem != null
  95. }
  96. else
  97. {
  98. // Printer name cannot be empty
  99. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  100. const isPrinterNameValid = addLocalPrinterDropDown.contentItem.isPrinterNameValid
  101. return localPrinterItem != null && isPrinterNameValid
  102. }
  103. }
  104. text: base.currentItem.next_page_button_text
  105. onClicked:
  106. {
  107. // Create a network printer or a local printer according to the selection
  108. if (addNetworkPrinterDropDown.contentShown)
  109. {
  110. // Create a network printer
  111. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  112. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  113. // If we have created a machine, go to the last page, which is the "cloud" page.
  114. base.goToPage("cloud")
  115. }
  116. else
  117. {
  118. // Create a local printer
  119. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  120. const printerName = addLocalPrinterDropDown.contentItem.printerName
  121. Cura.MachineManager.addMachine(localPrinterItem.id, printerName)
  122. base.showNextPage()
  123. }
  124. }
  125. }
  126. }