MenuItem.qml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. Text {
  6. id: menuItem
  7. text: name
  8. color: "white"
  9. opacity: 1
  10. font.family: "Calibri"
  11. font.pixelSize: menu.width / 8
  12. x: (parent.width - width )/ 2
  13. property bool selectedItem: false
  14. property int type
  15. signal itemSelected()
  16. transform: Rotation { id:rotationId; origin.x:width/2; origin.y:height/2; axis { x: 1; y: 0; z: 0 } angle: 0 }
  17. SequentialAnimation {
  18. id: toRotateRightAndCenterAnim
  19. PropertyAnimation { target: rotationId; easing.type: Easing.Linear;
  20. properties: "angle"; from: 0; to: 180; duration: 300 }
  21. PropertyAction { target: menuItem; property: "color"; value:"red"}
  22. PropertyAnimation { target: rotationId; easing.type: Easing.Linear;
  23. properties: "angle"; from: 180; to: 360; duration: 300 }
  24. PropertyAction { target: menuItem; property: "color"; value:"white"}
  25. }
  26. function selectItem(doSelect) {
  27. if (!toRotateRightAndCenterAnim.running) {
  28. GameEngine.playInternalSound(0)
  29. toRotateRightAndCenterAnim.restart()
  30. if (doSelect) {
  31. GameEngine.playInternalSound(1)
  32. selectionTimer.restart()
  33. }
  34. }
  35. }
  36. Timer {
  37. id: selectionTimer
  38. interval: 1000; running: false; repeat: false
  39. onTriggered: menuItem.itemSelected()
  40. }
  41. MouseArea {
  42. id: mouseArea;
  43. anchors.fill: parent
  44. onClicked: {
  45. selectItem(true)
  46. }
  47. }
  48. Keys.onSpacePressed: { selectItem(true) }
  49. Keys.onSelectPressed: { selectItem(true) }
  50. Keys.onEnterPressed: { selectItem(true) }
  51. Keys.onReleased: {
  52. if (event.key == Qt.Key_Down || event.key == Qt.Key_Up) {
  53. selectItem(false)
  54. }
  55. event.accepted = false
  56. }
  57. }