source: trunk/examples/declarative/toys/dynamicscene/dynamicscene.qml

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41import QtQuick 1.0
42import Qt.labs.particles 1.0
43import "qml"
44
45Item {
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 transitions: Transition {
219 PropertyAnimation { duration: 3000 }
220 ColorAnimation { duration: 3000 }
221 }
222
223}
Note: See TracBrowser for help on using the repository browser.