AddLocalPrinterScrollView.qml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.0 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. UM.I18nCatalog { id: catalog; name: "cura" }
  14. id: base
  15. height: childrenRect.height
  16. // The currently selected machine item in the local machine list.
  17. property var currentItem: (machineList.currentIndex >= 0)
  18. ? machineList.model.getItem(machineList.currentIndex)
  19. : null
  20. // The currently active (expanded) section/category, where section/category is the grouping of local machine items.
  21. property string currentSection: preferredCategory
  22. // By default (when this list shows up) we always expand the "Ultimaker" section.
  23. property string preferredCategory: "Ultimaker"
  24. property int maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll.
  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. Component.onCompleted:
  46. {
  47. updateCurrentItemUponSectionChange()
  48. }
  49. Item
  50. {
  51. id: localPrinterSelectionItem
  52. anchors.left: parent.left
  53. anchors.right: parent.right
  54. anchors.top: parent.top
  55. height: childrenRect.height
  56. // ScrollView + ListView for selecting a local printer to add
  57. ScrollView
  58. {
  59. id: scrollView
  60. anchors.left: parent.left
  61. anchors.right: parent.right
  62. anchors.top: parent.top
  63. height: maxItemCountAtOnce * UM.Theme.getSize("action_button").height
  64. ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
  65. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  66. clip: true
  67. ListView
  68. {
  69. id: machineList
  70. model: UM.DefinitionContainersModel
  71. {
  72. id: machineDefinitionsModel
  73. filter: { "visible": true }
  74. sectionProperty: "category"
  75. preferredSectionValue: preferredCategory
  76. }
  77. section.property: "section"
  78. section.delegate: sectionHeader
  79. delegate: machineButton
  80. }
  81. Component
  82. {
  83. id: sectionHeader
  84. Button
  85. {
  86. id: button
  87. width: ListView.view.width
  88. height: UM.Theme.getSize("action_button").height
  89. text: section
  90. property bool isActive: base.currentSection == section
  91. background: Rectangle
  92. {
  93. anchors.fill: parent
  94. color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  95. }
  96. contentItem: Item
  97. {
  98. width: childrenRect.width
  99. height: UM.Theme.getSize("action_button").height
  100. UM.RecolorImage
  101. {
  102. id: arrow
  103. anchors.left: parent.left
  104. width: UM.Theme.getSize("standard_arrow").width
  105. height: UM.Theme.getSize("standard_arrow").height
  106. sourceSize.width: width
  107. sourceSize.height: height
  108. color: UM.Theme.getColor("text")
  109. source: base.currentSection == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  110. }
  111. Label
  112. {
  113. id: label
  114. anchors.left: arrow.right
  115. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  116. verticalAlignment: Text.AlignVCenter
  117. text: button.text
  118. font: UM.Theme.getFont("default_bold")
  119. renderType: Text.NativeRendering
  120. }
  121. }
  122. onClicked:
  123. {
  124. base.currentSection = section
  125. base.updateCurrentItemUponSectionChange()
  126. }
  127. }
  128. }
  129. Component
  130. {
  131. id: machineButton
  132. Cura.RadioButton
  133. {
  134. id: radioButton
  135. anchors.left: parent.left
  136. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  137. anchors.right: parent.right
  138. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  139. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
  140. checked: ListView.view.currentIndex == index
  141. text: name
  142. visible: base.currentSection == section
  143. onClicked: ListView.view.currentIndex = index
  144. }
  145. }
  146. }
  147. }
  148. // Horizontal line
  149. Rectangle
  150. {
  151. id: horizontalLine
  152. anchors.top: localPrinterSelectionItem.bottom
  153. anchors.left: parent.left
  154. anchors.right: parent.right
  155. height: UM.Theme.getSize("default_lining").height
  156. color: UM.Theme.getColor("lining")
  157. }
  158. // User-editable printer name row
  159. Row
  160. {
  161. anchors.top: horizontalLine.bottom
  162. anchors.left: parent.left
  163. anchors.right: parent.right
  164. anchors.topMargin: UM.Theme.getSize("default_lining").height
  165. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  166. spacing: UM.Theme.getSize("default_margin").width
  167. Label
  168. {
  169. text: catalog.i18nc("@label", "Printer Name")
  170. anchors.verticalCenter: parent.verticalCenter
  171. font: UM.Theme.getFont("medium")
  172. verticalAlignment: Text.AlignVCenter
  173. renderType: Text.NativeRendering
  174. }
  175. Cura.TextField
  176. {
  177. id: printerNameTextField
  178. anchors.verticalCenter: parent.verticalCenter
  179. width: (parent.width / 2) | 0
  180. placeholderText: catalog.i18nc("@text", "Please give your printer a name")
  181. // Make sure that the fill is not empty
  182. validator: RegExpValidator { regExp: /.+/ }
  183. }
  184. }
  185. }