AddNetworkOrLocalPrinterContent.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.topMargin: 40
  18. anchors.horizontalCenter: parent.horizontalCenter
  19. horizontalAlignment: Text.AlignHCenter
  20. text: catalog.i18nc("@label", "Add a printer")
  21. color: UM.Theme.getColor("primary_button")
  22. font: UM.Theme.getFont("large_bold")
  23. renderType: Text.NativeRendering
  24. }
  25. DropDownWidget
  26. {
  27. id: addNetworkPrinterDropDown
  28. anchors.top: titleLabel.bottom
  29. anchors.left: parent.left
  30. anchors.right: parent.right
  31. anchors.margins: 20
  32. title: catalog.i18nc("@label", "Add a networked printer")
  33. contentShown: true // by default expand the network printer list
  34. onClicked:
  35. {
  36. if (contentShown)
  37. {
  38. addLocalPrinterDropDown.contentShown = false
  39. }
  40. }
  41. contentComponent: networkPrinterListComponent
  42. Component
  43. {
  44. id: networkPrinterListComponent
  45. AddNetworkPrinterScrollView
  46. {
  47. id: networkPrinterScrollView
  48. maxItemCountAtOnce: 6 // show at max 6 items at once, otherwise you need to scroll.
  49. onRefreshButtonClicked:
  50. {
  51. UM.OutputDeviceManager.startDiscovery()
  52. }
  53. onAddByIpButtonClicked:
  54. {
  55. base.goToPage("add_printer_by_ip")
  56. }
  57. }
  58. }
  59. }
  60. DropDownWidget
  61. {
  62. id: addLocalPrinterDropDown
  63. anchors.top: addNetworkPrinterDropDown.bottom
  64. anchors.left: parent.left
  65. anchors.right: parent.right
  66. anchors.margins: 20
  67. title: catalog.i18nc("@label", "Add a non-networked printer")
  68. onClicked:
  69. {
  70. if (contentShown)
  71. {
  72. addNetworkPrinterDropDown.contentShown = false
  73. }
  74. }
  75. contentComponent: localPrinterListComponent
  76. Component
  77. {
  78. id: localPrinterListComponent
  79. AddLocalPrinterScrollView
  80. {
  81. id: localPrinterView
  82. maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll.
  83. }
  84. }
  85. }
  86. Cura.PrimaryButton
  87. {
  88. id: nextButton
  89. anchors.right: parent.right
  90. anchors.bottom: parent.bottom
  91. anchors.margins: 40
  92. enabled:
  93. {
  94. // If the network printer dropdown is expanded, make sure that there is a selected item
  95. if (addNetworkPrinterDropDown.contentShown)
  96. {
  97. return addNetworkPrinterDropDown.contentItem.currentItem != null
  98. }
  99. else
  100. {
  101. return addLocalPrinterDropDown.contentItem.currentItem != null
  102. }
  103. }
  104. text: catalog.i18nc("@button", "Next")
  105. width: UM.Theme.getSize("welcome_pages_button").width
  106. fixedWidthMode: true
  107. onClicked:
  108. {
  109. // Create a network printer or a local printer according to the selection
  110. if (addNetworkPrinterDropDown.contentShown)
  111. {
  112. // Create a network printer
  113. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  114. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  115. // If we have created a machine, go to the last page, which is the "cloud" page.
  116. base.goToPage("cloud")
  117. }
  118. else
  119. {
  120. // Create a local printer
  121. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  122. Cura.MachineManager.addMachine(localPrinterItem.id)
  123. base.goToPage("machine_actions")
  124. }
  125. }
  126. }
  127. }