aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/animation/behaviors/FocusRect.qml
blob: 9841162e571cdc63a6fb8c1a73629869535a647f (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick

Rectangle {
    id: focusRect
    property string text

    x: 62
    y: 75
    width: 75
    height: 50
    radius: 6
    border.width: 4
    border.color: "white"
    color: "firebrick"

    // Set an 'elastic' behavior on the focusRect's x property.
    Behavior on x {
        NumberAnimation {
            easing.type: Easing.OutElastic
            easing.amplitude: 3.0
            easing.period: 2.0
            duration: 300
        }
    }

    //! [0]
    // Set an 'elastic' behavior on the focusRect's y property.
    Behavior on y {
        NumberAnimation {
            easing.type: Easing.OutElastic
            easing.amplitude: 3.0
            easing.period: 2.0
            duration: 300
        }
    }
    //! [0]

    Text {
        id: focusText
        text: focusRect.text
        anchors.centerIn: parent
        color: "white"
        font.pixelSize: 16
        font.bold: true

        // Set a behavior on the focusText's x property:
        // Set the opacity to 0, set the new text value, then set the opacity back to 1.
        Behavior on text {
            SequentialAnimation {
                NumberAnimation {
                    target: focusText
                    property: "opacity"
                    to: 0
                    duration: 150
                }
                NumberAnimation {
                    target: focusText
                    property: "opacity"
                    to: 1
                    duration: 150
                }
            }
        }
    }
}