FluPivot.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. Item {
  5. default property alias content: d.children
  6. property alias currentIndex: nav_list.currentIndex
  7. property color normalColor: FluTheme.dark ? FluColors.Grey120 : FluColors.Grey120
  8. property color hoverColor: FluTheme.dark ? FluColors.Grey10 : FluColors.Black
  9. id:control
  10. width: 400
  11. height: 300
  12. implicitHeight: height
  13. implicitWidth: width
  14. MouseArea{
  15. anchors.fill: parent
  16. preventStealing: true
  17. }
  18. FluObject{
  19. id:d
  20. }
  21. ListView{
  22. id:nav_list
  23. height: 40
  24. width: control.width
  25. model:d.children
  26. clip: true
  27. spacing: 20
  28. interactive: false
  29. orientation:ListView.Horizontal
  30. highlight: Item{
  31. clip: true
  32. Rectangle{
  33. height: 3
  34. radius: 1.5
  35. color: FluTheme.primaryColor.dark
  36. width: nav_list.currentItem ? nav_list.currentItem.width : 0
  37. y:37
  38. Behavior on width {
  39. NumberAnimation{
  40. duration: 150
  41. }
  42. }
  43. }
  44. }
  45. delegate: Button{
  46. id:item_button
  47. width: item_title.width
  48. height: nav_list.height
  49. background:Item{
  50. }
  51. contentItem: Item{
  52. FluText {
  53. id:item_title
  54. fontStyle: FluText.Title
  55. font.bold: false
  56. text: modelData.title
  57. anchors.centerIn: parent
  58. color: {
  59. if(item_button.hovered)
  60. return hoverColor
  61. return normalColor
  62. }
  63. }
  64. transitions: Transition {
  65. NumberAnimation{
  66. duration: 400;
  67. }
  68. }
  69. }
  70. onClicked: {
  71. nav_list.currentIndex = index
  72. }
  73. }
  74. }
  75. Item{
  76. id:container
  77. anchors{
  78. top: nav_list.bottom
  79. topMargin: 10
  80. left: parent.left
  81. right: parent.right
  82. bottom: parent.bottom
  83. }
  84. Repeater{
  85. model:d.children
  86. Loader{
  87. property var argument: modelData.argument
  88. anchors.fill: parent
  89. sourceComponent: modelData.contentItem
  90. visible: nav_list.currentIndex === index
  91. }
  92. }
  93. }
  94. }