diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-07 01:35:46 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-07 01:35:46 (GMT) |
commit | 4937e19f2ec5c51e31806eae1156bb3c19d1e485 (patch) | |
tree | eb5549de888c705a529ef333d39cd3d66db2c35a /examples/declarative/tutorials/samegame/samegame2 | |
parent | a996e73fa08f97ddbe5b860445d2ec7bd5cd69d0 (diff) | |
parent | 75b371c4445739540f135b4cbe099ebf5a182ead (diff) | |
download | Qt-4937e19f2ec5c51e31806eae1156bb3c19d1e485.zip Qt-4937e19f2ec5c51e31806eae1156bb3c19d1e485.tar.gz Qt-4937e19f2ec5c51e31806eae1156bb3c19d1e485.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'examples/declarative/tutorials/samegame/samegame2')
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/Block.qml | 10 | ||||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/Button.qml | 25 | ||||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/pics/background.png | bin | 0 -> 153328 bytes | |||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/pics/redStone.png | bin | 0 -> 2604 bytes | |||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/samegame.js | 59 | ||||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/samegame.qml | 39 |
6 files changed, 133 insertions, 0 deletions
diff --git a/examples/declarative/tutorials/samegame/samegame2/Block.qml b/examples/declarative/tutorials/samegame/samegame2/Block.qml new file mode 100644 index 0000000..228ac4e --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/Block.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Item { + id:block + + Image { id: img + source: "pics/redStone.png"; + anchors.fill: parent + } +} diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml new file mode 100644 index 0000000..2354218 --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -0,0 +1,25 @@ +import Qt 4.6 + +Rectangle { + id: Container + + signal clicked + property string text: "Button" + + color: activePalette.button; smooth: true + width: txtItem.width + 20; height: txtItem.height + 6 + border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + + gradient: Gradient { + GradientStop { + id: topGrad; position: 0.0 + color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + GradientStop { position: 1.0; color: activePalette.button } + } + + MouseRegion { id: mr; anchors.fill: parent; onClicked: Container.clicked() } + + Text { + id: txtItem; text: Container.text; anchors.centerIn: Container; color: activePalette.buttonText + } +} diff --git a/examples/declarative/tutorials/samegame/samegame2/pics/background.png b/examples/declarative/tutorials/samegame/samegame2/pics/background.png Binary files differnew file mode 100644 index 0000000..25e885f --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/pics/background.png diff --git a/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png b/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png Binary files differnew file mode 100644 index 0000000..b099f60 --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js new file mode 100644 index 0000000..064d87e --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -0,0 +1,59 @@ +//Note that X/Y referred to here are in game coordinates +var maxX = 10;//Nums are for tileSize 40 +var maxY = 15; +var tileSize = 40; +var maxIndex = maxX*maxY; +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 initBoard() +{ + //Calculate board size + maxX = Math.floor(background.width/tileSize); + maxY = Math.floor(background.height/tileSize); + maxIndex = maxY*maxX; + + //Initialize Board + board = new Array(maxIndex); + for(xIdx=0; xIdx<maxX; xIdx++){ + for(yIdx=0; yIdx<maxY; yIdx++){ + board[index(xIdx,yIdx)] = null; + createBlock(xIdx,yIdx); + } + } +} + +function createBlock(xIdx,yIdx){ + if(component==null) + component = createComponent(tileSrc); + + // 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 + // component you could use if you want to wait to load remote files. + if(component.isReady){ + dynamicObject = component.createObject(); + if(dynamicObject == null){ + print("error creating block"); + print(component.errorsString()); + return false; + } + dynamicObject.parent = background; + dynamicObject.x = xIdx*tileSize; + dynamicObject.y = yIdx*tileSize; + dynamicObject.width = tileSize; + dynamicObject.height = tileSize; + board[index(xIdx,yIdx)] = dynamicObject; + }else{//isError or isLoading + print("error loading block component"); + print(component.errorsString()); + return false; + } + return true; +} diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml new file mode 100644 index 0000000..e446fa4 --- /dev/null +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Rectangle { + id: Screen + width: 490; height: 720 + + SystemPalette { id: activePalette; colorGroup: Qt.Active } + Script { source: "samegame.js" } + + Item { + width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top + + Image { + id: background + anchors.fill: parent; source: "pics/background.png" + fillMode: "PreserveAspectCrop" + } + } + + Rectangle { + id: ToolBar + color: activePalette.window + height: 32; width: parent.width + anchors.bottom: Screen.bottom + + Button { + id: btnA; text: "New Game"; onClicked: initBoard(); + anchors.left: parent.left; anchors.leftMargin: 3 + anchors.verticalCenter: parent.verticalCenter + } + + Text { + id: Score + text: "Score: Who knows?"; font.bold: true + anchors.right: parent.right; anchors.rightMargin: 3 + anchors.verticalCenter: parent.verticalCenter + } + } +} |