AddNetworkPrinterScrollView.qml 9.2 KB

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