MenuBackButton.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import QtQuick 2.15
  2. Item {
  3. id: root
  4. width: 40
  5. height: 40
  6. property double iconMarigns: 8
  7. property double iconHeight: width - iconMarigns * 2
  8. signal clicked()
  9. signal back()
  10. SystemPalette {
  11. id: palette
  12. }
  13. MouseArea {
  14. id: ma
  15. anchors.fill: parent
  16. }
  17. Rectangle {
  18. id: bar1
  19. x: root.iconMarigns
  20. y: root.iconMarigns + root.iconHeight / 6
  21. width: root.iconHeight
  22. height: root.iconHeight / 9
  23. antialiasing: true
  24. color: palette.button
  25. }
  26. Rectangle {
  27. id: bar2
  28. x: root.iconMarigns
  29. y: root.iconMarigns + root.iconHeight / 2 - height / 2
  30. width: root.iconHeight
  31. height: root.iconHeight / 9
  32. antialiasing: true
  33. color: palette.button
  34. }
  35. Rectangle {
  36. id: bar3
  37. x: root.iconMarigns
  38. y: root.iconMarigns + root.iconHeight / 2 + height * 2
  39. width: root.iconHeight
  40. height: root.iconHeight / 9
  41. antialiasing: true
  42. color: palette.button
  43. }
  44. property int animationDuration: 450
  45. state: "menu"
  46. states: [
  47. State {
  48. name: "menu"
  49. PropertyChanges { ma.onClicked: root.clicked() }
  50. },
  51. State {
  52. name: "back"
  53. PropertyChanges { root.rotation: 180 }
  54. PropertyChanges { bar1.rotation: 45;
  55. bar1.width: root.iconHeight / 3 * 2;
  56. bar1.x: root.iconMarigns + root.iconHeight / 2;
  57. bar1.y: root.iconMarigns + root.iconHeight / 4 }
  58. PropertyChanges { bar2.width: root.iconHeight / 6 * 5 + 1;
  59. bar2.x: root.iconMarigns + root.iconHeight / 9 }
  60. PropertyChanges { bar3.rotation: -45;
  61. bar3.width: root.iconHeight / 3 * 2;
  62. bar3.x: root.iconMarigns + root.iconHeight / 2;
  63. bar3.y: root.iconMarigns + root.iconHeight / 3 * 2 }
  64. PropertyChanges { ma.onClicked: root.back() }
  65. },
  66. State {
  67. name: "hidden"
  68. PropertyChanges { ma.enabled: false }
  69. PropertyChanges { root.opacity: 0 }
  70. }
  71. ]
  72. transitions: [
  73. Transition {
  74. from: "hidden"; to: "*"
  75. SequentialAnimation
  76. {
  77. PropertyAction { targets: [root, bar1, bar2, bar3]; properties: "rotation, width, x, y" }
  78. NumberAnimation { target: root; property: "opacity"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  79. }
  80. },
  81. Transition {
  82. from: "*"; to: "hidden"
  83. SequentialAnimation
  84. {
  85. NumberAnimation { target: root; property: "opacity"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  86. PropertyAction { targets: [root, bar1, bar2, bar3]; properties: "rotation, width, x, y" }
  87. }
  88. },
  89. Transition {
  90. from: "menu"; to: "back"
  91. RotationAnimation { target: root; direction: RotationAnimation.Clockwise; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  92. PropertyAnimation { targets: [bar1, bar2, bar3]; properties: "rotation, width, x, y"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  93. },
  94. Transition {
  95. from: "back"; to: "menu"
  96. RotationAnimation { target: root; direction: RotationAnimation.Counterclockwise; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  97. PropertyAnimation { targets: [bar1, bar2, bar3]; properties: "rotation, width, x, y"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
  98. }
  99. ]
  100. }