FluProgressRing.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. Rectangle {
  5. property real linWidth : 5
  6. property real progress: 0.25
  7. property bool indeterminate: true
  8. readonly property real radius2 : radius - linWidth/2
  9. property color primaryColor : FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
  10. id: control
  11. width: 44
  12. height: 44
  13. radius: 22
  14. border.width: linWidth
  15. color: "#00000000"
  16. border.color: FluTheme.dark ? Qt.rgba(99/255,99/255,99/255,1) : Qt.rgba(214/255,214/255,214/255,1)
  17. onProgressChanged: {
  18. canvas.requestPaint()
  19. }
  20. Connections{
  21. target: FluTheme
  22. function onDarkChanged(){
  23. canvas.requestPaint()
  24. }
  25. }
  26. Component.onCompleted: {
  27. if(indeterminate){
  28. behavior.enabled = true
  29. control.rotation = 360
  30. }
  31. }
  32. Behavior on rotation{
  33. id:behavior
  34. enabled: false
  35. NumberAnimation{
  36. duration: 999
  37. easing.type: Easing.BezierSpline
  38. easing.bezierCurve: [0.55,0.55,0,1]
  39. onRunningChanged: {
  40. if(!running){
  41. behavior.enabled = false
  42. control.rotation = 0
  43. behavior.enabled = true
  44. control.rotation = 360
  45. }
  46. }
  47. }
  48. }
  49. Canvas {
  50. id:canvas
  51. anchors.fill: parent
  52. antialiasing: true
  53. renderTarget: Canvas.Image
  54. onPaint: {
  55. var ctx = canvas.getContext("2d");
  56. ctx.setTransform(1, 0, 0, 1, 0, 0);
  57. ctx.clearRect(0, 0, canvas.width, canvas.height);
  58. ctx.save();
  59. ctx.lineWidth = linWidth;
  60. ctx.strokeStyle = primaryColor;
  61. ctx.fillStyle = primaryColor;
  62. ctx.beginPath();
  63. ctx.arc(width/2, height/2, radius2 ,-0.5 * Math.PI,-0.5 * Math.PI + progress * 2 * Math.PI);
  64. ctx.stroke();
  65. ctx.closePath();
  66. ctx.restore();
  67. }
  68. }
  69. }