AddNetworkPrinterScrollView.qml 7.9 KB

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