diff options
author | Zeno Albisser <zeno.albisser@nokia.com> | 2010-08-16 08:06:11 -0400 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@nokia.com> | 2010-08-16 08:06:11 -0400 |
commit | d60d1c109d07e5a820afce632a872c31c1a87565 (patch) | |
tree | a2739aee3f654f1a4a4682b759fe79e004d36664 | |
parent | 910dd4743d88c57bfea51d0d48d66cc02fef36e9 (diff) | |
parent | d4501656b7ca7d137afe6e45a28f673eca4a69b9 (diff) |
Merge branch 'master' of gitorious.org:stuff/qml-dashboard
-rwxr-xr-x | animals/Animal.qml | 143 | ||||
-rw-r--r-- | animals/memory.js | 48 | ||||
-rw-r--r-- | animals/memory.qml | 64 | ||||
-rw-r--r-- | multilayer-dashboard/MainWidget.qml | 62 | ||||
-rw-r--r-- | multilayer-dashboard/RowWidget.qml | 82 | ||||
-rw-r--r-- | multilayer-dashboard/TapWidget.qml | 116 |
6 files changed, 351 insertions, 164 deletions
diff --git a/animals/Animal.qml b/animals/Animal.qml index 2cdc70a..3e598ee 100755 --- a/animals/Animal.qml +++ b/animals/Animal.qml @@ -17,12 +17,77 @@ Rectangle { // to identify pairs of animals property int type; + state: "back"; + + states: [ + State { + name: "back" + }, + State { + name: "front" + }, + State { + name: "solved"; + extend: "front"; + } + ] + + transitions: [ + Transition { + from: "*" + to: "solved"; + ParallelAnimation { + NumberAnimation { + target: flipable; + property: "angle"; + to: 180; + duration: 1000 + } + NumberAnimation { target: animalRectangle; property: "opacity"; to: 0.9; duration: 1000;} + } + }, + + Transition { + from: "back"; + to: "*"; + NumberAnimation { + target: flipable; + property: "angle"; + from: 0; + to: 180; + duration: 1000 + } + }, + + Transition { + from: "front"; + to: "back"; + SequentialAnimation { + ScriptAction { + script: console.log("transition"); + } + NumberAnimation { + target: flipable; + property: "angle"; + to: 180; + duration: 1000 + } + PauseAnimation { duration: 1000 } + NumberAnimation { + target: flipable; + property: "angle"; + to: 0; + duration: 1000 + } + } + } + ] + Flipable { - id: flipable - anchors.fill: parent + id: flipable; + property int angle: 0; - property int angle: 0 - property bool flipped: false + anchors.fill: parent; Rectangle { radius: 10; @@ -48,94 +113,38 @@ Rectangle { axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis angle: flipable.angle } - - states: State { - name: "back" - PropertyChanges { target: flipable; angle: 180 } - when: flipable.flipped - } - - transitions: Transition { - NumberAnimation { properties: "angle"; duration: 1000 } - } - } - - states: [ - State { - name: "" - PropertyChanges { - target: animalRectangle - rotation: 0 - - } - }, - State { - name: "rotated" - PropertyChanges { - target: animalRectangle - - } - } - ] - - function hide() { - hideTimer.start(); - console.log("hiding: " + image); - } - - Timer { - id: hideTimer - interval: 2000; running: false; repeat: false - onTriggered: flipable.flipped = false; - } - - function showFront() { - flipable.flipped = true; - parent.animalFlipped(animalRectangle); } GestureArea { anchors.fill: parent Tap { - onStarted: { console.log("tap started"); - animalRectangle.z = 1; - } - onCanceled: { console.log("tap canceled"); - } - onFinished: { console.log("tap finished"); - animalRectangle.showFront(); - } + onFinished: animalRectangle.parent.animalTapped(animalRectangle); } TapAndHold { - onStarted: { console.log("tap-and-hold started"); } - onFinished: { console.log("tap-and-hold finished"); - animalRectangle.state = ""; - } + onStarted: console.log("tap-and-hold started"); + onFinished: console.log("tap-and-hold finished"); } Pan { + onStarted: animalRectangle.z = 1; onUpdated: { animalRectangle.x += gesture.delta.x; animalRectangle.y += gesture.delta.y; } + onFinished: animalRectangle.z = 0; } Pinch { - onStarted: { - animalRectangle.state = "rotated"; - } - + onStarted: animalRectangle.z = 1; onUpdated: { animalRectangle.rotation += gesture.rotationAngle - gesture.lastRotationAngle animalRectangle.scale = animalRectangle.scale * gesture.scaleFactor; animalRectangle.x += gesture.centerPoint.x - gesture.lastCenterPoint.x animalRectangle.y += gesture.centerPoint.y - gesture.lastCenterPoint.y - - console.log("center: " + gesture.centerPoint.x + " last center: " + gesture.lastCenterPoint.x); - } + onFinished: animalRectangle.z = 0; } } } diff --git a/animals/memory.js b/animals/memory.js index a01083a..1e2167c 100644 --- a/animals/memory.js +++ b/animals/memory.js @@ -1,6 +1,6 @@ var component; var maxRow = 3; -var maxColumn = 6; +var maxColumn = 4; var maxIndex = maxColumn * maxRow; var finished = new Array(); var positions = new Array(); @@ -52,15 +52,51 @@ function createAnimal(image, animalId, column, row) { } } + +var visibleAnimal; +var lastClicked; +function tileClicked(animal) { + if (animal.state == "solved") { + console.log("I'm done already."); + return; + } + if (animal.state == "front") { + console.log("clicked on front"); + return; + } + + if (animal == visibleAnimal) { + console.log("tile already visible"); + return; + } + + if (visibleAnimal == null) { + console.log("first animal uncovered"); + visibleAnimal = animal; + animal.state = "front"; + return; + } + + // we got a second animal - is it a pair? + if (visibleAnimal.type == animal.type) { + MemoryLogic.finishedTiles(animal, visibleAnimal); + } else { + console.log("not the same type"); + visibleAnimal.state = "back"; + animal.state = "front"; + animal.state = "back"; + } + visibleAnimal = null; +} + function finishedTiles(a1, a2) { finished.push(a1, a2); + a1.state = "solved"; + a2.state = "solved"; if (finished.length == maxIndex) { - console.log("Victoria"); for (var i = 0; i < maxIndex; i++) { - finished[i].opacity = 0.5; - finished[i].height *= 0.5; - finished[i].width *= 0.5; - finished[i].hide(); + //finished[i].destroy(); + victoryText.visible = true; } } else { console.log("got " + finished.length + " of " + maxIndex); diff --git a/animals/memory.qml b/animals/memory.qml index 583be7f..1a51a9e 100644 --- a/animals/memory.qml +++ b/animals/memory.qml @@ -25,33 +25,55 @@ Rectangle { } } - // last seen front - property Animal visibleAnimal; - // is the current card the first one - property bool firstAnimal : true; - - function animalFlipped(animal) { - if (animal == visibleAnimal) { - return; + Rectangle { + id: victoryText + visible: false; + + anchors.centerIn: parent; + width: 200; + height: 50; + color: "white" + border.color: "blue" + opacity: 0.8; + z: 10; + + Text { + anchors.centerIn: parent + font.pointSize: 24; + text: "You win!"; + } + } + + Rectangle { + id: close; + width: 40; + height: 40; + color: "transparent"; + border.color: "black"; + radius: 5; + anchors.right: parent.right; + anchors.top: parent.top; + + Text { + anchors.centerIn: parent + text: "x"; + font.pointSize: 24; } - if (firstAnimal) { - visibleAnimal = animal; - firstAnimal = false; - } else { - firstAnimal = true; - if (visibleAnimal != animal && visibleAnimal != null) { - if (visibleAnimal.type != animal.type) { - console.log("not the same type"); - visibleAnimal.hide(); - animal.hide(); - } else { - MemoryLogic.finishedTiles(animal, visibleAnimal); + GestureArea { + anchors.fill: parent; + TapAndHold { + onFinished: { + console.log("close"); + Qt.quit(); } } - visibleAnimal = animal; } } + + function animalTapped(animal) { + MemoryLogic.tileClicked(animal); + } } diff --git a/multilayer-dashboard/MainWidget.qml b/multilayer-dashboard/MainWidget.qml index bf178c3..96003b6 100644 --- a/multilayer-dashboard/MainWidget.qml +++ b/multilayer-dashboard/MainWidget.qml @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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: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 Nokia Corporation 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 Qt 4.7 import Qt.labs.gestures 1.0 @@ -8,23 +48,23 @@ Rectangle { id: dashboard Rectangle { - id: rowWidgetContainer - RowWidget { - id: firstRow + id: rowWidgetContainer + RowWidget { + id: firstRow reparentWidget: dashboard topLevel: dashboard - } + } - RowWidget { - id: secondRow - anchors.left : firstRow.right + RowWidget { + id: secondRow + anchors.left : firstRow.right reparentWidget: dashboard topLevel: dashboard } - RowWidget { - id: thirdRow - anchors.left : secondRow.right + RowWidget { + id: thirdRow + anchors.left : secondRow.right //reparentWidget: dashboard topLevel: dashboard } @@ -41,7 +81,7 @@ Rectangle { anchors.fill: dashboard Pan { - when: gesture.delta.y < 5 && gesture.delta.x != 0 + when: Math.abs(gesture.delta.y) < Math.abs(gesture.delta.x) onUpdated: { rowWidgetContainer.pos.x = rowWidgetContainer.pos.x + gesture.delta.x; diff --git a/multilayer-dashboard/RowWidget.qml b/multilayer-dashboard/RowWidget.qml index f7f950b..fed0681 100644 --- a/multilayer-dashboard/RowWidget.qml +++ b/multilayer-dashboard/RowWidget.qml @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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: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 Nokia Corporation 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 Qt 4.7 import Qt.labs.gestures 1.0 @@ -9,29 +49,29 @@ Rectangle { property variant topLevel: myRow Rectangle { - id: tapWidgetContainer + id: tapWidgetContainer - TapWidget { - x: 10 - id: firstWidget - color: "green" + TapWidget { + x: 10 + id: firstWidget + color: "green" reparentWidget: myRow.reparentWidget - } - TapWidget { - x:10 - anchors.top : firstWidget.bottom - anchors.topMargin : 2.0 - id: secondWidget - color: "blue" + } + TapWidget { + x:10 + anchors.top : firstWidget.bottom + anchors.topMargin : 2.0 + id: secondWidget + color: "blue" reparentWidget: myRow.reparentWidget - } - TapWidget { - x:10 - anchors.top : secondWidget.bottom - anchors.topMargin : 2.0 - id: thirdWidget + } + TapWidget { + x:10 + anchors.top : secondWidget.bottom + anchors.topMargin : 2.0 + id: thirdWidget reparentWidget: myRow.reparentWidget - } + } property int maxY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? 0 : @@ -42,11 +82,11 @@ Rectangle { } // end Rectangle GestureArea { - id: rowGestureArea + id: rowGestureArea anchors.fill: parent Pan { - when: gesture.delta.x < 5 && gesture.delta.y != 0 + when: Math.abs(gesture.delta.y) > Math.abs(gesture.delta.x) onUpdated: { tapWidgetContainer.pos.y = tapWidgetContainer.pos.y + gesture.delta.y; diff --git a/multilayer-dashboard/TapWidget.qml b/multilayer-dashboard/TapWidget.qml index e3442cc..b80787f 100644 --- a/multilayer-dashboard/TapWidget.qml +++ b/multilayer-dashboard/TapWidget.qml @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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: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 Nokia Corporation 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 Qt 4.7 import Qt.labs.gestures 1.0 @@ -9,49 +49,49 @@ Rectangle { property variant reparentWidget : testWidget Rectangle { - id: innerWidget - color: "steelblue" - radius: 10 - opacity: 0.3 - anchors.fill: testWidget - - property bool fullScreen : false - - Text { - id: labelText - text: "Press me, Hold me!!!" - anchors.centerIn: parent - } - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onEntered: { if (!innerWidget.fullScreen) parent.opacity = 0.8 } - onExited: { if (!innerWidget.fullScreen) parent.opacity = 0.3 } - } - - GestureArea { - id: tapGestureArea - anchors.fill: parent - TapAndHold { + id: innerWidget + color: "steelblue" + radius: 10 + opacity: 0.3 + anchors.fill: testWidget + + property bool fullScreen : false + + Text { + id: labelText + text: "Press me, Hold me!!!" + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onEntered: { if (!innerWidget.fullScreen) parent.opacity = 0.8 } + onExited: { if (!innerWidget.fullScreen) parent.opacity = 0.3 } + } + + GestureArea { + id: tapGestureArea + anchors.fill: parent + TapAndHold { onFinished: { - if (!innerWidget.fullScreen) { + if (!innerWidget.fullScreen) { innerWidget.opacity = 1.0 - innerWidget.fullScreen = true + innerWidget.fullScreen = true innerWidget.parent = testWidget.reparentWidget innerWidget.anchors.fill = testWidget.reparentWidget - labelText.text = "Full Screen Widget" - } - else { - innerWidget.parent = testWidget - innerWidget.anchors.fill = testWidget - innerWidget.fullScreen = false - labelText.text = "Press me, Hold me!!!" - } - } - } - } + labelText.text = "Full Screen Widget" + } + else { + innerWidget.parent = testWidget + innerWidget.anchors.fill = testWidget + innerWidget.fullScreen = false + labelText.text = "Press me, Hold me!!!" + } + } + } + } } } |