AddPrinterScrollView.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. ScrollView
  8. {
  9. id: base
  10. property var currentItem: null
  11. property string currentSection: preferredCategory
  12. property string preferredCategory: "Ultimaker"
  13. background: Rectangle
  14. {
  15. anchors.fill: parent
  16. color: "white"
  17. }
  18. ListView
  19. {
  20. id: machineList
  21. model: UM.DefinitionContainersModel
  22. {
  23. id: machineDefinitionsModel
  24. filter: { "visible": true }
  25. sectionProperty: "category"
  26. preferredSectionValue: preferredCategory
  27. }
  28. section.property: "section"
  29. section.delegate: sectionHeader
  30. delegate: machineButton
  31. }
  32. Component
  33. {
  34. id: sectionHeader
  35. Button
  36. {
  37. id: button
  38. width: ListView.view.width
  39. height: UM.Theme.getSize("action_button").height
  40. text: section
  41. property bool isActive: base.currentSection == section
  42. background: Rectangle
  43. {
  44. anchors.fill: parent
  45. color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  46. }
  47. contentItem: Item
  48. {
  49. width: childrenRect.width
  50. height: UM.Theme.getSize("action_button").height
  51. UM.RecolorImage
  52. {
  53. id: arrow
  54. anchors.left: parent.left
  55. //anchors.verticalCenter: label.verticalCenter
  56. width: UM.Theme.getSize("standard_arrow").width
  57. height: UM.Theme.getSize("standard_arrow").height
  58. sourceSize.width: width
  59. sourceSize.height: height
  60. color: UM.Theme.getColor("text")
  61. source: base.currentSection == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  62. }
  63. Label
  64. {
  65. id: label
  66. anchors.left: arrow.right
  67. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  68. verticalAlignment: Text.AlignVCenter
  69. text: button.text
  70. font.bold: true
  71. renderType: Text.NativeRendering
  72. }
  73. }
  74. onClicked:
  75. {
  76. if (base.currentSection != section)
  77. {
  78. // Find the first machine from this section
  79. for (var i = 0; i < ListView.view.count; i++)
  80. {
  81. var item = ListView.view.model.getItem(i)
  82. if (item.section == section)
  83. {
  84. base.currentItem = item
  85. base.currentSection = item.section
  86. ListView.view.currentIndex = i
  87. break
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. Component
  95. {
  96. id: machineButton
  97. RadioButton
  98. {
  99. id: radioButton
  100. anchors.left: parent.left
  101. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  102. anchors.right: parent.right
  103. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  104. height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
  105. checked: ListView.view.currentIndex == index
  106. text: name
  107. font: UM.Theme.getFont("default")
  108. visible: base.currentSection == section
  109. background: Rectangle
  110. {
  111. anchors.fill: parent
  112. color: "transparent"
  113. }
  114. indicator: Rectangle
  115. {
  116. implicitWidth: 16
  117. implicitHeight: 16
  118. anchors.verticalCenter: parent.verticalCenter
  119. radius: width / 2
  120. border.width: UM.Theme.getSize("default_lining").width
  121. border.color: radioButton.hovered ? UM.Theme.getColor("small_button_text") : UM.Theme.getColor("small_button_text_hover")
  122. Rectangle {
  123. width: parent.width / 2
  124. height: width
  125. anchors.centerIn: parent
  126. radius: width / 2
  127. color: radioButton.hovered ? UM.Theme.getColor("primary_button_hover") : UM.Theme.getColor("primary_button")
  128. visible: radioButton.checked
  129. }
  130. }
  131. contentItem: Label
  132. {
  133. verticalAlignment: Text.AlignVCenter
  134. leftPadding: radioButton.indicator.width + radioButton.spacing
  135. text: radioButton.text
  136. font: radioButton.font
  137. renderType: Text.NativeRendering
  138. }
  139. onClicked:
  140. {
  141. ListView.view.currentIndex = index
  142. }
  143. }
  144. }
  145. }