Button.qml 1.1 KB

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