FlipableMirror.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * Copyright (c) 2011-2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import CustomItems 1.0
  6. Flipable {
  7. id: flipableMirror
  8. objectName: "FlipableMirror"
  9. property bool flipped: false
  10. property bool showCamera: false
  11. property int mirrorEffectId
  12. property bool zoomedIn: false
  13. property bool rotationRunning: false
  14. property int defaultX
  15. property int defaultY
  16. property int defaultWidth
  17. property int defaultHeight
  18. // Mirror rotation hint anim
  19. function rotationAnimation() {
  20. rotationHintAnim.restart();
  21. }
  22. // Enable camera, 2. camera if not flipped and 1. camera if flipped
  23. function enableCamera(enable) {
  24. showCamera = enable;
  25. if (flipableMirror.flipped) {
  26. mirrorFront.enableCamera(false); // 1 camera
  27. mirrorBack.enableCameraAt(enable,0); // 0 camera
  28. } else {
  29. mirrorBack.enableCamera(false); // 0 camera
  30. mirrorFront.enableCameraAt(enable,1); // 1 camera
  31. }
  32. }
  33. function saveToFile() {
  34. if (flipableMirror.flipped) {
  35. mirrorBack.saveToFile();
  36. } else {
  37. mirrorFront.saveToFile();
  38. }
  39. }
  40. function pauseCamera() {
  41. showCamera = false;
  42. mirrorFront.pauseCamera();
  43. mirrorBack.pauseCamera();
  44. }
  45. function isZooming()
  46. {
  47. var ret = false;
  48. if (zoomInAnim.running || zoomOutAnim.running)
  49. ret = true;
  50. return ret;
  51. }
  52. function isRotating()
  53. {
  54. var ret = false;
  55. if (rotationRunning)
  56. ret = true;
  57. return ret;
  58. }
  59. function doZoomIn()
  60. {
  61. if (zoomedIn || isRotating()) {
  62. return;
  63. }
  64. if (!zoomInAnim.running && !zoomOutAnim.running) {
  65. main.disableAllCameras();
  66. flipableMirror.z = main.getZ();
  67. defaultWidth = flipableMirror.width;
  68. defaultHeight = flipableMirror.height;
  69. defaultX = flipableMirror.x;
  70. defaultY = flipableMirror.y;
  71. zoomInAnim.restart();
  72. enableCamera(true);
  73. }
  74. }
  75. function doZoomOut()
  76. {
  77. if (!zoomedIn || isRotating()) {
  78. return;
  79. }
  80. if (!zoomInAnim.running && !zoomOutAnim.running) {
  81. main.disableAllCameras();
  82. zoomOutAnim.restart();
  83. enableCamera(true);
  84. }
  85. }
  86. ParallelAnimation {
  87. id: zoomInAnim
  88. PropertyAction { target: flickable; property: "interactive"; value: false }
  89. NumberAnimation { target: flipableMirror; property: "width"; to: main.fixedWidth - 50; duration:1000 }
  90. NumberAnimation { target: flipableMirror; property: "height"; to: main.fixedHeight - 100; duration: 1000;
  91. easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5}
  92. NumberAnimation { target: flipableMirror; property: "x"; to: flickable.contentX + 25; duration: 1000 }
  93. NumberAnimation { target: flipableMirror; property: "y"; to: flickable.yPos*-1 + 50; duration: 1000 }
  94. PropertyAction { target: flipableMirror; property: "zoomedIn"; value: true }
  95. }
  96. ParallelAnimation {
  97. id: zoomOutAnim
  98. NumberAnimation { target: flipableMirror; property: "width"; to: flipableMirror.defaultWidth; duration:1000 }
  99. NumberAnimation { target: flipableMirror; property: "height"; to: flipableMirror.defaultHeight; duration: 1000;
  100. easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5}
  101. NumberAnimation { target: flipableMirror; property: "x"; to: flipableMirror.defaultX; duration: 1000 }
  102. NumberAnimation { target: flipableMirror; property: "y"; to: flipableMirror.defaultY; duration: 1000 }
  103. PropertyAction { target: flipableMirror; property: "zoomedIn"; value: false }
  104. PropertyAction { target: flickable; property: "interactive"; value: true }
  105. }
  106. front: Mirror {
  107. id: mirrorFront
  108. mirrorEffectId: flipableMirror.mirrorEffectId
  109. onZoomIn: {
  110. doZoomIn();
  111. }
  112. onZoomOut: {
  113. doZoomOut();
  114. }
  115. }
  116. back: Mirror {
  117. id: mirrorBack
  118. mirrorEffectId: flipableMirror.mirrorEffectId
  119. onZoomIn: {
  120. doZoomIn();
  121. }
  122. onZoomOut: {
  123. doZoomOut();
  124. }
  125. }
  126. Component.onCompleted: {
  127. if(showCamera) {
  128. enableCamera(true);
  129. }
  130. }
  131. // Rotate y-axcel
  132. transform: Rotation {
  133. id: rotation
  134. origin.x: flipableMirror.width/2
  135. origin.y: flipableMirror.height/2
  136. axis.x: 0; axis.y: 1; axis.z: 0
  137. angle: 0
  138. }
  139. states: State {
  140. name: "back"
  141. PropertyChanges { target: rotation; angle: 180 }
  142. when: flipableMirror.flipped
  143. }
  144. transitions: Transition {
  145. SequentialAnimation {
  146. PropertyAction { target: flipableMirror; property: "rotationRunning"; value: true }
  147. NumberAnimation {target: rotation; property: "angle"; duration: 3200; easing.type: Easing.Linear }
  148. PropertyAction { target: flipableMirror; property: "rotationRunning"; value: false }
  149. }
  150. }
  151. SequentialAnimation {
  152. id: rotationHintAnim
  153. PropertyAction { target: flipableMirror; property: "rotationRunning"; value: true }
  154. NumberAnimation {target: rotation; property: "angle"; from:0; to:120;
  155. duration: 2100; easing.type: Easing.Linear }
  156. PauseAnimation { duration: 300 }
  157. NumberAnimation {target: rotation; property: "angle"; from:120; to:0;
  158. duration: 2100; easing.type: Easing.Linear }
  159. PropertyAction { target: flipableMirror; property: "rotationRunning"; value: false }
  160. }
  161. }