StartupFeedback.qml 5.25 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

Marco Martin's avatar
Marco Martin committed
28
29
import org.kde.plasma.private.nanoshell 2.0 as NanoShell

30
31
pragma Singleton

Marco Martin's avatar
Marco Martin committed
32
Window {
33
34
    id: window

Marco Martin's avatar
Marco Martin committed
35
    property alias backgroundColor: background.color
36
37
38
39
    Kirigami.ImageColors {
        id: colorGenerator
    }

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

        if (color !== undefined) {
Jonah Brüchert's avatar
Jonah Brüchert committed
50
            // Break binding to use custom color
51
            background.color = color
Jonah Brüchert's avatar
Jonah Brüchert committed
52
53
54
        } else {
            // Recreate binding
            background.color = Qt.binding(function() { return colorGenerator.dominant})
55
56
        }

57
58
59
60
61
        background.state = "open";
    }

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

63
64
    width: Screen.width
    height: Screen.height
65
    color: "transparent"
66
67
68
69
70
71
72
73
74
75
76
    onVisibleChanged: {
        if (!visible) {
            background.state = "closed";
        }
    }
    onActiveChanged: {
        if (!active) {
            background.state = "closed";
        }
    }

Marco Martin's avatar
Marco Martin committed
77
78
79
80
81
82
    Item {
        id: iconParent
        z: 2
        anchors.centerIn: background
        width: units.iconSizes.enormous
        height: width
83
84
        PlasmaCore.IconItem {
            id: icon
Marco Martin's avatar
Marco Martin committed
85
            anchors.fill:parent
86
87
88
89
90
91
92
93
94
95
96
            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
97
    }
Marco Martin's avatar
Marco Martin committed
98

Marco Martin's avatar
Marco Martin committed
99
100
101
102
103
    Rectangle {
        id: background
        width: window.width
        height: window.height

104
105
        color: colorGenerator.dominant

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

        states: [
            State {
                name: "closed"
                PropertyChanges {
                    target: window
                    visible: false
                }
Marco Martin's avatar
Marco Martin committed
115
116
117
118
                PropertyChanges {
                    target: fill
                    opacity: 0
                }
119
120
121
            },
            State {
                name: "open"
Marco Martin's avatar
Marco Martin committed
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
                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
142
143
144
145
146
147
148
149
150
                            from: background.scale
                            to: 1
                            duration: units.longDuration
                            easing.type: Easing.InOutQuad
                        }
                        ScaleAnimator {
                            target: iconParent
                            from: iconParent.scale
                            to: 1
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
                            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
                        }
                    }
Marco Martin's avatar
Marco Martin committed
169
170
171
172
173
174
175
                    OpacityAnimator {
                        target: fill
                        from: 0
                        to: 1
                        duration: units.shortDuration
                        easing.type: Easing.InOutQuad
                    }
176
177
178
179
180
                }
            }
        ]
    }
}