demochooser.qml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. import "content"
  6. Item {
  7. id: demoChooser
  8. signal minimizeApplication() // called when task switcher button is pressed
  9. property int selectedIndex: -1 // no selection at the beginning
  10. property int maxDemoIndex: 5 // used by for loops in javascript
  11. function hideUnselectedDemos() {
  12. for(var i=0; i<=maxDemoIndex; i++) {
  13. if(i != selectedIndex) {
  14. resolveDemoItem(i).hide()
  15. }
  16. }
  17. }
  18. function showAllDemos() {
  19. for(var i=0; i<=maxDemoIndex; i++) {
  20. resolveDemoItem(i).show()
  21. }
  22. }
  23. function resolveDemoItem(index) {
  24. if(index == 0) return slideShow
  25. if(index == 1) return sameGame
  26. if(index == 2) return memoryGame
  27. if(index == 3) return fancyPicker
  28. if(index == 4) return webcontent
  29. if(index == 5) return helloWorld
  30. return NULL
  31. }
  32. function demoStartRequest(index) {
  33. // Allow demo to get started if no demo is selected or the current demo is in code editor mode
  34. if((selectedIndex == index) || (selectedIndex == -1)) {
  35. selectedIndex = index
  36. hideUnselectedDemos()
  37. resolveDemoItem(index).state = "maximizedState"
  38. }
  39. }
  40. function codeEditorRequest(index) {
  41. // Allow demo to go to code editor only if current demo is maximized or no demo is currently started
  42. if((selectedIndex == index) || (selectedIndex == -1)) {
  43. selectedIndex = index
  44. resolveDemoItem(index).state = "inCodeEditorState"
  45. hideUnselectedDemos()
  46. }
  47. }
  48. function closed(index) {
  49. // Demo is closed from maximized or code editor, the state of the demo is changed to default state
  50. workAroundForHarmattan.closeSoftwareInputPanel();
  51. resolveDemoItem(index).state = "default"
  52. selectedIndex = -1
  53. showAllDemos()
  54. }
  55. Component.onCompleted: {
  56. if(codeprovider.getOSType() != 3) {
  57. // Task Switcher button is visible only in Maemo5
  58. taskSwitcher.visible = false
  59. }
  60. if(codeprovider.getOSType() == 6) {
  61. // Task Switcher button is visible only in Maemo6
  62. exitButton.visible = false
  63. }
  64. }
  65. anchors.fill: parent // the size is set in Qt code
  66. // Workaround for Harmattan to close VKB
  67. TextInput {
  68. id: workAroundForHarmattan
  69. opacity: 0
  70. }
  71. Image {
  72. id: backgroundImage
  73. anchors.fill: parent
  74. source: "back_gray.png"
  75. fillMode: "PreserveAspectCrop"
  76. Image {
  77. id: header
  78. anchors { left: parent.left; right: parent.right; top: parent.top }
  79. source: "back_header.png"
  80. fillMode: "PreserveAspectCrop"
  81. Button {
  82. id: taskSwitcher
  83. anchors { left: parent.left; leftMargin: 40; verticalCenter: parent.verticalCenter }
  84. source: "content/btn_taskbutton.png"; onClicked: demoChooser.minimizeApplication()
  85. }
  86. Image {
  87. id: title
  88. anchors.verticalCenter: parent.verticalCenter
  89. anchors.left: { if(taskSwitcher.visible == true) { return taskSwitcher.right } else { return parent.left } }
  90. anchors.leftMargin: 20
  91. source: "qtpl-title.png"
  92. }
  93. Image {
  94. id: logos
  95. anchors.left: title.right; anchors.leftMargin: 80
  96. anchors.verticalCenter: parent.verticalCenter
  97. source: "logos.png"
  98. }
  99. Button {
  100. id: exitButton
  101. anchors { right: parent.right; rightMargin: 25; verticalCenter: parent.verticalCenter }
  102. source: "content/exit.png"; onClicked: Qt.quit()
  103. }
  104. }
  105. Grid {
  106. id: demoGrid
  107. property int demoWidth: demoGrid.width / demoGrid.columns - demoGrid.spacing
  108. property int demoHeight: demoGrid.height / demoGrid.rows - demoGrid.spacing
  109. anchors { top: header.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 }
  110. anchors { left: parent.left; leftMargin: 25; right: parent.right; rightMargin: 25 }
  111. rows: 2; columns: 3; spacing: 10
  112. DemoItem {
  113. id: slideShow; index: 0; qmlFolder: "./slideshow/"
  114. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  115. qmlCode: codeprovider.loadQMLCode(":/content/slideshow/slideshow.qml")
  116. thumbnail: "qrc:/content/icon_slideshow.png"
  117. onStartSignal: { demoChooser.demoStartRequest(index) }
  118. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  119. onCloseSignal: { demoChooser.closed(index) }
  120. codeTemplateModel: modelSlideShow
  121. ListModel {
  122. id: modelSlideShow
  123. ListElement { titleText: "Slide change interval"; searchText: "interval: " }
  124. }
  125. }
  126. DemoItem {
  127. id: sameGame; index: 1; qmlFolder: "./samegame/"
  128. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  129. qmlCode: codeprovider.loadQMLCode(":/content/samegame/samegame.qml")
  130. thumbnail: "qrc:/content/icon_samegame.png"
  131. onStartSignal: { demoChooser.demoStartRequest(index) }
  132. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  133. onCloseSignal: { demoChooser.closed(index) }
  134. codeTemplateModel: modelSameGame
  135. ListModel {
  136. id: modelSameGame
  137. ListElement { titleText: "Ball size"; searchText: "blockSize: " }
  138. }
  139. }
  140. DemoItem {
  141. id: memoryGame; index: 2; qmlFolder: "./memorygame/"
  142. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  143. qmlCode: codeprovider.loadQMLCode(":/content/memorygame/memorygame.qml")
  144. thumbnail: "qrc:/content/icon_memorygame.png"
  145. onStartSignal: { demoChooser.demoStartRequest(index) }
  146. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  147. onCloseSignal: { demoChooser.closed(index) }
  148. codeTemplateModel: modelMemoryGame
  149. ListModel {
  150. id: modelMemoryGame
  151. ListElement { titleText: "Amount of cards"; searchText: "cards: " }
  152. ListElement { titleText: "Amount of card columns"; searchText: "columns: " }
  153. ListElement { titleText: "Amount of card rows"; searchText: "rows: " }
  154. }
  155. }
  156. DemoItem {
  157. id: fancyPicker; index: 3; qmlFolder: "./fancypicker/"
  158. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  159. qmlCode: codeprovider.loadQMLCode(":/content/fancypicker/fancypicker.qml")
  160. thumbnail: "qrc:/content/icon_fancypicker.png"
  161. onStartSignal: { demoChooser.demoStartRequest(index) }
  162. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  163. onCloseSignal: { demoChooser.closed(index) }
  164. }
  165. DemoItem {
  166. id: webcontent; index: 4; qmlFolder: "./webcontent/"
  167. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  168. qmlCode: codeprovider.loadQMLCode(":/content/webcontent/webcontent.qml")
  169. thumbnail: "qrc:/content/icon_webcontent.png"
  170. onStartSignal: { demoChooser.demoStartRequest(index) }
  171. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  172. onCloseSignal: { demoChooser.closed(index) }
  173. }
  174. DemoItem { id: helloWorld; index: 5; qmlFolder: "./helloworld/"
  175. width: demoGrid.demoWidth; height: demoGrid.demoHeight
  176. qmlCode: codeprovider.loadQMLCode(":/content/helloworld/hello.qml")
  177. thumbnail: "qrc:/content/icon_helloworld.png"
  178. onStartSignal: { demoChooser.demoStartRequest(index) }
  179. onCodeEditorSignal: { demoChooser.codeEditorRequest(index) }
  180. onCloseSignal: { demoChooser.closed(index) }
  181. codeTemplateModel: modelHelloWorld
  182. ListModel {
  183. id: modelHelloWorld
  184. ListElement { titleText: "Rotation speed"; searchText: "duration: " }
  185. }
  186. }
  187. }
  188. }
  189. }