From 95a92ae3881ee99a851b69c96fc2c3c985a0a0ed Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 19 Jan 2012 15:14:06 +1000 Subject: Adhere to examples standards more consistently Example subfolders should be named 'content' Change-Id: I23f5b0ef44108f54f9b1703f04faf02cafc78efb Reviewed-by: Martin Jones --- examples/declarative/calculator/Core/Button.qml | 84 ------ examples/declarative/calculator/Core/Display.qml | 68 ----- examples/declarative/calculator/Core/calculator.js | 91 ------- .../declarative/calculator/Core/images/button-.png | Bin 1288 -> 0 bytes .../calculator/Core/images/button-blue.png | Bin 1565 -> 0 bytes .../calculator/Core/images/button-green.png | Bin 1543 -> 0 bytes .../calculator/Core/images/button-purple.png | Bin 1566 -> 0 bytes .../calculator/Core/images/button-red.png | Bin 1586 -> 0 bytes .../declarative/calculator/Core/images/display.png | Bin 998 -> 0 bytes examples/declarative/calculator/Core/qmldir | 2 - examples/declarative/calculator/calculator.qml | 4 +- examples/declarative/calculator/content/Button.qml | 84 ++++++ .../declarative/calculator/content/Display.qml | 68 +++++ .../declarative/calculator/content/calculator.js | 91 +++++++ .../calculator/content/images/button-.png | Bin 0 -> 1288 bytes .../calculator/content/images/button-blue.png | Bin 0 -> 1565 bytes .../calculator/content/images/button-green.png | Bin 0 -> 1543 bytes .../calculator/content/images/button-purple.png | Bin 0 -> 1566 bytes .../calculator/content/images/button-red.png | Bin 0 -> 1586 bytes .../calculator/content/images/display.png | Bin 0 -> 998 bytes examples/declarative/calculator/content/qmldir | 2 + .../samegame/SamegameCore/BoomBlock.qml | 112 -------- .../declarative/samegame/SamegameCore/Button.qml | 75 ------ .../declarative/samegame/SamegameCore/Dialog.qml | 81 ------ .../declarative/samegame/SamegameCore/GameArea.qml | 92 ------- .../samegame/SamegameCore/NameInputDialog.qml | 93 ------- .../samegame/SamegameCore/pics/background.png | Bin 313930 -> 0 bytes .../samegame/SamegameCore/pics/blueStone.png | Bin 3054 -> 0 bytes .../samegame/SamegameCore/pics/greenStone.png | Bin 2932 -> 0 bytes .../samegame/SamegameCore/pics/particle.png | Bin 861 -> 0 bytes .../samegame/SamegameCore/pics/redStone.png | Bin 2902 -> 0 bytes .../samegame/SamegameCore/pics/yellowStone.png | Bin 3056 -> 0 bytes .../declarative/samegame/SamegameCore/samegame.js | 289 --------------------- .../declarative/samegame/content/BoomBlock.qml | 112 ++++++++ examples/declarative/samegame/content/Button.qml | 75 ++++++ examples/declarative/samegame/content/Dialog.qml | 81 ++++++ examples/declarative/samegame/content/GameArea.qml | 92 +++++++ .../samegame/content/NameInputDialog.qml | 93 +++++++ .../samegame/content/pics/background.png | Bin 0 -> 313930 bytes .../samegame/content/pics/blueStone.png | Bin 0 -> 3054 bytes .../samegame/content/pics/greenStone.png | Bin 0 -> 2932 bytes .../declarative/samegame/content/pics/particle.png | Bin 0 -> 861 bytes .../declarative/samegame/content/pics/redStone.png | Bin 0 -> 2902 bytes .../samegame/content/pics/yellowStone.png | Bin 0 -> 3056 bytes examples/declarative/samegame/content/samegame.js | 289 +++++++++++++++++++++ examples/declarative/samegame/samegame.qml | 4 +- 46 files changed, 991 insertions(+), 991 deletions(-) delete mode 100644 examples/declarative/calculator/Core/Button.qml delete mode 100644 examples/declarative/calculator/Core/Display.qml delete mode 100644 examples/declarative/calculator/Core/calculator.js delete mode 100644 examples/declarative/calculator/Core/images/button-.png delete mode 100644 examples/declarative/calculator/Core/images/button-blue.png delete mode 100644 examples/declarative/calculator/Core/images/button-green.png delete mode 100644 examples/declarative/calculator/Core/images/button-purple.png delete mode 100644 examples/declarative/calculator/Core/images/button-red.png delete mode 100644 examples/declarative/calculator/Core/images/display.png delete mode 100644 examples/declarative/calculator/Core/qmldir create mode 100644 examples/declarative/calculator/content/Button.qml create mode 100644 examples/declarative/calculator/content/Display.qml create mode 100644 examples/declarative/calculator/content/calculator.js create mode 100644 examples/declarative/calculator/content/images/button-.png create mode 100644 examples/declarative/calculator/content/images/button-blue.png create mode 100644 examples/declarative/calculator/content/images/button-green.png create mode 100644 examples/declarative/calculator/content/images/button-purple.png create mode 100644 examples/declarative/calculator/content/images/button-red.png create mode 100644 examples/declarative/calculator/content/images/display.png create mode 100644 examples/declarative/calculator/content/qmldir delete mode 100644 examples/declarative/samegame/SamegameCore/BoomBlock.qml delete mode 100644 examples/declarative/samegame/SamegameCore/Button.qml delete mode 100644 examples/declarative/samegame/SamegameCore/Dialog.qml delete mode 100644 examples/declarative/samegame/SamegameCore/GameArea.qml delete mode 100644 examples/declarative/samegame/SamegameCore/NameInputDialog.qml delete mode 100644 examples/declarative/samegame/SamegameCore/pics/background.png delete mode 100644 examples/declarative/samegame/SamegameCore/pics/blueStone.png delete mode 100644 examples/declarative/samegame/SamegameCore/pics/greenStone.png delete mode 100644 examples/declarative/samegame/SamegameCore/pics/particle.png delete mode 100644 examples/declarative/samegame/SamegameCore/pics/redStone.png delete mode 100644 examples/declarative/samegame/SamegameCore/pics/yellowStone.png delete mode 100755 examples/declarative/samegame/SamegameCore/samegame.js create mode 100644 examples/declarative/samegame/content/BoomBlock.qml create mode 100644 examples/declarative/samegame/content/Button.qml create mode 100644 examples/declarative/samegame/content/Dialog.qml create mode 100644 examples/declarative/samegame/content/GameArea.qml create mode 100644 examples/declarative/samegame/content/NameInputDialog.qml create mode 100644 examples/declarative/samegame/content/pics/background.png create mode 100644 examples/declarative/samegame/content/pics/blueStone.png create mode 100644 examples/declarative/samegame/content/pics/greenStone.png create mode 100644 examples/declarative/samegame/content/pics/particle.png create mode 100644 examples/declarative/samegame/content/pics/redStone.png create mode 100644 examples/declarative/samegame/content/pics/yellowStone.png create mode 100755 examples/declarative/samegame/content/samegame.js diff --git a/examples/declarative/calculator/Core/Button.qml b/examples/declarative/calculator/Core/Button.qml deleted file mode 100644 index 2b4e2f5b0f..0000000000 --- a/examples/declarative/calculator/Core/Button.qml +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -BorderImage { - id: button - - property alias operation: buttonText.text - property string color: "" - - Accessible.name: operation - Accessible.description: "This button does " + operation - Accessible.role: Accessible.Button - - signal clicked - - source: "images/button-" + color + ".png"; clip: true - border { left: 10; top: 10; right: 10; bottom: 10 } - - Rectangle { - id: shade - anchors.fill: button; radius: 10; color: "black"; opacity: 0 - } - - Text { - id: buttonText - anchors.centerIn: parent; anchors.verticalCenterOffset: -1 - font.pixelSize: parent.width > parent.height ? parent.height * .5 : parent.width * .5 - style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true - } - - MouseArea { - id: mouseArea - anchors.fill: parent - onClicked: { - doOp(operation) - button.clicked() - } - } - - states: State { - name: "pressed"; when: mouseArea.pressed == true - PropertyChanges { target: shade; opacity: .4 } - } -} diff --git a/examples/declarative/calculator/Core/Display.qml b/examples/declarative/calculator/Core/Display.qml deleted file mode 100644 index a3fa2e976a..0000000000 --- a/examples/declarative/calculator/Core/Display.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -BorderImage { - id: image - - property alias text : displayText.text - property alias currentOperation : operationText - - source: "images/display.png" - border { left: 10; top: 10; right: 10; bottom: 10 } - - Text { - id: displayText - anchors { - right: parent.right; verticalCenter: parent.verticalCenter; verticalCenterOffset: -1 - rightMargin: 6; left: operationText.right - } - font.pixelSize: parent.height * .6; text: "0"; horizontalAlignment: Text.AlignRight; elide: Text.ElideRight - color: "#343434"; smooth: true; font.bold: true - } - Text { - id: operationText - font.bold: true; font.pixelSize: parent.height * .7 - color: "#343434"; smooth: true - anchors { left: parent.left; leftMargin: 6; verticalCenterOffset: -3; verticalCenter: parent.verticalCenter } - } -} diff --git a/examples/declarative/calculator/Core/calculator.js b/examples/declarative/calculator/Core/calculator.js deleted file mode 100644 index 7c363c7f30..0000000000 --- a/examples/declarative/calculator/Core/calculator.js +++ /dev/null @@ -1,91 +0,0 @@ - -var curVal = 0 -var memory = 0 -var lastOp = "" -var timer = 0 - -function disabled(op) { - if (op == "." && display.text.toString().search(/\./) != -1) { - return true - } else if (op == squareRoot && display.text.toString().search(/-/) != -1) { - return true - } else { - return false - } -} - -function doOperation(op) { - if (disabled(op)) { - return - } - - if (op.toString().length==1 && ((op >= "0" && op <= "9") || op==".") ) { - if (display.text.toString().length >= 14) - return; // No arbitrary length numbers - if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp == ".") ) { - display.text = display.text + op.toString() - } else { - display.text = op - } - lastOp = op - return - } - lastOp = op - - if (display.currentOperation.text == "+") { - display.text = Number(display.text.valueOf()) + Number(curVal.valueOf()) - } else if (display.currentOperation.text == "-") { - display.text = Number(curVal) - Number(display.text.valueOf()) - } else if (display.currentOperation.text == multiplication) { - display.text = Number(curVal) * Number(display.text.valueOf()) - } else if (display.currentOperation.text == division) { - display.text = Number(Number(curVal) / Number(display.text.valueOf())).toString() - } else if (display.currentOperation.text == "=") { - } - - if (op == "+" || op == "-" || op == multiplication || op == division) { - display.currentOperation.text = op - curVal = display.text.valueOf() - return - } - - curVal = 0 - display.currentOperation.text = "" - - if (op == "1/x") { - display.text = (1 / display.text.valueOf()).toString() - } else if (op == "x^2") { - display.text = (display.text.valueOf() * display.text.valueOf()).toString() - } else if (op == "Abs") { - display.text = (Math.abs(display.text.valueOf())).toString() - } else if (op == "Int") { - display.text = (Math.floor(display.text.valueOf())).toString() - } else if (op == plusminus) { - display.text = (display.text.valueOf() * -1).toString() - } else if (op == squareRoot) { - display.text = (Math.sqrt(display.text.valueOf())).toString() - } else if (op == "mc") { - memory = 0; - } else if (op == "m+") { - memory += display.text.valueOf() - } else if (op == "mr") { - display.text = memory.toString() - } else if (op == "m-") { - memory = display.text.valueOf() - } else if (op == leftArrow) { - display.text = display.text.toString().slice(0, -1) - if (display.text.length == 0) { - display.text = "0" - } - } else if (op == "Off") { - Qt.quit(); - } else if (op == "C") { - display.text = "0" - } else if (op == "AC") { - curVal = 0 - memory = 0 - lastOp = "" - display.text ="0" - } -} - diff --git a/examples/declarative/calculator/Core/images/button-.png b/examples/declarative/calculator/Core/images/button-.png deleted file mode 100644 index 544e514536..0000000000 Binary files a/examples/declarative/calculator/Core/images/button-.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/images/button-blue.png b/examples/declarative/calculator/Core/images/button-blue.png deleted file mode 100644 index 5f92de32d0..0000000000 Binary files a/examples/declarative/calculator/Core/images/button-blue.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/images/button-green.png b/examples/declarative/calculator/Core/images/button-green.png deleted file mode 100644 index 36c93914c7..0000000000 Binary files a/examples/declarative/calculator/Core/images/button-green.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/images/button-purple.png b/examples/declarative/calculator/Core/images/button-purple.png deleted file mode 100644 index 347cbbea9d..0000000000 Binary files a/examples/declarative/calculator/Core/images/button-purple.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/images/button-red.png b/examples/declarative/calculator/Core/images/button-red.png deleted file mode 100644 index 3b335891ae..0000000000 Binary files a/examples/declarative/calculator/Core/images/button-red.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/images/display.png b/examples/declarative/calculator/Core/images/display.png deleted file mode 100644 index 9507f4382e..0000000000 Binary files a/examples/declarative/calculator/Core/images/display.png and /dev/null differ diff --git a/examples/declarative/calculator/Core/qmldir b/examples/declarative/calculator/Core/qmldir deleted file mode 100644 index a926b93fac..0000000000 --- a/examples/declarative/calculator/Core/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -Button Button.qml -Display Display.qml diff --git a/examples/declarative/calculator/calculator.qml b/examples/declarative/calculator/calculator.qml index d447822430..80f90f5fe9 100644 --- a/examples/declarative/calculator/calculator.qml +++ b/examples/declarative/calculator/calculator.qml @@ -41,8 +41,8 @@ import QtQuick 2.0 import QtQuick.Window 2.0 -import "Core" -import "Core/calculator.js" as CalcEngine +import "content" +import "content/calculator.js" as CalcEngine Rectangle { id: window diff --git a/examples/declarative/calculator/content/Button.qml b/examples/declarative/calculator/content/Button.qml new file mode 100644 index 0000000000..2b4e2f5b0f --- /dev/null +++ b/examples/declarative/calculator/content/Button.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +BorderImage { + id: button + + property alias operation: buttonText.text + property string color: "" + + Accessible.name: operation + Accessible.description: "This button does " + operation + Accessible.role: Accessible.Button + + signal clicked + + source: "images/button-" + color + ".png"; clip: true + border { left: 10; top: 10; right: 10; bottom: 10 } + + Rectangle { + id: shade + anchors.fill: button; radius: 10; color: "black"; opacity: 0 + } + + Text { + id: buttonText + anchors.centerIn: parent; anchors.verticalCenterOffset: -1 + font.pixelSize: parent.width > parent.height ? parent.height * .5 : parent.width * .5 + style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true + } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: { + doOp(operation) + button.clicked() + } + } + + states: State { + name: "pressed"; when: mouseArea.pressed == true + PropertyChanges { target: shade; opacity: .4 } + } +} diff --git a/examples/declarative/calculator/content/Display.qml b/examples/declarative/calculator/content/Display.qml new file mode 100644 index 0000000000..a3fa2e976a --- /dev/null +++ b/examples/declarative/calculator/content/Display.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +BorderImage { + id: image + + property alias text : displayText.text + property alias currentOperation : operationText + + source: "images/display.png" + border { left: 10; top: 10; right: 10; bottom: 10 } + + Text { + id: displayText + anchors { + right: parent.right; verticalCenter: parent.verticalCenter; verticalCenterOffset: -1 + rightMargin: 6; left: operationText.right + } + font.pixelSize: parent.height * .6; text: "0"; horizontalAlignment: Text.AlignRight; elide: Text.ElideRight + color: "#343434"; smooth: true; font.bold: true + } + Text { + id: operationText + font.bold: true; font.pixelSize: parent.height * .7 + color: "#343434"; smooth: true + anchors { left: parent.left; leftMargin: 6; verticalCenterOffset: -3; verticalCenter: parent.verticalCenter } + } +} diff --git a/examples/declarative/calculator/content/calculator.js b/examples/declarative/calculator/content/calculator.js new file mode 100644 index 0000000000..7c363c7f30 --- /dev/null +++ b/examples/declarative/calculator/content/calculator.js @@ -0,0 +1,91 @@ + +var curVal = 0 +var memory = 0 +var lastOp = "" +var timer = 0 + +function disabled(op) { + if (op == "." && display.text.toString().search(/\./) != -1) { + return true + } else if (op == squareRoot && display.text.toString().search(/-/) != -1) { + return true + } else { + return false + } +} + +function doOperation(op) { + if (disabled(op)) { + return + } + + if (op.toString().length==1 && ((op >= "0" && op <= "9") || op==".") ) { + if (display.text.toString().length >= 14) + return; // No arbitrary length numbers + if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp == ".") ) { + display.text = display.text + op.toString() + } else { + display.text = op + } + lastOp = op + return + } + lastOp = op + + if (display.currentOperation.text == "+") { + display.text = Number(display.text.valueOf()) + Number(curVal.valueOf()) + } else if (display.currentOperation.text == "-") { + display.text = Number(curVal) - Number(display.text.valueOf()) + } else if (display.currentOperation.text == multiplication) { + display.text = Number(curVal) * Number(display.text.valueOf()) + } else if (display.currentOperation.text == division) { + display.text = Number(Number(curVal) / Number(display.text.valueOf())).toString() + } else if (display.currentOperation.text == "=") { + } + + if (op == "+" || op == "-" || op == multiplication || op == division) { + display.currentOperation.text = op + curVal = display.text.valueOf() + return + } + + curVal = 0 + display.currentOperation.text = "" + + if (op == "1/x") { + display.text = (1 / display.text.valueOf()).toString() + } else if (op == "x^2") { + display.text = (display.text.valueOf() * display.text.valueOf()).toString() + } else if (op == "Abs") { + display.text = (Math.abs(display.text.valueOf())).toString() + } else if (op == "Int") { + display.text = (Math.floor(display.text.valueOf())).toString() + } else if (op == plusminus) { + display.text = (display.text.valueOf() * -1).toString() + } else if (op == squareRoot) { + display.text = (Math.sqrt(display.text.valueOf())).toString() + } else if (op == "mc") { + memory = 0; + } else if (op == "m+") { + memory += display.text.valueOf() + } else if (op == "mr") { + display.text = memory.toString() + } else if (op == "m-") { + memory = display.text.valueOf() + } else if (op == leftArrow) { + display.text = display.text.toString().slice(0, -1) + if (display.text.length == 0) { + display.text = "0" + } + } else if (op == "Off") { + Qt.quit(); + } else if (op == "C") { + display.text = "0" + } else if (op == "AC") { + curVal = 0 + memory = 0 + lastOp = "" + display.text ="0" + } +} + diff --git a/examples/declarative/calculator/content/images/button-.png b/examples/declarative/calculator/content/images/button-.png new file mode 100644 index 0000000000..544e514536 Binary files /dev/null and b/examples/declarative/calculator/content/images/button-.png differ diff --git a/examples/declarative/calculator/content/images/button-blue.png b/examples/declarative/calculator/content/images/button-blue.png new file mode 100644 index 0000000000..5f92de32d0 Binary files /dev/null and b/examples/declarative/calculator/content/images/button-blue.png differ diff --git a/examples/declarative/calculator/content/images/button-green.png b/examples/declarative/calculator/content/images/button-green.png new file mode 100644 index 0000000000..36c93914c7 Binary files /dev/null and b/examples/declarative/calculator/content/images/button-green.png differ diff --git a/examples/declarative/calculator/content/images/button-purple.png b/examples/declarative/calculator/content/images/button-purple.png new file mode 100644 index 0000000000..347cbbea9d Binary files /dev/null and b/examples/declarative/calculator/content/images/button-purple.png differ diff --git a/examples/declarative/calculator/content/images/button-red.png b/examples/declarative/calculator/content/images/button-red.png new file mode 100644 index 0000000000..3b335891ae Binary files /dev/null and b/examples/declarative/calculator/content/images/button-red.png differ diff --git a/examples/declarative/calculator/content/images/display.png b/examples/declarative/calculator/content/images/display.png new file mode 100644 index 0000000000..9507f4382e Binary files /dev/null and b/examples/declarative/calculator/content/images/display.png differ diff --git a/examples/declarative/calculator/content/qmldir b/examples/declarative/calculator/content/qmldir new file mode 100644 index 0000000000..a926b93fac --- /dev/null +++ b/examples/declarative/calculator/content/qmldir @@ -0,0 +1,2 @@ +Button Button.qml +Display Display.qml diff --git a/examples/declarative/samegame/SamegameCore/BoomBlock.qml b/examples/declarative/samegame/SamegameCore/BoomBlock.qml deleted file mode 100644 index 7bc0d31d6f..0000000000 --- a/examples/declarative/samegame/SamegameCore/BoomBlock.qml +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Item { - id: block - property bool dying: false - property bool spawned: false - property int type: 0 - property ParticleSystem particleSystem - - Behavior on x { - enabled: spawned; - SpringAnimation{ spring: 2; damping: 0.2 } - } - Behavior on y { - SpringAnimation{ spring: 2; damping: 0.2 } - } - - Image { - id: img - source: { - if(type == 0){ - "pics/redStone.png"; - } else if(type == 1) { - "pics/blueStone.png"; - } else { - "pics/greenStone.png"; - } - } - opacity: 0 - Behavior on opacity { NumberAnimation { duration: 200 } } - anchors.fill: parent - } - Emitter { - id: particles - system: particleSystem - group: { - if(type == 0){ - "red"; - } else if (type == 1) { - "blue"; - } else { - "green"; - } - } - anchors.fill: parent - - speed: TargetDirection{targetX: block.width/2; targetY: block.height/2; magnitude: -60; magnitudeVariation: 60} - shape: EllipseShape{fill:true} - enabled: false; - lifeSpan: 700; lifeSpanVariation: 100 - emitRate: 1000 - maximumEmitted: 100 //only fires 0.1s bursts (still 2x old number) - size: 28 - endSize: 14 - } - - states: [ - State { - name: "AliveState"; when: spawned == true && dying == false - PropertyChanges { target: img; opacity: 1 } - }, - - State { - name: "DeathState"; when: dying == true - StateChangeScript { script: {particleSystem.paused = false; particles.pulse(100);} } - PropertyChanges { target: img; opacity: 0 } - StateChangeScript { script: block.destroy(1000); } - } - ] -} diff --git a/examples/declarative/samegame/SamegameCore/Button.qml b/examples/declarative/samegame/SamegameCore/Button.qml deleted file mode 100644 index 5b64302c0f..0000000000 --- a/examples/declarative/samegame/SamegameCore/Button.qml +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: container - - property string text: "Button" - - signal clicked - - width: buttonLabel.width + 20; height: buttonLabel.height + 20 - smooth: true - border { width: 1; color: Qt.darker(activePalette.button) } - radius: 8 - color: activePalette.button - - gradient: Gradient { - GradientStop { - position: 0.0 - color: { - if (mouseArea.pressed) - return activePalette.dark - else - return activePalette.light - } - } - GradientStop { position: 1.0; color: activePalette.button } - } - - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } - - Text { - id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText; font.pixelSize: 24 - } -} diff --git a/examples/declarative/samegame/SamegameCore/Dialog.qml b/examples/declarative/samegame/SamegameCore/Dialog.qml deleted file mode 100644 index b4d3e00b4f..0000000000 --- a/examples/declarative/samegame/SamegameCore/Dialog.qml +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: page - anchors.centerIn: parent - - property Item text: dialogText - property bool open: false - - signal closed - signal opened - function forceClose() { - if(!open) - return; //already closed - page.open = false; - page.closed(); - page.opacity = 0; - } - - function show(txt) { - page.open = true; - page.opened(); - dialogText.text = txt; - page.opacity = 1; - } - - width: dialogText.width + 20; height: dialogText.height + 20 - color: "white" - border.width: 1 - opacity: 0 - visible: opacity > 0 - Behavior on opacity { - NumberAnimation { duration: 1000 } - } - - Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } - - MouseArea { anchors.fill: parent; onClicked: forceClose(); } -} - diff --git a/examples/declarative/samegame/SamegameCore/GameArea.qml b/examples/declarative/samegame/SamegameCore/GameArea.qml deleted file mode 100644 index 14c52e939c..0000000000 --- a/examples/declarative/samegame/SamegameCore/GameArea.qml +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 -import "samegame.js" as Logic - -Item { - id: gameCanvas - property int score: 0 - property int blockSize: 40 - property ParticleSystem ps: particleSystem - Image { - id: background - anchors.fill: parent - z: -1 - source: "pics/background.png" - fillMode: Image.PreserveAspectCrop - } - - width: 480 - height: 800 - MouseArea { - anchors.fill: parent; onClicked: Logic.handleClick(mouse.x,mouse.y); - } - ParticleSystem{ - id: particleSystem; - onEmptyChanged: if (empty) paused = true; - z:2 - ImageParticle { - groups: ["red"] - color: Qt.darker("red");//Actually want desaturated... - source: "pics/particle.png" - colorVariation: 0.4 - alpha: 0.1 - } - ImageParticle { - groups: ["green"] - color: Qt.darker("green");//Actually want desaturated... - source: "pics/particle.png" - colorVariation: 0.4 - alpha: 0.1 - } - ImageParticle { - groups: ["blue"] - color: Qt.darker("blue");//Actually want desaturated... - source: "pics/particle.png" - colorVariation: 0.4 - alpha: 0.1 - } - anchors.fill: parent - } -} - diff --git a/examples/declarative/samegame/SamegameCore/NameInputDialog.qml b/examples/declarative/samegame/SamegameCore/NameInputDialog.qml deleted file mode 100644 index 05578e0ab6..0000000000 --- a/examples/declarative/samegame/SamegameCore/NameInputDialog.qml +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -import QtQuick 2.0 - -Dialog { - id: nameInputDialog - - property int initialWidth: 0 - property alias name: nameInputText.text - - anchors.centerIn: parent - z: 22; - - Behavior on width { - NumberAnimation {} - enabled: nameInputDialog.initialWidth != 0 - } - - signal accepted(string name) - onClosed: { - if (nameInputText.text != "") - accepted(name); - } - Text { - id: dialogText - anchors { left: nameInputDialog.left; leftMargin: 20; verticalCenter: parent.verticalCenter } - text: "You won! Please enter your name: " - } - MouseArea { - anchors.fill: parent - onClicked: { - if (nameInputText.text == "") - nameInputText.openSoftwareInputPanel(); - else - nameInputDialog.forceClose(); - } - } - - TextInput { - id: nameInputText - anchors { verticalCenter: parent.verticalCenter; left: dialogText.right } - focus: visible - autoScroll: false - maximumLength: 24 - onTextChanged: { - var newWidth = nameInputText.width + dialogText.width + 40; - if ( (newWidth > nameInputDialog.width && newWidth < screen.width) - || (nameInputDialog.width > nameInputDialog.initialWidth) ) - nameInputDialog.width = newWidth; - } - onAccepted: { - nameInputDialog.forceClose(); - } - } -} diff --git a/examples/declarative/samegame/SamegameCore/pics/background.png b/examples/declarative/samegame/SamegameCore/pics/background.png deleted file mode 100644 index 3734a27744..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/background.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/pics/blueStone.png b/examples/declarative/samegame/SamegameCore/pics/blueStone.png deleted file mode 100644 index 20e43c75b6..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/blueStone.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/pics/greenStone.png b/examples/declarative/samegame/SamegameCore/pics/greenStone.png deleted file mode 100644 index b568a1900c..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/greenStone.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/pics/particle.png b/examples/declarative/samegame/SamegameCore/pics/particle.png deleted file mode 100644 index 5c83896d22..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/particle.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/pics/redStone.png b/examples/declarative/samegame/SamegameCore/pics/redStone.png deleted file mode 100644 index 36b09a2686..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/redStone.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/pics/yellowStone.png b/examples/declarative/samegame/SamegameCore/pics/yellowStone.png deleted file mode 100644 index b1ce76212c..0000000000 Binary files a/examples/declarative/samegame/SamegameCore/pics/yellowStone.png and /dev/null differ diff --git a/examples/declarative/samegame/SamegameCore/samegame.js b/examples/declarative/samegame/SamegameCore/samegame.js deleted file mode 100755 index 8c15af763a..0000000000 --- a/examples/declarative/samegame/SamegameCore/samegame.js +++ /dev/null @@ -1,289 +0,0 @@ -/* This script file handles the game logic */ -.pragma library - -var maxColumn = 10; -var maxRow = 15; -var maxIndex = maxColumn*maxRow; -var board = new Array(maxIndex); -var blockSrc = "BoomBlock.qml"; -var scoresURL = ""; -var gameDuration; -var component = Qt.createComponent(blockSrc); -var highScoreBar = -1; -var gameCanvas; -var nameInputDialog = null; -var dialog = null; - -// Index function used instead of a 2D array -function index(column, row) -{ - return column + row * maxColumn; -} - -function timeStr(msecs) -{ - var secs = Math.floor(msecs/1000); - var m = Math.floor(secs/60); - var ret = "" + m + "m " + (secs%60) + "s"; - return ret; -} - -function startNewGame(gc) -{ - gameCanvas = gc; - // Delete blocks from previous game - for (var i = 0; i < maxIndex; i++) { - if (board[i] != null) - board[i].destroy(); - } - - // Calculate board size - maxColumn = Math.floor(gameCanvas.width/gameCanvas.blockSize); - maxRow = Math.floor(gameCanvas.height/gameCanvas.blockSize); - maxIndex = maxRow * maxColumn; - - // Close dialogs - if(nameInputDialog != null) - nameInputDialog.forceClose(); - if(dialog != null) - dialog.forceClose(); - - // Initialize Board - board = new Array(maxIndex); - gameCanvas.score = 0; - for (var column = 0; column < maxColumn; column++) { - for (var row = 0; row < maxRow; row++) { - board[index(column, row)] = null; - createBlock(column, row); - } - } - gameDuration = new Date(); -} - -var fillFound; // Set after a floodFill call to the number of blocks found -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) -{ - if(gameCanvas == undefined){ - console.log("But the game hasn't started yet!"); - return; - } - 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) - return; - // If it's a valid block, remove it and all connected (does nothing if it's not connected) - floodFill(column,row, -1); - if (fillFound <= 0) - return; - gameCanvas.score += (fillFound - 1) * (fillFound - 1); - shuffleDown(); - victoryCheck(); -} - -function floodFill(column,row,type) -{ - if (board[index(column, row)] == null) - return; - var first = false; - if (type == -1) { - first = true; - type = board[index(column,row)].type; - - // Flood fill initialization - fillFound = 0; - floodBoard = new Array(maxIndex); - } - if (column >= maxColumn || column < 0 || row >= maxRow || row < 0) - return; - if (floodBoard[index(column, row)] == 1 || (!first && type != board[index(column, row)].type)) - return; - 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 blocks - board[index(column, row)].dying = true; - board[index(column, row)] = null; - fillFound += 1; -} - -function shuffleDown() -{ - // Fall down - for (var column = 0; column < maxColumn; column++) { - var fallDist = 0; - for (var row = maxRow - 1; row >= 0; row--) { - if (board[index(column,row)] == null) { - fallDist += 1; - } else { - if (fallDist > 0) { - var obj = board[index(column, row)]; - obj.y = (row + fallDist) * gameCanvas.blockSize; - board[index(column, row + fallDist)] = obj; - board[index(column, row)] = null; - } - } - } - } - // Fall to the left - fallDist = 0; - for (column = 0; column < maxColumn; column++) { - if (board[index(column, maxRow - 1)] == null) { - fallDist += 1; - } else { - if (fallDist > 0) { - for (row = 0; row < maxRow; row++) { - obj = board[index(column, row)]; - if (obj == null) - continue; - obj.x = (column - fallDist) * gameCanvas.blockSize; - board[index(column - fallDist,row)] = obj; - board[index(column, row)] = null; - } - } - } - } -} - -function victoryCheck() -{ - // Awards bonuses for no blocks left - var deservesBonus = true; - 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, maxRow - 1, -1))) { - gameDuration = new Date() - gameDuration; - if(nameInputDialog == null){ - nameInputDialog = Qt.createQmlObject('import "."; import "samegame.js" as Logic; NameInputDialog{onAccepted: Logic.saveHighScore(name)}', gameCanvas, "highscoredialog.qml"); - } - if(dialog == null){ - dialog = Qt.createComponent("Dialog.qml").createObject(gameCanvas); - } - initHighScoreBar(); - if(gameCanvas.score > highScoreBar){ - nameInputDialog.show("You won! Please enter your name: "); - nameInputDialog.initialWidth = nameInputDialog.text.width + 20; - if (nameInputDialog.name == "") - nameInputDialog.width = nameInputDialog.initialWidth; - nameInputDialog.text.opacity = 0; // Just a spacer - }else{ - dialog.show("You won!"); - } - } -} - -// Only floods up and right, to see if it can find adjacent same-typed blocks -function floodMoveCheck(column, row, type) -{ - if (column >= maxColumn || column < 0 || row >= maxRow || row < 0) - return false; - if (board[index(column, row)] == null) - return false; - var myType = board[index(column, row)].type; - if (type == myType) - return true; - return floodMoveCheck(column + 1, row, myType) || - floodMoveCheck(column, row - 1, board[index(column, row)].type); -} - -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 - // component you could use if you want to wait to load remote files. - if(component.status == 1){ - var dynamicObject = component.createObject(gameCanvas, - {"type": Math.floor(Math.random() * 3), - "x": column*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*gameCanvas.blockSize; - dynamicObject.spawned = true; - - board[index(column,row)] = dynamicObject; - }else{ - console.log("error loading block component"); - console.log(component.errorString()); - return false; - } - return true; -} - -function initHighScoreBar() -{ - var db = openDatabaseSync( - "SameGameScores", - "1.0", - "Local SameGame High Scores", - 100 - ); - db.transaction( - function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); - // Only show results for the current grid size - var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "' - + maxColumn + "x" + maxRow + '" ORDER BY score desc LIMIT 10'); - if(rs.rows.length < 10) - highScoreBar = 0; - else - highScoreBar = rs.rows.item(rs.rows.length - 1).score; - } - ); -} - -function saveHighScore(name) -{ - if (scoresURL != "") - sendHighScore(name); - // Offline storage - var db = openDatabaseSync( - "SameGameScores", - "1.0", - "Local SameGame High Scores", - 100 - ); - var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; - var data = [ - name, - gameCanvas.score, - maxColumn + "x" + maxRow, - Math.floor(gameDuration / 1000) - ]; - db.transaction( - function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); - tx.executeSql(dataStr, data); - - // Only show results for the current grid size - var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "' - + maxColumn + "x" + maxRow + '" ORDER BY score desc LIMIT 10'); - var r = "\nHIGH SCORES for this grid size\n\n" - for (var i = 0; i < rs.rows.length; i++) { - r += (i+1) + ". " + rs.rows.item(i).name + ' got ' - + rs.rows.item(i).score + ' points in ' - + rs.rows.item(i).time + ' seconds.\n'; - } - if(rs.rows.length == 10) - highScoreBar = rs.rows.item(9).score; - dialog.show(r); - } - ); -} diff --git a/examples/declarative/samegame/content/BoomBlock.qml b/examples/declarative/samegame/content/BoomBlock.qml new file mode 100644 index 0000000000..7bc0d31d6f --- /dev/null +++ b/examples/declarative/samegame/content/BoomBlock.qml @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Item { + id: block + property bool dying: false + property bool spawned: false + property int type: 0 + property ParticleSystem particleSystem + + Behavior on x { + enabled: spawned; + SpringAnimation{ spring: 2; damping: 0.2 } + } + Behavior on y { + SpringAnimation{ spring: 2; damping: 0.2 } + } + + Image { + id: img + source: { + if(type == 0){ + "pics/redStone.png"; + } else if(type == 1) { + "pics/blueStone.png"; + } else { + "pics/greenStone.png"; + } + } + opacity: 0 + Behavior on opacity { NumberAnimation { duration: 200 } } + anchors.fill: parent + } + Emitter { + id: particles + system: particleSystem + group: { + if(type == 0){ + "red"; + } else if (type == 1) { + "blue"; + } else { + "green"; + } + } + anchors.fill: parent + + speed: TargetDirection{targetX: block.width/2; targetY: block.height/2; magnitude: -60; magnitudeVariation: 60} + shape: EllipseShape{fill:true} + enabled: false; + lifeSpan: 700; lifeSpanVariation: 100 + emitRate: 1000 + maximumEmitted: 100 //only fires 0.1s bursts (still 2x old number) + size: 28 + endSize: 14 + } + + states: [ + State { + name: "AliveState"; when: spawned == true && dying == false + PropertyChanges { target: img; opacity: 1 } + }, + + State { + name: "DeathState"; when: dying == true + StateChangeScript { script: {particleSystem.paused = false; particles.pulse(100);} } + PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } + } + ] +} diff --git a/examples/declarative/samegame/content/Button.qml b/examples/declarative/samegame/content/Button.qml new file mode 100644 index 0000000000..5b64302c0f --- /dev/null +++ b/examples/declarative/samegame/content/Button.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: container + + property string text: "Button" + + signal clicked + + width: buttonLabel.width + 20; height: buttonLabel.height + 20 + smooth: true + border { width: 1; color: Qt.darker(activePalette.button) } + radius: 8 + color: activePalette.button + + gradient: Gradient { + GradientStop { + position: 0.0 + color: { + if (mouseArea.pressed) + return activePalette.dark + else + return activePalette.light + } + } + GradientStop { position: 1.0; color: activePalette.button } + } + + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } + + Text { + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText; font.pixelSize: 24 + } +} diff --git a/examples/declarative/samegame/content/Dialog.qml b/examples/declarative/samegame/content/Dialog.qml new file mode 100644 index 0000000000..b4d3e00b4f --- /dev/null +++ b/examples/declarative/samegame/content/Dialog.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + anchors.centerIn: parent + + property Item text: dialogText + property bool open: false + + signal closed + signal opened + function forceClose() { + if(!open) + return; //already closed + page.open = false; + page.closed(); + page.opacity = 0; + } + + function show(txt) { + page.open = true; + page.opened(); + dialogText.text = txt; + page.opacity = 1; + } + + width: dialogText.width + 20; height: dialogText.height + 20 + color: "white" + border.width: 1 + opacity: 0 + visible: opacity > 0 + Behavior on opacity { + NumberAnimation { duration: 1000 } + } + + Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } + + MouseArea { anchors.fill: parent; onClicked: forceClose(); } +} + diff --git a/examples/declarative/samegame/content/GameArea.qml b/examples/declarative/samegame/content/GameArea.qml new file mode 100644 index 0000000000..14c52e939c --- /dev/null +++ b/examples/declarative/samegame/content/GameArea.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 +import "samegame.js" as Logic + +Item { + id: gameCanvas + property int score: 0 + property int blockSize: 40 + property ParticleSystem ps: particleSystem + Image { + id: background + anchors.fill: parent + z: -1 + source: "pics/background.png" + fillMode: Image.PreserveAspectCrop + } + + width: 480 + height: 800 + MouseArea { + anchors.fill: parent; onClicked: Logic.handleClick(mouse.x,mouse.y); + } + ParticleSystem{ + id: particleSystem; + onEmptyChanged: if (empty) paused = true; + z:2 + ImageParticle { + groups: ["red"] + color: Qt.darker("red");//Actually want desaturated... + source: "pics/particle.png" + colorVariation: 0.4 + alpha: 0.1 + } + ImageParticle { + groups: ["green"] + color: Qt.darker("green");//Actually want desaturated... + source: "pics/particle.png" + colorVariation: 0.4 + alpha: 0.1 + } + ImageParticle { + groups: ["blue"] + color: Qt.darker("blue");//Actually want desaturated... + source: "pics/particle.png" + colorVariation: 0.4 + alpha: 0.1 + } + anchors.fill: parent + } +} + diff --git a/examples/declarative/samegame/content/NameInputDialog.qml b/examples/declarative/samegame/content/NameInputDialog.qml new file mode 100644 index 0000000000..05578e0ab6 --- /dev/null +++ b/examples/declarative/samegame/content/NameInputDialog.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 + +Dialog { + id: nameInputDialog + + property int initialWidth: 0 + property alias name: nameInputText.text + + anchors.centerIn: parent + z: 22; + + Behavior on width { + NumberAnimation {} + enabled: nameInputDialog.initialWidth != 0 + } + + signal accepted(string name) + onClosed: { + if (nameInputText.text != "") + accepted(name); + } + Text { + id: dialogText + anchors { left: nameInputDialog.left; leftMargin: 20; verticalCenter: parent.verticalCenter } + text: "You won! Please enter your name: " + } + MouseArea { + anchors.fill: parent + onClicked: { + if (nameInputText.text == "") + nameInputText.openSoftwareInputPanel(); + else + nameInputDialog.forceClose(); + } + } + + TextInput { + id: nameInputText + anchors { verticalCenter: parent.verticalCenter; left: dialogText.right } + focus: visible + autoScroll: false + maximumLength: 24 + onTextChanged: { + var newWidth = nameInputText.width + dialogText.width + 40; + if ( (newWidth > nameInputDialog.width && newWidth < screen.width) + || (nameInputDialog.width > nameInputDialog.initialWidth) ) + nameInputDialog.width = newWidth; + } + onAccepted: { + nameInputDialog.forceClose(); + } + } +} diff --git a/examples/declarative/samegame/content/pics/background.png b/examples/declarative/samegame/content/pics/background.png new file mode 100644 index 0000000000..3734a27744 Binary files /dev/null and b/examples/declarative/samegame/content/pics/background.png differ diff --git a/examples/declarative/samegame/content/pics/blueStone.png b/examples/declarative/samegame/content/pics/blueStone.png new file mode 100644 index 0000000000..20e43c75b6 Binary files /dev/null and b/examples/declarative/samegame/content/pics/blueStone.png differ diff --git a/examples/declarative/samegame/content/pics/greenStone.png b/examples/declarative/samegame/content/pics/greenStone.png new file mode 100644 index 0000000000..b568a1900c Binary files /dev/null and b/examples/declarative/samegame/content/pics/greenStone.png differ diff --git a/examples/declarative/samegame/content/pics/particle.png b/examples/declarative/samegame/content/pics/particle.png new file mode 100644 index 0000000000..5c83896d22 Binary files /dev/null and b/examples/declarative/samegame/content/pics/particle.png differ diff --git a/examples/declarative/samegame/content/pics/redStone.png b/examples/declarative/samegame/content/pics/redStone.png new file mode 100644 index 0000000000..36b09a2686 Binary files /dev/null and b/examples/declarative/samegame/content/pics/redStone.png differ diff --git a/examples/declarative/samegame/content/pics/yellowStone.png b/examples/declarative/samegame/content/pics/yellowStone.png new file mode 100644 index 0000000000..b1ce76212c Binary files /dev/null and b/examples/declarative/samegame/content/pics/yellowStone.png differ diff --git a/examples/declarative/samegame/content/samegame.js b/examples/declarative/samegame/content/samegame.js new file mode 100755 index 0000000000..8c15af763a --- /dev/null +++ b/examples/declarative/samegame/content/samegame.js @@ -0,0 +1,289 @@ +/* This script file handles the game logic */ +.pragma library + +var maxColumn = 10; +var maxRow = 15; +var maxIndex = maxColumn*maxRow; +var board = new Array(maxIndex); +var blockSrc = "BoomBlock.qml"; +var scoresURL = ""; +var gameDuration; +var component = Qt.createComponent(blockSrc); +var highScoreBar = -1; +var gameCanvas; +var nameInputDialog = null; +var dialog = null; + +// Index function used instead of a 2D array +function index(column, row) +{ + return column + row * maxColumn; +} + +function timeStr(msecs) +{ + var secs = Math.floor(msecs/1000); + var m = Math.floor(secs/60); + var ret = "" + m + "m " + (secs%60) + "s"; + return ret; +} + +function startNewGame(gc) +{ + gameCanvas = gc; + // Delete blocks from previous game + for (var i = 0; i < maxIndex; i++) { + if (board[i] != null) + board[i].destroy(); + } + + // Calculate board size + maxColumn = Math.floor(gameCanvas.width/gameCanvas.blockSize); + maxRow = Math.floor(gameCanvas.height/gameCanvas.blockSize); + maxIndex = maxRow * maxColumn; + + // Close dialogs + if(nameInputDialog != null) + nameInputDialog.forceClose(); + if(dialog != null) + dialog.forceClose(); + + // Initialize Board + board = new Array(maxIndex); + gameCanvas.score = 0; + for (var column = 0; column < maxColumn; column++) { + for (var row = 0; row < maxRow; row++) { + board[index(column, row)] = null; + createBlock(column, row); + } + } + gameDuration = new Date(); +} + +var fillFound; // Set after a floodFill call to the number of blocks found +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) +{ + if(gameCanvas == undefined){ + console.log("But the game hasn't started yet!"); + return; + } + 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) + return; + // If it's a valid block, remove it and all connected (does nothing if it's not connected) + floodFill(column,row, -1); + if (fillFound <= 0) + return; + gameCanvas.score += (fillFound - 1) * (fillFound - 1); + shuffleDown(); + victoryCheck(); +} + +function floodFill(column,row,type) +{ + if (board[index(column, row)] == null) + return; + var first = false; + if (type == -1) { + first = true; + type = board[index(column,row)].type; + + // Flood fill initialization + fillFound = 0; + floodBoard = new Array(maxIndex); + } + if (column >= maxColumn || column < 0 || row >= maxRow || row < 0) + return; + if (floodBoard[index(column, row)] == 1 || (!first && type != board[index(column, row)].type)) + return; + 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 blocks + board[index(column, row)].dying = true; + board[index(column, row)] = null; + fillFound += 1; +} + +function shuffleDown() +{ + // Fall down + for (var column = 0; column < maxColumn; column++) { + var fallDist = 0; + for (var row = maxRow - 1; row >= 0; row--) { + if (board[index(column,row)] == null) { + fallDist += 1; + } else { + if (fallDist > 0) { + var obj = board[index(column, row)]; + obj.y = (row + fallDist) * gameCanvas.blockSize; + board[index(column, row + fallDist)] = obj; + board[index(column, row)] = null; + } + } + } + } + // Fall to the left + fallDist = 0; + for (column = 0; column < maxColumn; column++) { + if (board[index(column, maxRow - 1)] == null) { + fallDist += 1; + } else { + if (fallDist > 0) { + for (row = 0; row < maxRow; row++) { + obj = board[index(column, row)]; + if (obj == null) + continue; + obj.x = (column - fallDist) * gameCanvas.blockSize; + board[index(column - fallDist,row)] = obj; + board[index(column, row)] = null; + } + } + } + } +} + +function victoryCheck() +{ + // Awards bonuses for no blocks left + var deservesBonus = true; + 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, maxRow - 1, -1))) { + gameDuration = new Date() - gameDuration; + if(nameInputDialog == null){ + nameInputDialog = Qt.createQmlObject('import "."; import "samegame.js" as Logic; NameInputDialog{onAccepted: Logic.saveHighScore(name)}', gameCanvas, "highscoredialog.qml"); + } + if(dialog == null){ + dialog = Qt.createComponent("Dialog.qml").createObject(gameCanvas); + } + initHighScoreBar(); + if(gameCanvas.score > highScoreBar){ + nameInputDialog.show("You won! Please enter your name: "); + nameInputDialog.initialWidth = nameInputDialog.text.width + 20; + if (nameInputDialog.name == "") + nameInputDialog.width = nameInputDialog.initialWidth; + nameInputDialog.text.opacity = 0; // Just a spacer + }else{ + dialog.show("You won!"); + } + } +} + +// Only floods up and right, to see if it can find adjacent same-typed blocks +function floodMoveCheck(column, row, type) +{ + if (column >= maxColumn || column < 0 || row >= maxRow || row < 0) + return false; + if (board[index(column, row)] == null) + return false; + var myType = board[index(column, row)].type; + if (type == myType) + return true; + return floodMoveCheck(column + 1, row, myType) || + floodMoveCheck(column, row - 1, board[index(column, row)].type); +} + +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 + // component you could use if you want to wait to load remote files. + if(component.status == 1){ + var dynamicObject = component.createObject(gameCanvas, + {"type": Math.floor(Math.random() * 3), + "x": column*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*gameCanvas.blockSize; + dynamicObject.spawned = true; + + board[index(column,row)] = dynamicObject; + }else{ + console.log("error loading block component"); + console.log(component.errorString()); + return false; + } + return true; +} + +function initHighScoreBar() +{ + var db = openDatabaseSync( + "SameGameScores", + "1.0", + "Local SameGame High Scores", + 100 + ); + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); + // Only show results for the current grid size + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "' + + maxColumn + "x" + maxRow + '" ORDER BY score desc LIMIT 10'); + if(rs.rows.length < 10) + highScoreBar = 0; + else + highScoreBar = rs.rows.item(rs.rows.length - 1).score; + } + ); +} + +function saveHighScore(name) +{ + if (scoresURL != "") + sendHighScore(name); + // Offline storage + var db = openDatabaseSync( + "SameGameScores", + "1.0", + "Local SameGame High Scores", + 100 + ); + var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; + var data = [ + name, + gameCanvas.score, + maxColumn + "x" + maxRow, + Math.floor(gameDuration / 1000) + ]; + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); + tx.executeSql(dataStr, data); + + // Only show results for the current grid size + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "' + + maxColumn + "x" + maxRow + '" ORDER BY score desc LIMIT 10'); + var r = "\nHIGH SCORES for this grid size\n\n" + for (var i = 0; i < rs.rows.length; i++) { + r += (i+1) + ". " + rs.rows.item(i).name + ' got ' + + rs.rows.item(i).score + ' points in ' + + rs.rows.item(i).time + ' seconds.\n'; + } + if(rs.rows.length == 10) + highScoreBar = rs.rows.item(9).score; + dialog.show(r); + } + ); +} diff --git a/examples/declarative/samegame/samegame.qml b/examples/declarative/samegame/samegame.qml index 43e956b359..8617a6b168 100644 --- a/examples/declarative/samegame/samegame.qml +++ b/examples/declarative/samegame/samegame.qml @@ -41,8 +41,8 @@ import QtQuick 2.0 import QtQuick.Particles 2.0 -import "SamegameCore" -import "SamegameCore/samegame.js" as Logic +import "content" +import "content/samegame.js" as Logic Rectangle { id: screen -- cgit v1.2.3