AddLocalPrinterScrollView.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 scroll view widget for adding a (local) printer. This scroll view shows a list view with printers
  9. // categorized into 3 categories: "Ultimaker", "Custom", and "Other".
  10. //
  11. Item
  12. {
  13. id: base
  14. // The currently selected machine item in the local machine list.
  15. property var currentItem: (machineList.currentIndex >= 0)
  16. ? machineList.model.getItem(machineList.currentIndex)
  17. : null
  18. // The currently active (expanded) section/category, where section/category is the grouping of local machine items.
  19. property string currentSection: "Ultimaker B.V."
  20. // By default (when this list shows up) we always expand the "Ultimaker" section.
  21. property var preferredCategories: {
  22. "Ultimaker B.V.": -2,
  23. "Custom": -1
  24. }
  25. // User-editable printer name
  26. property alias printerName: printerNameTextField.text
  27. property alias isPrinterNameValid: printerNameTextField.acceptableInput
  28. onCurrentItemChanged:
  29. {
  30. printerName = currentItem == null ? "" : currentItem.name
  31. }
  32. function updateCurrentItemUponSectionChange()
  33. {
  34. // Find the first machine from this section
  35. for (var i = 0; i < machineList.count; i++)
  36. {
  37. var item = machineList.model.getItem(i)
  38. if (item.section == base.currentSection)
  39. {
  40. machineList.currentIndex = i
  41. break
  42. }
  43. }
  44. }
  45. function getMachineName()
  46. {
  47. return machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).name : "";
  48. }
  49. function getMachineMetaDataEntry(key)
  50. {
  51. var metadata = machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).metadata : undefined;
  52. if (metadata)
  53. {
  54. return metadata[key];
  55. }
  56. return undefined;
  57. }
  58. Component.onCompleted:
  59. {
  60. updateCurrentItemUponSectionChange()
  61. }
  62. Row
  63. {
  64. id: localPrinterSelectionItem
  65. anchors.left: parent.left
  66. anchors.right: parent.right
  67. anchors.top: parent.top
  68. // ScrollView + ListView for selecting a local printer to add
  69. Cura.ScrollView
  70. {
  71. id: scrollView
  72. height: childrenHeight
  73. width: Math.floor(parent.width * 0.48)
  74. ListView
  75. {
  76. id: machineList
  77. // CURA-6793
  78. // Enabling the buffer seems to cause the blank items issue. When buffer is enabled, if the ListView's
  79. // individual item has a dynamic change on its visibility, the ListView doesn't redraw itself.
  80. // The default value of cacheBuffer is platform-dependent, so we explicitly disable it here.
  81. cacheBuffer: 0
  82. boundsBehavior: Flickable.StopAtBounds
  83. flickDeceleration: 20000 // To prevent the flicking behavior.
  84. model: UM.DefinitionContainersModel
  85. {
  86. id: machineDefinitionsModel
  87. filter: { "visible": true }
  88. sectionProperty: "manufacturer"
  89. preferredSections: preferredCategories
  90. }
  91. section.property: "section"
  92. section.delegate: sectionHeader
  93. delegate: machineButton
  94. }
  95. Component
  96. {
  97. id: sectionHeader
  98. Button
  99. {
  100. id: button
  101. width: ListView.view.width
  102. height: UM.Theme.getSize("action_button").height
  103. text: section
  104. property bool isActive: base.currentSection == section
  105. background: Rectangle
  106. {
  107. anchors.fill: parent
  108. color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  109. }
  110. contentItem: Item
  111. {
  112. width: childrenRect.width
  113. height: UM.Theme.getSize("action_button").height
  114. UM.RecolorImage
  115. {
  116. id: arrow
  117. anchors.left: parent.left
  118. width: UM.Theme.getSize("standard_arrow").width
  119. height: UM.Theme.getSize("standard_arrow").height
  120. sourceSize.width: width
  121. sourceSize.height: height
  122. color: UM.Theme.getColor("text")
  123. source: base.currentSection == section ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
  124. }
  125. Label
  126. {
  127. id: label
  128. anchors.left: arrow.right
  129. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  130. verticalAlignment: Text.AlignVCenter
  131. text: button.text
  132. font: UM.Theme.getFont("default_bold")
  133. color: UM.Theme.getColor("text")
  134. renderType: Text.NativeRendering
  135. }
  136. }
  137. onClicked:
  138. {
  139. base.currentSection = section
  140. base.updateCurrentItemUponSectionChange()
  141. }
  142. }
  143. }
  144. Component
  145. {
  146. id: machineButton
  147. Cura.RadioButton
  148. {
  149. id: radioButton
  150. anchors
  151. {
  152. left: parent !== null ? parent.left: undefined
  153. leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  154. right: parent !== null ? parent.right: undefined
  155. rightMargin: UM.Theme.getSize("default_margin").width
  156. }
  157. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
  158. checked: ListView.view.currentIndex == index
  159. text: name
  160. visible: base.currentSection == section
  161. onClicked: ListView.view.currentIndex = index
  162. }
  163. }
  164. }
  165. // Vertical line
  166. Rectangle
  167. {
  168. id: verticalLine
  169. anchors.top: parent.top
  170. height: childrenHeight - UM.Theme.getSize("default_lining").height
  171. width: UM.Theme.getSize("default_lining").height
  172. color: UM.Theme.getColor("lining")
  173. }
  174. // User-editable printer name row
  175. Column
  176. {
  177. width: Math.floor(parent.width * 0.52)
  178. spacing: UM.Theme.getSize("default_margin").width
  179. padding: UM.Theme.getSize("default_margin").width
  180. Label
  181. {
  182. width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
  183. wrapMode: Text.Wrap
  184. text: base.getMachineName()
  185. color: UM.Theme.getColor("primary_button")
  186. font: UM.Theme.getFont("huge")
  187. elide: Text.ElideRight
  188. }
  189. Grid
  190. {
  191. width: parent.width
  192. columns: 2
  193. rowSpacing: UM.Theme.getSize("default_lining").height
  194. columnSpacing: UM.Theme.getSize("default_margin").width
  195. verticalItemAlignment: Grid.AlignVCenter
  196. Label
  197. {
  198. id: manufacturerLabel
  199. text: catalog.i18nc("@label", "Manufacturer")
  200. font: UM.Theme.getFont("default")
  201. color: UM.Theme.getColor("text")
  202. renderType: Text.NativeRendering
  203. }
  204. Label
  205. {
  206. text: base.getMachineMetaDataEntry("manufacturer")
  207. width: parent.width - manufacturerLabel.width
  208. font: UM.Theme.getFont("default")
  209. color: UM.Theme.getColor("text")
  210. renderType: Text.NativeRendering
  211. wrapMode: Text.WordWrap
  212. }
  213. Label
  214. {
  215. id: profileAuthorLabel
  216. text: catalog.i18nc("@label", "Profile author")
  217. font: UM.Theme.getFont("default")
  218. color: UM.Theme.getColor("text")
  219. renderType: Text.NativeRendering
  220. }
  221. Label
  222. {
  223. text: base.getMachineMetaDataEntry("author")
  224. width: parent.width - profileAuthorLabel.width
  225. font: UM.Theme.getFont("default")
  226. color: UM.Theme.getColor("text")
  227. renderType: Text.NativeRendering
  228. wrapMode: Text.WordWrap
  229. }
  230. Label
  231. {
  232. id: printerNameLabel
  233. text: catalog.i18nc("@label", "Printer name")
  234. font: UM.Theme.getFont("default")
  235. color: UM.Theme.getColor("text")
  236. renderType: Text.NativeRendering
  237. }
  238. Cura.TextField
  239. {
  240. id: printerNameTextField
  241. placeholderText: catalog.i18nc("@text", "Please name your printer")
  242. maximumLength: 40
  243. width: parent.width - (printerNameLabel.width + (3 * UM.Theme.getSize("default_margin").width))
  244. validator: RegExpValidator
  245. {
  246. regExp: printerNameTextField.machineNameValidator.machineNameRegex
  247. }
  248. property var machineNameValidator: Cura.MachineNameValidator { }
  249. }
  250. }
  251. }
  252. }
  253. }