Updating git with latest code
[marketstoday] / src / qml / Library / CustomGestureArea.qml
1 import Qt 4.7
2
3 MouseArea {
4     anchors.fill: parent
5     signal swipeRight;
6     signal swipeLeft;
7     signal swipeUp;
8     signal swipeDown;
9
10     property int startX;
11     property int startY;
12
13     onPressed: {
14         startX = mouse.x;
15         startY = mouse.y;
16         console.log("Gesture started");
17     }
18
19     onReleased: {
20         var deltax = mouse.x - startX;
21         var deltay = mouse.y - startY;
22
23         if (Math.abs(deltax) > 40 || Math.abs(deltay) > 40) {
24             if (deltax > 30 && Math.abs(deltay) < 30) {
25                 // swipe right
26                 swipeRight();
27             } else if (deltax < -30 && Math.abs(deltay) < 30) {
28                 // swipe left
29                 swipeLeft();
30             } else if (Math.abs(deltax) < 30 && deltay > 30) {
31                 // swipe down
32                 swipeDown();
33             } else if (Math.abs(deltax) < 30 && deltay < 30) {
34                 // swipe up
35                 swipeUp();
36             }
37             console.log("Gesture ended");
38         }
39         else{
40             console.log("Gesture ended with deltax = "+deltax);
41         }
42     }
43 }