AddLocalPrinterScrollView.qml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.5 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. UM.Label
  126. {
  127. id: label
  128. anchors.left: arrow.right
  129. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  130. text: button.text
  131. font: UM.Theme.getFont("default_bold")
  132. }
  133. }
  134. onClicked:
  135. {
  136. base.currentSection = section
  137. base.updateCurrentItemUponSectionChange()
  138. }
  139. }
  140. }
  141. Component
  142. {
  143. id: machineButton
  144. Cura.RadioButton
  145. {
  146. id: radioButton
  147. anchors
  148. {
  149. left: parent !== null ? parent.left: undefined
  150. leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  151. right: parent !== null ? parent.right: undefined
  152. rightMargin: UM.Theme.getSize("default_margin").width
  153. }
  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. UM.Label
  178. {
  179. width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
  180. wrapMode: Text.Wrap
  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. UM.Label
  194. {
  195. id: manufacturerLabel
  196. text: catalog.i18nc("@label", "Manufacturer")
  197. }
  198. UM.Label
  199. {
  200. text: base.getMachineMetaDataEntry("manufacturer")
  201. width: parent.width - manufacturerLabel.width
  202. wrapMode: Text.WordWrap
  203. }
  204. UM.Label
  205. {
  206. id: profileAuthorLabel
  207. text: catalog.i18nc("@label", "Profile author")
  208. }
  209. UM.Label
  210. {
  211. text: base.getMachineMetaDataEntry("author")
  212. width: parent.width - profileAuthorLabel.width
  213. wrapMode: Text.WordWrap
  214. }
  215. UM.Label
  216. {
  217. id: printerNameLabel
  218. text: catalog.i18nc("@label", "Printer name")
  219. }
  220. Cura.TextField
  221. {
  222. id: printerNameTextField
  223. placeholderText: catalog.i18nc("@text", "Please name your printer")
  224. maximumLength: 40
  225. width: parent.width - (printerNameLabel.width + (3 * UM.Theme.getSize("default_margin").width))
  226. validator: RegExpValidator
  227. {
  228. regExp: printerNameTextField.machineNameValidator.machineNameRegex
  229. }
  230. property var machineNameValidator: Cura.MachineNameValidator { }
  231. }
  232. }
  233. }
  234. }
  235. }