AddLocalPrinterScrollView.qml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // Copyright (c) 2022 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.fill: parent
  66. //Selecting a local printer to add from this list.
  67. ListView
  68. {
  69. id: machineList
  70. width: Math.floor(parent.width * 0.48)
  71. height: parent.height
  72. clip: true
  73. ScrollBar.vertical: UM.ScrollBar {}
  74. model: UM.DefinitionContainersModel
  75. {
  76. id: machineDefinitionsModel
  77. filter: { "visible": true }
  78. sectionProperty: "manufacturer"
  79. preferredSections: preferredCategories
  80. }
  81. section.property: "section"
  82. section.delegate: Button
  83. {
  84. id: button
  85. width: machineList.width
  86. height: UM.Theme.getSize("action_button").height
  87. text: section
  88. property bool isActive: base.currentSection == section
  89. background: Rectangle
  90. {
  91. anchors.fill: parent
  92. color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  93. }
  94. contentItem: Item
  95. {
  96. width: childrenRect.width
  97. height: UM.Theme.getSize("action_button").height
  98. UM.RecolorImage
  99. {
  100. id: arrow
  101. anchors.left: parent.left
  102. width: UM.Theme.getSize("standard_arrow").width
  103. height: UM.Theme.getSize("standard_arrow").height
  104. sourceSize.width: width
  105. sourceSize.height: height
  106. color: UM.Theme.getColor("text")
  107. source: base.currentSection == section ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
  108. }
  109. UM.Label
  110. {
  111. id: label
  112. anchors.left: arrow.right
  113. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  114. text: button.text
  115. font: UM.Theme.getFont("default_bold")
  116. }
  117. }
  118. onClicked:
  119. {
  120. base.currentSection = section
  121. base.updateCurrentItemUponSectionChange()
  122. }
  123. }
  124. delegate: Cura.RadioButton
  125. {
  126. id: radioButton
  127. anchors
  128. {
  129. left: parent !== null ? parent.left : undefined
  130. leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  131. right: parent !== null ? parent.right : undefined
  132. rightMargin: UM.Theme.getSize("default_margin").width
  133. }
  134. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0 //This causes the scrollbar to vary in length due to QTBUG-76830.
  135. checked: machineList.currentIndex == index
  136. text: name
  137. visible: base.currentSection.toLowerCase() === section.toLowerCase()
  138. onClicked: machineList.currentIndex = index
  139. }
  140. }
  141. // Vertical line
  142. Rectangle
  143. {
  144. id: verticalLine
  145. anchors.top: parent.top
  146. height: parent.height - UM.Theme.getSize("default_lining").height
  147. width: UM.Theme.getSize("default_lining").height
  148. color: UM.Theme.getColor("lining")
  149. }
  150. // User-editable printer name row
  151. Column
  152. {
  153. width: Math.floor(parent.width * 0.52)
  154. spacing: UM.Theme.getSize("default_margin").width
  155. padding: UM.Theme.getSize("default_margin").width
  156. UM.Label
  157. {
  158. width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
  159. wrapMode: Text.Wrap
  160. text: base.getMachineName()
  161. color: UM.Theme.getColor("primary_button")
  162. font: UM.Theme.getFont("huge")
  163. elide: Text.ElideRight
  164. }
  165. Grid
  166. {
  167. width: parent.width
  168. columns: 2
  169. rowSpacing: UM.Theme.getSize("default_lining").height
  170. columnSpacing: UM.Theme.getSize("default_margin").width
  171. verticalItemAlignment: Grid.AlignVCenter
  172. UM.Label
  173. {
  174. id: manufacturerLabel
  175. text: catalog.i18nc("@label", "Manufacturer")
  176. }
  177. UM.Label
  178. {
  179. text: base.getMachineMetaDataEntry("manufacturer")
  180. width: parent.width - manufacturerLabel.width
  181. wrapMode: Text.WordWrap
  182. }
  183. UM.Label
  184. {
  185. id: profileAuthorLabel
  186. text: catalog.i18nc("@label", "Profile author")
  187. }
  188. UM.Label
  189. {
  190. text: base.getMachineMetaDataEntry("author")
  191. width: parent.width - profileAuthorLabel.width
  192. wrapMode: Text.WordWrap
  193. }
  194. UM.Label
  195. {
  196. id: printerNameLabel
  197. text: catalog.i18nc("@label", "Printer name")
  198. }
  199. Cura.TextField
  200. {
  201. id: printerNameTextField
  202. placeholderText: catalog.i18nc("@text", "Please name your printer")
  203. maximumLength: 40
  204. width: parent.width - (printerNameLabel.width + (3 * UM.Theme.getSize("default_margin").width))
  205. validator: RegExpValidator
  206. {
  207. regExp: printerNameTextField.machineNameValidator.machineNameRegex
  208. }
  209. property var machineNameValidator: Cura.MachineNameValidator { }
  210. }
  211. }
  212. }
  213. }
  214. }