dynamicscene.qml Example File
declarative/toys/dynamicscene/qml/dynamicscene/dynamicscene.qml
import QtQuick 1.0
import Qt.labs.particles 1.0
Item {
id: window
property int activeSuns: 0
width: 800; height: 480
MouseArea {
anchors.fill: parent
onClicked: window.focus = false;
}
Rectangle {
id: dialog
opacity: 0
anchors.centerIn: parent
width: dialogText.width + 6; height: dialogText.height + 6
border.color: 'black'
color: 'lightsteelblue'
z: 65535
function show(str){
dialogText.text = str;
dialogAnim.start();
}
Text {
id: dialogText
x: 3; y: 3
font.pixelSize: 14
}
SequentialAnimation {
id: dialogAnim
NumberAnimation { target: dialog; property:"opacity"; to: 1; duration: 1000 }
PauseAnimation { duration: 5000 }
NumberAnimation { target: dialog; property:"opacity"; to: 0; duration: 1000 }
}
}
Rectangle {
id: sky
anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter }
gradient: Gradient {
GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" }
GradientStop { id: gradientStopB; position: 1.0; color: "#437284" }
}
}
Particles {
id: stars
x: 0; y: 0; width: parent.width; height: parent.height / 2
source: "images/star.png"
angleDeviation: 360
velocity: 0; velocityDeviation: 0
count: parent.width / 10
fadeInDuration: 2800
opacity: 1
}
Rectangle {
id: ground
z: 2
anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.left; bottom: parent.bottom }
gradient: Gradient {
GradientStop { position: 0.0; color: "ForestGreen" }
GradientStop { position: 1.0; color: "DarkGreen" }
}
}
SystemPalette { id: activePalette }
Rectangle {
id: toolbox
width: 380
color: activePalette.window
anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
Column {
anchors.centerIn: parent
spacing: 8
Text { text: "Drag an item into the scene." }
Rectangle {
width: palette.width + 10; height: palette.height + 10
border.color: "black"
Row {
id: palette
anchors.centerIn: parent
spacing: 8
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "Sun.qml"
image: "images/sun.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "GenericSceneItem.qml"
image: "images/moon.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
image: "images/tree_s.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
image: "images/rabbit_brown.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
image: "images/rabbit_bw.png"
}
}
}
Text { text: "Active Suns: " + activeSuns }
Rectangle { width: parent.width; height: 1; color: "black" }
Text { text: "Arbitrary QML:" }
Rectangle {
width: 360; height: 240
TextEdit {
id: qmlText
anchors.fill: parent; anchors.margins: 5
readOnly: false
font.pixelSize: 14
wrapMode: TextEdit.WordWrap
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}"
}
}
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);
}
}
}
}
}
states: State {
name: "Day"
when: window.activeSuns > 0
PropertyChanges { target: gradientStopA; color: "DeepSkyBlue" }
PropertyChanges { target: gradientStopB; color: "SkyBlue" }
PropertyChanges { target: stars; opacity: 0 }
}
transitions: Transition {
PropertyAnimation { duration: 3000 }
ColorAnimation { duration: 3000 }
}
}