summaryrefslogtreecommitdiff
path: root/components/controls/CircularIndicator.qml
blob: 957899e5c0e742c9528f0f6da591fe381097ea8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import ".."
import qs.services
import qs.config
import Caelestia.Internal
import QtQuick
import QtQuick.Templates

BusyIndicator {
    id: root

    enum AnimType {
        Advance = 0,
        Retreat
    }

    enum AnimState {
        Stopped,
        Running,
        Completing
    }

    property real implicitSize: Appearance.font.size.normal * 3
    property real strokeWidth: Appearance.padding.small * 0.8
    property color fgColour: Colours.palette.m3primary
    property color bgColour: Colours.palette.m3secondaryContainer

    property alias type: manager.indeterminateAnimationType
    readonly property alias progress: manager.progress

    property real internalStrokeWidth: strokeWidth
    property int animState

    padding: 0
    implicitWidth: implicitSize
    implicitHeight: implicitSize

    Component.onCompleted: {
        if (running) {
            running = false;
            running = true;
        }
    }

    onRunningChanged: {
        if (running) {
            manager.completeEndProgress = 0;
            animState = CircularIndicator.Running;
        } else {
            if (animState == CircularIndicator.Running)
                animState = CircularIndicator.Completing;
        }
    }

    states: State {
        name: "stopped"
        when: !root.running

        PropertyChanges {
            root.opacity: 0
            root.internalStrokeWidth: root.strokeWidth / 3
        }
    }

    transitions: Transition {
        Anim {
            properties: "opacity,internalStrokeWidth"
            duration: manager.completeEndDuration * Appearance.anim.durations.scale
        }
    }

    contentItem: CircularProgress {
        anchors.fill: parent
        strokeWidth: root.internalStrokeWidth
        fgColour: root.fgColour
        bgColour: root.bgColour
        padding: root.padding
        rotation: manager.rotation
        startAngle: manager.startFraction * 360
        value: manager.endFraction - manager.startFraction
    }

    CircularIndicatorManager {
        id: manager
    }

    NumberAnimation {
        running: root.animState !== CircularIndicator.Stopped
        loops: Animation.Infinite
        target: manager
        property: "progress"
        from: 0
        to: 1
        duration: manager.duration * Appearance.anim.durations.scale
    }

    NumberAnimation {
        running: root.animState === CircularIndicator.Completing
        target: manager
        property: "completeEndProgress"
        from: 0
        to: 1
        duration: manager.completeEndDuration * Appearance.anim.durations.scale
        onFinished: {
            if (root.animState === CircularIndicator.Completing)
                root.animState = CircularIndicator.Stopped;
        }
    }
}