diff options
Diffstat (limited to 'animals/Animal.qml')
-rwxr-xr-x | animals/Animal.qml | 143 |
1 files changed, 76 insertions, 67 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; } } } |