CustomLoading.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import QtQuick 2.12
  2. import QtQuick.Controls 2.12
  3. Item {
  4. id: loadingControl
  5. //item圆圈个数
  6. property int itemCount: 10
  7. //item圆圈直径大小
  8. property int itemSize: 10
  9. //item变大范围
  10. property int itemExpand: 10
  11. //item圆圈颜色
  12. property color itemColor: mainAppColor
  13. //当前item,配合动画
  14. property int itemIndex: 0
  15. //轮转一次的时长
  16. property int duration: 1500
  17. //
  18. property bool running: visible
  19. implicitHeight: 100
  20. implicitWidth: 100
  21. NumberAnimation{
  22. target: loadingControl
  23. property: "itemIndex"
  24. from: 0
  25. to: loadingControl.itemCount-1
  26. loops: Animation.Infinite
  27. duration: loadingControl.duration
  28. running: loadingControl.running
  29. }
  30. //加一层item.margin来容纳item大小变化
  31. Item{
  32. id: content
  33. anchors.fill: parent
  34. anchors.margins: loadingControl.itemExpand/2+1
  35. Repeater{
  36. id: repeater
  37. model: loadingControl.itemCount
  38. Rectangle{
  39. id: item
  40. height: loadingControl.itemSize
  41. width: height
  42. x: content.width/2 - width/2
  43. y: content.height/2 - height/2
  44. radius: height/2
  45. color: loadingControl.itemColor
  46. //环绕在中心
  47. transform: [
  48. Translate {
  49. y: content.height/2-height/2
  50. },
  51. Rotation {
  52. angle: index / repeater.count * 360
  53. origin.x: width/2
  54. origin.y: height/2
  55. }
  56. ]
  57. //轮转到当前item时就切换状态
  58. state: loadingControl.itemIndex===index?"current":"normal"
  59. states: [
  60. State {
  61. name: "current"
  62. PropertyChanges {
  63. target: item
  64. opacity: 1
  65. height: loadingControl.itemSize+loadingControl.itemExpand
  66. }
  67. },
  68. State {
  69. name: "normal"
  70. PropertyChanges {
  71. target: item
  72. opacity: 0.1
  73. height: loadingControl.itemSize
  74. }
  75. }
  76. ]
  77. //大小和透明度的状态过渡
  78. transitions: [
  79. Transition {
  80. from: "current"
  81. to: "normal"
  82. NumberAnimation{
  83. properties: "opacity,height"
  84. duration: loadingControl.duration
  85. }
  86. },
  87. Transition {
  88. from: "normal"
  89. to: "current"
  90. NumberAnimation{
  91. properties: "opacity,height"
  92. duration: 0
  93. }
  94. }
  95. ]
  96. }
  97. }
  98. }
  99. }