demoitem.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. import "demoitemcore.js" as Core
  6. Item {
  7. id: gridItem
  8. property string qmlFolder // the path to demo qml
  9. property alias qmlCode: textEditor.text // the QML sourcecode
  10. property alias thumbnail: skin.source // the thumbnail of the demo
  11. property alias codeTemplateModel: textEditor.codeTemplateModel
  12. property int index // index of demo item in demo chooser
  13. signal startSignal(int index) // signaled when demo item is clicked
  14. signal codeEditorSignal(int index) // signaled when entering to code editor
  15. signal closeSignal(int index) // signaled when exiting from demo and code editor
  16. function hide() { hideAnimation.start() }
  17. function show() { showAnimation.start() }
  18. state: "default"
  19. Rectangle {
  20. id: container
  21. width: parent.width; height: parent.height
  22. color: "#373737"; clip: true; radius: 10
  23. // mouse area which does nothing to prevent item under gridItem to receive clicks
  24. MouseArea { anchors.fill: parent }
  25. TextEditor {
  26. id: textEditor
  27. anchors.fill: parent
  28. onTryDemoClicked: { startSignal(index) }
  29. onBackClicked: { closeSignal(index) }
  30. }
  31. Image {
  32. id: skin
  33. width: parent.width; height: parent.height; smooth: true
  34. MouseArea {
  35. anchors.fill: parent
  36. onClicked: { startSignal(index) }
  37. onPressAndHold: { codeEditorSignal(index) }
  38. }
  39. Rectangle {
  40. width: parent.width / 4
  41. height: parent.height / 4
  42. anchors { right: parent.right; bottom: parent.bottom }
  43. color: "gray"; radius: 6; opacity: 0.3
  44. MouseArea {
  45. id: mouseCorner
  46. property int xpressed
  47. property int ypressed
  48. anchors.fill: parent
  49. onPressed: { xpressed = mouseX; ypressed = mouseY }
  50. onPositionChanged: {
  51. if(gridItem.state == "inCodeEditorState") { return }
  52. var relX = xpressed - mouseX
  53. var relY = ypressed - mouseY
  54. var relMax = Math.max(relX, relY)
  55. // Only allow skin to be moved to upper left direction
  56. if((skin.x - relMax) <= 0) { skin.x = skin.x - relMax; skin.y = skin.y - relMax }
  57. if(skin.x < (gridItem.width / -5)) { codeEditorSignal(index) }
  58. }
  59. onReleased: { if(gridItem.state != "inCodeEditorState") { skin.x = 0; skin.y = 0 } }
  60. }
  61. }
  62. }
  63. // This will hold the dynamically loaded demo
  64. Item {
  65. id: demoHolder
  66. anchors { left: parent.left; top: parent.top; bottom: parent.bottom; right: sidePanel.left }
  67. opacity: 0
  68. ErrorDialog { id: errorDialog; anchors.centerIn: parent; onClosed: { textEditor.selectLine(lineNumber); codeEditorSignal(index) } }
  69. }
  70. SidePanel {
  71. id: sidePanel
  72. opacity: 0; width: 70
  73. source: "sidebar.png"
  74. anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
  75. onCloseClicked: { if(errorDialog.opacity != 0) errorDialog.forceClose(); closeSignal(index) }
  76. onCodeEditorClicked: { if(errorDialog.opacity != 0) errorDialog.forceClose(); codeEditorSignal(index) }
  77. }
  78. }
  79. // These two animations are used to hide (and show) "the other" demos when the user selected demo is started or to it's code editor is entered
  80. // by this way the performance of the application will be a lot greater!
  81. SequentialAnimation {
  82. id: hideAnimation
  83. alwaysRunToEnd: true
  84. PropertyAction { target: textEditor; properties: "visible"; value: false }
  85. PropertyAnimation { target: container; properties: "opacity"; to: 0; duration: 500 }
  86. }
  87. SequentialAnimation {
  88. id: showAnimation
  89. alwaysRunToEnd: true
  90. PauseAnimation { duration: 1500 }
  91. PropertyAnimation { target: container; properties: "opacity"; to: 1; duration: 500 }
  92. PropertyAction { target: textEditor; properties: "visible"; value: true }
  93. }
  94. states: [
  95. State {
  96. name: "default" //default
  97. PropertyChanges { target: skin; x: 0; y: 0 }
  98. StateChangeScript { name: "scriptUnloadDemo"; script: Core.unloadDemo() }
  99. },
  100. State {
  101. name: "maximizedState"
  102. PropertyChanges { target: gridItem; z: 1 }
  103. ParentChange { target: container; parent: demoChooser }
  104. PropertyChanges { target: container; x: 0; y: 0; width: parent.width; height: parent.height; opacity: 1; radius: 0; color: "black" }
  105. PropertyChanges { target: skin; x: 0; y: 0; opacity: 0.0 }
  106. StateChangeScript { name: "scriptLoadDemo"; script: Core.loadDemo() }
  107. PropertyChanges { target: demoHolder; opacity: 1 }
  108. PropertyChanges { target: sidePanel; opacity: 1}
  109. PropertyChanges { target: textEditor; opacity: 0 }
  110. StateChangeScript { name: "scriptStartDemo"; script: Core.startDemo() }
  111. },
  112. State {
  113. name: "inCodeEditorState"
  114. ParentChange { target: container; parent: demoChooser }
  115. PropertyChanges { target: skin; x: -1 * container.width; y: -1 * container.height; opacity: 0.0 }
  116. PropertyChanges { target: gridItem; z: 1 }
  117. PropertyChanges { target: container; x:0; y: 0; width: parent.width; height: parent.height; radius: 0 }
  118. StateChangeScript { name: "scriptUnloadDemo"; script: Core.unloadDemo() }
  119. }
  120. ]
  121. transitions: [
  122. Transition {
  123. from: "default"
  124. to: "maximizedState"
  125. reversible: false
  126. SequentialAnimation {
  127. PauseAnimation { duration: 500 }
  128. PropertyAction { target: textEditor; property: "opacity" }
  129. PropertyAction { target: gridItem; property: "z" }
  130. ParentAnimation {
  131. target: container
  132. PropertyAnimation { target: container; properties: "x,y,width,height,radius"; duration: 1000; easing.type: "InOutCubic" }
  133. PropertyAnimation { target: skin; property: "opacity" }
  134. }
  135. ScriptAction { scriptName: "scriptLoadDemo" }
  136. ParallelAnimation {
  137. PropertyAnimation { target: demoHolder; property: "opacity"; duration: 1000 }
  138. PropertyAnimation { target: sidePanel; property: "opacity"; duration: 1000 }
  139. }
  140. PauseAnimation { duration: 100 }
  141. ScriptAction { scriptName: "scriptStartDemo" }
  142. }
  143. },
  144. Transition {
  145. from: "maximizedState"
  146. to: "default"
  147. reversible: false
  148. SequentialAnimation {
  149. PropertyAnimation { target: demoHolder; property: "opacity"; duration: 500 }
  150. ScriptAction { scriptName: "scriptUnloadDemo" }
  151. ParentAnimation {
  152. target: container
  153. PropertyAnimation { target: container; properties: "x,y,width,height,opacity,radius"; duration: 1000; easing.type: "InOutCubic" }
  154. }
  155. PropertyAnimation { target: skin; property: "opacity" }
  156. PropertyAction { target: container; property: "color" }
  157. PropertyAction { target: textEditor; property: "opacity" }
  158. PropertyAction { target: gridItem; property: "z" }
  159. }
  160. },
  161. Transition {
  162. from: "default"
  163. to: "inCodeEditorState"
  164. reversible: false
  165. SequentialAnimation {
  166. PropertyAnimation { target: skin; properties: "x,y,opacity"; duration: 700 }
  167. ParentAnimation {
  168. target: container
  169. PropertyAnimation { target: textEditor; property: "radius"; duration: 1000 }
  170. PropertyAnimation { target: container; properties: "x,y,width,height,radius"; duration: 1000; easing.type: "InOutCubic" }
  171. }
  172. }
  173. },
  174. Transition {
  175. from: "inCodeEditorState"
  176. to: "default"
  177. reversible: false
  178. SequentialAnimation {
  179. ParentAnimation {
  180. target: container
  181. PropertyAnimation { target: container; properties: "x,y,width,height,opacity,radius"; duration: 1000; easing.type: "InOutCubic" }
  182. }
  183. PropertyAnimation { target: skin; properties: "x,y,opacity"; duration: 500 }
  184. PropertyAction { target: gridItem; property: "z" }
  185. }
  186. },
  187. Transition {
  188. from: "inCodeEditorState"
  189. to: "maximizedState"
  190. reversible: false
  191. SequentialAnimation {
  192. ParallelAnimation {
  193. PropertyAnimation { target: textEditor; property: "opacity"; duration: 1000 }
  194. ColorAnimation { target: container; duration: 1000 }
  195. }
  196. ScriptAction { scriptName: "scriptLoadDemo" }
  197. ParallelAnimation {
  198. PropertyAnimation { target: demoHolder; property: "opacity"; duration: 1000 }
  199. PropertyAnimation { target: sidePanel; property: "opacity"; duration: 1000 }
  200. }
  201. PauseAnimation { duration: 100 }
  202. ScriptAction { scriptName: "scriptStartDemo" }
  203. }
  204. },
  205. Transition {
  206. from: "maximizedState"
  207. to: "inCodeEditorState"
  208. reversible: false
  209. SequentialAnimation {
  210. PropertyAction { target: skin; properties: "x,y" }
  211. ParallelAnimation {
  212. PropertyAnimation { target: sidePanel; property: "opacity"; duration : 1000 }
  213. PropertyAnimation { target: demoHolder; property: "opacity"; duration: 1000 }
  214. }
  215. ScriptAction { scriptName: "scriptUnloadDemo" }
  216. ParallelAnimation {
  217. ColorAnimation { target: container; duration: 200 }
  218. PropertyAnimation { target: textEditor; property: "opacity"; duration: 1000 }
  219. }
  220. }
  221. }
  222. ]
  223. }