AddNetworkPrinterScrollView.qml 9.9 KB

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