Button.qml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. Item {
  6. id:button
  7. property int buttonId:0
  8. signal btnClicked(int buttonId)
  9. function sendBtnClicked()
  10. {
  11. if (buttonId!=0) {
  12. btnClicked(buttonId);
  13. }
  14. }
  15. Image {
  16. id: imageId_down
  17. opacity: 0
  18. anchors.fill: parent
  19. fillMode: Image.PreserveAspectFit
  20. smooth: true
  21. source: {
  22. if (buttonId==1)
  23. "qrc:/images/close_on.png"
  24. else if (buttonId==2)
  25. "qrc:/images/btn_info_down.png"
  26. else if (buttonId==3)
  27. "qrc:/images/btn_select_down.png"
  28. else
  29. console.log("Error: no buttonId defined")
  30. }
  31. }
  32. Image {
  33. id: imageId_up
  34. anchors.fill: parent
  35. fillMode: Image.PreserveAspectFit
  36. smooth: true
  37. source: {
  38. if (buttonId==1)
  39. "qrc:/images/close.png"
  40. else if (buttonId==2)
  41. "qrc:/images/btn_info.png"
  42. else if (buttonId==3)
  43. "qrc:/images/btn_select.png"
  44. else
  45. console.log("Error: no buttonId defined")
  46. }
  47. }
  48. SequentialAnimation {
  49. id:btnAnim
  50. PropertyAction { target: imageId_up; property: "opacity"; value: 0 }
  51. PropertyAction { target: imageId_down; property: "opacity"; value: 1 }
  52. PauseAnimation { duration: 500 }
  53. ScriptAction { script: sendBtnClicked(); }
  54. PropertyAction { target: imageId_down; property: "opacity"; value: 0 }
  55. PropertyAction { target: imageId_up; property: "opacity"; value: 1 }
  56. }
  57. MouseArea {
  58. anchors.fill: imageId_up
  59. onClicked: {
  60. btnAnim.restart()
  61. }
  62. }
  63. }