AddLocalPrinterScrollView.qml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  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.left: parent.left
  151. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  152. anchors.right: parent.right
  153. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  154. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
  155. checked: ListView.view.currentIndex == index
  156. text: name
  157. visible: base.currentSection == section
  158. onClicked: ListView.view.currentIndex = index
  159. }
  160. }
  161. }
  162. // Vertical line
  163. Rectangle
  164. {
  165. id: verticalLine
  166. anchors.top: parent.top
  167. height: childrenHeight - UM.Theme.getSize("default_lining").height
  168. width: UM.Theme.getSize("default_lining").height
  169. color: UM.Theme.getColor("lining")
  170. }
  171. // User-editable printer name row
  172. Column
  173. {
  174. width: Math.floor(parent.width * 0.52)
  175. spacing: UM.Theme.getSize("default_margin").width
  176. padding: UM.Theme.getSize("default_margin").width
  177. Label
  178. {
  179. width: parent.width
  180. wrapMode: Text.WordWrap
  181. text: base.getMachineName()
  182. color: UM.Theme.getColor("primary_button")
  183. font: UM.Theme.getFont("huge")
  184. elide: Text.ElideRight
  185. }
  186. Grid
  187. {
  188. width: parent.width
  189. columns: 2
  190. rowSpacing: UM.Theme.getSize("default_lining").height
  191. columnSpacing: UM.Theme.getSize("default_margin").width
  192. verticalItemAlignment: Grid.AlignVCenter
  193. Label
  194. {
  195. id: manufacturerLabel
  196. text: catalog.i18nc("@label", "Manufacturer")
  197. font: UM.Theme.getFont("default")
  198. color: UM.Theme.getColor("text")
  199. renderType: Text.NativeRendering
  200. }
  201. Label
  202. {
  203. text: base.getMachineMetaDataEntry("manufacturer")
  204. width: parent.width - manufacturerLabel.width
  205. font: UM.Theme.getFont("default")
  206. color: UM.Theme.getColor("text")
  207. renderType: Text.NativeRendering
  208. wrapMode: Text.WordWrap
  209. }
  210. Label
  211. {
  212. id: profileAuthorLabel
  213. text: catalog.i18nc("@label", "Profile author")
  214. font: UM.Theme.getFont("default")
  215. color: UM.Theme.getColor("text")
  216. renderType: Text.NativeRendering
  217. }
  218. Label
  219. {
  220. text: base.getMachineMetaDataEntry("author")
  221. width: parent.width - profileAuthorLabel.width
  222. font: UM.Theme.getFont("default")
  223. color: UM.Theme.getColor("text")
  224. renderType: Text.NativeRendering
  225. wrapMode: Text.WordWrap
  226. }
  227. Label
  228. {
  229. id: printerNameLabel
  230. text: catalog.i18nc("@label", "Printer name")
  231. font: UM.Theme.getFont("default")
  232. color: UM.Theme.getColor("text")
  233. renderType: Text.NativeRendering
  234. }
  235. Cura.TextField
  236. {
  237. id: printerNameTextField
  238. placeholderText: catalog.i18nc("@text", "Please name your printer")
  239. maximumLength: 40
  240. validator: RegExpValidator
  241. {
  242. regExp: printerNameTextField.machineNameValidator.machineNameRegex
  243. }
  244. property var machineNameValidator: Cura.MachineNameValidator { }
  245. }
  246. }
  247. }
  248. }
  249. }