2 * Copyright 2020 Robin Krens <robin@robinkrens.nl>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 import QtQuick.Controls 1.2
22 import QtQuick.Layouts 1.0
24 import org.kde.plasma.plasmoid 2.0 as Plasmoid
25 import org.kde.plasma.core 2.0 as PlasmaCore
26 import org.kde.plasma.components 2.0 as PlasmaComponents
28 import "../code/utils.js" as Utils
33 property var snow: [];
34 property int snowCount: Utils.getSnowCount(plasmoid.configuration.userCount);
35 readonly property int screenWidth: Qt.application.screens[0].width;
36 readonly property int screenHeight: Qt.application.screens[0].height;
41 function initializeSnow() {
43 if (snowFalling.running)
46 for (var i = 0; i < snowCount; i++) {
48 var component = Qt.createComponent("snowWindow.qml");
50 snow[i] = component.createObject(root);
52 snow[i].x = Math.random() * screenWidth;
53 snow[i].y = Math.random() * screenHeight;
54 snow[i].width = (Math.random() * 100) % snow[i].radius;
55 snow[i].height = snow[i].width;
59 function startSnow() {
61 for (var i = 0; i < snowCount; i++) {
62 snow[i].showMaximized();
64 snowFalling.running = true;
67 /* End snow flake and start a 'random' new one */
68 function endSnowFlake(i) {
73 var component = Qt.createComponent("snowWindow.qml");
74 snow[i] = component.createObject(root);
76 snow[i].x = Math.random() * screenWidth;
78 snow[i].width = (Math.random() * 100) % snow[i].radius;
79 snow[i].height = snow[i].width;
81 snow[i].showMaximized();
85 function destroySnow() {
87 if (!snowFalling.running)
90 snowFalling.running = false;
92 for (var i = 0; i < snowCount; i++) {
98 function updateSnow() {
100 if (userSpeed.currentText == '') { // hack
104 /* set config for new snow flakes */
105 plasmoid.configuration.userStyle = userStyle.textAt(userStyle.currentIndex);
106 plasmoid.configuration.userSize = userSize.textAt(userSize.currentIndex);
107 plasmoid.configuration.userSpeed = userSpeed.textAt(userSpeed.currentIndex);
109 if (!snowFalling.running || plasmoid.configuration.userSpeed == userSpeed.currentText) // don't update random speed if same
112 /* update current snow flakes*/
113 for (var i = 0; i < snowCount; i++) {
114 snow[i].fallingSpeed = Utils.getFallingSpeed(userSpeed.currentText);
118 /* Update snow count works a bit differently;
119 * can either kill all (implemented now) and start over;
120 * or slowly add/delete new snow flakes */
121 function updateCount() {
123 if (snowFalling == null) // quickhack
126 var alreadyRunning = snowFalling.running;
129 plasmoid.configuration.userCount = userCount.textAt(userCount.currentIndex);
137 Layout.minimumWidth: units.gridUnit * 14;
138 Layout.minimumHeight: units.gridUnit * 10;
143 flow: GridLayout.TopToBottom
146 Label { text: "Speed"; color: theme.textColor; }
147 Label { text: "Size"; color: theme.textColor; }
148 Label { text: "Style"; color: theme.textColor; }
149 Label { text: "Count"; color: theme.textColor; }
150 Button { id: letitsnow; text: "Let it snow!"; onClicked: { initializeSnow(); startSnow(); } }
152 ComboBox { id: userSpeed; width: 100; model: ["Slow", "Normal", "Fast"]; currentIndex: 1; onCurrentIndexChanged: updateSnow(); }
153 ComboBox { id: userSize; width: 100; model: ["Tiny", "Small", "Big"]; currentIndex: 2; onCurrentIndexChanged: updateSnow(); }
154 ComboBox { id: userStyle; width: 100; model: ["Classic", "Plain", "Romantic"]; currentIndex: 0; onCurrentIndexChanged: updateSnow(); }
155 ComboBox { id: userCount; width: 100; model: ["Few", "Medium", "Many"]; currentIndex: 1; onCurrentIndexChanged: updateCount(); }
157 Button { width: 100; text: "Stop"; onClicked: destroySnow(); }
165 interval: 50; running: false; repeat: true
169 for (var i = 0; i < snowCount; i++) {
170 if(snow[i].dir == 0) {
176 if (snow[i].disposition++ % snow[i].swirl == 0) {
177 snow[i].dir = !snow[i].dir;
180 if(snow[i].x > screenWidth) {
182 } else if (snow[i].x < 0) {
183 snow[i].x = screenWidth;
186 snow[i].y += snow[i].fallingSpeed;
188 if (snow[i].y > screenHeight) {
192 if(snow[i].rotationDirection == 0) {
193 snow[i].snowFlakeRotation += snow[i].rotationSpeed;
195 snow[i].snowFlakeRotation -= snow[i].rotationSpeed;