aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/stylekit/StyleKitAnimation.qml
blob: e7947eb48a260ce5534e5ea4c64f369c5fb04c7b (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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

ParallelAnimation {
    id: root
    property alias easing: colorAnimation.easing
    property alias duration: colorAnimation.duration

    property bool animateColors: false
    property bool animateControlGeometry: false

    property bool animateBackgroundColors: false
    property bool animateBackgroundGeometry: false
    property bool animateBackgroundRadii: false
    property bool animateBackgroundBorder: false
    property bool animateBackgroundShadow: false
    property bool animateBackgroundScaleAndRotation: false

    property bool animateHandleColors: false
    property bool animateHandleGeometry: false
    property bool animateHandleRadii: false
    property bool animateHandleBorder: false
    property bool animateHandleShadow: false
    property bool animateHandleScaleAndRotation: false

    property bool animateIndicatorColors: false
    property bool animateIndicatorGeometry: false
    property bool animateIndicatorBorder: false
    property bool animateIndicatorRadii: false
    property bool animateIndicatorShadow: false
    property bool animateIndicatorScaleAndRotation: false

    readonly property string __geometryProps:
        "$.implicitWidth, $.implicitHeight, "
        + "$.margins, $.leftMargin, $.rightMargin, $.topMargin, $.bottomMargin, "
        + "$.leftPadding, $.rightPadding, $.topPadding, $.bottomPadding, "
        + "$.minimumWidth, "
    readonly property string __colorProps:
        "$.color, $.border.color, $.image.color, $.shadow.color, "
    readonly property string __radiiProps:
        "$.radius, $.topLeftRadius, $.topRightRadius, $.bottomLeftRadius, $.bottomRightRadius, "
    readonly property string __scaleAndRotationProps: "$.scale, $.rotation, "
    readonly property string __borderProps: "$.border.width, "
    readonly property string __shadowProps:
        "$.shadow.verticalOffset, $.shadow.horizontalOffset, "
        + "$.shadow.scale, $.shadow.blur, "


    function __animateIndicators(doAnimate, anim, props) {
        if (!doAnimate)
            return
        anim.properties += props.replace(/\$/g, "indicator")
        anim.properties += props.replace(/\$/g, "indicator.foreground")
        anim.properties += props.replace(/\$/g, "indicator.up")
        anim.properties += props.replace(/\$/g, "indicator.up.foreground")
        anim.properties += props.replace(/\$/g, "indicator.down")
        anim.properties += props.replace(/\$/g, "indicator.down.foreground")
    }

    function __animateHandles(doAnimate, anim, props) {
        if (!doAnimate)
            return
        anim.properties += props.replace(/\$/g, "handle")
        anim.properties += props.replace(/\$/g, "handle.first")
        anim.properties += props.replace(/\$/g, "handle.second")
    }

    Component.onCompleted: {
        if (animateControlGeometry)
            numberAnimation.properties += "spacing, padding, leftPadding, rightPadding, topPadding, bottomPadding"

        if (animateBackgroundGeometry)
            numberAnimation.properties += __geometryProps.replace(/\$/g, "background")
        if (animateBackgroundRadii)
            numberAnimation.properties += __radiiProps.replace(/\$/g, "background")
        if (animateBackgroundBorder)
            numberAnimation.properties += __borderProps.replace(/\$/g, "background")
        if (animateBackgroundShadow)
            numberAnimation.properties += __shadowProps.replace(/\$/g, "background")
        if (animateBackgroundScaleAndRotation)
            numberAnimation.properties += __scaleAndRotationProps.replace(/\$/g, "background")

        __animateIndicators(animateIndicatorGeometry, numberAnimation, __geometryProps)
        __animateIndicators(animateIndicatorRadii, numberAnimation, __radiiProps)
        __animateIndicators(animateIndicatorBorder, numberAnimation, __borderProps)
        __animateIndicators(animateIndicatorShadow, numberAnimation, __shadowProps)
        __animateIndicators(animateIndicatorScaleAndRotation, numberAnimation, __scaleAndRotationProps)

        __animateHandles(animateHandleGeometry, numberAnimation, __geometryProps)
        __animateHandles(animateHandleRadii, numberAnimation, __radiiProps)
        __animateHandles(animateHandleBorder, numberAnimation, __borderProps)
        __animateHandles(animateHandleShadow, numberAnimation, __shadowProps)
        __animateHandles(animateHandleScaleAndRotation, numberAnimation, __scaleAndRotationProps)

        if (!animateColors) {
            /* Note: a ColorAnimation will animate all colors by default if 'properties'
             * is empty. So we take advantage of that, and only add the per-delegate properties
             * when not all colors should animate. For the same reason, we need to set properties
             * to something else than "" if no colors should animate. */
            if (animateBackgroundColors)
                colorAnimation.properties += __colorProps.replace(/\$/g, "background")
            __animateIndicators(animateIndicatorColors, colorAnimation, __colorProps)
            __animateHandles(animateHandleColors, colorAnimation, __colorProps)

            if (colorAnimation.properties === "")
                colorAnimation.properties = "_none_"
        }
    }

    ColorAnimation {
        id: colorAnimation
    }

    NumberAnimation {
        id: numberAnimation
        easing: root.easing
        duration: root.duration
    }
}