8973ddd17dd4562a88fcfc450c764242a0491f6d
[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: (Math.random() * 100) % 3 + 1; /* falling rotation */
39         property int rotationSpeed: getRandomIntInclusive(1,4);
40         property int rotationDirection: getRandomIntInclusive(0,1);
41         //property int fallingSpeed: (Math.random() * 100) % 3 + 2; 
42         property int fallingSpeed: Utils.getFallingSpeed(plasmoid.configuration.userSpeed);
43
44         //width: 80; height: 80;
45         opacity: 0.5;
46         color: "transparent";
47
48         flags: Qt.WindowStaysOnTopHint 
49                 | Qt.FramelessWindowHint
50                 | Qt.WA_TransparentForMouseEvents
51                 | Qt.WA_TranslucentBackground 
52                 | Qt.X11BypassWindowManagerHint;
53
54         /* Basic functions (fro, developer.mozilla.org) */
55         function getRandomIntInclusive(min, max) {
56                 min = Math.ceil(min);
57                 max = Math.floor(max);
58                 return Math.floor(Math.random() * (max - min + 1) + min);
59         }
60
61         Rectangle {
62                 
63                 id: snowFlake;
64                 
65                 anchors.fill: parent;
66                 radius: plasmoid.configuration.userStyle == "Plain" ? 50 : 0;
67                 color: plasmoid.configuration.userStyle == "Plain" ? "white" : "transparent";
68                 
69                 Image {
70                         id: snowFlakeImage;
71
72                         function setImage() {
73
74                                 var imgSrc = "";
75                                 switch(plasmoid.configuration.userStyle) {
76                                         case "Classic":
77                                         imgSrc = "../images/classic.png";
78                                         break;
79                                         case "Plain":
80                                         break;
81                                         case "Romantic":
82                                         imgSrc = "../images/romantic.png";
83                                         break;
84                                 }       
85                                 return imgSrc;
86                         }
87
88                         anchors.fill: parent;
89                         source: setImage(); 
90                         //source:  "../images/romantic.png";
91                 }
92
93         }
94
95
96 }