main.qml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import QtMobility.serviceframework 1.1
  6. import QtMobility.systeminfo 1.2
  7. import QtMultimediaKit 1.1
  8. import CustomItems 1.0
  9. import "JavaScript.js" as JavaScript
  10. Rectangle {
  11. id: main
  12. width: 360; height: 640
  13. anchors.fill: parent
  14. color: "black"
  15. // WhoWhereDaemon service
  16. property variant daemonService: 0
  17. // ContactsView
  18. property variant contactsView: 0
  19. // InfoView
  20. property variant infoView: 0
  21. // Show/hide ContactsView
  22. function showContacts(enable)
  23. {
  24. if (enable) {
  25. // Create ContactsView dynamically
  26. if (!contactsView) {
  27. var component = Qt.createComponent("qrc:/ContactsView.qml");
  28. if (component.status == Component.Ready) {
  29. contactsView = component.createObject(main);
  30. }
  31. }
  32. water.pauseWater(true);
  33. contactsView.show();
  34. } else {
  35. // Hide ContactsView
  36. if (contactsView) {
  37. water.pauseWater(false);
  38. contactsView.opacity = 0;
  39. }
  40. }
  41. }
  42. // Show/hide InfoView
  43. function showInfo(enable)
  44. {
  45. if (enable) {
  46. water.setWaterUpdateSpeed(200);
  47. // Create InfoView dynamically
  48. if (!infoView) {
  49. var component = Qt.createComponent("qrc:/InfoView.qml");
  50. if (component.status == Component.Ready) {
  51. infoView = component.createObject(main);
  52. }
  53. }
  54. infoView.opacity = 1;
  55. } else {
  56. // Hide ContactsView
  57. if (infoView) {
  58. infoView.opacity = 0;
  59. water.setWaterUpdateSpeed(80);
  60. }
  61. }
  62. }
  63. // Application start sound
  64. Audio {
  65. id: playMusic
  66. source: appFolder + "13564__acclivity__GullsByTheSea.wav"
  67. volume: 0.4
  68. }
  69. // QtMobility Service FW
  70. // Connect WhoWhereDaemon Service
  71. Service {
  72. id: daemonServiceId
  73. interfaceName: "com.nokia.qt.examples.qwhowheredaemon"
  74. Component.onCompleted: {
  75. main.daemonService = daemonServiceId.serviceObject;
  76. console.log(daemonServiceId.serviceName);
  77. if (daemonServiceId.valid) {
  78. console.log("Service valid");
  79. // Read values form Daemot to UI
  80. if(JavaScript.isDaemonEnabled()) {
  81. onOffSwitch.state = "on";
  82. }
  83. if (JavaScript.isGpsRunningEnabled()) {
  84. console.log("gps running");
  85. gpsSwitch.state = "on";
  86. }
  87. knobDial.value = JavaScript.getGpsAccuracy();
  88. } else {
  89. console.log("Service NOT valid!");
  90. }
  91. }
  92. }
  93. // Listening device profile (silent or not)
  94. DeviceInfo {
  95. id: deviceInfo
  96. }
  97. Component.onCompleted: {
  98. audioTimer.restart();
  99. }
  100. Timer {
  101. id: audioTimer
  102. interval: 3000
  103. repeat: false
  104. onTriggered: {
  105. splashScreen.opacity = 0;
  106. water.opacity = 1;
  107. if (deviceInfo.currentProfile != 1){
  108. playMusic.play();
  109. }
  110. }
  111. }
  112. // Water background
  113. WaterItem {
  114. id:water
  115. anchors.fill: parent
  116. opacity: 0;
  117. }
  118. // Application background paper
  119. Image {
  120. id: background
  121. anchors.fill: parent
  122. anchors.centerIn: parent
  123. anchors.topMargin: 40
  124. anchors.bottomMargin: 40
  125. anchors.leftMargin: 10
  126. anchors.rightMargin: 10
  127. fillMode: Image.PreserveAspectFit
  128. source: "qrc:/images/back_portrait.png"
  129. smooth: true
  130. }
  131. // Gps icon
  132. GpsIcon {
  133. width: 50
  134. height: 50
  135. x: 5
  136. y: 5
  137. }
  138. // Exit
  139. Button {
  140. id: exit
  141. buttonId: 1
  142. width: 50
  143. height: 50
  144. x: parent.width - width - 5
  145. y: 5
  146. onBtnClicked: {
  147. Qt.quit();
  148. }
  149. }
  150. // Main content
  151. Item {
  152. id: mainContent
  153. anchors.fill: background
  154. smooth: true
  155. property int rowHeight: background.height * 0.105
  156. property int colWidth: background.width * 0.28
  157. // 1. row ---------------------------------------------------------
  158. Image {
  159. id: logo
  160. anchors.top: mainContent.top
  161. anchors.left: mainContent.left
  162. anchors.leftMargin: 10
  163. anchors.topMargin: background.height * 0.05
  164. width: mainContent.rowHeight * 2.2
  165. height: mainContent.rowHeight * 2.2
  166. fillMode: Image.PreserveAspectFit
  167. source: "qrc:/images/logo.png"
  168. smooth: true
  169. }
  170. Button {
  171. id: info
  172. buttonId: 2
  173. anchors.top: mainContent.top
  174. anchors.right: mainContent.right
  175. anchors.rightMargin: 40
  176. anchors.topMargin: background.height * 0.1
  177. width: mainContent.colWidth
  178. height: mainContent.rowHeight
  179. onBtnClicked: {
  180. main.showInfo(true);
  181. }
  182. }
  183. // 2. row --------------------------------------------------------
  184. Text {
  185. anchors.top: logo.bottom
  186. anchors.right: logo.right
  187. anchors.topMargin: 15
  188. color:"black"
  189. font.pointSize: 6
  190. text:"Server activated"
  191. smooth: true
  192. }
  193. Switch {
  194. id: onOffSwitch
  195. anchors.top: logo.bottom
  196. anchors.left: info.left
  197. anchors.topMargin: 5
  198. width: mainContent.colWidth
  199. height: mainContent.rowHeight
  200. onSwitched: {
  201. JavaScript.enableDaemon(on);
  202. }
  203. }
  204. // 3. row --------------------------------------------------------
  205. Text {
  206. anchors.top: onOffSwitch.bottom
  207. anchors.right: logo.right
  208. anchors.topMargin: 15
  209. color:"black"
  210. font.pointSize: 6
  211. text:"GPS always on"
  212. smooth: true
  213. }
  214. Switch {
  215. id: gpsSwitch
  216. anchors.top: onOffSwitch.bottom
  217. anchors.left: info.left
  218. anchors.topMargin: 5
  219. width: mainContent.colWidth
  220. height: mainContent.rowHeight
  221. }
  222. Connections {
  223. target:gpsSwitch
  224. onSwitched: {
  225. JavaScript.keepGpsRunning(on);
  226. }
  227. }
  228. // 4. row --------------------------------------------------------
  229. Text {
  230. anchors.top: gpsSwitch.bottom
  231. anchors.right: logo.right
  232. anchors.topMargin: 20
  233. color:"black"
  234. font.pointSize: 6
  235. text:"GPS accuracy"
  236. smooth: true
  237. }
  238. KnobDial {
  239. id: knobDial
  240. anchors.top: gpsSwitch.bottom
  241. anchors.left: info.left
  242. anchors.topMargin: 10
  243. width: mainContent.rowHeight
  244. height: mainContent.rowHeight
  245. }
  246. // 5. row --------------------------------------------------------
  247. Text {
  248. id: sendTxt
  249. anchors.top: knobDial.bottom
  250. anchors.right: logo.right
  251. anchors.topMargin: 20
  252. color:"black"
  253. font.pointSize: 6
  254. text:"Send location to..."
  255. smooth: true
  256. }
  257. Button {
  258. id: contactBtn
  259. buttonId: 3
  260. anchors.top: knobDial.bottom
  261. anchors.left: info.left
  262. anchors.topMargin: 10
  263. width: mainContent.colWidth
  264. height: mainContent.rowHeight
  265. onBtnClicked: {
  266. showContacts(true);
  267. }
  268. }
  269. // WhoWhereDaemon log screen
  270. DaemonLog {
  271. id: logScreen
  272. anchors.top: contactBtn.bottom
  273. anchors.topMargin: 10
  274. anchors.horizontalCenter: parent.horizontalCenter
  275. width: background.width - 70
  276. height: mainContent.rowHeight * 1.4
  277. }
  278. }
  279. MouseArea {
  280. id: mainMouseArea
  281. anchors.fill: parent
  282. onPressed: {
  283. // Note: need to handle onPressed() for
  284. // igonore MouseArea
  285. showContacts(false);
  286. showInfo(false);
  287. mouse.accepted = false;
  288. }
  289. }
  290. // Spalsh screen
  291. Rectangle {
  292. id:splashScreen
  293. anchors.fill: parent
  294. color: "black"
  295. Image {
  296. anchors.fill: parent
  297. source: "qrc:/images/back_portrait.png"
  298. smooth: true
  299. }
  300. Image {
  301. anchors.centerIn: parent
  302. fillMode: Image.PreserveAspectFit
  303. source: "qrc:/images/logo.png"
  304. smooth: true
  305. }
  306. }
  307. }