FluExpander.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Window
  4. import FluentUI
  5. Item {
  6. property string headerText: "Titlte"
  7. property bool expand: false
  8. property int contentHeight : 300
  9. default property alias content: container.data
  10. id:root
  11. height: layout_header.height + container.height
  12. width: 400
  13. implicitWidth: width
  14. implicitHeight: height
  15. Rectangle{
  16. id:layout_header
  17. width: parent.width
  18. height: 45
  19. radius: 4
  20. color: FluTheme.dark ? Window.active ? Qt.rgba(38/255,44/255,54/255,1) : Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
  21. border.color: FluTheme.dark ? Window.active ? Qt.rgba(55/255,55/255,55/255,1) : Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1)
  22. Behavior on color{
  23. ColorAnimation {
  24. duration: 300
  25. }
  26. }
  27. Behavior on border.color{
  28. ColorAnimation {
  29. duration: 300
  30. }
  31. }
  32. MouseArea{
  33. id:root_mouse
  34. anchors.fill: parent
  35. hoverEnabled: true
  36. onClicked: {
  37. expand = !expand
  38. }
  39. }
  40. FluText{
  41. text: headerText
  42. anchors{
  43. verticalCenter: parent.verticalCenter
  44. left: parent.left
  45. leftMargin: 15
  46. }
  47. }
  48. FluIconButton{
  49. anchors{
  50. verticalCenter: parent.verticalCenter
  51. right: parent.right
  52. rightMargin: 15
  53. }
  54. color:{
  55. if(root_mouse.containsMouse || hovered){
  56. return FluTheme.dark ? Qt.rgba(73/255,73/255,73/255,1) : Qt.rgba(245/255,245/255,245/255,1)
  57. }
  58. return FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
  59. }
  60. onClicked: {
  61. expand = !expand
  62. }
  63. contentItem: FluIcon{
  64. rotation: expand?0:180
  65. iconSource:FluentIcons.ChevronUp
  66. iconSize: 15
  67. Behavior on rotation {
  68. NumberAnimation{
  69. duration: 150
  70. }
  71. }
  72. }
  73. }
  74. }
  75. Rectangle{
  76. id:container
  77. width: parent.width
  78. clip: true
  79. anchors{
  80. top: layout_header.bottom
  81. topMargin: -1
  82. left: layout_header.left
  83. }
  84. radius: 4
  85. color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
  86. border.color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1)
  87. height: expand ? contentHeight : 0
  88. Behavior on height {
  89. NumberAnimation{
  90. duration: 167
  91. easing.type: Easing.BezierSpline
  92. easing.bezierCurve: expand ? [ 0, 0, 0, 1 ] : [ 1, 0, 0, 0 ]
  93. }
  94. }
  95. }
  96. }