main.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import QtQuick 1.0
  2. //import QtMobility.feedback 1.1
  3. import P2PEngine 1.0
  4. /*!
  5. * \file
  6. * \brief Main qml file for the application.
  7. *
  8. * Main application view shows the local images and remote images.
  9. */
  10. Rectangle {
  11. id: mainView
  12. width: 360
  13. height: 640
  14. P2PEngine {
  15. id: iEngine
  16. // Update remote images
  17. onShowRemoteImages: {
  18. anim.running = false;
  19. image6.source = iEngine.getRemoteImageFile(0);
  20. image7.source = iEngine.getRemoteImageFile(1);
  21. image8.source = iEngine.getRemoteImageFile(2);
  22. image9.source = iEngine.getRemoteImageFile(3);
  23. image10.source = iEngine.getRemoteImageFile(4);
  24. image11.source = iEngine.getRemoteImageFile(5);
  25. }
  26. // Update view after exchange has been done or start new game
  27. onUpdateView: {
  28. anim.running = false;
  29. image0.source = iEngine.getLocalImageFile(0);
  30. image1.source = iEngine.getLocalImageFile(1);
  31. image2.source = iEngine.getLocalImageFile(2);
  32. image3.source = iEngine.getLocalImageFile(3);
  33. image4.source = iEngine.getLocalImageFile(4);
  34. image5.source = iEngine.getLocalImageFile(5);
  35. image6.source = iEngine.getRemoteImageFile(0);
  36. image7.source = iEngine.getRemoteImageFile(1);
  37. image8.source = iEngine.getRemoteImageFile(2);
  38. image9.source = iEngine.getRemoteImageFile(3);
  39. image10.source = iEngine.getRemoteImageFile(4);
  40. image11.source = iEngine.getRemoteImageFile(5);
  41. }
  42. // Show congratulation message
  43. onShowWinnerMessage:{
  44. congratulations.visible = true;
  45. }
  46. }
  47. RectangleBackground {
  48. id: localListOfImages
  49. x: 19
  50. y: 16
  51. anchors.right:remoteListOfImages.left
  52. anchors.left: parent.left
  53. Grid {
  54. id: localImageGrid
  55. anchors.fill: parent
  56. anchors.rightMargin: 20
  57. anchors.leftMargin: 20
  58. rows: 6; columns: 1;
  59. // Show local images
  60. Image {
  61. id: image0
  62. source: {iEngine.getLocalImageFile(0)}
  63. MouseArea {
  64. id: myMouse0
  65. anchors.fill: parent
  66. onClicked: {
  67. //themeEffect.play();
  68. anim.running = false;
  69. anim.target = image0;
  70. anim.running = true;
  71. iEngine.setImageForExchange(0);
  72. }
  73. }
  74. }
  75. Image {
  76. id: image1
  77. source: {iEngine.getLocalImageFile(1)}
  78. MouseArea {
  79. id: myMouse1
  80. anchors.fill: parent
  81. onClicked: {
  82. //themeEffect.play();
  83. anim.running = false;
  84. anim.target = image1;
  85. anim.running = true;
  86. iEngine.setImageForExchange(1);
  87. }
  88. }
  89. }
  90. Image {
  91. id: image2
  92. source: {iEngine.getLocalImageFile(2)}
  93. MouseArea {
  94. id: myMouse2
  95. anchors.fill: parent
  96. onClicked: {
  97. //themeEffect.play();
  98. anim.running = false;
  99. anim.target = image2;
  100. anim.running = true;
  101. iEngine.setImageForExchange(2);
  102. }
  103. }
  104. }
  105. Image {
  106. id: image3
  107. source: {iEngine.getLocalImageFile(3)}
  108. MouseArea {
  109. id: myMouse3
  110. anchors.fill: parent
  111. onClicked: {
  112. //themeEffect.play();
  113. anim.running = false;
  114. anim.target = image3;
  115. anim.running = true;
  116. iEngine.setImageForExchange(3);
  117. }
  118. }
  119. }
  120. Image {
  121. id: image4
  122. source: {iEngine.getLocalImageFile(4)}
  123. MouseArea {
  124. id: myMouse4
  125. anchors.fill: parent
  126. onClicked: {
  127. //themeEffect.play();
  128. anim.running = false;
  129. anim.target = image4;
  130. anim.running = true;
  131. iEngine.setImageForExchange(4);
  132. }
  133. }
  134. }
  135. Image {
  136. id: image5
  137. source: {iEngine.getLocalImageFile(5)}
  138. MouseArea {
  139. id: myMouse5
  140. anchors.fill: parent
  141. onClicked: {
  142. //themeEffect.play();
  143. anim.running = false;
  144. anim.target = image5;
  145. anim.running = true;
  146. iEngine.setImageForExchange(5);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. RectangleBackground {
  153. id: remoteListOfImages
  154. x: 195
  155. y: 16
  156. anchors.right: parent.right
  157. // Show remote shapes
  158. Grid {
  159. id: remoteImageGrid
  160. anchors.fill: parent
  161. anchors.rightMargin: 20
  162. anchors.leftMargin: 20
  163. rows: 6; columns: 1;
  164. Image { id: image6 }
  165. Image { id: image7 }
  166. Image { id: image8 }
  167. Image { id: image9 }
  168. Image { id: image10 }
  169. Image { id: image11 }
  170. }
  171. }
  172. /* ThemeEffect {
  173. id: themeEffect
  174. effect: ThemeEffect.SensitiveItem;
  175. }
  176. */
  177. // Animate image for exchange
  178. RotationAnimation on rotation {
  179. id: anim;
  180. loops: Animation.Infinite
  181. from: 0
  182. to: 360
  183. duration: 4000;
  184. running: false;
  185. property: "rotation" ;
  186. }
  187. // How to play description
  188. MessageBox {
  189. id: aboutP2PExample
  190. Text {
  191. id: aboutText
  192. x: 16
  193. y: 70
  194. width: 270
  195. wrapMode: Text.WordWrap
  196. font.family: "Times New Roman"
  197. font.pixelSize: 17
  198. text: "This example application shows how to create a peer-to-peer connection between two NFC devices using the LLCP protocol.<BR><B>Goal of the game:</B><BR>You need to collect shapes of one type.<BR><B>How to play:</B><BR> Touch another device to see the other player's shapes. Tap the shape on the left which you would like to change. Touch the other device again to exchange shapes.<BR>Good luck!<BR>"
  199. }
  200. }
  201. // Congratulation message
  202. MessageBox {
  203. id: congratulations
  204. visible: false;
  205. Text {
  206. id: congratulationsText
  207. x: 16
  208. y: 70
  209. width: 270
  210. color: "red";
  211. horizontalAlignment: Text.AlignHCenter
  212. text: "<BR><B>CONGRATULATIONS!<BR><BR>You are a Winner!</B>"
  213. font.family: "Times New Roman"
  214. font.pixelSize: 25
  215. }
  216. MouseArea {
  217. id: mouseArea1
  218. anchors.fill: parent;
  219. onClicked: {
  220. iEngine.doReset();
  221. anim.running = false;
  222. congratulations.visible = false
  223. }
  224. }
  225. }
  226. /*
  227. Image {
  228. source : "close.png"
  229. x: mainView.width - width
  230. y: 5
  231. width: 50;
  232. height: 50;
  233. MouseArea {
  234. anchors.fill: parent;
  235. onClicked: { Qt.quit(); }
  236. }
  237. }
  238. */
  239. }