AddNetworkPrinterScrollView.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 is the widget for adding a network printer. There are 2 parts in this widget. One is a scroll view of a list
  9. // of discovered network printers. Beneath the scroll view is a container with 3 buttons: "Refresh", "Add by IP", and
  10. // "Troubleshooting".
  11. //
  12. Item
  13. {
  14. id: base
  15. height: networkPrinterInfo.height + controlsRectangle.height
  16. property alias maxItemCountAtOnce: networkPrinterListView.maxItemCountAtOnce
  17. property var currentItem: (networkPrinterListView.currentIndex >= 0)
  18. ? networkPrinterListView.model[networkPrinterListView.currentIndex]
  19. : null
  20. signal refreshButtonClicked()
  21. signal addByIpButtonClicked()
  22. signal addCloudPrinterButtonClicked()
  23. Item
  24. {
  25. id: networkPrinterInfo
  26. height: networkPrinterListView.visible ? networkPrinterListView.height : noPrinterLabel.height
  27. anchors.left: parent.left
  28. anchors.right: parent.right
  29. anchors.top: parent.top
  30. UM.Label
  31. {
  32. id: noPrinterLabel
  33. height: UM.Theme.getSize("setting_control").height + UM.Theme.getSize("default_margin").height
  34. anchors.left: parent.left
  35. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  36. text: catalog.i18nc("@label", "There is no printer found over your network.")
  37. visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
  38. }
  39. ListView
  40. {
  41. id: networkPrinterListView
  42. anchors.top: parent.top
  43. anchors.left: parent.left
  44. anchors.right: parent.right
  45. height: Math.min(contentHeight, (maxItemCountAtOnce * UM.Theme.getSize("action_button").height) - UM.Theme.getSize("default_margin").height)
  46. ScrollBar.vertical: UM.ScrollBar
  47. {
  48. id: networkPrinterScrollBar
  49. }
  50. clip: true
  51. property int maxItemCountAtOnce: 8 // show at max 8 items at once, otherwise you need to scroll.
  52. visible: networkPrinterListView.count > 0
  53. model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
  54. cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
  55. section.property: "modelData.sectionName"
  56. section.criteria: ViewSection.FullString
  57. section.delegate: UM.Label
  58. {
  59. anchors.left: parent.left
  60. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  61. width: parent.width - networkPrinterScrollBar.width - UM.Theme.getSize("default_margin").width
  62. height: UM.Theme.getSize("setting_control").height
  63. text: section
  64. color: UM.Theme.getColor("small_button_text")
  65. }
  66. Component.onCompleted:
  67. {
  68. var toSelectIndex = -1
  69. // Select the first one that's not "unknown" and is the host a group by default.
  70. for (var i = 0; i < count; i++)
  71. {
  72. if (!model[i].isUnknownMachineType && model[i].isHostOfGroup)
  73. {
  74. toSelectIndex = i
  75. break
  76. }
  77. }
  78. currentIndex = toSelectIndex
  79. }
  80. // CURA-6483 For some reason currentIndex can be reset to 0. This check is here to prevent automatically
  81. // selecting an unknown or non-host printer.
  82. onCurrentIndexChanged:
  83. {
  84. var item = model[currentIndex]
  85. if (!item || item.isUnknownMachineType || !item.isHostOfGroup)
  86. {
  87. currentIndex = -1
  88. }
  89. }
  90. delegate: Cura.MachineSelectorButton
  91. {
  92. text: modelData.device.name
  93. width: networkPrinterListView.width - networkPrinterScrollBar.width
  94. outputDevice: modelData.device
  95. enabled: !modelData.isUnknownMachineType && modelData.isHostOfGroup
  96. printerTypeLabelAutoFit: true
  97. // update printer types for all items in the list
  98. updatePrinterTypesOnlyWhenChecked: false
  99. updatePrinterTypesFunction: updateMachineTypes
  100. // show printer type as it is
  101. printerTypeLabelConversionFunction: function(value) { return value }
  102. function updateMachineTypes()
  103. {
  104. printerTypesList = [ modelData.readableMachineType ]
  105. }
  106. checkable: false
  107. selected: networkPrinterListView.currentIndex == model.index
  108. onClicked:
  109. {
  110. networkPrinterListView.currentIndex = index
  111. }
  112. }
  113. }
  114. }
  115. // Horizontal line separating the buttons (below) and the discovered network printers (above)
  116. Rectangle
  117. {
  118. id: separator
  119. anchors.left: parent.left
  120. anchors.top: networkPrinterInfo.bottom
  121. anchors.right: parent.right
  122. height: UM.Theme.getSize("default_lining").height
  123. color: UM.Theme.getColor("lining")
  124. }
  125. Item
  126. {
  127. id: controlsRectangle
  128. anchors.left: parent.left
  129. anchors.right: parent.right
  130. anchors.top: separator.bottom
  131. height: UM.Theme.getSize("message_action_button").height + UM.Theme.getSize("default_margin").height
  132. Cura.SecondaryButton
  133. {
  134. id: refreshButton
  135. anchors.left: parent.left
  136. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  137. anchors.verticalCenter: parent.verticalCenter
  138. text: catalog.i18nc("@label", "Refresh")
  139. height: UM.Theme.getSize("message_action_button").height
  140. onClicked: base.refreshButtonClicked()
  141. }
  142. Cura.SecondaryButton
  143. {
  144. id: addPrinterByIpButton
  145. anchors.left: refreshButton.right
  146. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  147. anchors.verticalCenter: parent.verticalCenter
  148. text: catalog.i18nc("@label", "Add printer by IP")
  149. height: UM.Theme.getSize("message_action_button").height
  150. onClicked: base.addByIpButtonClicked()
  151. }
  152. Cura.SecondaryButton
  153. {
  154. id: addCloudPrinterButton
  155. anchors.left: addPrinterByIpButton.right
  156. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  157. anchors.verticalCenter: parent.verticalCenter
  158. text: catalog.i18nc("@label", "Add cloud printer")
  159. height: UM.Theme.getSize("message_action_button").height
  160. onClicked: {
  161. CuraApplication.getDiscoveredCloudPrintersModel().clear()
  162. Cura.API.account.sync(true)
  163. base.addCloudPrinterButtonClicked()
  164. }
  165. }
  166. Item
  167. {
  168. id: troubleshootingButton
  169. anchors.right: parent.right
  170. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  171. anchors.verticalCenter: parent.verticalCenter
  172. height: troubleshootingLinkIcon.height
  173. width: troubleshootingLinkIcon.width + troubleshootingLabel.width + UM.Theme.getSize("thin_margin").width
  174. UM.ColorImage
  175. {
  176. id: troubleshootingLinkIcon
  177. anchors.right: troubleshootingLabel.left
  178. anchors.rightMargin: UM.Theme.getSize("thin_margin").width
  179. anchors.verticalCenter: parent.verticalCenter
  180. height: troubleshootingLabel.height
  181. width: height
  182. color: UM.Theme.getColor("text_link")
  183. source: UM.Theme.getIcon("LinkExternal")
  184. }
  185. UM.Label
  186. {
  187. id: troubleshootingLabel
  188. anchors.right: parent.right
  189. anchors.verticalCenter: parent.verticalCenter
  190. text: catalog.i18nc("@label", "Troubleshooting")
  191. font: UM.Theme.getFont("default")
  192. color: UM.Theme.getColor("text_link")
  193. }
  194. MouseArea
  195. {
  196. anchors.fill: parent
  197. hoverEnabled: true
  198. onClicked:
  199. {
  200. // open the troubleshooting URL with web browser
  201. const url = "https://ultimaker.com/in/cura/troubleshooting/network?utm_source=cura&utm_medium=software&utm_campaign=add-network-printer"
  202. Qt.openUrlExternally(url)
  203. }
  204. onEntered:
  205. {
  206. troubleshootingLabel.font.underline = true
  207. }
  208. onExited:
  209. {
  210. troubleshootingLabel.font.underline = false
  211. }
  212. }
  213. }
  214. }
  215. }