style, speed, size and count parameters
authorRobin Krens <robin@robinkrens.nl>
Wed, 25 Nov 2020 14:11:27 +0000 (15:11 +0100)
committerRobin Krens <robin@robinkrens.nl>
Wed, 25 Nov 2020 14:11:27 +0000 (15:11 +0100)
.gitignore
contents/code/utils.js [new file with mode: 0644]
contents/config/config.qml
contents/config/main.xml
contents/images/classic.png [new file with mode: 0644]
contents/images/romantic.png [new file with mode: 0644]
contents/images/snow1.png [deleted file]
contents/ui/ConfigGeneral.qml
contents/ui/main.qml
contents/ui/snowWindow.qml
metadata.desktop

index 86950b3..c9f21b5 100644 (file)
@@ -1 +1,2 @@
 *.qmlc
+*.jsc
diff --git a/contents/code/utils.js b/contents/code/utils.js
new file mode 100644 (file)
index 0000000..e77ec49
--- /dev/null
@@ -0,0 +1,69 @@
+
+function getSnowCount(countStr) {
+       
+       var cnt = 25;
+       switch(countStr) {
+               case "Few":
+                       cnt = 12;
+                       break;
+               case "Medium":
+                       cnt = 25;
+                       break;
+               case "Many":
+                       cnt = 50;
+                       break;
+               }
+
+       return cnt;
+}
+
+function getSnowSize(sizeStr) {
+       
+       var size;
+       switch(sizeStr) {
+               case "Tiny":
+                       size = 25;
+                       break;
+               case "Small":
+                       size = 50;
+                       break;
+               case "Big":
+                       size = 100;
+                       break;
+               }
+
+       return size;
+}
+
+function getSnowStyle(style) {
+       
+       var style;
+       switch(styleStr) {
+               case "Classic":
+                       break;
+               case "Plain":
+                       break;
+               case "Romantic":
+                       break;
+               }
+
+       return style;
+}
+
+function getFallingSpeed(speedStr) {
+
+       var speedFunc;
+       switch(speedStr) {
+               case "Slow":
+                       speedFunc =  (Math.random() * 100) % 2 + 1; 
+                       break;
+               case "Normal":
+                       speedFunc =  (Math.random() * 100) % 3 + 2; 
+                       break;
+               case "Fast":
+                       speedFunc = (Math.random() * 100) % 6 + 4;
+                       break;
+               }
+
+       return speedFunc;
+}
index dca86fd..1a27aeb 100644 (file)
@@ -4,8 +4,8 @@ import org.kde.plasma.configuration 2.0
 
 ConfigModel {
     ConfigCategory {
-         name: i18n("Appearance")
-         icon: "view-list-icons"
+         name: i18n("General")
+         icon: "settings-configure"
          source: "ConfigGeneral.qml"
     }
 }
index 9c334d6..6fcb922 100644 (file)
@@ -5,10 +5,22 @@
       http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
   <kcfgfile name=""/>
 
-  <group name="Appearance">
-         <entry name="item_color" type="String">
-                 <label>Set item color shade</label>
-                 <default>red</default>
+  <group name="General">
+         <entry name="userCount" type="String">
+                 <label>Set snow count</label>
+                 <default>Medium</default>
+         </entry>
+         <entry name="userSpeed" type="String">
+                 <label>Set falling speed</label>
+                 <default>Normal</default>
+         </entry>
+         <entry name="userSize" type="String">
+                 <label>Set snow size</label>
+                 <default>Big</default>
+         </entry>
+         <entry name="userStyle" type="String">
+                 <label>Set snow style</label>
+                 <default>Classic</default>
          </entry>
   </group>
 
diff --git a/contents/images/classic.png b/contents/images/classic.png
new file mode 100644 (file)
index 0000000..922f5af
Binary files /dev/null and b/contents/images/classic.png differ
diff --git a/contents/images/romantic.png b/contents/images/romantic.png
new file mode 100644 (file)
index 0000000..4178e4d
Binary files /dev/null and b/contents/images/romantic.png differ
diff --git a/contents/images/snow1.png b/contents/images/snow1.png
deleted file mode 100644 (file)
index 9ab4522..0000000
Binary files a/contents/images/snow1.png and /dev/null differ
index 59e2cbf..84b66b6 100644 (file)
@@ -29,7 +29,6 @@ Item {
        height: childrenRect.height
        implicitWidth: pageColumn.implicitWidth
        implicitHeight: pageColumn.implicitHeight
-       property string cfg_item_color;
 
        SystemPalette {
                id: sypal
@@ -41,19 +40,10 @@ Item {
 
                anchors.left: parent.left
                PlasmaExtras.Heading {
-               text: i18nc("Heading for colors", "Item shade color")
+               text: i18nc("TOD", "No config options (yet)")
                color: syspal.text
                level: 3
        }
 
-       /* User can't specify an exact color, since i'm using
-        * gradients and alpha for colors */
-       QtControls.ComboBox {
-               id: dot
-               model: ["red", "green", "blue"];
-               currentIndex: dot.model.indexOf(cfg_item_color)
-               onActivated: cfg_item_color = model[index]
-       }
-
     }
 }
index 8881ec7..b6bb57e 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-import QtQuick 2.6
+import QtQuick 2.3
+import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.0
-import QtQuick.Window 2.2
 
-//import org.kde.plasma.plasmoid 2.0 as Plasmoid
-//import org.kde.plasma.core 2.0 as PlasmaCore
-//import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.plasma.plasmoid 2.0 as Plasmoid
+import org.kde.plasma.core 2.0 as PlasmaCore
+import org.kde.plasma.components 2.0 as PlasmaComponents
 
-import QtQuick 2.3
-import QtQuick.Controls 1.2
+import "../code/utils.js" as Utils
 
 Item {
        id: root;
        
        property var snow: [];
-       readonly property int snowCount: 25;
+       property int snowCount: Utils.getSnowCount(plasmoid.configuration.userCount);
        readonly property int screenWidth: Qt.application.screens[0].width;
        readonly property int screenHeight: Qt.application.screens[0].height;
-       
-       Button {
 
-               id: letitsnow;
+       width: 250;
+       height: 180;
 
-               anchors.centerIn: parent;
-               text: "Let it snow!";
+       function initializeSnow() {
 
-               onClicked: {
-                       
-                       for (var i = 0; i < snowCount; i++) {
-                               
-                               var component = Qt.createComponent("snowWindow.qml");
+               if (snowFalling.running)
+                       return;
+
+               for (var i = 0; i < snowCount; i++) {
                                
-                               snow[i] = component.createObject(root);
+                       var component = Qt.createComponent("snowWindow.qml");
+                       
+                       snow[i] = component.createObject(root);
                                
-                               snow[i].x = Math.random() * screenWidth;
-                               snow[i].y = Math.random() * screenHeight;
+                       snow[i].x = Math.random() * screenWidth;
+                       snow[i].y = Math.random() * screenHeight;
+                       snow[i].width = (Math.random() * 100) % snow[i].radius;
+                       snow[i].height = snow[i].width;
+               }
+       }
 
-                               snow[i].width = (Math.random() * 100) % snow[i].radius;
-                               snow[i].height = snow[i].width;
+       function startSnow() {
 
-                               snow[i].showMaximized();
-                       }
+               for (var i = 0; i < snowCount; i++) {
+                       snow[i].showMaximized();
+               }
+               snowFalling.running = true;
+       }
+
+       /* End snow flake and start a 'random' new one */
+       function endSnowFlake(i) { 
+               
+               snow[i].close();
+               snow[i].destroy();
+               
+               var component = Qt.createComponent("snowWindow.qml");
+               snow[i] = component.createObject(root);
+       
+               snow[i].x = Math.random() * screenWidth;
+               snow[i].y = -10;
+               snow[i].width = (Math.random() * 100) % snow[i].radius;
+               snow[i].height = snow[i].width;
+
+               snow[i].showMaximized();
+
+       }
+
+       function destroySnow() {
+
+               if (!snowFalling.running)
+                       return;
+
+               snowFalling.running = false;
+               
+               for (var i = 0; i < snowCount; i++) {
+                       snow[i].close();
+                       snow[i].destroy();
+               }
+       }
+
+       function updateSnow() {
+
+               if (userSpeed.currentText == '') { // hack
+                       console.log('not initialized yet');     
+                       return;
+               }
+
+               /* set config for new snow flakes */
+               plasmoid.configuration.userStyle = userStyle.textAt(userStyle.currentIndex);
+               plasmoid.configuration.userSize = userSize.textAt(userSize.currentIndex);
+               plasmoid.configuration.userSpeed = userSpeed.textAt(userSpeed.currentIndex);
+       
+               if (!snowFalling.running || plasmoid.configuration.userSpeed == userSpeed.currentText) // don't update random speed if same
+                       return;
+
+               /* update current snow flakes*/
+               for (var i = 0; i < snowCount; i++) {
+                       snow[i].fallingSpeed = Utils.getFallingSpeed(userSpeed.currentText);
+               }
+       }
+       
+       /* Update snow count works a bit differently; 
+        * can either kill all (implemented now) and start over;
+        * or slowly add/delete new snow flakes  */
+       function updateCount() {
+
+               var alreadyRunning = snowFalling.running;
+               
+               destroySnow();
+               plasmoid.configuration.userCount = userCount.textAt(userCount.currentIndex);
+               initializeSnow();
+
+               if (alreadyRunning)
+                       startSnow();
+
+       }
+
+        GridLayout {
+                id: gridLayout
+                rows: 5
+                flow: GridLayout.TopToBottom
+                anchors.fill: parent
+
+                Label { text: "Speed"; color: theme.textColor; }
+                Label { text: "Size"; color: theme.textColor; }
+               Label { text: "Style"; color: theme.textColor;  }
+               Label { text: "Count"; color: theme.textColor;  }
+               Button { id: letitsnow; text: "Let it snow!"; onClicked: { initializeSnow(); startSnow(); } }
+
+                ComboBox { id: userSpeed; width: 100; model: ["Slow", "Normal", "Fast"]; currentIndex: 1; onCurrentIndexChanged: updateSnow(); }       
+                ComboBox { id: userSize; width: 100; model: ["Tiny", "Small", "Big"]; currentIndex: 2; onCurrentIndexChanged: updateSnow(); }  
+               ComboBox { id: userStyle; width: 100; model: ["Classic", "Plain", "Romantic"]; currentIndex: 0; onCurrentIndexChanged: updateSnow(); }  
+               ComboBox { id: userCount; width: 100; model: ["Few", "Medium", "Many"]; currentIndex: 1; onCurrentIndexChanged: updateCount(); }        
                        
-                       snowFalling.running = true;
-               }
+               Button { width: 100; text: "Stop"; onClicked: destroySnow(); }
+
        }
 
        Timer {
 
                id: snowFalling
 
-               function test() {
-               }
-
                interval: 50; running: false; repeat: true
                
                onTriggered: {
@@ -92,25 +178,10 @@ Item {
                                        snow[i].x = 1440;
                                }
 
-                               //snow[i].y += 2;
                                snow[i].y += snow[i].fallingSpeed;
 
                                if (snow[i].y > screenHeight) {
-                                       //snow[i].y = 0;
-                                       
-                                       snow[i].close();
-                                       snow[i].destroy();
-                                       
-                                       var component = Qt.createComponent("snowWindow.qml");
-                                       snow[i] = component.createObject(root);
-                               
-                                       snow[i].x = Math.random() * screenWidth;
-                                       snow[i].y = 0;
-                                       snow[i].width = (Math.random() * 100) % snow[i].radius;
-                                       snow[i].height = snow[i].width;
-
-                                       snow[i].showMaximized();
-
+                                       endSnowFlake(i);        
                                }
 
                                if(snow[i].rotationDirection == 0) {
@@ -121,6 +192,6 @@ Item {
 
                        }
                }
-       }
+       }
 
 }
index 7273f6e..8973ddd 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-import QtQuick 2.6
-import QtQuick.Controls 1.4
+import QtQuick 2.3
+import QtQuick.Controls 1.2
 import QtQuick.Window 2.2
 
+import org.kde.plasma.plasmoid 2.0
+
+import "../code/utils.js" as Utils
+
 ApplicationWindow {
        
        id: root;
 
-       property int dir: (Math.random() * 100) % 2; /* could go either left or right */
-       property int radius: 100; /* size of snowflake */
-       property int swirl: (Math.random() * 1000) % 55 + 2; /* random falling 'swirl' */
+       property int dir: getRandomIntInclusive(0,1); /* could go either left or right */
+       property int radius: Utils.getSnowSize(plasmoid.configuration.userSize); /* size of snowflake */
+       property int swirl: getRandomIntInclusive(35,200); /* random falling 'swirl' */
        property int disposition: 0;
        property alias snowFlakeRotation: snowFlake.rotation;
-       property int rotationSpeed: (Math.random() * 100) % 3 + 1; /* falling rotation */
-       property int rotationDirection: (Math.random() * 100) % 2;
-       property int fallingSpeed: (Math.random() * 100) % 3 + 2;
+       //property int rotationSpeed: (Math.random() * 100) % 3 + 1; /* falling rotation */
+       property int rotationSpeed: getRandomIntInclusive(1,4);
+       property int rotationDirection: getRandomIntInclusive(0,1);
+       //property int fallingSpeed: (Math.random() * 100) % 3 + 2; 
+       property int fallingSpeed: Utils.getFallingSpeed(plasmoid.configuration.userSpeed);
 
        //width: 80; height: 80;
        opacity: 0.5;
@@ -45,19 +51,43 @@ ApplicationWindow {
                | Qt.WA_TranslucentBackground 
                | Qt.X11BypassWindowManagerHint;
 
+       /* Basic functions (fro, developer.mozilla.org) */
+       function getRandomIntInclusive(min, max) {
+               min = Math.ceil(min);
+               max = Math.floor(max);
+               return Math.floor(Math.random() * (max - min + 1) + min);
+       }
+
        Rectangle {
                
                id: snowFlake;
                
                anchors.fill: parent;
-               //radius: 3;
-               color: "transparent";
+               radius: plasmoid.configuration.userStyle == "Plain" ? 50 : 0;
+               color: plasmoid.configuration.userStyle == "Plain" ? "white" : "transparent";
                
                Image {
                        id: snowFlakeImage;
 
+                       function setImage() {
+
+                               var imgSrc = "";
+                               switch(plasmoid.configuration.userStyle) {
+                                       case "Classic":
+                                       imgSrc = "../images/classic.png";
+                                       break;
+                                       case "Plain":
+                                       break;
+                                       case "Romantic":
+                                       imgSrc = "../images/romantic.png";
+                                       break;
+                               }       
+                               return imgSrc;
+                       }
+
                        anchors.fill: parent;
-                       source: "../images/snow1.png";
+                       source: setImage(); 
+                       //source:  "../images/romantic.png";
                }
 
        }
index 9f02ec9..d86d39f 100644 (file)
@@ -20,5 +20,3 @@ X-KDE-PluginInfo-License=GPL
 X-KDE-PluginInfo-EnabledByDefault=true
 X-KDE-FormFactors=desktop
 
-[Settings]
-FallbackTheme=breeze-dark