AddNetworkPrinterScrollView.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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: 0 // Workaround for https://bugreports.qt.io/browse/QTBUG-49224
  61. Component.onCompleted:
  62. {
  63. // Select the first one that's not "unknown" by default.
  64. for (var i = 0; i < count; i++)
  65. {
  66. if (!model[i].isUnknownMachineType)
  67. {
  68. currentIndex = i
  69. break
  70. }
  71. }
  72. }
  73. Component
  74. {
  75. id: sectionHeading
  76. Label
  77. {
  78. anchors.left: parent.left
  79. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  80. height: UM.Theme.getSize("setting_control").height
  81. text: section
  82. font: UM.Theme.getFont("default")
  83. color: UM.Theme.getColor("small_button_text")
  84. verticalAlignment: Text.AlignVCenter
  85. renderType: Text.NativeRendering
  86. }
  87. }
  88. delegate: Cura.MachineSelectorButton
  89. {
  90. text: modelData.device.name
  91. width: networkPrinterListView.width
  92. outputDevice: modelData.device
  93. enabled: !modelData.isUnknownMachineType && modelData.isHostOfGroup
  94. printerTypeLabelAutoFit: true
  95. // update printer types for all items in the list
  96. updatePrinterTypesOnlyWhenChecked: false
  97. updatePrinterTypesFunction: updateMachineTypes
  98. // show printer type as it is
  99. printerTypeLabelConversionFunction: function(value) { return value }
  100. function updateMachineTypes()
  101. {
  102. printerTypesList = [ modelData.readableMachineType ]
  103. }
  104. checkable: false
  105. selected: ListView.view.currentIndex == model.index
  106. onClicked:
  107. {
  108. ListView.view.currentIndex = index
  109. }
  110. }
  111. }
  112. }
  113. }
  114. // Horizontal line separating the buttons (below) and the discovered network printers (above)
  115. Rectangle
  116. {
  117. id: separator
  118. anchors.left: parent.left
  119. anchors.top: networkPrinterInfo.bottom
  120. anchors.right: parent.right
  121. height: UM.Theme.getSize("default_lining").height
  122. color: UM.Theme.getColor("lining")
  123. }
  124. Item
  125. {
  126. id: controlsRectangle
  127. anchors.left: parent.left
  128. anchors.right: parent.right
  129. anchors.top: separator.bottom
  130. height: UM.Theme.getSize("message_action_button").height + UM.Theme.getSize("default_margin").height
  131. Cura.SecondaryButton
  132. {
  133. id: refreshButton
  134. anchors.left: parent.left
  135. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  136. anchors.verticalCenter: parent.verticalCenter
  137. text: catalog.i18nc("@label", "Refresh")
  138. height: UM.Theme.getSize("message_action_button").height
  139. onClicked: base.refreshButtonClicked()
  140. }
  141. Cura.SecondaryButton
  142. {
  143. id: addPrinterByIpButton
  144. anchors.left: refreshButton.right
  145. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  146. anchors.verticalCenter: parent.verticalCenter
  147. text: catalog.i18nc("@label", "Add printer by IP")
  148. height: UM.Theme.getSize("message_action_button").height
  149. onClicked: base.addByIpButtonClicked()
  150. }
  151. Item
  152. {
  153. id: troubleshootingButton
  154. anchors.right: parent.right
  155. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  156. anchors.verticalCenter: parent.verticalCenter
  157. height: troubleshootingLinkIcon.height
  158. width: troubleshootingLinkIcon.width + troubleshootingLabel.width + UM.Theme.getSize("default_margin").width
  159. UM.RecolorImage
  160. {
  161. id: troubleshootingLinkIcon
  162. anchors.right: troubleshootingLabel.left
  163. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  164. anchors.verticalCenter: parent.verticalCenter
  165. height: troubleshootingLabel.height
  166. width: height
  167. sourceSize.height: width
  168. color: UM.Theme.getColor("text_link")
  169. source: UM.Theme.getIcon("external_link")
  170. }
  171. Label
  172. {
  173. id: troubleshootingLabel
  174. anchors.right: parent.right
  175. anchors.verticalCenter: parent.verticalCenter
  176. text: catalog.i18nc("@label", "Troubleshooting")
  177. font: UM.Theme.getFont("default")
  178. color: UM.Theme.getColor("text_link")
  179. linkColor: UM.Theme.getColor("text_link")
  180. renderType: Text.NativeRendering
  181. }
  182. MouseArea
  183. {
  184. anchors.fill: parent
  185. hoverEnabled: true
  186. onClicked:
  187. {
  188. // open the troubleshooting URL with web browser
  189. const url = "https://ultimaker.com/in/cura/troubleshooting/network"
  190. Qt.openUrlExternally(url)
  191. }
  192. onEntered:
  193. {
  194. troubleshootingLabel.font.underline = true
  195. }
  196. onExited:
  197. {
  198. troubleshootingLabel.font.underline = false
  199. }
  200. }
  201. }
  202. }
  203. }