more cleanup
[qt-letitsnow] / contents / ui / snowWindow.qml
1
2 /*
3  *   Copyright 2020 Robin Krens <robin@robinkrens.nl>
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU Library General Public License as
7  *   published by the Free Software Foundation; either version 2 or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details
14  *
15  *   You should have received a copy of the GNU Library General Public
16  *   License along with this program; if not, write to the
17  *   Free Software Foundation, Inc.,
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 import QtQuick 2.3
22 import QtQuick.Controls 1.2
23 import QtQuick.Window 2.2
24
25 import org.kde.plasma.plasmoid 2.0
26
27 import "../code/utils.js" as Utils
28
29 ApplicationWindow {
30         
31         id: root;
32
33         property int dir: getRandomIntInclusive(0,1); /* could go either left or right */
34         property int radius: Utils.getSnowSize(plasmoid.configuration.userSize); /* size of snowflake */
35         property int swirl: getRandomIntInclusive(35,200); /* random falling 'swirl' */
36         property int disposition: 0;
37         property alias snowFlakeRotation: snowFlake.rotation;
38         property int rotationSpeed: getRandomIntInclusive(1,4);
39         property int rotationDirection: getRandomIntInclusive(0,1);
40         property int fallingSpeed: Utils.getFallingSpeed(plasmoid.configuration.userSpeed);
41
42         opacity: 0.5;
43         color: "transparent";
44
45         flags: Qt.WindowStaysOnTopHint 
46                 | Qt.FramelessWindowHint
47                 | Qt.WA_TransparentForMouseEvents
48                 | Qt.WA_TranslucentBackground 
49                 | Qt.X11BypassWindowManagerHint;
50
51         /* Basic functions (fro, developer.mozilla.org) */
52         function getRandomIntInclusive(min, max) {
53                 min = Math.ceil(min);
54                 max = Math.floor(max);
55                 return Math.floor(Math.random() * (max - min + 1) + min);
56         }
57
58         Rectangle {
59                 
60                 id: snowFlake;
61                 
62                 anchors.fill: parent;
63                 radius: plasmoid.configuration.userStyle == "Plain" ? 50 : 0;
64                 color: plasmoid.configuration.userStyle == "Plain" ? "white" : "transparent";
65                 
66                 Image {
67                         id: snowFlakeImage;
68
69                         function setImage() {
70
71                                 var imgSrc = "";
72                                 switch(plasmoid.configuration.userStyle) {
73                                         case "Classic":
74                                         imgSrc = "../images/classic.png";
75                                         break;
76                                         case "Plain":
77                                         break;
78                                         case "Romantic":
79                                         imgSrc = "../images/romantic.png";
80                                         break;
81                                 }       
82                                 return imgSrc;
83                         }
84
85                         anchors.fill: parent;
86                         source: setImage(); 
87                 }
88
89         }
90
91
92 }