AddNetworkPrinterScrollView.qml 9.1 KB

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