summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-04-13 00:13:23 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-04-13 04:49:30 (GMT)
commit573a5f2a0b07d094c7fdf1c1a1bddb4261f2ede6 (patch)
tree8b6874911aa761a71aa1583e0d16b2155263d291 /examples
parent0da942310515e82627a502f9cba662d0ea2ae2b6 (diff)
downloadQt-573a5f2a0b07d094c7fdf1c1a1bddb4261f2ede6.zip
Qt-573a5f2a0b07d094c7fdf1c1a1bddb4261f2ede6.tar.gz
Qt-573a5f2a0b07d094c7fdf1c1a1bddb4261f2ede6.tar.bz2
Fix example code style
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/Block.qml7
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/Button.qml20
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/samegame.qml23
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/Block.qml7
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/Button.qml20
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.qml23
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Block.qml22
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Button.qml20
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Dialog.qml13
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/samegame.qml34
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml65
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/Button.qml20
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml13
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/samegame.qml43
14 files changed, 206 insertions, 124 deletions
diff --git a/examples/declarative/tutorials/samegame/samegame1/Block.qml b/examples/declarative/tutorials/samegame/samegame1/Block.qml
index 7cf819b..a535235 100644
--- a/examples/declarative/tutorials/samegame/samegame1/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/Block.qml
@@ -2,11 +2,12 @@
import Qt 4.7
Item {
- id:block
+ id: block
- Image { id: img
- source: "../shared/pics/redStone.png";
+ Image {
+ id: img
anchors.fill: parent
+ source: "../shared/pics/redStone.png";
}
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml
index 8ad7c0f..e8034ac 100644
--- a/examples/declarative/tutorials/samegame/samegame1/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml
@@ -4,25 +4,31 @@ import Qt 4.7
Rectangle {
id: container
- signal clicked
property string text: "Button"
- color: activePalette.button; smooth: true
+ signal clicked
+
width: buttonLabel.width + 20; height: buttonLabel.height + 6
- border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
+ smooth: true
+ border { width: 1; color: Qt.darker(activePalette.button) }
+ radius: 8
+ // color the button with a gradient
gradient: Gradient {
GradientStop {
position: 0.0
- color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light }
+ color: {
+ if (mouseArea.pressed)
+ return activePalette.dark
+ else
+ return activePalette.light
+ }
}
GradientStop { position: 1.0; color: activePalette.button }
}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
- Text {
- id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
- }
+ Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText }
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
index ae881ba..eec77ae 100644
--- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
@@ -3,37 +3,40 @@ import Qt 4.7
Rectangle {
id: screen
+
width: 490; height: 720
SystemPalette { id: activePalette }
Item {
- width: parent.width; anchors.top: parent.top; anchors.bottom: toolbar.top
+ width: parent.width
+ anchors { top: parent.top; bottom: toolBar.top }
Image {
id: background
- anchors.fill: parent; source: "../shared/pics/background.jpg"
+ anchors.fill: parent
+ source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
}
Rectangle {
- id: toolbar
+ id: toolBar
+ width: parent.width; height: 32
color: activePalette.window
- height: 32; width: parent.width
anchors.bottom: screen.bottom
Button {
- text: "New Game"; onClicked: console.log("Starting a new game...");
- anchors.left: parent.left; anchors.leftMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "New Game"
+ onClicked: console.log("Starting a new game...")
}
Text {
id: score
- text: "Score: Who knows?"; font.bold: true
- anchors.right: parent.right; anchors.rightMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "Score: Who knows?"
+ font.bold: true
}
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/Block.qml b/examples/declarative/tutorials/samegame/samegame2/Block.qml
index 44ff5d7..88b3d79 100644
--- a/examples/declarative/tutorials/samegame/samegame2/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/Block.qml
@@ -1,10 +1,11 @@
import Qt 4.7
Item {
- id:block
+ id: block
- Image { id: img
- source: "../shared/pics/redStone.png";
+ Image {
+ id: img
anchors.fill: parent
+ source: "../shared/pics/redStone.png";
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml
index cf4c61b..8d322de5 100644
--- a/examples/declarative/tutorials/samegame/samegame2/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml
@@ -3,24 +3,30 @@ import Qt 4.7
Rectangle {
id: container
- signal clicked
property string text: "Button"
- color: activePalette.button; smooth: true
+ signal clicked
+
width: buttonLabel.width + 20; height: buttonLabel.height + 6
- border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
+ smooth: true
+ border { width: 1; color: Qt.darker(activePalette.button) }
+ radius: 8
+ // color the button with a gradient
gradient: Gradient {
GradientStop {
position: 0.0
- color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light }
+ color: {
+ if (mouseArea.pressed)
+ return activePalette.dark
+ else
+ return activePalette.light
+ }
}
GradientStop { position: 1.0; color: activePalette.button }
}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
- Text {
- id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
- }
+ Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText }
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
index e0706c2..7a17d16 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
@@ -5,39 +5,42 @@ import "samegame.js" as SameGame
Rectangle {
id: screen
+
width: 490; height: 720
SystemPalette { id: activePalette }
Item {
- width: parent.width; anchors.top: parent.top; anchors.bottom: toolbar.top
+ width: parent.width
+ anchors { top: parent.top; bottom: toolBar.top }
Image {
id: background
- anchors.fill: parent; source: "../shared/pics/background.jpg"
+ anchors.fill: parent
+ source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
}
Rectangle {
- id: toolbar
+ id: toolBar
+ width: parent.width; height: 32
color: activePalette.window
- height: 32; width: parent.width
anchors.bottom: screen.bottom
//![1]
Button {
- text: "New Game"; onClicked: SameGame.startNewGame();
- anchors.left: parent.left; anchors.leftMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "New Game"
+ onClicked: SameGame.startNewGame()
}
//![1]
Text {
id: score
- text: "Score: Who knows?"; font.bold: true
- anchors.right: parent.right; anchors.rightMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "Score: Who knows?"
+ font.bold: true
}
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/Block.qml b/examples/declarative/tutorials/samegame/samegame3/Block.qml
index bb48ac8..dd0fb48 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Block.qml
@@ -2,20 +2,22 @@
import Qt 4.7
Item {
- id:block
+ id: block
+
property int type: 0
- Image { id: img
+ Image {
+ id: img
+
+ anchors.fill: parent
source: {
- if(type == 0){
- "../shared/pics/redStone.png";
- } else if(type == 1) {
- "../shared/pics/blueStone.png";
- } else {
- "../shared/pics/greenStone.png";
- }
+ if (type == 0)
+ return "../shared/pics/redStone.png";
+ else if (type == 1)
+ return "../shared/pics/blueStone.png";
+ else
+ return "../shared/pics/greenStone.png";
}
- anchors.fill: parent
}
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml
index cf4c61b..8d322de5 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml
@@ -3,24 +3,30 @@ import Qt 4.7
Rectangle {
id: container
- signal clicked
property string text: "Button"
- color: activePalette.button; smooth: true
+ signal clicked
+
width: buttonLabel.width + 20; height: buttonLabel.height + 6
- border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
+ smooth: true
+ border { width: 1; color: Qt.darker(activePalette.button) }
+ radius: 8
+ // color the button with a gradient
gradient: Gradient {
GradientStop {
position: 0.0
- color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light }
+ color: {
+ if (mouseArea.pressed)
+ return activePalette.dark
+ else
+ return activePalette.light
+ }
}
GradientStop { position: 1.0; color: activePalette.button }
}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
- Text {
- id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
- }
+ Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText }
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
index a76b517..be3a7b7 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
@@ -3,21 +3,30 @@ import Qt 4.7
Rectangle {
id: page
+
+ signal closed
+
function forceClose() {
page.closed();
page.opacity = 0;
}
+
function show(txt) {
dialogText.text = txt;
page.opacity = 1;
}
- signal closed();
- color: "white"; border.width: 1; width: dialogText.width + 20; height: dialogText.height + 20;
+
+ width: dialogText.width + 20; height: dialogText.height + 20
+ color: "white"
+ border.width: 1
opacity: 0
+
Behavior on opacity {
NumberAnimation { duration: 1000 }
}
+
Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" }
+
MouseArea { anchors.fill: parent; onClicked: forceClose(); }
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
index cdf99d7..bc5f2f8 100644
--- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
@@ -4,31 +4,37 @@ import "samegame.js" as SameGame
Rectangle {
id: screen
+
width: 490; height: 720
SystemPalette { id: activePalette }
Item {
- width: parent.width; anchors.top: parent.top; anchors.bottom: toolbar.top
+ width: parent.width
+ anchors { top: parent.top; bottom: toolBar.top }
Image {
id: background
- anchors.fill: parent; source: "../shared/pics/background.jpg"
+ anchors.fill: parent
+ source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
//![1]
Item {
id: gameCanvas
+
property int score: 0
property int blockSize: 40
- z: 20; anchors.centerIn: parent
- width: parent.width - (parent.width % blockSize);
- height: parent.height - (parent.height % blockSize);
+ width: parent.width - (parent.width % blockSize)
+ height: parent.height - (parent.height % blockSize)
+ anchors.centerIn: parent
+ z: 20
MouseArea {
- anchors.fill: parent; onClicked: SameGame.handleClick(mouse.x,mouse.y);
+ anchors.fill: parent
+ onClicked: SameGame.handleClick(mouse.x, mouse.y)
}
}
//![1]
@@ -39,22 +45,22 @@ Rectangle {
//![2]
Rectangle {
- id: toolbar
+ id: toolBar
+ width: parent.width; height: 32
color: activePalette.window
- height: 32; width: parent.width
anchors.bottom: screen.bottom
Button {
- text: "New Game"; onClicked: SameGame.startNewGame();
- anchors.left: parent.left; anchors.leftMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "New Game"
+ onClicked: SameGame.startNewGame()
}
Text {
id: score
- text: "Score: " + gameCanvas.score; font.bold: true
- anchors.right: parent.right; anchors.rightMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "Score: Who knows?"
+ font.bold: true
}
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
index 243df75..d3a9df7 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
@@ -1,9 +1,12 @@
import Qt 4.7
import Qt.labs.particles 1.0
-Item { id:block
+Item {
+ id: block
+
property int type: 0
property bool dying: false
+
//![1]
property bool spawned: false
property int targetX: 0
@@ -14,47 +17,59 @@ Item { id:block
//![1]
//![2]
- Image { id: img
+ Image {
+ id: img
+
+ anchors.fill: parent
source: {
- if(type == 0){
- "../../shared/pics/redStone.png";
- } else if(type == 1) {
- "../../shared/pics/blueStone.png";
- } else {
- "../../shared/pics/greenStone.png";
- }
+ if (type == 0)
+ return "../../shared/pics/redStone.png";
+ else if (type == 1)
+ return "../../shared/pics/blueStone.png";
+ else
+ return "../../shared/pics/greenStone.png";
}
opacity: 0
- Behavior on opacity { NumberAnimation { properties:"opacity"; duration: 200 } }
- anchors.fill: parent
+
+ Behavior on opacity {
+ NumberAnimation { properties:"opacity"; duration: 200 }
+ }
}
//![2]
//![3]
- Particles { id: particles
- width:1; height:1; anchors.centerIn: parent;
- emissionRate: 0;
- lifeSpan: 700; lifeSpanDeviation: 600;
+ Particles {
+ id: particles
+
+ width: 1; height: 1
+ anchors.centerIn: parent
+
+ emissionRate: 0
+ lifeSpan: 700; lifeSpanDeviation: 600
angle: 0; angleDeviation: 360;
- velocity: 100; velocityDeviation:30;
+ velocity: 100; velocityDeviation: 30
source: {
- if(type == 0){
- "../../shared/pics/redStar.png";
- } else if (type == 1) {
- "../../shared/pics/blueStar.png";
- } else {
- "../../shared/pics/greenStar.png";
- }
+ if (type == 0)
+ return "../../shared/pics/redStar.png";
+ else if (type == 1)
+ return "../../shared/pics/blueStar.png";
+ else
+ return "../../shared/pics/greenStar.png";
}
}
//![3]
//![4]
states: [
- State{ name: "AliveState"; when: spawned == true && dying == false
+ State {
+ name: "AliveState"
+ when: spawned == true && dying == false
PropertyChanges { target: img; opacity: 1 }
},
- State{ name: "DeathState"; when: dying == true
+
+ State {
+ name: "DeathState"
+ when: dying == true
StateChangeScript { script: particles.burst(50); }
PropertyChanges { target: img; opacity: 0 }
StateChangeScript { script: block.destroy(1000); }
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
index cf4c61b..8d322de5 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
@@ -3,24 +3,30 @@ import Qt 4.7
Rectangle {
id: container
- signal clicked
property string text: "Button"
- color: activePalette.button; smooth: true
+ signal clicked
+
width: buttonLabel.width + 20; height: buttonLabel.height + 6
- border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
+ smooth: true
+ border { width: 1; color: Qt.darker(activePalette.button) }
+ radius: 8
+ // color the button with a gradient
gradient: Gradient {
GradientStop {
position: 0.0
- color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light }
+ color: {
+ if (mouseArea.pressed)
+ return activePalette.dark
+ else
+ return activePalette.light
+ }
}
GradientStop { position: 1.0; color: activePalette.button }
}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
- Text {
- id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
- }
+ Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText }
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
index 15f5b19..adb3f9e 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
@@ -2,20 +2,29 @@ import Qt 4.7
Rectangle {
id: page
+
+ signal closed
+
function forceClose() {
page.closed();
page.opacity = 0;
}
+
function show(txt) {
dialogText.text = txt;
page.opacity = 1;
}
- signal closed();
- color: "white"; border.width: 1; width: dialogText.width + 20; height: dialogText.height + 20;
+
+ width: dialogText.width + 20; height: dialogText.height + 20
+ color: "white"
+ border.width: 1
opacity: 0
+
Behavior on opacity {
NumberAnimation { duration: 1000 }
}
+
Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" }
+
MouseArea { anchors.fill: parent; onClicked: forceClose(); }
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
index 5d5c81f..c83743b 100644
--- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
@@ -4,16 +4,19 @@ import "content/samegame.js" as SameGame
Rectangle {
id: screen
+
width: 490; height: 720
SystemPalette { id: activePalette }
Item {
- width: parent.width; anchors.top: parent.top; anchors.bottom: toolBar.top
+ width: parent.width
+ anchors { top: parent.top; bottom: toolBar.top }
Image {
id: background
- anchors.fill: parent; source: "../shared/pics/background.jpg"
+ anchors.fill: parent
+ source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
@@ -36,43 +39,49 @@ Rectangle {
//![0]
Dialog {
- id: nameInputDialog; anchors.centerIn: parent; z: 22;
+ id: nameInputDialog
+
+ anchors.centerIn: parent
+ z: 22
+
Text {
- id: spacer
+ id: dialogText
opacity: 0
text: " You won! Please enter your name:"
}
+
TextInput {
- id: editor
+ id: nameInput
+ width: 72
+ anchors { verticalCenter: parent.verticalCenter; left: dialogText.right }
+ focus: true
+
onAccepted: {
- if(nameInputDialog.opacity==1&&editor.text!="")
- SameGame.saveHighScore(editor.text);
+ if (nameInputDialog.opacity == 1 && nameInput.text != "")
+ SameGame.saveHighScore(nameInput.text);
nameInputDialog.forceClose();
}
- anchors.verticalCenter: parent.verticalCenter
- width: 72; focus: true
- anchors.left: spacer.right
}
}
//![0]
Rectangle {
id: toolBar
+ width: parent.width; height: 32
color: activePalette.window
- height: 32; width: parent.width
anchors.bottom: screen.bottom
Button {
- text: "New Game"; onClicked: SameGame.startNewGame();
- anchors.left: parent.left; anchors.leftMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "New Game"
+ onClicked: SameGame.startNewGame()
}
Text {
id: score
- text: "Score: " + gameCanvas.score; font.bold: true
- anchors.right: parent.right; anchors.rightMargin: 3
- anchors.verticalCenter: parent.verticalCenter
+ anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter }
+ text: "Score: Who knows?"
+ font.bold: true
}
}
}