From 5a158f6c65efb78beec10b27329f56d99717e03b Mon Sep 17 00:00:00 2001
From: Filippo Scognamiglio <flscogna@gmail.com>
Date: Wed, 25 Dec 2013 21:04:10 +0100
Subject: [PATCH] readded an improved screen flickering

---
 qml/cool-old-term/SettingsWindow.qml |  5 +++++
 qml/cool-old-term/main.qml           | 26 ++++++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/qml/cool-old-term/SettingsWindow.qml b/qml/cool-old-term/SettingsWindow.qml
index 784265f..679d8f9 100644
--- a/qml/cool-old-term/SettingsWindow.qml
+++ b/qml/cool-old-term/SettingsWindow.qml
@@ -72,6 +72,11 @@ ApplicationWindow {
                         onValueChanged: shadersettings.screen_distortion = value;
                         Component.onCompleted:  _value = shadersettings.screen_distortion;
                     }
+                    SettingComponent{
+                        name: "Screen flickering"
+                        onValueChanged: shadersettings.brightness_flickering = value;
+                        Component.onCompleted:  _value = shadersettings.brightness_flickering;
+                    }
                 }
             }
         }
diff --git a/qml/cool-old-term/main.qml b/qml/cool-old-term/main.qml
index 2499ae9..96d54e1 100644
--- a/qml/cool-old-term/main.qml
+++ b/qml/cool-old-term/main.qml
@@ -91,15 +91,25 @@ ApplicationWindow{
 
             property real scanlines: shadersettings.scanlines ? 1.0 : 0.0
 
-            NumberAnimation on brightness{
-                property real randval: 0
-                to: 1.0
-                duration: 300
-                onStopped: {
-                    to = 1 - Math.random() * shadersettings.brightness_flickering;
-                    start();
+            Behavior on brightness {
+                NumberAnimation{
+                    duration: 250
+                    onRunningChanged:
+                        if(!running) shadercontainer.brightness = 1.0;
                 }
-                running: false
+            }
+
+            Timer{
+                property real randval
+                id: flickertimer
+                interval: 500
+                onTriggered: {
+                    randval = Math.random();
+                    if(randval < shadersettings.brightness_flickering)
+                        shadercontainer.brightness = Math.random() * 0.5 + 0.5;
+                }
+                running: true
+                repeat: true
             }
 
             property real deltay: 3 / terminal.height