StartupFeedback.qml 4.68 KB
Newer Older
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
/*
 *   Copyright 2015 Marco Martin <notmart@gmail.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.12
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import QtGraphicalEffects 1.12

26
27
import org.kde.kirigami 2.13 as Kirigami

28
29
30
31
32
pragma Singleton

Window {
    id: window

33
34
35
36
37
38
    Kirigami.ImageColors {
        id: colorGenerator

        source: icon.source
    }

39
    function open(splashIcon, title, x, y, sourceIconSize, color) {
Marco Martin's avatar
Marco Martin committed
40
41
        iconParent.scale = sourceIconSize/iconParent.width;
        background.scale = 0;
42
43
44
45
        background.x = -window.width/2 + x
        background.y = -window.height/2 + y
        window.title = title;
        icon.source = splashIcon;
46
47
48
49
50

        if (color !== undefined) {
            background.color = color
        }

51
52
53
54
55
        background.state = "open";
    }

    property alias state: background.state
    property alias icon: icon.source
56

57
58
59
60
61
62
63
64
65
66
67
68
69
    width: Screen.width
    height: Screen.height
    onVisibleChanged: {
        if (!visible) {
            background.state = "closed";
        }
    }
    onActiveChanged: {
        if (!active) {
            background.state = "closed";
        }
    }

Marco Martin's avatar
Marco Martin committed
70
71
72
73
74
    Timer {
        running: background.state == "open"
        interval: 15000
        onTriggered: background.state = "closed";
    }
75

Marco Martin's avatar
Marco Martin committed
76
77
78
79
80
81
    Item {
        id: iconParent
        z: 2
        anchors.centerIn: background
        width: units.iconSizes.enormous
        height: width
82
83
        PlasmaCore.IconItem {
            id: icon
Marco Martin's avatar
Marco Martin committed
84
            anchors.fill:parent
85
86
87
88
89
90
91
92
93
94
95
            colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
        }
        DropShadow {
            anchors.fill: icon
            horizontalOffset: 0
            verticalOffset: 0
            radius: 8.0
            samples: 17
            color: "#80000000"
            source: icon
        }
Marco Martin's avatar
Marco Martin committed
96
97
98
99
100
101
    }
    Rectangle {
        id: background
        width: window.width
        height: window.height

102
103
        color: colorGenerator.dominant

Marco Martin's avatar
Marco Martin committed
104
        state: "closed"
105
106
107
108
109
110
111
112
113
114
115

        states: [
            State {
                name: "closed"
                PropertyChanges {
                    target: window
                    visible: false
                }
            },
            State {
                name: "open"
Marco Martin's avatar
Marco Martin committed
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                PropertyChanges {
                    target: window
                    visible: true
                }
            }
        ]

        transitions: [
            Transition {
                from: "closed"
                SequentialAnimation {
                    ScriptAction {
                        script: { 
                            window.showMaximized();
                        }
                    }
                    ParallelAnimation {
                        ScaleAnimator {
                            target: background
Marco Martin's avatar
Marco Martin committed
136
137
138
139
140
141
142
143
144
                            from: background.scale
                            to: 1
                            duration: units.longDuration
                            easing.type: Easing.InOutQuad
                        }
                        ScaleAnimator {
                            target: iconParent
                            from: iconParent.scale
                            to: 1
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                            duration: units.longDuration
                            easing.type: Easing.InOutQuad
                        }
                        NumberAnimation {
                            target: background
                            property: "x"
                            to: 0
                            duration: units.longDuration
                            easing.type: Easing.InOutQuad
                        }
                        NumberAnimation {
                            target: background
                            property: "y"
                            to: 0
                            duration: units.longDuration
                            easing.type: Easing.InOutQuad
                        }
                    }
                }
            }
        ]
    }
}