Button.qml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. import "Game.js" as GameScript
  6. Item {
  7. property string buttonPath // for example "qrc:/gfx/exit.png"
  8. property int buttonId: 0
  9. property bool animationEnabled: true
  10. signal btnClicked(int buttonId)
  11. width: 30 // Default width
  12. height: 30 // Default height
  13. smooth: true
  14. Image {
  15. id: image
  16. anchors.fill: parent
  17. source: buttonPath
  18. fillMode: Image.PreserveAspectFit
  19. smooth: true
  20. scale: 1.0
  21. }
  22. SequentialAnimation {
  23. id:anim
  24. running: false
  25. PropertyAction { target: image; property: "scale"; value: 0.7 }
  26. PauseAnimation { duration: 200 }
  27. PropertyAction { target: image; property: "scale"; value: 1.0 }
  28. }
  29. Timer {
  30. id: buttonPressedTimer
  31. interval: 300; running: false; repeat: false
  32. onTriggered: btnClicked(buttonId)
  33. }
  34. MouseArea {
  35. anchors.fill: parent
  36. onPressed: {
  37. if (animationEnabled && !anim.running) {
  38. anim.restart();
  39. }
  40. buttonPressedTimer.restart();
  41. }
  42. }
  43. }