Reduce assumptions in examples
authorAlan Alpert <alan.alpert@nokia.com>
Tue, 27 Mar 2012 08:00:33 +0000 (18:00 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 28 Mar 2012 03:49:28 +0000 (05:49 +0200)
-dynamic scene, don't set duration on running animation (doesn't work)
-dynamic scene, just use set colors instead of system palette (in case
platform doesn't support it right, like N900)
-dynamic scene, calculator and shadereffects, don't rely on root item being
automatically in scope (possibly confusing)

Change-Id: I1eec018d5387424dc6b07bf51c1b2184b3048553
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
examples/demos/calculator/CalculatorCore/calculator.js
examples/demos/calculator/calculator-mobile.qml
examples/qml/dynamicscene/content/Button.qml
examples/qml/dynamicscene/content/Sun.qml
examples/qml/dynamicscene/dynamicscene.qml
examples/quick/shadereffects/shadereffects.qml

index e2b5692..b4b0d9e 100644 (file)
@@ -7,7 +7,7 @@ var timer = 0
 function disabled(op) {
     if (op == "." && display.text.toString().search(/\./) != -1) {
         return true
-    } else if (op == squareRoot &&  display.text.toString().search(/-/) != -1) {
+    } else if (op == window.squareRoot &&  display.text.toString().search(/-/) != -1) {
         return true
     } else {
         return false
@@ -16,9 +16,9 @@ function disabled(op) {
 
 function doOperation(op) {
     if (op == '*')//Keyboard Aliases
-        op = multiplication;
+        op = window.multiplication;
     if (op == '/')
-        op = division;
+        op = window.division;
     if (disabled(op)) {
         return
     }
@@ -40,14 +40,14 @@ function doOperation(op) {
         display.text = Number(display.text.valueOf()) + Number(curVal.valueOf())
     } else if (display.currentOperation.text == "-") {
         display.text = Number(curVal) - Number(display.text.valueOf())
-    } else if (display.currentOperation.text == multiplication) {
+    } else if (display.currentOperation.text == window.multiplication) {
         display.text = Number(curVal) * Number(display.text.valueOf())
-    } else if (display.currentOperation.text == division) {
+    } else if (display.currentOperation.text == window.division) {
         display.text = Number(Number(curVal) / Number(display.text.valueOf())).toString()
     } else if (display.currentOperation.text == "=") {
     }
 
-    if (op == "+" || op == "-" || op == multiplication || op == division) {
+    if (op == "+" || op == "-" || op == window.multiplication || op == window.division) {
         display.currentOperation.text = op
         curVal = display.text.valueOf()
         return
@@ -64,9 +64,9 @@ function doOperation(op) {
         display.text = (Math.abs(display.text.valueOf())).toString()
     } else if (op == "Int") {
         display.text = (Math.floor(display.text.valueOf())).toString()
-    } else if (op == plusminus) {
+    } else if (op == window.plusminus) {
         display.text = (display.text.valueOf() * -1).toString()
-    } else if (op == squareRoot) {
+    } else if (op == window.squareRoot) {
         display.text = (Math.sqrt(display.text.valueOf())).toString()
     } else if (op == "mc") {
         memory = 0;
@@ -76,7 +76,7 @@ function doOperation(op) {
         display.text = memory.toString()
     } else if (op == "m-") {
         memory = display.text.valueOf()
-    } else if (op == leftArrow) {
+    } else if (op == window.leftArrow) {
         display.text = display.text.toString().slice(0, -1)
         if (display.text.length == 0) {
             display.text = "0"
index 7ee622f..d042c75 100644 (file)
@@ -95,7 +95,7 @@ Rectangle {
                 Row {
                     spacing: 6
                     Button { width: column.w; height: column.h; color: 'purple'; operation: "Off" }
-                    Button { width: column.w; height: column.h; color: 'purple'; operation: leftArrow }
+                    Button { width: column.w; height: column.h; color: 'purple'; operation: window.leftArrow }
                     Button { width: column.w; height: column.h; color: 'purple'; operation: "C" }
                     Button { width: column.w; height: column.h; color: 'purple'; operation: "AC" }
                 }
@@ -118,12 +118,12 @@ Rectangle {
                     Button { width: grid.w; height: column.h; operation: "7"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "8"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "9"; color: 'blue' }
-                    Button { width: grid.w; height: column.h; operation: division }
-                    Button { width: grid.w; height: column.h; operation: squareRoot }
+                    Button { width: grid.w; height: column.h; operation: window.division }
+                    Button { width: grid.w; height: column.h; operation: window.squareRoot }
                     Button { width: grid.w; height: column.h; operation: "4"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "5"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "6"; color: 'blue' }
-                    Button { width: grid.w; height: column.h; operation: multiplication }
+                    Button { width: grid.w; height: column.h; operation: window.multiplication }
                     Button { width: grid.w; height: column.h; operation: "x^2" }
                     Button { width: grid.w; height: column.h; operation: "1"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "2"; color: 'blue' }
@@ -132,7 +132,7 @@ Rectangle {
                     Button { width: grid.w; height: column.h; operation: "1/x" }
                     Button { width: grid.w; height: column.h; operation: "0"; color: 'blue' }
                     Button { width: grid.w; height: column.h; operation: "." }
-                    Button { width: grid.w; height: column.h; operation: plusminus }
+                    Button { width: grid.w; height: column.h; operation: window.plusminus }
                     Button { width: grid.w; height: column.h; operation: "+" }
                     Button { width: grid.w; height: column.h; operation: "="; color: 'red' }
                 }
index 0146922..ba7db50 100644 (file)
@@ -54,16 +54,14 @@ Rectangle {
     gradient: Gradient {
         GradientStop {
             position: 0.0
-            color: !mouseArea.pressed ? activePalette.light : activePalette.button
+            color: !mouseArea.pressed ? "#eeeeee" : "#888888"
         }
         GradientStop {
             position: 1.0
-            color: !mouseArea.pressed ? activePalette.button : activePalette.dark
+            color: !mouseArea.pressed ? "#888888" : "#333333"
         }
     }
 
-    SystemPalette { id: activePalette }
-
     MouseArea {
         id: mouseArea
         anchors.fill: parent
@@ -75,6 +73,5 @@ Rectangle {
         anchors.centerIn:parent
         font.pointSize: 10
         text: parent.text
-        color: activePalette.buttonText
     }
 }
index b84516e..9a956c9 100644 (file)
@@ -47,32 +47,27 @@ Image {
     property string image: "images/sun.png"
 
     source: image
-
-    // once item is created, start moving offscreen
-    NumberAnimation on y {
-        to: (window.height / 2) + window.centerOffset
-        running: created
-        onRunningChanged: {
-            if (running)
-                duration = (window.height + window.centerOffset - sun.y) * 10;
-            else
-                state = "OffScreen"
-        }
-    }
-
-    states: State {
-        name: "OffScreen"
-        StateChangeScript {
-            script: { sun.created = false; sun.destroy() }
-        }
-    }
-
     onCreatedChanged: {
         if (created) {
             sun.z = 1;    // above the sky but below the ground layer 
             window.activeSuns++;
+            // once item is created, start moving offscreen
+            dropYAnim.duration = (window.height + window.centerOffset - sun.y) * 16;
+            dropAnim.running = true;
         } else {
             window.activeSuns--;
         }
     }
+
+    SequentialAnimation on y{
+        id: dropAnim
+        running: false
+        NumberAnimation {
+            id: dropYAnim
+            to: (window.height / 2) + window.centerOffset
+        }
+        ScriptAction {
+            script: { sun.created = false; sun.destroy() }
+        }
+    }
 }
index c64df5c..66521b8 100644 (file)
@@ -95,7 +95,7 @@ Item {
    // sky
     Rectangle {
         id: sky
-        anchors { left: parent.left; top: toolbox.bottom; right: parent.right;  bottomMargin: -centerOffset; bottom: parent.verticalCenter }
+        anchors { left: parent.left; top: toolbox.bottom; right: parent.right;  bottomMargin: -window.centerOffset; bottom: parent.verticalCenter }
         gradient: Gradient {
             GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" }
             GradientStop { id: gradientStopB; position: 1.0; color: "#437284" }
@@ -127,21 +127,19 @@ Item {
     Rectangle {
         id: ground
         z: 2    // just above the sun so that the sun can set behind it
-        anchors { left: parent.left; top: parent.verticalCenter; topMargin: centerOffset; right: parent.right; bottom: parent.bottom }
+        anchors { left: parent.left; top: parent.verticalCenter; topMargin: window.centerOffset; right: parent.right; bottom: parent.bottom }
         gradient: Gradient {
             GradientStop { position: 0.0; color: "ForestGreen" }
             GradientStop { position: 1.0; color: "DarkGreen" }
         }
     }
 
-    SystemPalette { id: activePalette }
-
-    // right-hand panel
+    // top panel
     Rectangle {
         id: toolbox
 
-        height: centerOffset * 2
-        color: activePalette.window
+        height: window.centerOffset * 2
+        color: "white"
         anchors { right: parent.right; top: parent.top; left: parent.left}
 
         Column {
@@ -192,7 +190,7 @@ Item {
                 }
             }
 
-            Text { text: "Active Suns: " + activeSuns }
+            Text { text: "Active Suns: " + window.activeSuns }
         }
     }
 
@@ -202,7 +200,7 @@ Item {
         z: 1000
         width: parent.width
         height: popupColumn.height + 16
-        color: activePalette.window
+        color: "white"
 
         property bool poppedUp: false
         property int downY: window.height - (createButton.height + 16)
@@ -213,7 +211,6 @@ Item {
         Column {
             id: popupColumn
             y: 8
-            anchors.centerIn: parent
             spacing: 8
 
             Row {
@@ -250,7 +247,7 @@ Item {
                     selectByMouse: true
                     wrapMode: TextEdit.WordWrap
 
-                    text: "import QtQuick 2.0\nImage {\n    id: smile\n    x: 360 * Math.random()\n    y: 180 * Math.random() \n    source: 'content/images/face-smile.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 1500\n    }\n    Component.onCompleted: smile.destroy(1500);\n}"
+                    text: "import QtQuick 2.0\nImage {\n    id: smile\n    x: 360 * Math.random()\n    y: 40 * Math.random() \n    source: 'content/images/face-smile.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 1500\n    }\n    Component.onCompleted: smile.destroy(1500);\n}"
                 }
             }
         }
index b76c960..25efa5f 100644 (file)
@@ -43,6 +43,7 @@ import QtQuick 2.0
 import "content"
 
 Rectangle {
+    id: root
     width: 320
     height: 480
 /*!
@@ -56,10 +57,10 @@ Rectangle {
 */
     property color col: "lightsteelblue"
     gradient: Gradient {
-        GradientStop { position: 0.0; color: Qt.tint(col, "#20FFFFFF") }
-        GradientStop { position: 0.1; color: Qt.tint(col, "#20AAAAAA") }
-        GradientStop { position: 0.9; color: Qt.tint(col, "#20666666") }
-        GradientStop { position: 1.0; color: Qt.tint(col, "#20000000") }
+        GradientStop { position: 0.0; color: Qt.tint(root.col, "#20FFFFFF") }
+        GradientStop { position: 0.1; color: Qt.tint(root.col, "#20AAAAAA") }
+        GradientStop { position: 0.9; color: Qt.tint(root.col, "#20666666") }
+        GradientStop { position: 1.0; color: Qt.tint(root.col, "#20000000") }
     }
 
     ShaderEffectSource {
@@ -241,7 +242,7 @@ Rectangle {
             width: 160
             height: 160
             property variant source: theSource
-            property color tint: sliderToColor(colorizeSlider.value)
+            property color tint: root.sliderToColor(colorizeSlider.value)
             fragmentShader: "
                 uniform sampler2D source;
                 uniform lowp vec4 tint;