AddNetworkPrinterScrollView.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. import "../PrinterSelector"
  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. height: networkPrinterInfo.height + controlsRectangle.height
  17. property alias maxItemCountAtOnce: networkPrinterScrollView.maxItemCountAtOnce
  18. property var currentItem: (networkPrinterListView.currentIndex >= 0)
  19. ? networkPrinterListView.model[networkPrinterListView.currentIndex]
  20. : null
  21. signal refreshButtonClicked()
  22. signal addByIpButtonClicked()
  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: maxItemCountAtOnce * UM.Theme.getSize("action_button").height
  51. visible: networkPrinterListView.count > 0
  52. clip: true
  53. ListView
  54. {
  55. id: networkPrinterListView
  56. anchors.fill: parent
  57. model: CuraApplication.getDiscoveredPrintersModel().discovered_printers
  58. Component.onCompleted:
  59. {
  60. // Select the first one that's not "unknown" by default.
  61. for (var i = 0; i < count; i++)
  62. {
  63. if (!model[i].is_unknown_machine_type)
  64. {
  65. currentIndex = i
  66. break
  67. }
  68. }
  69. }
  70. delegate: MachineSelectorButton
  71. {
  72. text: modelData.device.name
  73. anchors.left: parent.left
  74. anchors.right: parent.right
  75. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  76. outputDevice: modelData.device
  77. enabled: !modelData.is_unknown_machine_type
  78. printerTypeLabelAutoFit: true
  79. updatePrinterTypesFunction: updateMachineTypes
  80. // show printer type as it is
  81. printerTypeLabelConversionFunction: function(value) { return value }
  82. function updateMachineTypes()
  83. {
  84. printerTypesList = [ modelData.readable_machine_type ]
  85. }
  86. checkable: false
  87. selected: ListView.view.currentIndex == model.index
  88. onClicked:
  89. {
  90. ListView.view.currentIndex = index
  91. }
  92. }
  93. }
  94. }
  95. }
  96. Item
  97. {
  98. id: controlsRectangle
  99. anchors.left: parent.left
  100. anchors.right: parent.right
  101. anchors.top: networkPrinterInfo.bottom
  102. // Horizontal line separating the buttons (below) and the discovered network printers (above)
  103. Rectangle
  104. {
  105. anchors.left: parent.left
  106. anchors.top: parent.top
  107. anchors.right: parent.right
  108. height: UM.Theme.getSize("default_lining").width
  109. color: UM.Theme.getColor("lining")
  110. }
  111. height: UM.Theme.getSize("message_action_button").height + UM.Theme.getSize("default_margin").height
  112. Cura.SecondaryButton
  113. {
  114. id: refreshButton
  115. anchors.left: parent.left
  116. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  117. anchors.verticalCenter: parent.verticalCenter
  118. text: catalog.i18nc("@label", "Refresh")
  119. height: UM.Theme.getSize("message_action_button").height
  120. onClicked: base.refreshButtonClicked()
  121. }
  122. Cura.SecondaryButton
  123. {
  124. id: addPrinterByIpButton
  125. anchors.left: refreshButton.right
  126. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  127. anchors.verticalCenter: parent.verticalCenter
  128. text: catalog.i18nc("@label", "Add printer by IP")
  129. height: UM.Theme.getSize("message_action_button").height
  130. onClicked: base.addByIpButtonClicked()
  131. }
  132. Item
  133. {
  134. id: troubleshootingButton
  135. anchors.right: parent.right
  136. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  137. anchors.verticalCenter: parent.verticalCenter
  138. height: troubleshootingLinkIcon.height
  139. width: troubleshootingLinkIcon.width + troubleshootingLabel.width + UM.Theme.getSize("default_margin").width
  140. UM.RecolorImage
  141. {
  142. id: troubleshootingLinkIcon
  143. anchors.right: troubleshootingLabel.left
  144. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  145. anchors.verticalCenter: parent.verticalCenter
  146. height: troubleshootingLabel.height
  147. width: height
  148. sourceSize.height: width
  149. color: UM.Theme.getColor("text_link")
  150. source: UM.Theme.getIcon("external_link")
  151. }
  152. Label
  153. {
  154. id: troubleshootingLabel
  155. anchors.right: parent.right
  156. anchors.verticalCenter: parent.verticalCenter
  157. text: catalog.i18nc("@label", "Troubleshooting")
  158. font: UM.Theme.getFont("default")
  159. color: UM.Theme.getColor("text_link")
  160. linkColor: UM.Theme.getColor("text_link")
  161. renderType: Text.NativeRendering
  162. }
  163. MouseArea
  164. {
  165. anchors.fill: parent
  166. hoverEnabled: true
  167. onClicked:
  168. {
  169. // open the troubleshooting URL with web browser
  170. var url = "https://ultimaker.com/incoming-links/cura/material-compatibilty" // TODO
  171. Qt.openUrlExternally(url)
  172. }
  173. onEntered:
  174. {
  175. troubleshootingLabel.font.underline = true
  176. }
  177. onExited:
  178. {
  179. troubleshootingLabel.font.underline = false
  180. }
  181. }
  182. }
  183. }
  184. }