main.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import Qt 4.7
  2. import "../colibri"
  3. import "../js/FutuHeia.js" as FutuHeia
  4. import "../js/OAuth.js" as FutuAuth
  5. Item {
  6. id: appItem
  7. // Get width and height set from C++
  8. width: screenWidth
  9. height: screenHeight
  10. // We start from the splash screen
  11. state: "showingSplashView"
  12. // Is the application authenticated
  13. property bool authenticated: false
  14. property int authStep: 0
  15. property string requestToken: ""
  16. property string requestTokenSecret: ""
  17. property string accessToken: ""
  18. property string accessTokenSecret: ""
  19. property string authWebViewUrl: ""
  20. property bool loadingSports: false;
  21. property string applicationFont: "Nokia Sans"
  22. property int applicationFontSize: 24
  23. property int heiaBorderWidth: 4
  24. property color heiaDarkGrey: "#666666"
  25. property color heiaMediumGrey: "#999999"
  26. property color heiaLightGrey: "#cccccc"
  27. property color heiaYellow: "#f9f02e"
  28. property color heiaOrange: "orange" // Todo select good value
  29. property color heiaGreen: "green" // Todo select good value
  30. property color heiaFocusColorInner: "lightblue"
  31. property color heiaFocusColorOuter: "white"
  32. property string heiaModuleBackground: "transparent"
  33. property string heiaBackgroundImage: "background.png"
  34. property string heiaTextColor: "white"
  35. property int splashTimeout: 2000 //
  36. // date select props
  37. property alias date: mainView.selectedDate
  38. property alias month: mainView.selectedMonth
  39. property alias year: mainView.selectedYear
  40. // time distance props
  41. property alias durationHours: mainView.selectedHours
  42. property alias durationMinutes: mainView.selectedMinutes
  43. property alias distance: mainView.selectedDistance
  44. // mood props
  45. property alias mood: mainView.selectedMood
  46. property alias comment: mainView.selectedComment
  47. // sports props
  48. property alias selectedName: mainView.selectedName
  49. property alias selectedId: mainView.selectedId
  50. property string postsButtonText: qsTr("Show posts");
  51. property string userId: "32566593178" // test user. TODO: input field for this
  52. Image {
  53. id: background
  54. source: heiaBackgroundImage
  55. anchors.fill: parent
  56. }
  57. // When main.qml has loaded call our initialization Javascript function
  58. Component.onCompleted: {
  59. state = "showingSplash"
  60. if (FutuAuth.checkTokens()) {
  61. authenticated = true;
  62. splashTimer.start();
  63. }
  64. }
  65. Timer {
  66. id: splashTimer
  67. interval: splashTimeout
  68. repeat: false
  69. onTriggered: {
  70. FutuAuth.init();
  71. }
  72. }
  73. function initialized() {
  74. FutuHeia.log("initialized");
  75. appItem.loadingSports = true;
  76. FutuHeia.getSports(1); // Get first page of sports
  77. }
  78. Image {
  79. x: 0
  80. y: 0
  81. source: "background.png"
  82. }
  83. // Application "screens" which we move left to right and back according to state
  84. AuthView {
  85. id: authView
  86. x: FutuHeia.getCoordinateXForView(-1)
  87. y: 0
  88. width: parent.width
  89. height: parent.height
  90. }
  91. SplashView {
  92. id: splashView
  93. x: FutuHeia.getCoordinateXForView(0)
  94. y: 0
  95. width: parent.width
  96. height: parent.height
  97. }
  98. MainView {
  99. clip: true
  100. id: mainView
  101. x: FutuHeia.getCoordinateXForView(1)
  102. y: 0
  103. width: parent.width
  104. height: parent.height
  105. }
  106. LogView {
  107. id: logView
  108. x: FutuHeia.getCoordinateXForView(2)
  109. y: 0
  110. width: parent.width/2
  111. height: parent.height
  112. }
  113. CLButton {
  114. anchors.top: parent.top
  115. anchors.topMargin: 10
  116. anchors.right: parent.right
  117. anchors.rightMargin: 10
  118. width: 35
  119. height: 35
  120. text: qsTr("X")
  121. fontWeight: "Bold"
  122. onClicked: Qt.quit();
  123. hoveredStateOn: false
  124. borderColor: appItem.heiaFocusColorOuter
  125. color: appItem.heiaFocusColorInner
  126. colorWhenPressed: appItem.heiaOrange
  127. gradientDefaultOn: false
  128. gradientPressedOn: false
  129. gradientSelectedOn: false
  130. textColor: "black"
  131. borderWidth: 4
  132. }
  133. // Model for the sports selector
  134. Sports {
  135. id: sportsModel;
  136. }
  137. // Application states
  138. states: [
  139. State {
  140. name: "showingAuthView"
  141. PropertyChanges {
  142. target: authView
  143. x: FutuHeia.getCoordinateXForView(0);
  144. }
  145. PropertyChanges {
  146. target: splashView
  147. x: FutuHeia.getCoordinateXForView(1);
  148. }
  149. PropertyChanges {
  150. target: mainView
  151. x: FutuHeia.getCoordinateXForView(2);
  152. }
  153. PropertyChanges {
  154. target: logView
  155. x: FutuHeia.getCoordinateXForView(3);
  156. }
  157. },
  158. State {
  159. name: "showingSplashView"
  160. PropertyChanges {
  161. target: authView
  162. x: FutuHeia.getCoordinateXForView(-1);
  163. }
  164. PropertyChanges {
  165. target: splashView
  166. x: FutuHeia.getCoordinateXForView(0);
  167. }
  168. PropertyChanges {
  169. target: mainView
  170. x: FutuHeia.getCoordinateXForView(1);
  171. }
  172. PropertyChanges {
  173. target: logView
  174. x: FutuHeia.getCoordinateXForView(2);
  175. }
  176. },
  177. State {
  178. name: "showingMain"
  179. PropertyChanges {
  180. target: authView
  181. x: FutuHeia.getCoordinateXForView(-2);
  182. }
  183. PropertyChanges {
  184. target: splashView
  185. x: FutuHeia.getCoordinateXForView(-1);
  186. }
  187. PropertyChanges {
  188. target: mainView
  189. x: FutuHeia.getCoordinateXForView(0);
  190. }
  191. PropertyChanges {
  192. target: logView
  193. x: FutuHeia.getCoordinateXForView(1);
  194. }
  195. },
  196. State {
  197. name: "showingLog"
  198. PropertyChanges {
  199. target: authView
  200. x: FutuHeia.getCoordinateXForView(-3);
  201. }
  202. PropertyChanges {
  203. target: splashView
  204. x: FutuHeia.getCoordinateXForView(-2);
  205. }
  206. PropertyChanges {
  207. target: mainView
  208. x: FutuHeia.getCoordinateXForView(0);
  209. }
  210. PropertyChanges {
  211. target: logView
  212. x: FutuHeia.getCoordinateXForView(0) + screenWidth/2;
  213. }
  214. }
  215. ]
  216. transitions: [
  217. Transition {
  218. from: "*"; to: "*"
  219. NumberAnimation { properties: "x"; easing.type: Easing.OutBounce; duration: 1000; }
  220. }
  221. ]
  222. }