Svelte new form for dynamic scene example
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 19 Jan 2012 05:59:59 +0000 (15:59 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Jan 2012 01:23:18 +0000 (02:23 +0100)
Change-Id: Ic6a3616ea06c8085e6ccd7e3e13566f36aadcc0f
Reviewed-by: Martin Jones <martin.jones@nokia.com>

examples/declarative/toys/dynamicscene/content/PerspectiveItem.qml
examples/declarative/toys/dynamicscene/content/Sun.qml
examples/declarative/toys/dynamicscene/content/itemCreation.js
examples/declarative/toys/dynamicscene/dynamicscene.qml

index f3e0bb8..33d4a38 100644 (file)
@@ -47,7 +47,7 @@ Image {
     property string image 
 
     property double scaledBottom: y + (height + height*scale) / 2 
-    property bool onLand: scaledBottom > window.height / 2
+    property bool onLand: scaledBottom > (window.height / 2 + window.centerOffset)
 
     source: image
     opacity: onLand ? 1 : 0.25
index 7c41ba2..4652829 100644 (file)
@@ -50,11 +50,11 @@ Image {
 
     // once item is created, start moving offscreen
     NumberAnimation on y {
-        to: window.height / 2
+        to: (window.height / 2) + window.centerOffset
         running: created
         onRunningChanged: {
             if (running)
-                duration = (window.height - sun.y) * 10;
+                duration = (window.height + window.centerOffset - sun.y) * 10;
             else
                 state = "OffScreen"
         }
index 4ee74c2..40f5415 100644 (file)
@@ -51,7 +51,7 @@ function endDrag(mouse)
     if (draggedItem == null)
         return;
 
-    if (draggedItem.x + draggedItem.width > toolbox.x) { //Don't drop it in the toolbox
+    if (draggedItem.y < toolbox.height) { //Don't drop it in the toolbox
         draggedItem.destroy();
         draggedItem = null;
     } else {
index daf7845..54bbf61 100644 (file)
@@ -46,9 +46,9 @@ Item {
     id: window
 
     property int activeSuns: 0
+    property int centerOffset: 72
 
-    //This is a desktop-sized example
-    width: 800; height: 480
+    height: 480; width: 360
 
 
     MouseArea {
@@ -86,10 +86,16 @@ Item {
         }
     }
 
-    // sky
+    Item {
+        id: scene
+        anchors { top: sky.top; bottom: ground.bottom; left: parent.left; right: parent.right}
+        z: 10
+    }
+
+   // sky
     Rectangle {
         id: sky
-        anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter }
+        anchors { left: parent.left; top: toolbox.bottom; right: parent.right;  bottomMargin: -centerOffset; bottom: parent.verticalCenter }
         gradient: Gradient {
             GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" }
             GradientStop { id: gradientStopB; position: 1.0; color: "#437284" }
@@ -121,7 +127,7 @@ 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; right: toolbox.left; bottom: parent.bottom }
+        anchors { left: parent.left; top: parent.verticalCenter; topMargin: centerOffset; right: parent.right; bottom: parent.bottom }
         gradient: Gradient {
             GradientStop { position: 0.0; color: "ForestGreen" }
             GradientStop { position: 1.0; color: "DarkGreen" }
@@ -134,9 +140,9 @@ Item {
     Rectangle {
         id: toolbox
 
-        width: 380
+        height: centerOffset * 2
         color: activePalette.window
-        anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
+        anchors { right: parent.right; top: parent.top; left: parent.left}
 
         Column {
             anchors.centerIn: parent
@@ -187,10 +193,51 @@ Item {
             }
 
             Text { text: "Active Suns: " + activeSuns }
+        }
+    }
+
+    //Popup toolbox down the bottom
+    Rectangle {
+        id: popupToolbox
+        z: 1000
+        width: parent.width
+        height: popupColumn.height + 16
+        color: activePalette.window
+
+        property bool poppedUp: false
+        property int downY: window.height - (createButton.height + 16)
+        property int upY: window.height - (popupColumn.height + 16)
+        y: poppedUp ? upY : downY
+        Behavior on y { NumberAnimation {}}
+
+        Column {
+            id: popupColumn
+            y: 8
+            anchors.centerIn: parent
+            spacing: 8
 
-            Rectangle { width: parent.width; height: 1; color: "black" }
+            Row {
+                height: createButton.height
+                spacing: 8
+                Text { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter }
+                Button {
+                    id: popupButton
+                    text: popupToolbox.poppedUp ? "Hide" : "Show"
+                    onClicked: popupToolbox.poppedUp = !popupToolbox.poppedUp
+                }
+                Button {
+                    id: createButton
+                    text: "Create"
+                    onClicked: {
+                        try {
+                            Qt.createQmlObject(qmlText.text, scene, 'CustomObject');
+                        } catch(err) {
+                            dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
+                        }
+                    }
+                }
 
-            Text { text: "Arbitrary QML:" }
+            }
 
             Rectangle {
                 width: 360; height: 240
@@ -200,22 +247,12 @@ Item {
                     anchors.fill: parent; anchors.margins: 5
                     readOnly: false
                     font.pixelSize: 14
+                    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}"
                 }
             }
-
-            Button {
-                text: "Create"
-                onClicked: {
-                    try { 
-                        Qt.createQmlObject(qmlText.text, window, 'CustomObject');
-                    } catch(err) {
-                        dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
-                    }
-                }
-            }
         }
     }