MaterialsBrandSection.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import QtQuick.Dialogs 1.2
  8. import UM 1.2 as UM
  9. import Cura 1.0 as Cura
  10. Item
  11. {
  12. id: brand_section
  13. property var sectionName: ""
  14. property var elementsModel // This can be a MaterialTypesModel or GenericMaterialsModel or FavoriteMaterialsModel
  15. property var hasMaterialTypes: true // It indicates wheather it has material types or not
  16. property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1
  17. height: childrenRect.height
  18. width: parent.width
  19. Rectangle
  20. {
  21. id: brand_header_background
  22. color:
  23. {
  24. if(!expanded && sectionName == materialList.currentBrand)
  25. {
  26. return UM.Theme.getColor("favorites_row_selected")
  27. }
  28. else
  29. {
  30. return UM.Theme.getColor("favorites_header_bar")
  31. }
  32. }
  33. anchors.fill: brand_header
  34. }
  35. Row
  36. {
  37. id: brand_header
  38. width: parent.width
  39. Label
  40. {
  41. id: brand_name
  42. text: sectionName
  43. height: UM.Theme.getSize("favorites_row").height
  44. width: parent.width - UM.Theme.getSize("favorites_button").width
  45. verticalAlignment: Text.AlignVCenter
  46. leftPadding: (UM.Theme.getSize("default_margin").width / 2) | 0
  47. }
  48. Button
  49. {
  50. text: ""
  51. implicitWidth: UM.Theme.getSize("favorites_button").width
  52. implicitHeight: UM.Theme.getSize("favorites_button").height
  53. UM.RecolorImage
  54. {
  55. anchors
  56. {
  57. verticalCenter: parent.verticalCenter
  58. horizontalCenter: parent.horizontalCenter
  59. }
  60. width: UM.Theme.getSize("standard_arrow").width
  61. height: UM.Theme.getSize("standard_arrow").height
  62. color: "black"
  63. source: brand_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  64. }
  65. style: ButtonStyle
  66. {
  67. background: Item { }
  68. }
  69. }
  70. }
  71. MouseArea
  72. {
  73. anchors.fill: brand_header
  74. onPressed:
  75. {
  76. const i = materialList.expandedBrands.indexOf(sectionName)
  77. if (i > -1)
  78. {
  79. // Remove it
  80. materialList.expandedBrands.splice(i, 1)
  81. brand_section.expanded = false
  82. }
  83. else
  84. {
  85. // Add it
  86. materialList.expandedBrands.push(sectionName)
  87. brand_section.expanded = true
  88. }
  89. UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";"));
  90. }
  91. }
  92. Column
  93. {
  94. id: brandMaterialList
  95. anchors.top: brand_header.bottom
  96. width: parent.width
  97. anchors.left: parent.left
  98. height: brand_section.expanded ? childrenRect.height : 0
  99. visible: brand_section.expanded
  100. Repeater
  101. {
  102. model: elementsModel
  103. delegate: Loader
  104. {
  105. id: loader
  106. width: parent.width
  107. property var element: model
  108. sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
  109. }
  110. }
  111. }
  112. Component
  113. {
  114. id: materialsTypeSection
  115. MaterialsTypeSection
  116. {
  117. materialType: element
  118. }
  119. }
  120. Component
  121. {
  122. id: materialSlot
  123. MaterialsSlot
  124. {
  125. material: element
  126. }
  127. }
  128. Connections
  129. {
  130. target: UM.Preferences
  131. onPreferenceChanged:
  132. {
  133. if (preference !== "cura/expanded_types" && preference !== "cura/expanded_brands")
  134. {
  135. return;
  136. }
  137. expanded = materialList.expandedBrands.indexOf(sectionName) > -1
  138. }
  139. }
  140. }