summaryrefslogtreecommitdiffstats
path: root/QtLauncher/CornerFrameImage.qml
blob: 796ff0bba26c9896147985a7396bd347eb59aa3d (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick

Item {
    id: root
    property alias source: contentRect.newImageSource

    onWidthChanged: contentRect.openChanged()
    onHeightChanged: contentRect.openChanged()

    Item {
        id: glowItem
        anchors.fill: contentRect
        visible: contentRect.open

        SequentialAnimation on opacity {
            running: glowItem.visible
            loops: SequentialAnimation.Infinite
            OpacityAnimator {
                from: 0
                to: .5
                duration: 2000
                easing.type: Easing.InOutSine
            }
            OpacityAnimator {
                from: .5
                to: .0
                duration: 2000
                easing.type: Easing.InOutSine
            }
            PauseAnimation {
                duration: 1000
            }
        }

        Image {
            id: borderCorner1
            source: "images/glow_corner.png"
            anchors.right: glowItem.left
            anchors.bottom: glowItem.top
            width: pageMargin * 1.5
            height: width
        }
        Image {
            id: border1
            source: "images/glow_border.png"
            anchors.left: borderCorner1.right
            anchors.right: borderCorner2.left
            anchors.bottom: glowItem.top
            height: pageMargin * 1.5
        }
        Image {
            id: borderCorner2
            source: "images/glow_corner.png"
            anchors.left: glowItem.right
            anchors.bottom: glowItem.top
            width: pageMargin * 1.5
            height: width
            mirror: true
        }
        Image {
            id: border2
            source: "images/glow_border2.png"
            anchors.left: glowItem.right
            anchors.top: borderCorner2.bottom
            anchors.bottom: borderCorner3.top
            mirror: true
            width: pageMargin * 1.5
        }
        Image {
            id: border3
            source: "images/glow_border2.png"
            anchors.right: glowItem.left
            anchors.top: borderCorner1.bottom
            anchors.bottom: borderCorner3.top
            width: pageMargin * 1.5
        }
        Image {
            id: borderCorner3
            source: "images/glow_corner.png"
            anchors.right: glowItem.left
            anchors.top: glowItem.bottom
            mirrorVertically: true
            width: pageMargin * 1.5
            height: width
        }

        Image {
            id: border4
            source: "images/glow_border.png"
            anchors.left: borderCorner3.right
            anchors.right: borderCorner4.left
            anchors.top: glowItem.bottom
            mirrorVertically: true
            height: pageMargin * 1.5
        }

        Image {
            id: borderCorner4
            source: "images/glow_corner.png"
            anchors.left: glowItem.right
            anchors.top: glowItem.bottom
            mirror: true
            mirrorVertically: true
            width: pageMargin * 1.5
            height: width
        }
    }

    Image {
        id: contentRect
        width: -root.width * .006
        height: -root.width * .006
        anchors.centerIn: parent
        smooth: !imageAnimation.running
        property bool open: false
        property string newImageSource: ""

        Rectangle {
            anchors.fill: parent
            color: "transparent"
            border.color: ViewSettings.neon
            border.width: 1
        }

        onNewImageSourceChanged: {
            if (contentRect.open && contentRect.newImageSource) {
                changeImageAnimation.restart()
            } else if (!contentRect.newImageSource.endsWith("_missing")) {
                contentRect.source = contentRect.newImageSource
            }
        }

        onStatusChanged: {
            if (status == Image.Ready)
                contentRect.open = true
            else if (status == Image.Error)
                contentRect.open = false
        }

        onOpenChanged: {
            if (open) {
                var scaleFactor = Math.min(root.width / sourceSize.width, root.height / sourceSize.height)
                contentRect.width = sourceSize.width * scaleFactor
                contentRect.height = sourceSize.height * scaleFactor
            } else {
                contentRect.width = -root.width * .006
                contentRect.height = -root.width * .006
            }
        }

        Behavior on width { NumberAnimation { id: imageAnimation; duration: 500; easing.type: Easing.InOutSine }}
        Behavior on height { NumberAnimation { duration: 500; easing.type: Easing.InOutSine }}

        SequentialAnimation {
            id: changeImageAnimation

            PropertyAction { target: contentRect; property: "open"; value: false}
            PauseAnimation { duration: 500 }

            ScriptAction {
                script: {
                    if (contentRect.newImageSource.endsWith("_missing")) contentRect.newImageSource = ""
                    contentRect.source = contentRect.newImageSource
                }
            }
        }

        Image {
            id: topCorner
            width: contentRect.open && contentRect.status == Image.Ready ? root.width * .2: root.width * .25
            height: width
            x: -width*.124
            y: x
            source: "images/QtCorner.png"

            Behavior on width { NumberAnimation { duration: 500; easing.type: Easing.InOutSine }}
        }

        Image {
            id: bottomCorner
            width: topCorner.width
            height: width
            x: parent.width - width + width * .124
            y: parent.height - height + width * .124
            source: "images/QtCorner.png"
            mirror: true
            mirrorVertically: true
        }
    }
}