diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-22 05:34:41 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-22 05:36:35 (GMT) |
commit | 888d29c9c138ca3d698985f090ceb3db912ade0f (patch) | |
tree | aa991f683dd8e7ea4b05d029dd75b32321fde3c0 /examples | |
parent | 42de973ff156383beed62a6b1bce70b56b360078 (diff) | |
download | Qt-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 'examples')
-rw-r--r-- | examples/declarative/dynamic/qml/PaletteItem.qml | 8 | ||||
-rw-r--r-- | examples/declarative/sql/hello.qml | 35 | ||||
-rw-r--r-- | examples/declarative/tic-tac-toe/tic-tac-toe.qml | 154 | ||||
-rw-r--r-- | examples/declarative/webview/content/FieldText.qml | 38 | ||||
-rw-r--r-- | examples/declarative/webview/content/SpinSquare.qml | 2 |
5 files changed, 43 insertions, 194 deletions
diff --git a/examples/declarative/dynamic/qml/PaletteItem.qml b/examples/declarative/dynamic/qml/PaletteItem.qml index 8a9a9ee..08bdc40 100644 --- a/examples/declarative/dynamic/qml/PaletteItem.qml +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -1,13 +1,13 @@ import Qt 4.6 +import "itemCreation.js" as Code GenericItem { id: itemButton property string file - Script { source: "itemCreation.js" } MouseArea { anchors.fill: parent; - onPressed: startDrag(mouse); - onPositionChanged: moveDrag(mouse); - onReleased: endDrag(mouse); + onPressed: Code.startDrag(mouse); + onPositionChanged: Code.moveDrag(mouse); + onReleased: Code.endDrag(mouse); } } diff --git a/examples/declarative/sql/hello.qml b/examples/declarative/sql/hello.qml index 277dfeb..29e084c 100644 --- a/examples/declarative/sql/hello.qml +++ b/examples/declarative/sql/hello.qml @@ -1,30 +1,29 @@ import Qt 4.6 Text { - Script { - function findGreetings() { - var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000); + function findGreetings() { + var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000); - db.transaction( - function(tx) { - // Create the database if it doesn't already exist - tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + db.transaction( + function(tx) { + // Create the database if it doesn't already exist + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); - // Add (another) greeting row - tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + // Add (another) greeting row + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); - // Show all added greetings - var rs = tx.executeSql('SELECT * FROM Greeting'); + // Show all added greetings + var rs = tx.executeSql('SELECT * FROM Greeting'); - var r = "" - for(var i = 0; i < rs.rows.length; i++) { - r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n" - } - text = r + var r = "" + for(var i = 0; i < rs.rows.length; i++) { + r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n" } - ) - } + text = r + } + ) } + text: "?" Component.onCompleted: findGreetings() } diff --git a/examples/declarative/tic-tac-toe/tic-tac-toe.qml b/examples/declarative/tic-tac-toe/tic-tac-toe.qml index ae187d2..4bb1e3f 100644 --- a/examples/declarative/tic-tac-toe/tic-tac-toe.qml +++ b/examples/declarative/tic-tac-toe/tic-tac-toe.qml @@ -1,5 +1,6 @@ import Qt 4.6 import "content" +import "tic-tac-toe.js" as Logic Item { id: game @@ -29,164 +30,17 @@ Item { height: board.height/3 onClicked: { if (!endtimer.running) { - if (!makeMove(index,"X")) - computerTurn() + if (!Logic.makeMove(index,"X")) + Logic.computerTurn() } } } } - Script { - function winner(board) - { - for (var i=0; i<3; ++i) { - if (board.children[i].state!="" - && board.children[i].state==board.children[i+3].state - && board.children[i].state==board.children[i+6].state) - return true - - if (board.children[i*3].state!="" - && board.children[i*3].state==board.children[i*3+1].state - && board.children[i*3].state==board.children[i*3+2].state) - return true - } - - if (board.children[0].state!="" - && board.children[0].state==board.children[4].state!="" - && board.children[0].state==board.children[8].state!="") - return true - - if (board.children[2].state!="" - && board.children[2].state==board.children[4].state!="" - && board.children[2].state==board.children[6].state!="") - return true - - return false - } - - function restart() - { - // No moves left - start again - for (var i=0; i<9; ++i) - board.children[i].state = "" - } - - function makeMove(pos,player) - { - board.children[pos].state = player - if (winner(board)) { - win(player + " wins") - return true - } else { - return false - } - } - - function computerTurn() - { - var r = Math.random(); - if(r < game.difficulty){ - smartAI(); - }else{ - randAI(); - } - } - - function smartAI() - { - function boardCopy(a){ - var ret = new Object; - ret.children = new Array(9); - for(var i = 0; i<9; i++){ - ret.children[i] = new Object; - ret.children[i].state = a.children[i].state; - } - return ret; - } - for(var i=0; i<9; i++){ - var simpleBoard = boardCopy(board); - if (board.children[i].state == "") { - simpleBoard.children[i].state = "O"; - if(winner(simpleBoard)){ - makeMove(i,"O") - return - } - } - } - for(var i=0; i<9; i++){ - var simpleBoard = boardCopy(board); - if (board.children[i].state == "") { - simpleBoard.children[i].state = "X"; - if(winner(simpleBoard)){ - makeMove(i,"O") - return - } - } - } - function thwart(a,b,c){//If they are at a, try b or c - if (board.children[a].state == "X") { - if (board.children[b].state == "") { - makeMove(b,"O") - return true - }else if (board.children[c].state == "") { - makeMove(c,"O") - return true - } - } - return false; - } - if(thwart(4,0,2)) return; - if(thwart(0,4,3)) return; - if(thwart(2,4,1)) return; - if(thwart(6,4,7)) return; - if(thwart(8,4,5)) return; - if(thwart(1,4,2)) return; - if(thwart(3,4,0)) return; - if(thwart(5,4,8)) return; - if(thwart(7,4,6)) return; - for(var i =0; i<9; i++){//Backup - if (board.children[i].state == "") { - makeMove(i,"O") - return - } - } - restart(); - } - - function randAI() - { - var open = 0; - for (var i=0; i<9; ++i) - if (board.children[i].state == "") { - open += 1; - } - if(open == 0){ - restart(); - return; - } - var openA = new Array(open);//JS doesn't have lists I can append to (i think) - var acc = 0; - for (var i=0; i<9; ++i) - if (board.children[i].state == "") { - openA[acc] = i; - acc += 1; - } - var choice = openA[Math.floor(Math.random() * open)]; - makeMove(choice, "O"); - } - - function win(s) - { - msg.text = s - msg.opacity = 1 - endtimer.running = true - } - } - Timer { id: endtimer interval: 1600 - onTriggered: { msg.opacity = 0; restart() } + onTriggered: { msg.opacity = 0; Logic.restart() } } } diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml index d282209..1da9219 100644 --- a/examples/declarative/webview/content/FieldText.qml +++ b/examples/declarative/webview/content/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 { diff --git a/examples/declarative/webview/content/SpinSquare.qml b/examples/declarative/webview/content/SpinSquare.qml index 466c99e..b65a29d 100644 --- a/examples/declarative/webview/content/SpinSquare.qml +++ b/examples/declarative/webview/content/SpinSquare.qml @@ -15,7 +15,7 @@ Item { width: root.width height: width } - rotation: NumberAnimation { + NumberAnimation on rotation { from: 0 to: 360 repeat: true |