diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-04-09 00:20:31 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-04-09 00:20:31 (GMT) |
commit | 411404e5126936d691d5bb2b77d1754902fab5e0 (patch) | |
tree | 41d046c9029a2d58947c3855de672af2b8b18a7a /examples/declarative | |
parent | 04664c6ed9a86d146c91ef57990d8ffdf3afa59d (diff) | |
parent | bb07e7d2f4f3e8940ebcc12334b4b723e450d374 (diff) | |
download | Qt-411404e5126936d691d5bb2b77d1754902fab5e0.zip Qt-411404e5126936d691d5bb2b77d1754902fab5e0.tar.gz Qt-411404e5126936d691d5bb2b77d1754902fab5e0.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'examples/declarative')
23 files changed, 183 insertions, 191 deletions
diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 97f4791..63fc9c6 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -19,8 +19,8 @@ Rectangle { x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 SpringFollow on scale { - source: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), - Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) + to: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), + Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) spring: 1 damping: 0.05 } diff --git a/examples/declarative/clocks/content/Clock.qml b/examples/declarative/clocks/content/Clock.qml index a315ccc..c853174 100644 --- a/examples/declarative/clocks/content/Clock.qml +++ b/examples/declarative/clocks/content/Clock.qml @@ -36,7 +36,7 @@ Item { origin.x: 7.5; origin.y: 73; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) + to: (clock.hours * 30) + (clock.minutes * 0.5) } } } @@ -50,7 +50,7 @@ Item { origin.x: 6.5; origin.y: 83; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 + to: clock.minutes * 6 } } } @@ -64,7 +64,7 @@ Item { origin.x: 2.5; origin.y: 80; angle: 0 SpringFollow on angle { spring: 5; damping: 0.25; modulus: 360 - source: clock.seconds * 6 + to: clock.seconds * 6 } } } diff --git a/examples/declarative/dial/content/Dial.qml b/examples/declarative/dial/content/Dial.qml index 7fd638a..f9ab3e3 100644 --- a/examples/declarative/dial/content/Dial.qml +++ b/examples/declarative/dial/content/Dial.qml @@ -29,7 +29,7 @@ Item { SpringFollow on angle { spring: 1.4 damping: .15 - source: Math.min(Math.max(-130, root.value*2.6 - 130), 133) + to: Math.min(Math.max(-130, root.value*2.6 - 130), 133) } } } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 5493f99..2b54dd8 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: petHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - SpringFollow on y { source: list1.currentItem.y; spring: 3; damping: 0.1 } + SpringFollow on y { to: list1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml index 3ebbeab..ce1dd69 100644 --- a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -20,7 +20,7 @@ Rectangle { origin.x: 7.5; origin.y: 73; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) + to: (clock.hours * 30) + (clock.minutes * 0.5) } } } @@ -34,7 +34,7 @@ Rectangle { origin.x: 6.5; origin.y: 83; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 + to: clock.minutes * 6 } } } diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 8eee2ad..6798c32 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -8,12 +8,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -21,7 +21,7 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + 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 23a25f3..ae881ba 100644 --- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml @@ -24,7 +24,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: console.log("Starting a new game..."); + text: "New Game"; onClicked: console.log("Starting a new game..."); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index 0ec3a8b..d7cbd8d 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -1,16 +1,16 @@ //![0] //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 -var maxY = 15; +var maxColumn = 10;//Nums are for tileSize 40 +var maxRow = 15; var tileSize = 40; -var maxIndex = maxX*maxY; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "Block.qml"; var component; //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function initBoard() @@ -22,21 +22,21 @@ function initBoard() } //Calculate board size - maxX = Math.floor(background.width/tileSize); - maxY = Math.floor(background.height/tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(background.width/tileSize); + maxRow = Math.floor(background.height/tileSize); + maxIndex = maxRow*maxColumn; //Initialize Board board = new Array(maxIndex); - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ if(component==null) component = createComponent(tileSrc); @@ -52,11 +52,11 @@ function createBlock(xIdx,yIdx){ return false; } dynamicObject.parent = background; - dynamicObject.x = xIdx*tileSize; - dynamicObject.y = yIdx*tileSize; + dynamicObject.x = column*tileSize; + dynamicObject.y = row*tileSize; dynamicObject.width = tileSize; dynamicObject.height = tileSize; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml index a8a58ba..d98d383 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -27,7 +27,7 @@ Rectangle { //![1] Button { - id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + 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 69bae7c..6c358d6 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -8,16 +8,16 @@ Rectangle { page.opacity = 0; } function show(txt) { - myText.text = txt; + dialogText.text = txt; page.opacity = 1; } signal closed(); - color: "white"; border.width: 1; width: myText.width + 20; height: 60; + color: "white"; border.width: 1; width: dialogText.width + 20; height: 60; opacity: 0 Behavior on opacity { NumberAnimation { duration: 1000 } } - Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } + 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.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 33449fa..432e88f 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -1,23 +1,23 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 -var maxY = 15; -var maxIndex = maxX*maxY; +var maxColumn = 10;//Nums are for tileSize 40 +var maxRow = 15; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "Block.qml"; var component; //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function initBoard() { //Calculate board size - maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); - maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize); + maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize); + maxIndex = maxRow*maxColumn; //Close dialogs dialog.forceClose(); @@ -25,15 +25,15 @@ function initBoard() //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ if(component==null) component = createComponent(tileSrc); @@ -50,11 +50,11 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*gameCanvas.tileSize; - dynamicObject.y = yIdx*gameCanvas.tileSize; + dynamicObject.x = column*gameCanvas.tileSize; + dynamicObject.y = row*gameCanvas.tileSize; dynamicObject.width = gameCanvas.tileSize; dynamicObject.height = gameCanvas.tileSize; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); @@ -69,14 +69,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //![1] function handleClick(x,y) { - var xIdx = Math.floor(x/gameCanvas.tileSize); - var yIdx = Math.floor(y/gameCanvas.tileSize); - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + var column = Math.floor(x/gameCanvas.tileSize); + var row = Math.floor(y/gameCanvas.tileSize); + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; //If it's a valid tile, remove it and all connected (does nothing if it's not connected) - floodFill(xIdx,yIdx, -1); + floodFill(column,row, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -85,67 +85,67 @@ function handleClick(x,y) } //![1] -function floodFill(xIdx,yIdx,type) +function floodFill(column,row,type) { - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; var first = false; if(type == -1){ first = true; - type = board[index(xIdx,yIdx)].type; + type = board[index(column,row)].type; //Flood fill initialization fillFound = 0; floodBoard = new Array(maxIndex); } - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) + if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type)) return; - floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type); - floodFill(xIdx-1,yIdx,type); - floodFill(xIdx,yIdx+1,type); - floodFill(xIdx,yIdx-1,type); + floodBoard[index(column, row)] = 1; + floodFill(column+1,row,type); + floodFill(column-1,row,type); + floodFill(column,row+1,type); + floodFill(column,row-1,type); if(first==true && fillFound == 0) return;//Can't remove single tiles - board[index(xIdx,yIdx)].opacity = 0; - board[index(xIdx,yIdx)] = null; + board[index(column,row)].opacity = 0; + board[index(column,row)] = null; fillFound += 1; } function shuffleDown() { //Fall down - for(var xIdx=0; xIdx<maxX; xIdx++){ + for(var column=0; column<maxColumn; column++){ var fallDist = 0; - for(var yIdx=maxY-1; yIdx>=0; yIdx--){ - if(board[index(xIdx,yIdx)] == null){ + for(var row=maxRow-1; row>=0; row--){ + if(board[index(column,row)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - var obj = board[index(xIdx,yIdx)]; + var obj = board[index(column,row)]; obj.y += fallDist * gameCanvas.tileSize; - board[index(xIdx,yIdx+fallDist)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column,row+fallDist)] = obj; + board[index(column,row)] = null; } } } } //Fall to the left var fallDist = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - if(board[index(xIdx, maxY - 1)] == null){ + for(var column=0; column<maxColumn; column++){ + if(board[index(column, maxRow - 1)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - var obj = board[index(xIdx,yIdx)]; + for(var row=0; row<maxRow; row++){ + var obj = board[index(column,row)]; if(obj == null) continue; obj.x -= fallDist * gameCanvas.tileSize; - board[index(xIdx-fallDist,yIdx)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column-fallDist,row)] = obj; + board[index(column,row)] = null; } } } @@ -157,27 +157,27 @@ function victoryCheck() { //awards bonuses for no tiles left var deservesBonus = true; - for(var xIdx=maxX-1; xIdx>=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) + for(var column=maxColumn-1; column>=0; column--) + if(board[index(column, maxRow - 1)] != null) deservesBonus = false; if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))) + if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1))) dialog.show("Game Over. Your score is " + gameCanvas.score); } //![2] //only floods up and right, to see if it can find adjacent same-typed tiles -function floodMoveCheck(xIdx, yIdx, type) +function floodMoveCheck(column, row, type) { - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return false; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return false; - var myType = board[index(xIdx, yIdx)].type; + var myType = board[index(column, row)].type; if(type == myType) return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || - floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); + return floodMoveCheck(column + 1, row, myType) || + floodMoveCheck(column, row - 1, board[index(column,row)].type); } diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index cd9dca5..9623932 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -45,7 +45,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index b598b3f..243df75 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -9,8 +9,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - SpringFollow on x { source: targetX; spring: 2; damping: 0.2; enabled: spawned } - SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { to: targetX; spring: 2; damping: 0.2; enabled: spawned } + SpringFollow on y { to: targetY; spring: 2; damping: 0.2 } //![1] //![2] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + 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 49fd5f6..0716bb3 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -7,15 +7,15 @@ Rectangle { page.opacity = 0; } function show(txt) { - myText.text = txt; + dialogText.text = txt; page.opacity = 1; } signal closed(); - color: "white"; border.width: 1; width: myText.width + 20; height: 60; + color: "white"; border.width: 1; width: dialogText.width + 20; height: 60; opacity: 0 Behavior on opacity { NumberAnimation { duration: 1000 } } - Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } + Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } + MouseArea { anchors.fill: parent; onClicked: forceClose(); } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 2a0d718..a905f7d 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -1,8 +1,8 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for gameCanvas.tileSize 40 -var maxY = 15; -var maxIndex = maxX*maxY; +var maxColumn = 10;//Nums are for gameCanvas.tileSize 40 +var maxRow = 15; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; //var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; @@ -11,8 +11,8 @@ var timer; var component = createComponent(tileSrc); //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function timeStr(msecs) { @@ -22,11 +22,6 @@ function timeStr(msecs) { return ret; } -function getTileSize() -{ - return tileSize; -} - function initBoard() { for(var i = 0; i<maxIndex; i++){ @@ -36,27 +31,25 @@ function initBoard() } //Calculate board size - maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); - maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize); + maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize); + maxIndex = maxRow*maxColumn; //Close dialogs - scoreName.forceClose(); + nameInputDialog.forceClose(); dialog.forceClose(); - var a = new Date(); //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } - timer = new Date(); - print(timer.valueOf() - a.valueOf()); + timer = new Date(); } var fillFound;//Set after a floodFill call to the number of tiles found @@ -64,14 +57,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope function handleClick(x,y) { - var xIdx = Math.floor(x/gameCanvas.tileSize); - var yIdx = Math.floor(y/gameCanvas.tileSize); - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + var column = Math.floor(x/gameCanvas.tileSize); + var row = Math.floor(y/gameCanvas.tileSize); + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; //If it's a valid tile, remove it and all connected (does nothing if it's not connected) - floodFill(xIdx,yIdx, -1); + floodFill(column,row, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -79,67 +72,67 @@ function handleClick(x,y) victoryCheck(); } -function floodFill(xIdx,yIdx,type) +function floodFill(column,row,type) { - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; var first = false; if(type == -1){ first = true; - type = board[index(xIdx,yIdx)].type; - + type = board[index(column,row)].type; + //Flood fill initialization fillFound = 0; floodBoard = new Array(maxIndex); } - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) + if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type)) return; - floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type); - floodFill(xIdx-1,yIdx,type); - floodFill(xIdx,yIdx+1,type); - floodFill(xIdx,yIdx-1,type); + floodBoard[index(column, row)] = 1; + floodFill(column+1,row,type); + floodFill(column-1,row,type); + floodFill(column,row+1,type); + floodFill(column,row-1,type); if(first==true && fillFound == 0) return;//Can't remove single tiles - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null; + board[index(column,row)].dying = true; + board[index(column,row)] = null; fillFound += 1; } function shuffleDown() { //Fall down - for(var xIdx=0; xIdx<maxX; xIdx++){ + for(var column=0; column<maxColumn; column++){ var fallDist = 0; - for(var yIdx=maxY-1; yIdx>=0; yIdx--){ - if(board[index(xIdx,yIdx)] == null){ + for(var row=maxRow-1; row>=0; row--){ + if(board[index(column,row)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - var obj = board[index(xIdx,yIdx)]; + var obj = board[index(column,row)]; obj.targetY += fallDist * gameCanvas.tileSize; - board[index(xIdx,yIdx+fallDist)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column,row+fallDist)] = obj; + board[index(column,row)] = null; } } } } //Fall to the left fallDist = 0; - for(xIdx=0; xIdx<maxX; xIdx++){ - if(board[index(xIdx, maxY - 1)] == null){ + for(column=0; column<maxColumn; column++){ + if(board[index(column, maxRow - 1)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - for(yIdx=0; yIdx<maxY; yIdx++){ - obj = board[index(xIdx,yIdx)]; + for(row=0; row<maxRow; row++){ + obj = board[index(column,row)]; if(obj == null) continue; obj.targetX -= fallDist * gameCanvas.tileSize; - board[index(xIdx-fallDist,yIdx)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column-fallDist,row)] = obj; + board[index(column,row)] = null; } } } @@ -150,34 +143,33 @@ function victoryCheck() { //awards bonuses for no tiles left var deservesBonus = true; - for(var xIdx=maxX-1; xIdx>=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) + for(var column=maxColumn-1; column>=0; column--) + if(board[index(column, maxRow - 1)] != null) deservesBonus = false; if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ + if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1))){ timer = new Date() - timer; - scoreName.show("You won! Please enter your name: "); - //dialog.show("Game Over. Your score is " + gameCanvas.score); + nameInputDialog.show("You won! Please enter your name: "); } } //only floods up and right, to see if it can find adjacent same-typed tiles -function floodMoveCheck(xIdx, yIdx, type) +function floodMoveCheck(column, row, type) { - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return false; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return false; - var myType = board[index(xIdx, yIdx)].type; + var myType = board[index(column, row)].type; if(type == myType) return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || - floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); + return floodMoveCheck(column + 1, row, myType) || + floodMoveCheck(column, row - 1, board[index(column,row)].type); } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ // Note that we don't wait for the component to become ready. This will // only work if the block QML is a local file. Otherwise the component will // not be ready immediately. There is a statusChanged signal on the @@ -191,13 +183,13 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*gameCanvas.tileSize; - dynamicObject.targetX = xIdx*gameCanvas.tileSize; - dynamicObject.targetY = yIdx*gameCanvas.tileSize; + dynamicObject.x = column*gameCanvas.tileSize; + dynamicObject.targetX = column*gameCanvas.tileSize; + dynamicObject.targetY = row*gameCanvas.tileSize; dynamicObject.width = gameCanvas.tileSize; dynamicObject.height = gameCanvas.tileSize; dynamicObject.spawned = true; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); @@ -213,7 +205,7 @@ function saveHighScore(name) { //OfflineStorage var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; - var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; + var data = [name, gameCanvas.score, maxColumn+"x"+maxRow ,Math.floor(timer/1000)]; db.transaction( function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); @@ -236,7 +228,7 @@ function saveHighScore(name) { function sendHighScore(name) { var postman = new XMLHttpRequest() var postData = "name="+name+"&score="+gameCanvas.score - +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000); + +"&gridSize="+maxColumn+"x"+maxRow +"&time="+Math.floor(timer/1000); postman.open("POST", scoresURL, true); postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); postman.onreadystatechange = function() { diff --git a/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php b/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php index 3cceb2d..daf480e 100755 --- a/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php +++ b/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php @@ -8,10 +8,7 @@ $time = $_POST["time"]; if($name == "") $name = "Anonymous"; - //if($grid != "10x10"){ - //Need a standard, so as to reject others? - //} - $file = fopen("score_data.xml", "a"); #It's XML. Happy? + $file = fopen("score_data.xml", "a"); $ret = fwrite($file, "<record><score>". $score . "</score><name>" . $name . "</name><gridSize>" . $grid . "</gridSize><seconds>" . $time . "</seconds></record>\n"); diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 3c66fbf..fe35e3b 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -23,8 +23,8 @@ Rectangle { property int tileSize: 40 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 { anchors.fill: parent; onClicked: SameGame.handleClick(mouse.x,mouse.y); @@ -36,7 +36,7 @@ Rectangle { //![0] Dialog { - id: scoreName; anchors.centerIn: parent; z: 22; + id: nameInputDialog; anchors.centerIn: parent; z: 22; Text { id: spacer opacity: 0 @@ -45,9 +45,9 @@ Rectangle { TextInput { id: editor onAccepted: { - if(scoreName.opacity==1&&editor.text!="") - saveHighScore(editor.text); - scoreName.forceClose(); + if(nameInputDialog.opacity==1&&editor.text!="") + SameGame.saveHighScore(editor.text); + nameInputDialog.forceClose(); } anchors.verticalCenter: parent.verticalCenter width: 72; focus: true @@ -63,7 +63,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: {SameGame.initBoard();} + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 7c98c69..240183f 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -31,7 +31,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - SpringFollow on y { source: ball.targetY; velocity: 200 } + SpringFollow on y { to: ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -52,7 +52,7 @@ Rectangle { color: "Lime" x: 2; width: 20; height: 90 SpringFollow on y { - source: ball.y - 45; velocity: 300 + to: ball.y - 45; velocity: 300 enabled: ball.direction == 'left' } } @@ -61,7 +61,7 @@ Rectangle { color: "Lime" x: page.width - 22; width: 20; height: 90 SpringFollow on y { - source: ball.y-45; velocity: 300 + to: ball.y-45; velocity: 300 enabled: ball.direction == 'right' } } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index efaaf7a..724fcc8 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -17,7 +17,6 @@ Component { Repeater { model: notes - Item { property int randomX: Math.random() * 500 + 100 property int randomY: Math.random() * 200 + 50 @@ -26,7 +25,7 @@ Component { x: randomX; y: randomY SpringFollow on rotation { - source: -flickable.horizontalVelocity / 100 + to: -flickable.horizontalVelocity / 100 spring: 2.0; damping: 0.15 } @@ -54,8 +53,12 @@ Component { id: mouse onClicked: { myText.focus = true } anchors.fill: parent - drag.target: stickyPage; drag.axis: MouseArea.XandYAxis; drag.minimumY: 0; drag.maximumY: page.height - 80 - drag.minimumX: 100; drag.maximumX: page.width - 140 + drag.target: stickyPage + drag.axis: "XandYAxis" + drag.minimumY: 0 + drag.maximumY: page.height - 80 + drag.minimumX: 100 + drag.maximumX: page.width - 140 } } } diff --git a/examples/declarative/velocity/note-yellow.png b/examples/declarative/velocity/note-yellow.png Binary files differnew file mode 100644 index 0000000..8ddecc8 --- /dev/null +++ b/examples/declarative/velocity/note-yellow.png |