summaryrefslogtreecommitdiffstats
path: root/demos/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-22 05:34:41 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-22 05:36:35 (GMT)
commit888d29c9c138ca3d698985f090ceb3db912ade0f (patch)
treeaa991f683dd8e7ea4b05d029dd75b32321fde3c0 /demos/declarative
parent42de973ff156383beed62a6b1bce70b56b360078 (diff)
downloadQt-888d29c9c138ca3d698985f090ceb3db912ade0f.zip
Qt-888d29c9c138ca3d698985f090ceb3db912ade0f.tar.gz
Qt-888d29c9c138ca3d698985f090ceb3db912ade0f.tar.bz2
Deprecate inline Script {} blocks
Inline blocks/includes have been replaced with an import syntax: import "foo.js" as Foo this gives better separation between QML and code. Imported script blocks also have a mandatory qualifier, which leads to better optimization potential.
Diffstat (limited to 'demos/declarative')
-rw-r--r--demos/declarative/calculator/calculator.js2
-rw-r--r--demos/declarative/calculator/calculator.qml4
-rw-r--r--demos/declarative/flickr/flickr-desktop.qml28
-rw-r--r--demos/declarative/flickr/mobile/GridDelegate.qml24
-rw-r--r--demos/declarative/flickr/mobile/TitleBar.qml14
-rw-r--r--demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml9
-rw-r--r--demos/declarative/photoviewer/PhotoViewerCore/script/script.js2
-rw-r--r--demos/declarative/photoviewer/photoviewer.qml2
-rwxr-xr-xdemos/declarative/samegame/SamegameCore/samegame.js5
-rw-r--r--demos/declarative/samegame/samegame.qml15
-rw-r--r--demos/declarative/snake/content/HighScoreModel.qml26
-rw-r--r--demos/declarative/snake/snake.qml27
-rw-r--r--demos/declarative/webbrowser/content/FlickableWebView.qml24
-rw-r--r--demos/declarative/webbrowser/content/fieldtext/FieldText.qml38
14 files changed, 101 insertions, 119 deletions
diff --git a/demos/declarative/calculator/calculator.js b/demos/declarative/calculator/calculator.js
index cd6490a..f172daf 100644
--- a/demos/declarative/calculator/calculator.js
+++ b/demos/declarative/calculator/calculator.js
@@ -14,7 +14,7 @@ function disabled(op) {
}
}
-function doOp(op) {
+function doOperation(op) {
if (disabled(op)) {
return;
}
diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml
index 66705e2..1644968 100644
--- a/demos/declarative/calculator/calculator.qml
+++ b/demos/declarative/calculator/calculator.qml
@@ -1,10 +1,12 @@
import Qt 4.6
+import "calculator.js" as CalcEngine
Rectangle {
width: 320; height: 270; color: palette.window
+ function doOp(operation) { CalcEngine.doOperation(operation); }
+
SystemPalette { id: palette }
- Script { source: "calculator.js" }
Column {
x: 2; spacing: 10;
diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml
index 99216cb..4de2202 100644
--- a/demos/declarative/flickr/flickr-desktop.qml
+++ b/demos/declarative/flickr/flickr-desktop.qml
@@ -31,21 +31,19 @@ Item {
}
}
- Script {
- function photoClicked() {
- imageDetails.photoTitle = title;
- imageDetails.photoDescription = description;
- imageDetails.photoTags = tags;
- imageDetails.photoWidth = photoWidth;
- imageDetails.photoHeight = photoHeight;
- imageDetails.photoType = photoType;
- imageDetails.photoAuthor = photoAuthor;
- imageDetails.photoDate = photoDate;
- imageDetails.photoUrl = url;
- imageDetails.rating = 0;
- wrapper.state = "Details";
- }
- }
+ function photoClicked() {
+ imageDetails.photoTitle = title;
+ imageDetails.photoDescription = description;
+ imageDetails.photoTags = tags;
+ imageDetails.photoWidth = photoWidth;
+ imageDetails.photoHeight = photoHeight;
+ imageDetails.photoType = photoType;
+ imageDetails.photoAuthor = photoAuthor;
+ imageDetails.photoDate = photoDate;
+ imageDetails.photoUrl = url;
+ imageDetails.rating = 0;
+ wrapper.state = "Details";
+ }
Rectangle {
id: whiteRect; anchors.fill: parent; color: "white"; radius: 5
diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml
index 291d874..767315c 100644
--- a/demos/declarative/flickr/mobile/GridDelegate.qml
+++ b/demos/declarative/flickr/mobile/GridDelegate.qml
@@ -5,19 +5,17 @@
Item {
id: wrapper; width: 79; height: 79
- Script {
- function photoClicked() {
- imageDetails.photoTitle = title;
- imageDetails.photoTags = tags;
- imageDetails.photoWidth = photoWidth;
- imageDetails.photoHeight = photoHeight;
- imageDetails.photoType = photoType;
- imageDetails.photoAuthor = photoAuthor;
- imageDetails.photoDate = photoDate;
- imageDetails.photoUrl = url;
- imageDetails.rating = 0;
- scaleMe.state = "Details";
- }
+ function photoClicked() {
+ imageDetails.photoTitle = title;
+ imageDetails.photoTags = tags;
+ imageDetails.photoWidth = photoWidth;
+ imageDetails.photoHeight = photoHeight;
+ imageDetails.photoType = photoType;
+ imageDetails.photoAuthor = photoAuthor;
+ imageDetails.photoDate = photoDate;
+ imageDetails.photoUrl = url;
+ imageDetails.rating = 0;
+ scaleMe.state = "Details";
}
Item {
diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml
index 0a06771..e92ba59 100644
--- a/demos/declarative/flickr/mobile/TitleBar.qml
+++ b/demos/declarative/flickr/mobile/TitleBar.qml
@@ -11,12 +11,10 @@ Item {
id: container
width: (parent.width * 2) - 55 ; height: parent.height
- Script {
- function accept() {
- titleBar.state = ""
- background.state = ""
- rssModel.tags = editor.text
- }
+ function accept() {
+ titleBar.state = ""
+ background.state = ""
+ rssModel.tags = editor.text
}
Text {
@@ -32,7 +30,7 @@ Item {
Button {
id: tagButton; x: titleBar.width - 50; width: 45; height: 32; text: "..."
- onClicked: if (titleBar.state == "Tags") accept(); else titleBar.state = "Tags"
+ onClicked: if (titleBar.state == "Tags") container.accept(); else titleBar.state = "Tags"
anchors.verticalCenter: parent.verticalCenter
}
@@ -57,7 +55,7 @@ Item {
Item {
id: returnKey
- Keys.onReturnPressed: accept()
+ Keys.onReturnPressed: container.accept()
Keys.onEscapePressed: titleBar.state = ""
}
}
diff --git a/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml b/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml
index 89fe3e8..ab36122 100644
--- a/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml
+++ b/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml
@@ -1,4 +1,5 @@
import Qt 4.6
+import "script/script.js" as Script
Package {
Item { id: stackItem; Package.name: 'stack'; width: 160; height: 153; z: stackItem.PathView.z }
@@ -28,9 +29,9 @@ Package {
Rectangle {
id: placeHolder
- property int w: getWidth(content)
- property int h: getHeight(content)
- property double s: calculateScale(w, h, photoWrapper.width)
+ property int w: Script.getWidth(content)
+ property int h: Script.getHeight(content)
+ property double s: Script.calculateScale(w, h, photoWrapper.width)
color: '#878787'; anchors.centerIn: parent; smooth: true; border.color: 'white'; border.width: 3
width: w * s; height: h * s; visible: originalImage.status != Image.Ready
@@ -42,7 +43,7 @@ Package {
}
BusyIndicator { anchors.centerIn: parent; on: originalImage.status != Image.Ready }
Image {
- id: originalImage; smooth: true; source: "http://" + getImagePath(content)
+ id: originalImage; smooth: true; source: "http://" + Script.getImagePath(content)
fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
}
Image {
diff --git a/demos/declarative/photoviewer/PhotoViewerCore/script/script.js b/demos/declarative/photoviewer/PhotoViewerCore/script/script.js
index ae24ea1..e8ef93a 100644
--- a/demos/declarative/photoviewer/PhotoViewerCore/script/script.js
+++ b/demos/declarative/photoviewer/PhotoViewerCore/script/script.js
@@ -1,3 +1,5 @@
+.pragma library
+
function getWidth(string) {
return (string.match(/width=\"([0-9]+)\"/))[1]
}
diff --git a/demos/declarative/photoviewer/photoviewer.qml b/demos/declarative/photoviewer/photoviewer.qml
index 02134ac..5e4be4c 100644
--- a/demos/declarative/photoviewer/photoviewer.qml
+++ b/demos/declarative/photoviewer/photoviewer.qml
@@ -10,8 +10,6 @@ Rectangle {
width: 800; height: 480; color: "#d5d6d8"
- Script { source: "PhotoViewerCore/script/script.js" }
-
ListModel {
id: photosModel
ListElement { tag: "Flowers" }
diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js
index 1214b79..a119a88 100755
--- a/demos/declarative/samegame/SamegameCore/samegame.js
+++ b/demos/declarative/samegame/SamegameCore/samegame.js
@@ -22,11 +22,6 @@ function timeStr(msecs) {
return ret;
}
-function getTileSize()
-{
- return tileSize;
-}
-
function initBoard()
{
for(var i = 0; i<maxIndex; i++){
diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml
index 3b19cbe..f084ff6 100644
--- a/demos/declarative/samegame/samegame.qml
+++ b/demos/declarative/samegame/samegame.qml
@@ -1,5 +1,6 @@
import Qt 4.6
import SamegameCore 1.0
+import "SamegameCore/samegame.js" as Logic
Rectangle {
id: screen
@@ -22,15 +23,13 @@ Rectangle {
property int score: 0
property int tileSize: 40
- Script { source: "SamegameCore/samegame.js" }
-
z: 20; anchors.centerIn: parent
- width: parent.width - (parent.width % getTileSize());
- height: parent.height - (parent.height % getTileSize());
+ width: parent.width - (parent.width % tileSize);
+ height: parent.height - (parent.height % tileSize);
MouseArea {
id: gameMR
- anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y);
+ anchors.fill: parent; onClicked: Logic.handleClick(mouse.x,mouse.y);
}
}
}
@@ -57,7 +56,7 @@ Rectangle {
}
onAccepted: {
if(scoreName.opacity==1&&editor.text!="")
- saveHighScore(editor.text);
+ Logic.saveHighScore(editor.text);
scoreName.forceClose();
}
anchors.verticalCenter: parent.verticalCenter
@@ -73,13 +72,13 @@ Rectangle {
anchors.bottom: screen.bottom
Button {
- id: btnA; text: "New Game"; onClicked: {initBoard();}
+ id: btnA; text: "New Game"; onClicked: Logic.initBoard();
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
Button {
- id: btnB; text: "Quit"; onClicked: {Qt.quit();}
+ id: btnB; text: "Quit"; onClicked: Qt.quit();
anchors.left: btnA.right; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
diff --git a/demos/declarative/snake/content/HighScoreModel.qml b/demos/declarative/snake/content/HighScoreModel.qml
index f585ce8..076e3ff 100644
--- a/demos/declarative/snake/content/HighScoreModel.qml
+++ b/demos/declarative/snake/content/HighScoreModel.qml
@@ -41,21 +41,19 @@ ListModel {
property string topPlayer: ""
property int maxScores: 10
- Script {
- function db()
- {
- return openDatabaseSync("HighScoreModel", "1.0", "Generic High Score Functionality for QML", 1000000);
- }
- function ensureTables(tx)
- {
- tx.executeSql('CREATE TABLE IF NOT EXISTS HighScores(game TEXT, score INT, player TEXT)', []);
- }
+ function __db()
+ {
+ return openDatabaseSync("HighScoreModel", "1.0", "Generic High Score Functionality for QML", 1000000);
+ }
+ function __ensureTables(tx)
+ {
+ tx.executeSql('CREATE TABLE IF NOT EXISTS HighScores(game TEXT, score INT, player TEXT)', []);
}
function fillModel() {
- db().transaction(
+ __db().transaction(
function(tx) {
- ensureTables(tx);
+ __ensureTables(tx);
var rs = tx.executeSql("SELECT score,player FROM HighScores WHERE game=? ORDER BY score DESC", [game]);
model.clear();
if (rs.rows.length > 0) {
@@ -74,9 +72,9 @@ ListModel {
}
function savePlayerScore(player,score) {
- db().transaction(
+ __db().transaction(
function(tx) {
- ensureTables(tx);
+ __ensureTables(tx);
tx.executeSql("INSERT INTO HighScores VALUES(?,?,?)", [game,score,player]);
fillModel();
}
@@ -88,7 +86,7 @@ ListModel {
}
function clearScores() {
- db().transaction(
+ __db().transaction(
function(tx) {
tx.executeSql("DELETE FROM HighScores WHERE game=?", [game]);
fillModel();
diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml
index 317c7de..68c2b78 100644
--- a/demos/declarative/snake/snake.qml
+++ b/demos/declarative/snake/snake.qml
@@ -1,13 +1,12 @@
import Qt 4.6
import "content" as Content
+import "content/snake.js" as Logic
Rectangle {
id: screen;
SystemPalette { id: activePalette }
color: activePalette.window
- Script { source: "content/snake.js" }
-
property int gridSize : 34
property int margin: 4
property int numRowsAvailable: Math.floor((height-32-2*margin)/gridSize)
@@ -36,19 +35,19 @@ Rectangle {
id: heartbeat;
interval: heartbeatInterval;
repeat: true
- onTriggered: { move() }
+ onTriggered: { Logic.move() }
}
Timer {
id: halfbeat;
interval: halfbeatInterval;
repeat: true
running: heartbeat.running
- onTriggered: { moveSkull() }
+ onTriggered: { Logic.moveSkull() }
}
Timer {
interval: 700;
- onTriggered: {startNewGame(); }
+ onTriggered: { Logic.startNewGame(); }
}
Timer {
@@ -105,13 +104,13 @@ Rectangle {
anchors.fill: parent
onPressed: {
if (!head || !heartbeat.running) {
- startNewGame();
+ Logic.startNewGame();
return;
}
if (direction == 0 || direction == 2)
- scheduleDirection((mouseX > (head.x + head.width/2)) ? 1 : 3);
+ Logic.scheduleDirection((mouseX > (head.x + head.width/2)) ? 1 : 3);
else
- scheduleDirection((mouseY > (head.y + head.height/2)) ? 2 : 0);
+ Logic.scheduleDirection((mouseY > (head.y + head.height/2)) ? 2 : 0);
}
}
}
@@ -149,7 +148,7 @@ Rectangle {
anchors.bottom: screen.bottom
Content.Button {
- id: btnA; text: "New Game"; onClicked: {startNewGame();}
+ id: btnA; text: "New Game"; onClicked: Logic.startNewGame();
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
@@ -163,11 +162,11 @@ Rectangle {
}
focus: true
- Keys.onSpacePressed: startNewGame();
- Keys.onLeftPressed: if (state == "starting" || direction != 1) scheduleDirection(3);
- Keys.onRightPressed: if (state == "starting" || direction != 3) scheduleDirection(1);
- Keys.onUpPressed: if (state == "starting" || direction != 2) scheduleDirection(0);
- Keys.onDownPressed: if (state == "starting" || direction != 0) scheduleDirection(2);
+ Keys.onSpacePressed: Logic.startNewGame();
+ Keys.onLeftPressed: if (state == "starting" || direction != 1) Logic.scheduleDirection(3);
+ Keys.onRightPressed: if (state == "starting" || direction != 3) Logic.scheduleDirection(1);
+ Keys.onUpPressed: if (state == "starting" || direction != 2) Logic.scheduleDirection(0);
+ Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2);
states: [
State {
diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml
index 30a5d78..759cff6 100644
--- a/demos/declarative/webbrowser/content/FlickableWebView.qml
+++ b/demos/declarative/webbrowser/content/FlickableWebView.qml
@@ -25,21 +25,19 @@ Flickable {
pixelCacheSize: 4000000
transformOrigin: Item.TopLeft
- Script {
- function fixUrl(url)
- {
- if (url == "") return url
- if (url[0] == "/") return "file://"+url
- if (url.indexOf(":")<0) {
- if (url.indexOf(".")<0 || url.indexOf(" ")>=0) {
- // Fall back to a search engine; hard-code Wikipedia
- return "http://en.wikipedia.org/w/index.php?search="+url
- } else {
- return "http://"+url
- }
+ function fixUrl(url)
+ {
+ if (url == "") return url
+ if (url[0] == "/") return "file://"+url
+ if (url.indexOf(":")<0) {
+ if (url.indexOf(".")<0 || url.indexOf(" ")>=0) {
+ // Fall back to a search engine; hard-code Wikipedia
+ return "http://en.wikipedia.org/w/index.php?search="+url
+ } else {
+ return "http://"+url
}
- return url
}
+ return url
}
url: fixUrl(webBrowser.urlString)
diff --git a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml
index d282209..1da9219 100644
--- a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml
+++ b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml
@@ -10,30 +10,26 @@ Item {
signal cancelled
signal startEdit
- Script {
-
- function edit() {
- if (!mouseGrabbed) {
- fieldText.startEdit();
- fieldText.state='editing';
- mouseGrabbed=true;
- }
- }
-
- function confirm() {
- fieldText.state='';
- fieldText.text = textEdit.text;
- mouseGrabbed=false;
- fieldText.confirmed();
+ function edit() {
+ if (!mouseGrabbed) {
+ fieldText.startEdit();
+ fieldText.state='editing';
+ mouseGrabbed=true;
}
+ }
- function reset() {
- textEdit.text = fieldText.text;
- fieldText.state='';
- mouseGrabbed=false;
- fieldText.cancelled();
- }
+ function confirm() {
+ fieldText.state='';
+ fieldText.text = textEdit.text;
+ mouseGrabbed=false;
+ fieldText.confirmed();
+ }
+ function reset() {
+ textEdit.text = fieldText.text;
+ fieldText.state='';
+ mouseGrabbed=false;
+ fieldText.cancelled();
}
Image {