summaryrefslogtreecommitdiffstats
path: root/examples/gestures/collidingmice/gesturerecognizerlinjazax.h
blob: 07172f1c2185f2c17c6c47ce9e06446e6eaa7d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef GESTURERECOGNIZERLINJAZAX_H
#define GESTURERECOGNIZERLINJAZAX_H

#include <QList>
#include <QPoint>
#include <QString>
#include <QGesture>
#include <QGestureRecognizer>

#include "linjazaxgesture.h"

struct Direction
{
    QString direction;
    QPoint point;

    Direction(QString dir, const QPoint &pt)
        : direction(dir), point(pt) { }
    Direction()
        : direction() { }

    inline bool isEmpty() const { return direction.isEmpty(); }
    inline bool isNull() const { return direction.isEmpty(); }
};
typedef QList<Direction> DirectionList;

class DirectionSimpleRecognizer
{
public:
    DirectionSimpleRecognizer();
    Direction addPosition(const QPoint &pos);
    DirectionList getDirections() const;
    void reset();

private:
    QPoint lastPoint;
    DirectionList directions;
};

class GestureRecognizerLinjaZax : public QGestureRecognizer
{
    Q_OBJECT
public:
    GestureRecognizerLinjaZax();

    QGestureRecognizer::Result filterEvent(const QEvent *event);
    QGesture* getGesture();

    void reset();

private:
    void internalReset();

    QPoint pressedPos;
    QPoint lastPos;
    QPoint currentPos;
    bool mousePressed;
    bool gestureFinished;
    QString lastDirections;
    QString currentDirection;
    DirectionSimpleRecognizer simpleRecognizer;
    LinjaZaxGesture::ZoomState zoomState;
};

#endif