Message.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. Item {
  6. id: message
  7. smooth: true
  8. opacity: 0
  9. function showMessage(text, speed)
  10. {
  11. clear();
  12. textLabel.border.color = "white";
  13. message.width = gameArea.xDim - 10
  14. message.height = gameArea.yDim * 0.1
  15. textLabel.text = text;
  16. textLabel.fontPixelSize = message.height * 0.33;
  17. messageAnim.restart();
  18. }
  19. function showErrorMessage(text, speed)
  20. {
  21. clear();
  22. textLabel.border.color = "red";
  23. message.width = gameArea.xDim - 10
  24. message.height = gameArea.yDim * 0.1
  25. textLabel.text = text;
  26. textLabel.fontPixelSize = message.height * 0.33;
  27. messageAnim.restart();
  28. }
  29. function clear()
  30. {
  31. messageAnim.stop();
  32. message.opacity = 0;
  33. }
  34. transform: Rotation {
  35. id: rotation
  36. origin.x: message.width * 0.5;
  37. origin.y: message.height * 0.5;
  38. axis.x:1; axis.y:0; axis.z:0
  39. angle:90
  40. }
  41. SequentialAnimation {
  42. id: messageAnim
  43. PropertyAction { target: message; properties: "opacity"; value: 1 }
  44. PropertyAction { target: message; properties: "x";
  45. value: (gameArea.xDim - message.width) * 0.5 }
  46. PropertyAction { target: message; properties: "y"; value: 5 }
  47. NumberAnimation { target: rotation; property: "angle"; from: 90; to:0; duration: 600 }
  48. PauseAnimation { duration: 3000 }
  49. NumberAnimation { target: rotation; property: "angle"; from: 0; to:90; duration: 600 }
  50. PropertyAction { target: message; properties: "opacity"; value: 0 }
  51. }
  52. TextLabel {
  53. id: textLabel
  54. anchors.fill: parent
  55. opacity: 1
  56. border.color: "black"
  57. gradient: Gradient {
  58. GradientStop { position: 0.0; color: "transparent" }
  59. GradientStop { position: 0.6; color: "black" }
  60. GradientStop { position: 0.8; color: "black" }
  61. GradientStop { position: 1.0; color: "#ee01e6" }
  62. }
  63. mouseAreaEnabled: false
  64. textVerticalAlignment: Text.AlignVCenter
  65. }
  66. MouseArea {
  67. anchors.fill: parent
  68. onClicked: message.clear();
  69. }
  70. }