TopInfoPanel.qml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import QtQuick 1.1
  2. import Qt.labs.particles 1.0
  3. Rectangle {
  4. id: topInfoPanel
  5. anchors.horizontalCenter: parent.horizontalCenter
  6. width: parent.width - 14
  7. height: 80
  8. radius: 10
  9. border.color: "blue"
  10. z: 10
  11. property string icon: ""
  12. property color colorBorder: "lightblue"
  13. property string text: "Blah-blah-blah"
  14. property bool closeOnClicked: true
  15. signal clicked()
  16. signal opened()
  17. signal closed()
  18. property color colorMain: "white"
  19. property int __numScreen: 0
  20. function showPanel() {
  21. topInfoPanel.state = "visible"
  22. }
  23. function hidePanel() {
  24. topInfoPanel.state = "hidden"
  25. }
  26. function showPanelTime( time_ms ) {
  27. topInfoPanel.state = "visible"
  28. if( !timerHide.running ) {
  29. timerHide.interval = time_ms
  30. timerHide.start()
  31. }
  32. }
  33. function chShowPanel() {
  34. if( topInfoPanel.state == "hidden" ) {
  35. topInfoPanel.state = "visible"
  36. } else {
  37. topInfoPanel.state = "hidden"
  38. }
  39. }
  40. Timer {
  41. id: timerHide
  42. interval: 3000
  43. repeat: false
  44. onTriggered: {
  45. hidePanel()
  46. }
  47. }
  48. gradient: Gradient {
  49. GradientStop { position: 0; color: colorBorder }
  50. GradientStop { position: 0.15; color: colorMain }
  51. GradientStop { position: 0.85; color: colorMain }
  52. GradientStop { position: 1; color: colorBorder }
  53. }
  54. Rectangle {
  55. anchors.fill: parent
  56. anchors.margins: 1
  57. clip: true
  58. color: "transparent"
  59. radius: parent.radius
  60. Rectangle {
  61. width: parent.height
  62. height: parent.width
  63. anchors.centerIn: parent
  64. rotation: 270
  65. radius: parent.radius
  66. gradient: Gradient {
  67. GradientStop { position: 0; color: colorBorder }
  68. GradientStop { position: 0.05; color: "transparent" }
  69. GradientStop { position: 0.95; color: "transparent" }
  70. GradientStop { position: 1; color: colorBorder }
  71. }
  72. }
  73. }
  74. /*******************************************************/
  75. Image {
  76. id: imgFrame
  77. source: topInfoPanel.icon
  78. anchors.verticalCenter: parent.verticalCenter
  79. smooth: true
  80. anchors.left: parent.left
  81. anchors.leftMargin: 10
  82. height: parent.height - 16
  83. width: height
  84. visible: source != ""
  85. }
  86. Text {
  87. anchors.verticalCenter: parent.verticalCenter
  88. anchors.left: imgFrame.source == "" ? parent.left : imgFrame.right
  89. anchors.leftMargin: 10
  90. font.pixelSize: 24
  91. text: topInfoPanel.text
  92. }
  93. /*Item {
  94. id: wrapperText
  95. anchors.verticalCenter: parent.verticalCenter
  96. anchors.left: imgFrame.source == "" ? parent.left : imgFrame.right
  97. anchors.leftMargin: 10
  98. property string txt: topInfoPanel.text
  99. //Component.onCompleted: { console.debug("state:["+wrapperText.txt.length+"]") }
  100. Text {
  101. id: text
  102. text: wrapperText.txt
  103. anchors.fill: parent
  104. font.pixelSize: 26
  105. wrapMode: Text.WordWrap
  106. }
  107. Text {
  108. id: dummyText
  109. text: wrapperText.txt
  110. visible: false
  111. }
  112. states: [
  113. State {
  114. name: "wide text"
  115. when: wrapperText.txt.length > 20
  116. PropertyChanges {
  117. target: wrapperText
  118. width: topInfoPanel.width - 10
  119. //height: topInfoPanel.height - 10
  120. height: 75
  121. }
  122. },
  123. State {
  124. name: "not wide text"
  125. when: wrapperText.txt.length <= 20
  126. PropertyChanges {
  127. target: wrapperText
  128. width: dummyText.paintedWidth
  129. height: dummyText.height
  130. }
  131. }
  132. ]
  133. }*/
  134. MouseArea {
  135. id: maPanel
  136. anchors.fill: parent
  137. onClicked: {
  138. topInfoPanel.clicked()
  139. if( topInfoPanel.closeOnClicked ) {
  140. topInfoPanel.state = "hidden"
  141. if( timerHide.running ) {
  142. timerHide.stop()
  143. }
  144. }
  145. }
  146. }
  147. /*******************************************************/
  148. state: "hidden"
  149. states: [
  150. State {
  151. name: "visible"
  152. AnchorChanges { target: topInfoPanel; anchors.top: parent.top }
  153. PropertyChanges { target: topInfoPanel; scale: 1 }
  154. PropertyChanges { target: topInfoPanel; anchors.topMargin: 5 + (topInfoPanel.height+5)*__numScreen }
  155. },
  156. State {
  157. name: "hidden"
  158. AnchorChanges { target: topInfoPanel; anchors.bottom: parent.top }
  159. PropertyChanges { target: topInfoPanel; scale: 0 }
  160. }
  161. ]
  162. property int timeVtoH: 300
  163. property int timeHtoV: 300
  164. transitions: [
  165. Transition {
  166. from: "hidden"; to: "visible"
  167. SequentialAnimation {
  168. ScriptAction { script: { topInfoPanel.opened(); particles.burst( 20 ) } }
  169. ParallelAnimation {
  170. NumberAnimation { duration: timeHtoV; property: "scale"; easing.type: Easing.InOutQuad }
  171. AnchorAnimation { duration: timeHtoV; easing.type: Easing.InOutQuad }
  172. }
  173. }
  174. },
  175. Transition {
  176. from: "visible"; to: "hidden"
  177. SequentialAnimation {
  178. ScriptAction { script: { particles.burst( 20 ) } }
  179. ParallelAnimation {
  180. NumberAnimation { duration: timeVtoH; property: "scale"; easing.type: Easing.InOutQuad }
  181. AnchorAnimation { duration: timeVtoH; easing.type: Easing.InOutQuad }
  182. }
  183. ScriptAction { script: { topInfoPanel.closed(); } }
  184. }
  185. }
  186. ]
  187. Particles {
  188. id: particles
  189. x: parent.width/2
  190. y: parent.height/2
  191. source: "qrc:/qml/images/star.png"
  192. count: -1
  193. angle: 0
  194. angleDeviation: 360
  195. emissionRate: 0
  196. velocity: 300
  197. lifeSpan: 800
  198. }
  199. }