BusyIndicator.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import QtQuick 2.0
  2. /* BusyIndicator is an animated item idicating that something is loading.
  3. It should be used when duration of loading is unknown and loading
  4. progress will not be shown. BusyIndicator is more lightweight in
  5. loading time and animation complexity than ProgressIndicator.
  6. The API is defined in AbstractBusyIndicator.
  7. */
  8. AbstractBusyIndicator {
  9. id: root
  10. width: priv.__pixelSize
  11. height: priv.__pixelSize
  12. visible: !priv.__isHidden
  13. ParallelAnimation {
  14. id: showAnimation
  15. NumberAnimation {
  16. target: shaderEffect
  17. property: "showing"
  18. to: 1.0
  19. duration: 2000
  20. easing.type: Easing.OutElastic
  21. easing.period: 0.5
  22. }
  23. NumberAnimation {
  24. target: shaderEffect
  25. property: "opacity"
  26. to: 1.0
  27. duration: 1000
  28. easing.type: Easing.OutQuad
  29. }
  30. }
  31. SequentialAnimation {
  32. id: hideAnimation
  33. ParallelAnimation {
  34. NumberAnimation {
  35. target: shaderEffect
  36. property: "showing"
  37. to: 0.2
  38. duration: 500
  39. easing.type: Easing.InQuad
  40. }
  41. NumberAnimation {
  42. target: shaderEffect
  43. property: "opacity"
  44. to: 0.0
  45. duration: 500
  46. easing.type: Easing.OutQuad
  47. }
  48. }
  49. PropertyAction {
  50. target: priv
  51. property: "__isHidden"
  52. value: true
  53. }
  54. }
  55. Image {
  56. id: sourceItem
  57. anchors.centerIn: parent
  58. source: root.invertedTheme ? "images/dots_512_invert.png" : "images/dots_512.png"
  59. sourceSize.width: priv.__pixelSize
  60. sourceSize.height: priv.__pixelSize
  61. visible: false
  62. }
  63. ShaderEffect {
  64. id: shaderEffect
  65. property variant source: sourceItem
  66. property real showing: 0.2
  67. property real animPos: 0
  68. NumberAnimation on animPos {
  69. loops: Animation.Infinite
  70. from: 0
  71. to: 2 * Math.PI
  72. duration: 3000
  73. easing.type: Easing.Bezier
  74. easing.bezierCurve: [ 0.2, 0.2, 0.4, 0.6, 1, 1 ]
  75. running: root.running
  76. }
  77. width: priv.__pixelSize
  78. height: priv.__pixelSize
  79. opacity: 0.0
  80. scale: showing
  81. mesh: GridMesh {
  82. resolution: Qt.size(2 + priv.__pixelSize/32, 2 + priv.__pixelSize/32)
  83. }
  84. vertexShader: "
  85. uniform highp mat4 qt_Matrix;
  86. attribute highp vec4 qt_Vertex;
  87. attribute highp vec2 qt_MultiTexCoord0;
  88. varying highp vec2 qt_TexCoord0;
  89. uniform highp float animPos;
  90. uniform highp float showing;
  91. void main() {
  92. highp vec4 pos = qt_Vertex;
  93. gl_Position = qt_Matrix * pos;
  94. const highp float size = 0.6;
  95. const highp float zoom = 0.4;
  96. const highp float cradius = 0.3;
  97. const highp float hPi = 3.14159/2.0;
  98. highp vec2 tc = qt_MultiTexCoord0;
  99. highp vec2 cen = vec2(0.5 + sin(animPos)*cradius, 0.5 + sin(animPos-hPi)*cradius);
  100. highp float dis = distance(tc, cen);
  101. highp float opacity = smoothstep(0.0, size, dis);
  102. highp vec2 dir = zoom * (cen - tc);
  103. // show/hide animation
  104. highp vec2 twist = 0.5 + (tc-0.5)+(0.14*sin(tc*200.0)-0.07);
  105. tc = mix(twist, tc, showing);
  106. qt_TexCoord0 = tc + dir*(1.0 - opacity);
  107. }"
  108. }
  109. }