aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/fluentwinui3/BusyIndicator.qml
blob: 1d59ea147449741bc6b7a194c64976559ed90b93 (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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

import QtQuick
import QtQuick.Templates as T
import QtQuick.Shapes

T.BusyIndicator {
    id: control

    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                            implicitContentWidth + leftPadding + rightPadding)
    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                             implicitContentHeight + topPadding + bottomPadding)

    contentItem: Item {
        implicitWidth: 32
        implicitHeight: 32
        x: (control.availableWidth - width) / 2
        y: (control.availableHeight - height) / 2

        property Shape ring: Shape {
            parent: control.contentItem
            x: (parent.width - width) / 2
            y: (parent.height - height) / 2
            implicitWidth: parent.implicitWidth
            implicitHeight: parent.implicitHeight
            width: Math.min(control.contentItem.width, control.contentItem.height)
            height: width
            preferredRendererType: Shape.CurveRenderer
            antialiasing: true

            ShapePath {
                fillColor: "transparent"
                strokeColor: control.palette.accent
                strokeWidth: control.contentItem.ring.width >= 64 ? 6 : control.contentItem.ring.width <= 16 ? 1 : 3

                capStyle: ShapePath.RoundCap

                PathAngleArc {
                    centerX: control.contentItem.ring.width / 2
                    centerY: control.contentItem.ring.height / 2
                    radiusX: control.contentItem.ring.width / 2 - 2
                    radiusY: radiusX
                    startAngle: -90
                    sweepAngle: 120

                    SequentialAnimation on startAngle {
                        loops: Animation.Infinite
                        running: control.visible && control.running
                        NumberAnimation { from: 0; to: 450; duration: 1000 }
                        NumberAnimation { from: 450; to: 1080; duration: 1000 }
                    }

                    SequentialAnimation on sweepAngle {
                        loops: Animation.Infinite
                        running: control.visible && control.running
                        NumberAnimation { from: 0; to: 180; duration: 1000 }
                        NumberAnimation { from: 180; to: 0; duration: 1000 }
                    }
                }
            }
        }
    }
}