MainPage.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import QtWebKit 1.0 // QtWebKit QML Module
  7. import WhereAmI 1.0 // For GeoPermissionHandler
  8. Page {
  9. id: mainPage
  10. /*!
  11. Splash screen content.
  12. */
  13. Rectangle {
  14. id: splashScreenContent
  15. anchors.fill: parent
  16. color: "white"
  17. z: 10
  18. Behavior on opacity {
  19. SequentialAnimation {
  20. PauseAnimation { duration: 1000 }
  21. NumberAnimation { duration: 500 }
  22. }
  23. }
  24. Image {
  25. id: splashScreenImage
  26. anchors.fill: parent
  27. fillMode: Image.PreserveAspectFit
  28. smooth: true
  29. source: "qrc:/splash-screen-image.png"
  30. }
  31. }
  32. Flickable {
  33. id: flickable
  34. anchors.fill: parent
  35. contentWidth: webView.width
  36. contentHeight: webView.height
  37. /*!
  38. The web view for displaying and running the application content which
  39. is written with HTML5 and JavaScript.
  40. */
  41. WebView {
  42. id: webView
  43. preferredWidth: mainPage.width
  44. preferredHeight: mainPage.height
  45. smooth: false
  46. url: "qrc:/index.html"
  47. settings.javascriptEnabled: true
  48. settings.localContentCanAccessRemoteUrls: true
  49. onLoadFinished: {
  50. console.debug("Loaded URL: " + url);
  51. if (splashScreenContent.opacity > 0) {
  52. // Hide the splash screen and switch to the correct set of
  53. // tool bar tools.
  54. splashScreenContent.opacity = 0;
  55. toolBar.tools = mainToolBarLayout;
  56. }
  57. }
  58. onAlert: console.log("Alert: " + message);
  59. /*!
  60. QML functions which can be called from JavaScript in HTML context.
  61. Example:
  62. window.qml.qmlMethod();
  63. window.qml.qmlMethodWithParam(1);
  64. */
  65. javaScriptWindowObjects: QtObject {
  66. WebView.windowObjectName: "qml"
  67. function qmlMethodWithParam(param) {
  68. console.log("WebView.qml: qmlMethodWithParam(): " + param);
  69. }
  70. function qmlMethod() {
  71. console.log("WebView.qml: qmlMethod()");
  72. }
  73. }
  74. }
  75. }
  76. ScrollDecorator {
  77. flickableItem: flickable
  78. }
  79. /*!
  80. The busy indicator is shown when the web view is loading the content.
  81. */
  82. BusyIndicator {
  83. width: 100
  84. height: 100
  85. anchors {
  86. bottom: parent.bottom
  87. horizontalCenter: parent.horizontalCenter
  88. margins: 100
  89. }
  90. z: 10
  91. opacity: (webView.progress - 1) * -1
  92. running: webView.progress < 1
  93. }
  94. /*!
  95. GeoPermissionHandler handles the feature permission requests from web
  96. pages. If the permission requested is QmainPage::Geolocation the handler
  97. grants the permission. See src/geopermissionhandler.cpp for more
  98. information.
  99. */
  100. GeoPermissionHandler {
  101. view: webView
  102. }
  103. /*!
  104. The main tool bar layout.
  105. */
  106. ToolBarLayout {
  107. id: mainToolBarLayout
  108. ToolButton {
  109. iconSource: "toolbar-back"
  110. onClicked: Qt.quit();
  111. }
  112. ToolButton {
  113. iconSource: "toolbar-refresh"
  114. onClicked: {
  115. // Call JavaSript function in geolocation.js
  116. webView.evaluateJavaScript("update()");
  117. }
  118. }
  119. ToolButton {
  120. iconSource: "qrc:/info-icon.png"
  121. onClicked: {
  122. // Call JavaSript function in geolocation.js to show the info
  123. // page content and change the tool bar layout.
  124. webView.evaluateJavaScript("showInfo()");
  125. toolBar.tools = infoPageToolBarLayout;
  126. }
  127. }
  128. }
  129. /*!
  130. The info page tool bar layout.
  131. */
  132. ToolBarLayout {
  133. id: infoPageToolBarLayout
  134. ToolButton {
  135. iconSource: "toolbar-back"
  136. onClicked: {
  137. // Call JavaSript function in geolocation.js to hide the info
  138. // page content and change the tool bar layout.
  139. webView.evaluateJavaScript("closeInfo()");
  140. webView.url = "qrc:/index.html"
  141. toolBar.tools = mainToolBarLayout;
  142. }
  143. }
  144. }
  145. /*!
  146. The tool bar content shown when the splash screen is visible. Provides
  147. only an exit button.
  148. */
  149. ToolBarLayout {
  150. id: splashScreenToolBarLayout
  151. ToolButton {
  152. iconSource: "toolbar-back"
  153. onClicked: Qt.quit();
  154. }
  155. }
  156. // Set the main tool bar when the application is loaded
  157. Component.onCompleted: mainPage.tools = splashScreenToolBarLayout;
  158. }