Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import QtQuick 2.0
  2.  
  3. MouseArea {
  4. property point origin
  5. property bool ready: false
  6. signal click();
  7. signal move(int x, int y)
  8. signal swipe(string direction)
  9.  
  10. onPressed: {
  11. drag.axis = Drag.XAndYAxis
  12. origin = Qt.point(mouse.x, mouse.y)
  13. }
  14.  
  15. onClicked: {
  16. canceled(mouse);
  17. }
  18.  
  19. onPositionChanged: {
  20. switch (drag.axis) {
  21. case Drag.XAndYAxis:
  22. if (Math.abs(mouse.x - origin.x) > 16) {
  23. drag.axis = Drag.XAxis
  24. }
  25. else if (Math.abs(mouse.y - origin.y) > 16) {
  26. drag.axis = Drag.YAxis
  27. }
  28. break
  29. case Drag.XAxis:
  30. move(mouse.x - origin.x, 0)
  31. break
  32. case Drag.YAxis:
  33. move(0, mouse.y - origin.y)
  34. break
  35. }
  36. }
  37.  
  38. onReleased: {
  39. if (Math.abs(mouse.x - origin.x) < 20 && Math.abs(mouse.y - origin.y < 20)) {
  40. click();
  41. } else {
  42.  
  43. switch (drag.axis) {
  44. case Drag.XAndYAxis:
  45. canceled(mouse)
  46. break
  47. case Drag.XAxis:
  48. swipe(mouse.x - origin.x < 0 ? "left" : "right")
  49. break
  50. case Drag.YAxis:
  51. swipe(mouse.y - origin.y < 0 ? "up" : "down")
  52. break
  53. }
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement