aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAntti Piira <apiira@blackberry.com>2013-10-23 17:34:18 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 19:18:46 +0100
commit77faf3f2c79d3d914e03ba9fc152c6b6054037ba (patch)
tree5c6b64920ee64e082f260a4194b30f38dd1e0f27 /examples
parentd232fa7c8cd01364d32a95eef7e711f3ae857d2c (diff)
Modify SameGame to use QML Singleton
Converts SameGame to use QML Singleton for storing global settings data that was previously stored in javascript files. In addition adds a BlackBerry specific selector to load a different singleton settings instance. Change-Id: If511e5efd0e539c764ab70eca4fb0f2874b6240e Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/demos/samegame/content/+blackberry/Settings.qml (renamed from examples/quick/demos/samegame/content/+blackberry/settings.js)21
-rw-r--r--examples/quick/demos/samegame/content/BBSettings.qml61
-rw-r--r--examples/quick/demos/samegame/content/BlockEmitter.qml4
-rw-r--r--examples/quick/demos/samegame/content/GameArea.qml2
-rw-r--r--examples/quick/demos/samegame/content/PaintEmitter.qml2
-rw-r--r--examples/quick/demos/samegame/content/SamegameText.qml2
-rw-r--r--examples/quick/demos/samegame/content/Settings.qml (renamed from examples/quick/demos/samegame/content/settings.js)24
-rw-r--r--examples/quick/demos/samegame/content/qmldir14
-rwxr-xr-xexamples/quick/demos/samegame/content/samegame.js27
-rw-r--r--examples/quick/demos/samegame/samegame.qml5
-rw-r--r--examples/quick/demos/samegame/samegame.qrc6
11 files changed, 121 insertions, 47 deletions
diff --git a/examples/quick/demos/samegame/content/+blackberry/settings.js b/examples/quick/demos/samegame/content/+blackberry/Settings.qml
index a86d2a9a1a..be747691ce 100644
--- a/examples/quick/demos/samegame/content/+blackberry/settings.js
+++ b/examples/quick/demos/samegame/content/+blackberry/Settings.qml
@@ -38,19 +38,10 @@
**
****************************************************************************/
-.pragma library
+pragma Singleton
+import QtQml 2.0
-//This should be switched over once a proper QML settings API exists
-
-var menuDelay = 500
-
-var headerHeight = 70
-var footerHeight = 100
-
-var fontPixelSize = 55
-
-var blockSize = 64
-
-var toolButtonHeight = 64
-
-var menuButtonSpacing = 15
+// Instantiating a BBSettings class that can be easily tweaked for future
+// BB devices (we may have more selectors added)
+BBSettings {
+}
diff --git a/examples/quick/demos/samegame/content/BBSettings.qml b/examples/quick/demos/samegame/content/BBSettings.qml
new file mode 100644
index 0000000000..ea1c70e50d
--- /dev/null
+++ b/examples/quick/demos/samegame/content/BBSettings.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml 2.0
+
+QtObject {
+ // This height/width is here for desktop testing, otherwise
+ // we could just use Screen.width/Screen.height.
+ property int screenHeight: 1280
+ property int screenWidth: 768
+
+ property int menuDelay: 500
+
+ property int headerHeight: 70
+ property int footerHeight: 100
+
+ property int fontPixelSize: 55
+
+ property int blockSize: 64
+
+ property int toolButtonHeight: 64
+
+ property int menuButtonSpacing: 15
+}
diff --git a/examples/quick/demos/samegame/content/BlockEmitter.qml b/examples/quick/demos/samegame/content/BlockEmitter.qml
index 49ee38d376..a38deaf941 100644
--- a/examples/quick/demos/samegame/content/BlockEmitter.qml
+++ b/examples/quick/demos/samegame/content/BlockEmitter.qml
@@ -40,8 +40,8 @@
import QtQuick 2.0
import QtQuick.Particles 2.0
-
-import "settings.js" as Settings
+// Needed for singletons QTBUG-34418
+import "."
Emitter {
property Item block: parent
diff --git a/examples/quick/demos/samegame/content/GameArea.qml b/examples/quick/demos/samegame/content/GameArea.qml
index 6e72161320..cf66014fa3 100644
--- a/examples/quick/demos/samegame/content/GameArea.qml
+++ b/examples/quick/demos/samegame/content/GameArea.qml
@@ -41,6 +41,7 @@
import QtQuick 2.0
import QtQuick.Particles 2.0
import "samegame.js" as Logic
+import "."
Item {
id: gameCanvas
@@ -54,6 +55,7 @@ Item {
property alias backgroundVisible: bg.visible
property string background: "gfx/background.png"
property string blockFile: "Block.qml"
+ property int blockSize: Settings.blockSize
onBlockFileChanged: Logic.changeBlock(blockFile);
property alias particlePack: auxLoader.source
//For multiplayer
diff --git a/examples/quick/demos/samegame/content/PaintEmitter.qml b/examples/quick/demos/samegame/content/PaintEmitter.qml
index 85d148de92..dcf68f511d 100644
--- a/examples/quick/demos/samegame/content/PaintEmitter.qml
+++ b/examples/quick/demos/samegame/content/PaintEmitter.qml
@@ -40,7 +40,7 @@
import QtQuick 2.0
import QtQuick.Particles 2.0
-import "settings.js" as Settings
+import "."
Emitter {
property Item block: parent
diff --git a/examples/quick/demos/samegame/content/SamegameText.qml b/examples/quick/demos/samegame/content/SamegameText.qml
index e3bee989fb..2d36e6adab 100644
--- a/examples/quick/demos/samegame/content/SamegameText.qml
+++ b/examples/quick/demos/samegame/content/SamegameText.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import "settings.js" as Settings
+import "."
Text {
font.pixelSize: Settings.fontPixelSize;
diff --git a/examples/quick/demos/samegame/content/settings.js b/examples/quick/demos/samegame/content/Settings.qml
index e09dee9af3..d21170df53 100644
--- a/examples/quick/demos/samegame/content/settings.js
+++ b/examples/quick/demos/samegame/content/Settings.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Research In Motion
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -38,19 +38,23 @@
**
****************************************************************************/
-.pragma library
+pragma Singleton
+import QtQml 2.0
-//This should be switched over once a proper QML settings API exists
+QtObject {
+ property int screenHeight: 480
+ property int screenWidth: 320
-var menuDelay = 500
+ property int menuDelay: 500
-var headerHeight = 20 // 70 on BB10
-var footerHeight = 44 // 100 on BB10
+ property int headerHeight: 20 // 70 on BB10
+ property int footerHeight: 44 // 100 on BB10
-var fontPixelSize = 14 // 55 on BB10
+ property int fontPixelSize: 14 // 55 on BB10
-var blockSize = 32 // 64 on BB10
+ property int blockSize: 32 // 64 on BB10
-var toolButtonHeight = 32 // 64 on BB10
+ property int toolButtonHeight: 32 // 64 on BB10
-var menuButtonSpacing = 0 // 15 on BB10
+ property int menuButtonSpacing: 0 // 15 on BB10
+}
diff --git a/examples/quick/demos/samegame/content/qmldir b/examples/quick/demos/samegame/content/qmldir
new file mode 100644
index 0000000000..727989d006
--- /dev/null
+++ b/examples/quick/demos/samegame/content/qmldir
@@ -0,0 +1,14 @@
+singleton Settings 1.0 Settings.qml
+BBSettings 1.0 BBSettings.qml
+Block 1.0 Block.qml
+BlockEmitter 1.0 BlockEmitter.qml
+Button 1.0 Button.qml
+GameArea 1.0 GameArea.qml
+LogoAnimation 1.0 LogoAnimation.qml
+MenuEmitter 1.0 MenuEmitter.qml
+PaintEmitter 1.0 PaintEmitter.qml
+PrimaryPack 1.0 PrimaryPack.qml
+PuzzleBlock 1.0 PuzzleBlock.qml
+SamegameText 1.0 SamegameText.qml
+SimpleBlock 1.0 SimpleBlock.qml
+SmokeText 1.0 SmokeText.qml
diff --git a/examples/quick/demos/samegame/content/samegame.js b/examples/quick/demos/samegame/content/samegame.js
index 5bb24d70db..99154320ca 100755
--- a/examples/quick/demos/samegame/content/samegame.js
+++ b/examples/quick/demos/samegame/content/samegame.js
@@ -41,7 +41,6 @@
/* This script file handles the game logic */
.pragma library
.import QtQuick.LocalStorage 2.0 as Sql
-.import "settings.js" as Settings
var maxColumn = 10;
var maxRow = 13;
@@ -111,8 +110,8 @@ function startNewGame(gc, mode, map)
gc.gameOver = false;
gc.mode = gameMode;
// Calculate board size
- maxColumn = Math.floor(gameCanvas.width/Settings.blockSize);
- maxRow = Math.floor(gameCanvas.height/Settings.blockSize);
+ maxColumn = Math.floor(gameCanvas.width/gameCanvas.blockSize);
+ maxRow = Math.floor(gameCanvas.height/gameCanvas.blockSize);
maxIndex = maxRow * maxColumn;
if (gameMode == "arcade") //Needs to be after board sizing
getHighScore();
@@ -143,8 +142,8 @@ function handleClick(x,y)
{
if (betweenTurns || gameOver || gameCanvas == undefined)
return;
- var column = Math.floor(x/Settings.blockSize);
- var row = Math.floor(y/Settings.blockSize);
+ var column = Math.floor(x/gameCanvas.blockSize);
+ var row = Math.floor(y/gameCanvas.blockSize);
if (column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return;
if (board[index(column, row)] == null)
@@ -212,7 +211,7 @@ function shuffleDown()
} else {
if (fallDist > 0) {
var obj = board[index(column, row)];
- obj.y = (row + fallDist) * Settings.blockSize;
+ obj.y = (row + fallDist) * gameCanvas.blockSize;
board[index(column, row + fallDist)] = obj;
board[index(column, row)] = null;
}
@@ -230,7 +229,7 @@ function shuffleDown()
obj = board[index(column, row)];
if (obj == null)
continue;
- obj.x = (column - fallDist) * Settings.blockSize;
+ obj.x = (column - fallDist) * gameCanvas.blockSize;
board[index(column - fallDist,row)] = obj;
board[index(column, row)] = null;
}
@@ -251,7 +250,7 @@ function shuffleUp()
} else {
if (fallDist > 0) {
var obj = board[index(column, row)];
- obj.y = (row - fallDist) * Settings.blockSize;
+ obj.y = (row - fallDist) * gameCanvas.blockSize;
board[index(column, row - fallDist)] = obj;
board[index(column, row)] = null;
}
@@ -269,7 +268,7 @@ function shuffleUp()
obj = board[index(column, row)];
if (obj == null)
continue;
- obj.x = (column - fallDist) * Settings.blockSize;
+ obj.x = (column - fallDist) * gameCanvas.blockSize;
board[index(column - fallDist,row)] = obj;
board[index(column, row)] = null;
}
@@ -372,17 +371,17 @@ function createBlock(column,row,type)
}
var dynamicObject = component.createObject(gameCanvas,
{"type": type,
- "x": column*Settings.blockSize,
- "y": -1*Settings.blockSize,
- "width": Settings.blockSize,
- "height": Settings.blockSize,
+ "x": column*gameCanvas.blockSize,
+ "y": -1*gameCanvas.blockSize,
+ "width": gameCanvas.blockSize,
+ "height": gameCanvas.blockSize,
"particleSystem": gameCanvas.ps});
if (dynamicObject == null){
console.log("error creating block");
console.log(component.errorString());
return false;
}
- dynamicObject.y = row*Settings.blockSize;
+ dynamicObject.y = row*gameCanvas.blockSize;
dynamicObject.spawned = true;
board[index(column,row)] = dynamicObject;
diff --git a/examples/quick/demos/samegame/samegame.qml b/examples/quick/demos/samegame/samegame.qml
index 23cdf94acc..b9c3876ded 100644
--- a/examples/quick/demos/samegame/samegame.qml
+++ b/examples/quick/demos/samegame/samegame.qml
@@ -41,12 +41,11 @@
import QtQuick 2.0
import QtQuick.Particles 2.0
import "content/samegame.js" as Logic
-import "content/settings.js" as Settings
import "content"
Rectangle {
id: root
- width: 320; height: 480
+ width: Settings.screenWidth; height: Settings.screenHeight
property int acc: 0
@@ -119,6 +118,8 @@ Rectangle {
Column {
y: 100 + 40
spacing: Settings.menuButtonSpacing
+ width: parent.width
+ height: parent.height - (140 + Settings.footerHeight)
Button {
width: root.width
diff --git a/examples/quick/demos/samegame/samegame.qrc b/examples/quick/demos/samegame/samegame.qrc
index 40b7cb6478..e51d3fae05 100644
--- a/examples/quick/demos/samegame/samegame.qrc
+++ b/examples/quick/demos/samegame/samegame.qrc
@@ -1,8 +1,10 @@
<RCC>
<qresource prefix="/demos/samegame">
<file>samegame.qml</file>
- <file>content/settings.js</file>
- <file>content/+blackberry/settings.js</file>
+ <file>content/qmldir</file>
+ <file>content/Settings.qml</file>
+ <file>content/BBSettings.qml</file>
+ <file>content/+blackberry/Settings.qml</file>
<file>content/gfx/text-p1-won.png</file>
<file>content/gfx/background-puzzle.png</file>
<file>content/gfx/background.png</file>