ToolButton.qml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import QtQuick 1.0
  2. Image {
  3. id: imgButton
  4. signal clicked
  5. property alias icon: imgButton.source
  6. property int pauseAnim: 0
  7. property int durationAnim: 400
  8. opacity: 1
  9. smooth: true
  10. Behavior on scale { NumberAnimation { duration: 150 } }
  11. Image {
  12. id: glowFrame
  13. source: "qrc:/qml/images/bar_glow.png"
  14. anchors.centerIn: parent
  15. Behavior on opacity { NumberAnimation { duration: 150 } }
  16. opacity:0
  17. scale: parent.scale
  18. smooth: true
  19. }
  20. states: [
  21. State {
  22. name: "normal"
  23. AnchorChanges {
  24. target: imgButton
  25. anchors.verticalCenter: parent.verticalCenter
  26. }
  27. },
  28. State {
  29. name: "hide"
  30. AnchorChanges {
  31. target: imgButton
  32. anchors.top: parent.bottom
  33. }
  34. }
  35. ]
  36. transitions: Transition {
  37. SequentialAnimation {
  38. PauseAnimation { duration: imgButton.pauseAnim }
  39. AnchorAnimation { duration: imgButton.durationAnim; easing.type: Easing.OutElastic }
  40. }
  41. }
  42. state: "hide"
  43. MouseArea {
  44. anchors.fill: parent
  45. onClicked: {
  46. imgButton.clicked()
  47. }
  48. onPressedChanged: {
  49. if( pressed ) {
  50. glowFrame.opacity = 1
  51. imgButton.scale = 0.95
  52. } else {
  53. glowFrame.opacity = 0
  54. imgButton.scale = 1.0
  55. }
  56. }
  57. }
  58. Component.onCompleted: imgButton.state = "normal"
  59. }