FluFlipView.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. Item{
  6. property bool vertical: false
  7. default property alias content : swipe.contentData
  8. property alias currentIndex: swipe.currentIndex
  9. id:control
  10. width: 400
  11. height: 300
  12. implicitWidth: width
  13. implicitHeight: height
  14. QtObject{
  15. id:d
  16. property bool flag: true
  17. }
  18. MouseArea{
  19. anchors.fill: parent
  20. preventStealing: true
  21. onWheel:
  22. (wheel)=>{
  23. if(!d.flag)
  24. return
  25. if (wheel.angleDelta.y > 0){
  26. btn_start.clicked()
  27. }else{
  28. btn_end.clicked()
  29. }
  30. d.flag = false
  31. timer.restart()
  32. }
  33. }
  34. Timer{
  35. id:timer
  36. interval: 250
  37. onTriggered: {
  38. d.flag = true
  39. }
  40. }
  41. SwipeView {
  42. id:swipe
  43. clip: true
  44. interactive: false
  45. orientation:control.vertical ? Qt.Vertical : Qt.Horizontal
  46. anchors.fill: parent
  47. }
  48. Button{
  49. id:btn_start
  50. height: vertical ? 20 : 40
  51. width: vertical ? 40 : 20
  52. anchors{
  53. left: vertical ? undefined : parent.left
  54. leftMargin: vertical ? undefined : 2
  55. verticalCenter: vertical ? undefined : parent.verticalCenter
  56. horizontalCenter: !vertical ? undefined : parent.horizontalCenter
  57. top: !vertical ? undefined :parent.top
  58. topMargin: !vertical ? undefined :2
  59. }
  60. background: Rectangle{
  61. radius: 4
  62. color:FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,0.97) : Qt.rgba(237/255,237/255,237/255,0.97)
  63. }
  64. contentItem:FluIcon{
  65. iconSource: vertical ? FluentIcons.CaretUpSolid8 : FluentIcons.CaretLeftSolid8
  66. width: 10
  67. height: 10
  68. iconSize: 10
  69. iconColor: btn_start.hovered ? FluColors.Grey220 : FluColors.Grey120
  70. anchors.centerIn: parent
  71. }
  72. visible: swipe.currentIndex !==0
  73. onClicked: {
  74. swipe.currentIndex = Math.max(swipe.currentIndex - 1, 0)
  75. }
  76. }
  77. Button{
  78. id:btn_end
  79. height: vertical ? 20 : 40
  80. width: vertical ? 40 : 20
  81. anchors{
  82. right: vertical ? undefined : parent.right
  83. rightMargin: vertical ? undefined : 2
  84. verticalCenter: vertical ? undefined : parent.verticalCenter
  85. horizontalCenter: !vertical ? undefined : parent.horizontalCenter
  86. bottom: !vertical ? undefined :parent.bottom
  87. bottomMargin: !vertical ? undefined :2
  88. }
  89. background: Rectangle{
  90. radius: 4
  91. color:FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,0.97) : Qt.rgba(237/255,237/255,237/255,0.97)
  92. }
  93. visible: swipe.currentIndex !== swipe.count - 1
  94. contentItem:FluIcon{
  95. iconSource: vertical ? FluentIcons.CaretDownSolid8 : FluentIcons.CaretRightSolid8
  96. width: 10
  97. height: 10
  98. iconSize: 10
  99. iconColor: btn_end.hovered ? FluColors.Grey220 : FluColors.Grey120
  100. anchors.centerIn: parent
  101. }
  102. onClicked: {
  103. swipe.currentIndex = Math.min(swipe.currentIndex + 1,swipe.count-1)
  104. }
  105. }
  106. }