AddLocalPrinterScrollView.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Controls 2.14
  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.ColorImage
  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. color: UM.Theme.getColor("text")
  105. source: base.currentSection == section ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
  106. }
  107. UM.Label
  108. {
  109. id: label
  110. anchors.left: arrow.right
  111. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  112. text: button.text
  113. font: UM.Theme.getFont("default_bold")
  114. }
  115. }
  116. onClicked:
  117. {
  118. base.currentSection = section
  119. base.updateCurrentItemUponSectionChange()
  120. }
  121. }
  122. delegate: Cura.RadioButton
  123. {
  124. id: radioButton
  125. anchors
  126. {
  127. left: parent !== null ? parent.left : undefined
  128. leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  129. right: parent !== null ? parent.right : undefined
  130. rightMargin: UM.Theme.getSize("default_margin").width
  131. }
  132. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0 //This causes the scrollbar to vary in length due to QTBUG-76830.
  133. checked: machineList.currentIndex == index
  134. text: name
  135. visible: base.currentSection.toLowerCase() === section.toLowerCase()
  136. onClicked: machineList.currentIndex = index
  137. }
  138. }
  139. // Vertical line
  140. Rectangle
  141. {
  142. id: verticalLine
  143. anchors.top: parent.top
  144. height: parent.height - UM.Theme.getSize("default_lining").height
  145. width: UM.Theme.getSize("default_lining").height
  146. color: UM.Theme.getColor("lining")
  147. }
  148. // User-editable printer name row
  149. Column
  150. {
  151. width: Math.floor(parent.width * 0.52)
  152. spacing: UM.Theme.getSize("default_margin").width
  153. padding: UM.Theme.getSize("default_margin").width
  154. UM.Label
  155. {
  156. width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
  157. text: base.getMachineName()
  158. color: UM.Theme.getColor("primary_button")
  159. font: UM.Theme.getFont("huge")
  160. elide: Text.ElideRight
  161. }
  162. Grid
  163. {
  164. width: parent.width
  165. columns: 2
  166. rowSpacing: UM.Theme.getSize("default_lining").height
  167. columnSpacing: UM.Theme.getSize("default_margin").width
  168. verticalItemAlignment: Grid.AlignVCenter
  169. UM.Label
  170. {
  171. id: manufacturerLabel
  172. text: catalog.i18nc("@label", "Manufacturer")
  173. }
  174. UM.Label
  175. {
  176. text: base.getMachineMetaDataEntry("manufacturer")
  177. width: parent.width - manufacturerLabel.width
  178. wrapMode: Text.WordWrap
  179. }
  180. UM.Label
  181. {
  182. id: profileAuthorLabel
  183. text: catalog.i18nc("@label", "Profile author")
  184. }
  185. UM.Label
  186. {
  187. text: base.getMachineMetaDataEntry("author")
  188. width: parent.width - profileAuthorLabel.width
  189. wrapMode: Text.WordWrap
  190. }
  191. UM.Label
  192. {
  193. id: printerNameLabel
  194. text: catalog.i18nc("@label", "Printer name")
  195. }
  196. Cura.TextField
  197. {
  198. id: printerNameTextField
  199. placeholderText: catalog.i18nc("@text", "Please name your printer")
  200. maximumLength: 40
  201. width: parent.width - (printerNameLabel.width + (3 * UM.Theme.getSize("default_margin").width))
  202. validator: RegularExpressionValidator
  203. {
  204. regularExpression: printerNameTextField.machineNameValidator.machineNameRegex
  205. }
  206. property var machineNameValidator: Cura.MachineNameValidator { }
  207. }
  208. }
  209. }
  210. }
  211. }