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

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

55
56
57
58
59
        background.state = "open";
    }

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

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

Marco Martin's avatar
Marco Martin committed
75
76
77
78
79
    Timer {
        running: background.state == "open"
        interval: 15000
        onTriggered: background.state = "closed";
    }
80

Marco Martin's avatar
Marco Martin committed
81
82
83
84
85
86
    Item {
        id: iconParent
        z: 2
        anchors.centerIn: background
        width: units.iconSizes.enormous
        height: width
87
88
        PlasmaCore.IconItem {
            id: icon
Marco Martin's avatar
Marco Martin committed
89
            anchors.fill:parent
90
91
92
93
94
95
96
97
98
99
100
            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
101
102
103
104
105
106
    }
    Rectangle {
        id: background
        width: window.width
        height: window.height

107
108
        color: colorGenerator.dominant

Marco Martin's avatar
Marco Martin committed
109
        state: "closed"
110
111
112
113
114
115
116
117
118
119
120

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

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