CategoryButton.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 UM 1.5 as UM
  12. Button
  13. {
  14. id: base
  15. height: enabled ? UM.Theme.getSize("section_header").height : 0
  16. property var expanded: false
  17. property alias arrow: categoryArrow
  18. property alias categoryIcon: icon.source
  19. property alias labelText: categoryLabel.text
  20. states:
  21. [
  22. State
  23. {
  24. name: "disabled"
  25. when: !base.enabled
  26. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_disabled_text") }
  27. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_disabled_text") }
  28. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category_disabled") }
  29. },
  30. State
  31. {
  32. name: "hovered"
  33. when: base.hovered
  34. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_active_text") }
  35. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_active_text") }
  36. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category_hover") }
  37. },
  38. State
  39. {
  40. name: "active"
  41. when: base.pressed || base.activeFocus
  42. PropertyChanges { target: categoryLabel; color: UM.Theme.getColor("setting_category_active_text") }
  43. PropertyChanges { target: icon; color: UM.Theme.getColor("setting_category_active_text") }
  44. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_category") }
  45. }
  46. ]
  47. background: Rectangle
  48. {
  49. id: backgroundRectangle
  50. height: base.height
  51. color: UM.Theme.getColor("setting_category")
  52. Behavior on color { ColorAnimation { duration: 50 } }
  53. Rectangle
  54. {
  55. //Lining on top
  56. anchors.top: parent.top
  57. color: UM.Theme.getColor("border_main")
  58. height: UM.Theme.getSize("default_lining").height
  59. width: parent.width
  60. }
  61. }
  62. contentItem: Item
  63. {
  64. anchors.fill: parent
  65. UM.Label
  66. {
  67. id: categoryLabel
  68. anchors
  69. {
  70. left: parent.left
  71. leftMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("section_icon").width
  72. right: parent.right
  73. verticalCenter: parent.verticalCenter
  74. }
  75. textFormat: Text.PlainText
  76. font: UM.Theme.getFont("medium_bold")
  77. color: UM.Theme.getColor("setting_category_text")
  78. fontSizeMode: Text.HorizontalFit
  79. minimumPointSize: 8
  80. }
  81. UM.RecolorImage
  82. {
  83. id: categoryArrow
  84. anchors.verticalCenter: parent.verticalCenter
  85. anchors.right: parent.right
  86. anchors.rightMargin: UM.Theme.getSize("narrow_margin").width
  87. width: UM.Theme.getSize("standard_arrow").width
  88. height: UM.Theme.getSize("standard_arrow").height
  89. sourceSize.height: width
  90. color: UM.Theme.getColor("setting_control_button")
  91. source: expanded ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleLeft")
  92. }
  93. }
  94. UM.RecolorImage
  95. {
  96. id: icon
  97. anchors.verticalCenter: parent.verticalCenter
  98. anchors.left: parent.left
  99. anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
  100. color: UM.Theme.getColor("setting_category_text")
  101. width: UM.Theme.getSize("section_icon").width
  102. height: UM.Theme.getSize("section_icon").height
  103. sourceSize.width: width
  104. sourceSize.height: width
  105. }
  106. }