CustomBusyIndicatorStyle.qml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import QtQuick 2.3
  2. import QtQuick.Controls.Styles 1.3
  3. BusyIndicatorStyle {
  4. id: style
  5. property int lines: 11
  6. property real length: 10 // % of the width of the control
  7. property real width: 5 // % of the height of the control
  8. property real radius: 13 // % of the width of the control
  9. property real corner: 1 // between 0 and 1
  10. property real speed: 100 // smaller is faster
  11. property real trail: 0.6 // between 0 and 1
  12. property bool clockWise: true
  13. property real opacity: 0.7
  14. property string color: "#7B756B"
  15. property string highlightColor: "white"
  16. property string bgColor: "black"
  17. indicator: Rectangle {
  18. color: style.bgColor
  19. visible: control.running
  20. Repeater {
  21. id: repeat
  22. model: style.lines
  23. Rectangle {
  24. property real factor: control.width / 200
  25. color: style.color
  26. opacity: style.opacity
  27. Behavior on color {
  28. ColorAnimation {
  29. from: style.highlightColor
  30. duration: style.speed * style.lines * style.trail
  31. }
  32. }
  33. radius: style.corner * height / 2
  34. width: style.length * factor
  35. height: style.width * factor
  36. x: control.width / 2 + style.radius * factor
  37. y: control.height / 2 - height / 2
  38. transform: Rotation {
  39. origin.x: -style.radius * factor
  40. origin.y: height / 2
  41. angle: index * (360 / repeat.count)
  42. }
  43. Timer {
  44. id: reset
  45. interval: style.speed * (style.clockWise ? index : style.lines - index)
  46. onTriggered: {
  47. parent.opacity = 1
  48. parent.color = style.highlightColor
  49. reset2.start()
  50. }
  51. }
  52. Timer {
  53. id: reset2
  54. interval: style.speed
  55. onTriggered: {
  56. parent.opacity = style.opacity
  57. parent.color = style.color
  58. }
  59. }
  60. Timer {
  61. id: globalTimer // for a complete cycle
  62. interval: style.speed * style.lines
  63. onTriggered: {
  64. reset.start()
  65. }
  66. triggeredOnStart: true
  67. repeat: true
  68. }
  69. Component.onCompleted: {
  70. globalTimer.start()
  71. }
  72. }
  73. }
  74. }
  75. }