2023-02-28 23:57:55 +08:00
|
|
|
|
import QtQuick 2.12
|
|
|
|
|
import QtQuick.Controls 2.12
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
2023-02-28 23:57:55 +08:00
|
|
|
|
Rectangle {
|
|
|
|
|
id: control
|
|
|
|
|
|
|
|
|
|
width: 60
|
|
|
|
|
height: 60
|
|
|
|
|
radius: 30
|
|
|
|
|
border.width: linWidth
|
|
|
|
|
color: "#00000000"
|
2023-03-01 11:58:30 +08:00
|
|
|
|
border.color: FluApp.isDark ? Qt.rgba(41/255,41/255,41/255,1) : Qt.rgba(214/255,214/255,214/255,1)
|
2023-02-28 23:57:55 +08:00
|
|
|
|
property real linWidth : 6
|
|
|
|
|
property real progress: 0.25
|
|
|
|
|
property bool indeterminate: true
|
|
|
|
|
readonly property real radius2 : radius - linWidth/2
|
2023-03-06 12:09:06 +08:00
|
|
|
|
property color primaryColor : FluApp.isDark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
|
2023-02-28 23:57:55 +08:00
|
|
|
|
|
|
|
|
|
onProgressChanged: {
|
|
|
|
|
canvas.requestPaint()
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 11:58:30 +08:00
|
|
|
|
Connections{
|
|
|
|
|
target: FluApp
|
|
|
|
|
function onIsDarkChanged(isDark){
|
|
|
|
|
canvas.requestPaint()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
if(indeterminate){
|
|
|
|
|
behavior.enabled = true
|
|
|
|
|
control.rotation = 360
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-28 23:57:55 +08:00
|
|
|
|
Behavior on rotation{
|
2023-03-01 11:58:30 +08:00
|
|
|
|
id:behavior
|
|
|
|
|
enabled: false
|
2023-02-28 23:57:55 +08:00
|
|
|
|
NumberAnimation{
|
2023-03-01 11:58:30 +08:00
|
|
|
|
duration: 1000
|
2023-02-28 23:57:55 +08:00
|
|
|
|
onRunningChanged: {
|
|
|
|
|
if(!running){
|
2023-03-01 11:58:30 +08:00
|
|
|
|
behavior.enabled = false
|
2023-02-28 23:57:55 +08:00
|
|
|
|
control.rotation = 0
|
2023-03-01 11:58:30 +08:00
|
|
|
|
behavior.enabled = true
|
|
|
|
|
control.rotation = 360
|
2023-02-28 23:57:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Canvas {
|
|
|
|
|
id:canvas
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
antialiasing: true
|
|
|
|
|
renderTarget: Canvas.Image
|
|
|
|
|
onPaint: {
|
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
ctx.save();
|
|
|
|
|
ctx.lineWidth = linWidth;
|
|
|
|
|
ctx.strokeStyle = primaryColor;
|
|
|
|
|
ctx.fillStyle = primaryColor;
|
|
|
|
|
ctx.beginPath();
|
|
|
|
|
ctx.arc(width/2, height/2, radius2 ,-0.5 * Math.PI,-0.5 * Math.PI + progress * 2 * Math.PI);
|
|
|
|
|
ctx.stroke();
|
|
|
|
|
ctx.closePath();
|
2023-03-01 11:58:30 +08:00
|
|
|
|
// var start_x = width/2 + Math.cos(-0.5 * Math.PI) * radius2;
|
|
|
|
|
// var start_y = height/2 + Math.sin(-0.5 * Math.PI) * radius2;
|
|
|
|
|
// ctx.beginPath();
|
|
|
|
|
// ctx.arc(start_x, start_y, 3, 0, 2*Math.PI);
|
|
|
|
|
// ctx.fill();
|
|
|
|
|
// ctx.closePath();
|
|
|
|
|
// var end_x = width/2 + Math.cos(-0.5 * Math.PI + progress * 2 * Math.PI) * radius2;
|
|
|
|
|
// var end_y = height/2 + Math.sin(-0.5 * Math.PI + progress * 2 * Math.PI) * radius2;
|
|
|
|
|
// ctx.beginPath();
|
|
|
|
|
// ctx.arc(end_x, end_y, 3, 0, 2*Math.PI);
|
|
|
|
|
// ctx.fill();
|
|
|
|
|
// ctx.closePath();
|
2023-02-28 23:57:55 +08:00
|
|
|
|
ctx.restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
|
|
|
|
}
|