MaterialsBrandSection.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium 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. Rectangle
  11. {
  12. id: brand_section
  13. property var expanded: materialList.expandedBrands.indexOf(model.name) > -1
  14. property var types_model: model.material_types
  15. height: childrenRect.height
  16. width: parent.width
  17. Rectangle
  18. {
  19. id: brand_header_background
  20. color:
  21. {
  22. if(!expanded && model.name == materialList.currentBrand)
  23. {
  24. return UM.Theme.getColor("favorites_row_selected")
  25. }
  26. else
  27. {
  28. return UM.Theme.getColor("favorites_header_bar")
  29. }
  30. }
  31. anchors.fill: brand_header
  32. }
  33. Row
  34. {
  35. id: brand_header
  36. width: parent.width
  37. Label
  38. {
  39. id: brand_name
  40. text: model.name
  41. height: UM.Theme.getSize("favorites_row").height
  42. width: parent.width - UM.Theme.getSize("favorites_button").width
  43. verticalAlignment: Text.AlignVCenter
  44. leftPadding: 4
  45. }
  46. Button
  47. {
  48. text: ""
  49. implicitWidth: UM.Theme.getSize("favorites_button").width
  50. implicitHeight: UM.Theme.getSize("favorites_button").height
  51. UM.RecolorImage {
  52. anchors
  53. {
  54. verticalCenter: parent.verticalCenter
  55. horizontalCenter: parent.horizontalCenter
  56. }
  57. width: UM.Theme.getSize("standard_arrow").width
  58. height: UM.Theme.getSize("standard_arrow").height
  59. sourceSize.width: width
  60. sourceSize.height: height
  61. color: "black"
  62. source: brand_section.expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  63. }
  64. style: ButtonStyle
  65. {
  66. background: Rectangle
  67. {
  68. anchors.fill: parent
  69. color: "transparent"
  70. }
  71. }
  72. }
  73. }
  74. MouseArea
  75. {
  76. anchors.fill: brand_header
  77. onPressed:
  78. {
  79. const i = materialList.expandedBrands.indexOf(model.name)
  80. if (i > -1)
  81. {
  82. // Remove it
  83. materialList.expandedBrands.splice(i, 1)
  84. brand_section.expanded = false
  85. }
  86. else
  87. {
  88. // Add it
  89. materialList.expandedBrands.push(model.name)
  90. brand_section.expanded = true
  91. }
  92. UM.Preferences.setValue("cura/expanded_brands", materialList.expandedBrands.join(";"));
  93. }
  94. }
  95. Column
  96. {
  97. anchors.top: brand_header.bottom
  98. width: parent.width
  99. anchors.left: parent.left
  100. height: brand_section.expanded ? childrenRect.height : 0
  101. visible: brand_section.expanded
  102. Repeater
  103. {
  104. model: types_model
  105. delegate: MaterialsTypeSection {}
  106. }
  107. }
  108. Connections
  109. {
  110. target: UM.Preferences
  111. onPreferenceChanged:
  112. {
  113. expanded = materialList.expandedBrands.indexOf(model.name) > -1
  114. }
  115. }
  116. }