AddLocalPrinterScrollView.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. ScrollView
  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: preferredCategory
  20. // By default (when this list shows up) we always expand the "Ultimaker" section.
  21. property string preferredCategory: "Ultimaker"
  22. ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
  23. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  24. property int maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll.
  25. height: maxItemCountAtOnce * UM.Theme.getSize("action_button").height
  26. clip: true
  27. function updateCurrentItemUponSectionChange()
  28. {
  29. // Find the first machine from this section
  30. for (var i = 0; i < machineList.count; i++)
  31. {
  32. var item = machineList.model.getItem(i)
  33. if (item.section == base.currentSection)
  34. {
  35. machineList.currentIndex = i
  36. break
  37. }
  38. }
  39. }
  40. Component.onCompleted:
  41. {
  42. updateCurrentItemUponSectionChange()
  43. }
  44. ListView
  45. {
  46. id: machineList
  47. model: UM.DefinitionContainersModel
  48. {
  49. id: machineDefinitionsModel
  50. filter: { "visible": true }
  51. sectionProperty: "category"
  52. preferredSectionValue: preferredCategory
  53. }
  54. section.property: "section"
  55. section.delegate: sectionHeader
  56. delegate: machineButton
  57. }
  58. Component
  59. {
  60. id: sectionHeader
  61. Button
  62. {
  63. id: button
  64. width: ListView.view.width
  65. height: UM.Theme.getSize("action_button").height
  66. text: section
  67. property bool isActive: base.currentSection == section
  68. background: Rectangle
  69. {
  70. anchors.fill: parent
  71. color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  72. }
  73. contentItem: Item
  74. {
  75. width: childrenRect.width
  76. height: UM.Theme.getSize("action_button").height
  77. UM.RecolorImage
  78. {
  79. id: arrow
  80. anchors.left: parent.left
  81. width: UM.Theme.getSize("standard_arrow").width
  82. height: UM.Theme.getSize("standard_arrow").height
  83. sourceSize.width: width
  84. sourceSize.height: height
  85. color: UM.Theme.getColor("text")
  86. source: base.currentSection == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  87. }
  88. Label
  89. {
  90. id: label
  91. anchors.left: arrow.right
  92. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  93. verticalAlignment: Text.AlignVCenter
  94. text: button.text
  95. font.bold: true
  96. renderType: Text.NativeRendering
  97. }
  98. }
  99. onClicked:
  100. {
  101. base.currentSection = section
  102. base.updateCurrentItemUponSectionChange()
  103. }
  104. }
  105. }
  106. Component
  107. {
  108. id: machineButton
  109. Cura.RadioButton
  110. {
  111. id: radioButton
  112. anchors.left: parent.left
  113. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  114. anchors.right: parent.right
  115. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  116. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
  117. checked: ListView.view.currentIndex == index
  118. text: name
  119. visible: base.currentSection == section
  120. }
  121. }
  122. }