Message.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2010 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. Rectangle {
  6. id: message
  7. border.color: "black"
  8. border.width: 1
  9. radius: 8
  10. smooth: true
  11. opacity: 0 // transparent = 0 by default
  12. color: "black"
  13. property string txt
  14. property int animSpeed
  15. function showMessage(text,speed) {
  16. message.border.color = "black"
  17. message.y = 50
  18. message.width = gameArea.width / 5 * 4
  19. message.height = gameArea.height / 8 * 1
  20. txt = text
  21. animSpeed = speed
  22. message.opacity = 1
  23. messageText.font.pixelSize = parent.width / 14
  24. messageAnim.restart()
  25. }
  26. function showErrorMessage(text,speed) {
  27. message.border.color = "red"
  28. message.y = 50
  29. message.width = gameArea.width / 5 * 4
  30. message.height = gameArea.height / 8 * 1
  31. txt = text
  32. animSpeed = speed
  33. message.opacity = 1
  34. messageText.font.pixelSize = parent.width / 14
  35. messageAnim.restart()
  36. }
  37. function showInfoMessage() {
  38. message.border.color = "white"
  39. txt = "<a href=\"https://projects.forum.nokia.com/quickhit\">QuickHit</a>" +
  40. "<p>" +
  41. "Forum Nokia <br>" +
  42. "Qt Quick Game Example <br>" +
  43. "</p>" +
  44. "<p>" +
  45. "Sounds were loaded from freesound.org under Creative Commons Sampling Plus 1.0 license.<br>" +
  46. "</p>" +
  47. "<p>" +
  48. "Sounds were created by these nicknames:<br>" +
  49. "HardPCM<br>" +
  50. "Matt_G<br>" +
  51. "klankbeeld<br>" +
  52. "steveygos93<br>" +
  53. "joe93barlow<br>" +
  54. "ljudman<br>" +
  55. "Jovica<br>" +
  56. "patchen<br>" +
  57. "nthompson<br>" +
  58. "</p>"
  59. animSpeed = 9000
  60. message.opacity = 1
  61. message.y = 10
  62. message.height = gameArea.height - message.y - 10
  63. message.width = gameArea.width - 20
  64. messageText.font.pixelSize = parent.width / 16
  65. messageAnim.restart()
  66. }
  67. //gradient: Gradient {
  68. // GradientStop { position: 0.0; color: "white" }
  69. // GradientStop { position: 1.0; color: "black" }
  70. //}
  71. SequentialAnimation {
  72. id: messageAnim
  73. PropertyAnimation {
  74. target: message; properties: "x";
  75. from: message.width*-1; to: gameArea.width; duration: animSpeed; easing.type: Easing.OutInExpo}
  76. PropertyAction { target: message; properties: "opacity"; value: 0 }
  77. }
  78. MouseArea {
  79. anchors.fill: parent
  80. onClicked: {
  81. messageAnim.stop()
  82. message.opacity = 0
  83. }
  84. }
  85. Text {
  86. id: messageText
  87. anchors.fill: parent
  88. anchors.margins: 10
  89. text: txt
  90. wrapMode: Text.WordWrap
  91. color: "white"
  92. font.family: "Calibri"
  93. font.pixelSize: parent.width / 14
  94. font.bold: true
  95. onLinkActivated: {
  96. GameEngine.openLink(link)
  97. }
  98. }
  99. }