AddNetworkOrLocalPrinterContent.qml 4.2 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.topMargin: UM.Theme.getSize("welcome_pages_default_margin").height
  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. }
  83. }
  84. }
  85. Cura.PrimaryButton
  86. {
  87. id: nextButton
  88. anchors.right: parent.right
  89. anchors.bottom: parent.bottom
  90. anchors.margins: UM.Theme.getSize("welcome_pages_default_margin").width
  91. enabled:
  92. {
  93. // If the network printer dropdown is expanded, make sure that there is a selected item
  94. if (addNetworkPrinterDropDown.contentShown)
  95. {
  96. return addNetworkPrinterDropDown.contentItem.currentItem != null
  97. }
  98. else
  99. {
  100. return addLocalPrinterDropDown.contentItem.currentItem != null
  101. }
  102. }
  103. text: catalog.i18nc("@button", "Next")
  104. width: 140
  105. fixedWidthMode: true
  106. onClicked:
  107. {
  108. // Create a network printer or a local printer according to the selection
  109. if (addNetworkPrinterDropDown.contentShown)
  110. {
  111. // Create a network printer
  112. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  113. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  114. }
  115. else
  116. {
  117. // Create a local printer
  118. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  119. Cura.MachineManager.addMachine(localPrinterItem.id)
  120. }
  121. // TODO: implement machine actions
  122. // If we have created a machine, go to the last page, which is the "cloud" page.
  123. base.goToPage("cloud")
  124. }
  125. }
  126. }