Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / declarative / qtquick1 / toys / dynamicscene / dynamicscene.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 1.0
42 import Qt.labs.particles 1.0
43 import "qml"
44
45 Item {
46     id: window
47
48     property int activeSuns: 0
49
50     //This is a desktop-sized example
51     width: 800; height: 480
52
53
54     MouseArea {
55         anchors.fill: parent
56         onClicked: window.focus = false;
57     }
58
59     //This is the message box that pops up when there's an error
60     Rectangle {
61         id: dialog
62
63         opacity: 0
64         anchors.centerIn: parent
65         width: dialogText.width + 6; height: dialogText.height + 6
66         border.color: 'black'
67         color: 'lightsteelblue'
68         z: 65535 //Arbitrary number chosen to be above all the items, including the scaled perspective ones.
69
70         function show(str){
71             dialogText.text = str;
72             dialogAnim.start();
73         }
74
75         Text {
76             id: dialogText
77             x: 3; y: 3
78             font.pixelSize: 14
79         }
80
81         SequentialAnimation {
82             id: dialogAnim
83             NumberAnimation { target: dialog; property:"opacity"; to: 1; duration: 1000 }
84             PauseAnimation { duration: 5000 }
85             NumberAnimation { target: dialog; property:"opacity"; to: 0; duration: 1000 }
86         }
87     }
88
89     // sky
90     Rectangle {
91         id: sky
92         anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter }
93         gradient: Gradient {
94             GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" }
95             GradientStop { id: gradientStopB; position: 1.0; color: "#437284" }
96         }
97     }
98
99     // stars (when there's no sun)
100     Particles {
101         id: stars
102         x: 0; y: 0; width: parent.width; height: parent.height / 2
103         source: "images/star.png"
104         angleDeviation: 360
105         velocity: 0; velocityDeviation: 0
106         count: parent.width / 10
107         fadeInDuration: 2800
108         opacity: 1
109     }
110
111     // ground
112     Rectangle {
113         id: ground
114         z: 2    // just above the sun so that the sun can set behind it
115         anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.left; bottom: parent.bottom }
116         gradient: Gradient {
117             GradientStop { position: 0.0; color: "ForestGreen" }
118             GradientStop { position: 1.0; color: "DarkGreen" }
119         }
120     }
121
122     SystemPalette { id: activePalette }
123
124     // right-hand panel
125     Rectangle {
126         id: toolbox
127
128         width: 380
129         color: activePalette.window
130         anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
131
132         Column {
133             anchors.centerIn: parent
134             spacing: 8
135
136             Text { text: "Drag an item into the scene." }
137
138             Rectangle {
139                 width: palette.width + 10; height: palette.height + 10
140                 border.color: "black"
141
142                 Row {
143                     id: palette
144                     anchors.centerIn: parent
145                     spacing: 8
146
147                     PaletteItem {
148                         anchors.verticalCenter: parent.verticalCenter
149                         componentFile: "Sun.qml"
150                         image: "../images/sun.png"
151                     }
152                     PaletteItem {
153                         anchors.verticalCenter: parent.verticalCenter
154                         componentFile: "GenericSceneItem.qml"
155                         image: "../images/moon.png"
156                     }
157                     PaletteItem {
158                         anchors.verticalCenter: parent.verticalCenter
159                         componentFile: "PerspectiveItem.qml"
160                         image: "../images/tree_s.png"
161                     }
162                     PaletteItem {
163                         anchors.verticalCenter: parent.verticalCenter
164                         componentFile: "PerspectiveItem.qml"
165                         image: "../images/rabbit_brown.png"
166                     }
167                     PaletteItem {
168                         anchors.verticalCenter: parent.verticalCenter
169                         componentFile: "PerspectiveItem.qml"
170                         image: "../images/rabbit_bw.png"
171                     }
172                 }
173             }
174
175             Text { text: "Active Suns: " + activeSuns }
176
177             Rectangle { width: parent.width; height: 1; color: "black" }
178
179             Text { text: "Arbitrary QML:" }
180
181             Rectangle {
182                 width: 360; height: 240
183
184                 TextEdit {
185                     id: qmlText
186                     anchors.fill: parent; anchors.margins: 5
187                     readOnly: false
188                     font.pixelSize: 14
189                     wrapMode: TextEdit.WordWrap
190
191                     text: "import QtQuick 1.0\nImage {\n    id: smile\n    x: 360 * Math.random()\n    y: 180 * Math.random() \n    source: 'images/face-smile.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 1500\n    }\n    Component.onCompleted: smile.destroy(1500);\n}"
192                 }
193             }
194
195             Button {
196                 text: "Create"
197                 onClicked: {
198                     try {
199                         Qt.createQmlObject(qmlText.text, window, 'CustomObject');
200                     } catch(err) {
201                         dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
202                     }
203                 }
204             }
205         }
206     }
207
208     //Day state, for when a sun is added to the scene
209     states: State {
210         name: "Day"
211         when: window.activeSuns > 0
212
213         PropertyChanges { target: gradientStopA; color: "DeepSkyBlue" }
214         PropertyChanges { target: gradientStopB; color: "SkyBlue" }
215         PropertyChanges { target: stars; opacity: 0 }
216     }
217
218     //! [top-level transitions]
219     transitions: Transition {
220         PropertyAnimation { duration: 3000 }
221         ColorAnimation { duration: 3000 }
222     }
223     //! [top-level transitions]
224 }