CategoryButton.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. // Button used to collapse and de-collapse group, or a category, of settings
  4. // the button contains
  5. // - the title of the category,
  6. // - an optional icon and
  7. // - a chevron button to display the colapsetivity of the settings
  8. // Mainly used for the collapsable categories in the settings pannel
  9. import QtQuick 2.2
  10. import QtQuick.Controls 2.1
  11. import QtQuick.Layouts 1.1
  12. import UM 1.5 as UM
  13. Button
  14. {
  15. id: base
  16. height: UM.Theme.getSize("section_header").height
  17. property var expanded: false
  18. property bool indented: false
  19. property alias arrow: categoryArrow
  20. property alias categoryIcon: icon.source
  21. property alias labelText: categoryLabel.text
  22. property alias labelFont: categoryLabel.font
  23. leftPadding: UM.Theme.getSize("narrow_margin").width
  24. rightPadding: UM.Theme.getSize("narrow_margin").width
  25. states:
  26. [
  27. State
  28. {
  29. name: "disabled"
  30. when: !base.enabled
  31. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_disabled_text") }
  32. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_disabled_text") }
  33. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category_disabled") }
  34. },
  35. State
  36. {
  37. name: "hovered"
  38. when: base.hovered
  39. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_active_text") }
  40. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_active_text") }
  41. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category_hover") }
  42. },
  43. State
  44. {
  45. name: "active"
  46. when: base.pressed || base.activeFocus
  47. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_active_text") }
  48. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_active_text") }
  49. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category") }
  50. }
  51. ]
  52. background: Rectangle
  53. {
  54. id: backgroundRectangle
  55. color: UM.Theme.getColor("setting_category")
  56. Behavior on color { ColorAnimation { duration: 50 } }
  57. // Lining on top
  58. Rectangle
  59. {
  60. anchors.top: parent.top
  61. color: UM.Theme.getColor("border_main")
  62. height: UM.Theme.getSize("default_lining").height
  63. width: parent.width
  64. }
  65. }
  66. contentItem: Item
  67. {
  68. id: content
  69. //spacing: UM.Theme.getSize("narrow_margin").width
  70. UM.ColorImage
  71. {
  72. id: icon
  73. source: ""
  74. visible: icon.source != ""
  75. anchors.verticalCenter: parent.verticalCenter
  76. color: UM.Theme.getColor("setting_category_text")
  77. width: visible ? UM.Theme.getSize("section_icon").width: 0
  78. height: UM.Theme.getSize("section_icon").height
  79. anchors.leftMargin: base.indented ? UM.Theme.getSize("default_margin").width: 0
  80. }
  81. UM.Label
  82. {
  83. id: categoryLabel
  84. Layout.fillWidth: true
  85. anchors.right: categoryArrow.left
  86. anchors.left: icon.right
  87. anchors.leftMargin: base.indented ? UM.Theme.getSize("default_margin").width + UM.Theme.getSize("narrow_margin").width: UM.Theme.getSize("narrow_margin").width
  88. anchors.verticalCenter: parent.verticalCenter
  89. elide: Text.ElideRight
  90. wrapMode: Text.NoWrap
  91. font: UM.Theme.getFont("medium_bold")
  92. color: UM.Theme.getColor("setting_category_text")
  93. }
  94. UM.ColorImage
  95. {
  96. id: categoryArrow
  97. anchors.right: parent.right
  98. width: UM.Theme.getSize("standard_arrow").width
  99. height: UM.Theme.getSize("standard_arrow").height
  100. anchors.verticalCenter: parent.verticalCenter
  101. color: UM.Theme.getColor("setting_control_button")
  102. source: expanded ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleLeft")
  103. }
  104. }
  105. }