aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/stylekit/ProgressBar.qml
blob: ebb6868b0fe589b19bb4f658ada544b9911eb6b3 (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
// Copyright (C) 2025 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 Qt.labs.StyleKit
import Qt.labs.StyleKit.impl

T.ProgressBar {
    id: control

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

    leftPadding: styleReader.leftPadding
    topPadding: styleReader.topPadding
    rightPadding: styleReader.rightPadding
    bottomPadding: styleReader.bottomPadding
    spacing: styleReader.spacing

    StyleKitControl.controlType: styleReader.type
    StyleKitReader {
        id: styleReader
        type: StyleKitReader.ProgressBar
        enabled: control.enabled
        focused: control.activeFocus
        hovered: control.hovered
        palette: control.palette
    }

    contentItem: IndicatorDelegate {
        parentControl: control
        indicatorProperties: styleReader.indicator
        secondProgress: control.visualPosition

        Connections {
            target: control
            function onIndeterminateChanged() {
                if (indeterminate) {
                    control.contentItem.firstProgress = 0
                    control.contentItem.secondProgress = 0
                    control.contentItem.indeterminateAnim.restart()
                } else {
                    control.contentItem.indeterminateAnim.stop()
                    control.contentItem.firstProgress = 0
                    control.contentItem.secondProgress = Qt.binding(()=>{ return control.visualPosition })
                }
            }
        }

        Behavior on firstProgress {
            enabled: !control.indeterminate && !control.contentItem.indeterminateAnim.running
            NumberAnimation {
                duration: 100
                easing.type: Easing.Linear
            }
        }

        Behavior on secondProgress {
            enabled: !control.indeterminate && !control.contentItem.indeterminateAnim.running
            NumberAnimation {
                duration: 100
                easing.type: Easing.Linear
            }
        }

        property Animation indeterminateAnim: SequentialAnimation {
            running: control.indeterminate
            loops: Animation.Infinite
            NumberAnimation {
                target: control.contentItem
                property: "secondProgress"
                to: 1
                duration: 300
                easing.type: Easing.Linear
            }
            NumberAnimation {
                target: control.contentItem
                property: "firstProgress"
                to: 0.95
                duration: 600
                easing.type: Easing.OutExpo
            }
            NumberAnimation {
                target: control.contentItem
                property: "firstProgress"
                to: 0
                duration: 300
                easing.type: Easing.Linear
            }
            NumberAnimation {
                target: control.contentItem
                property: "secondProgress"
                to: 0.05
                duration: 600
                easing.type: Easing.OutExpo
            }
        }
    }

    background: BackgroundDelegate {
        parentControl: control
        backgroundProperties: styleReader.background
    }
}