00001
00024 #ifndef MYTHGESTURE_H
00025 #define MYTHGESTURE_H
00026
00027 #include <sys/types.h>
00028
00029 #include <QPoint>
00030 #include <QList>
00031 #include <QString>
00032 #include <QEvent>
00033
00038 class MythGestureEvent : public QEvent
00039 {
00040 public:
00044 enum Gesture {
00045 Unknown,
00046
00047
00048 Up,
00049 Down,
00050 Left,
00051 Right,
00052
00053
00054 UpLeft,
00055 UpRight,
00056 DownLeft,
00057 DownRight,
00058
00059
00060 UpThenLeft,
00061 UpThenRight,
00062 DownThenLeft,
00063 DownThenRight,
00064 LeftThenUp,
00065 LeftThenDown,
00066 RightThenUp,
00067 RightThenDown,
00068
00069
00070 Click,
00071
00072
00073 MaxGesture
00074 };
00075
00076 enum Button {
00077 NoButton,
00078 LeftButton,
00079 RightButton,
00080 MiddleButton,
00081 Aux1Button,
00082 Aux2Button
00083 };
00084
00090 MythGestureEvent(Gesture gesture, Button button = LeftButton) :
00091 QEvent(kEventType), m_gesture(Unknown)
00092 {
00093 m_position = QPoint(0,0);
00094 m_button = button;
00095 (gesture >= MaxGesture) ? m_gesture = MaxGesture : m_gesture = gesture;
00096 }
00097
00103 inline Gesture gesture(void) const { return m_gesture; }
00104
00109 operator QString() const;
00110
00111 void SetPosition(QPoint position) { m_position = position; }
00112 QPoint GetPosition() const { return m_position; }
00113
00114 void SetButton(Button button) { m_button = button; }
00115 Button GetButton(void) const { return m_button; }
00116
00117 static Type kEventType;
00118
00119 private:
00120 Gesture m_gesture;
00121 QPoint m_position;
00122 Button m_button;
00123
00124 };
00125
00126
00127 class MythGesturePrivate;
00128
00140 class MythGesture
00141 {
00142 public:
00152 explicit MythGesture(size_t max_points = 10000, size_t min_points = 50,
00153 size_t max_sequence = 20, size_t scale_ratio = 4,
00154 float bin_percent = 0.07);
00155 ~MythGesture();
00156
00160 void start(void);
00161
00168 void stop(void);
00169
00174 bool recording(void) const;
00175
00180 MythGestureEvent *gesture(void) const;
00181
00187 bool record(const QPoint &p);
00188
00193 bool hasMinimumPoints(void) const { return (uint)points.size() >= min_points; }
00194
00195 protected:
00196
00203 QString translate(void);
00204
00210 void adjustExtremes(int x, int y);
00211
00212 private:
00213
00214 bool m_recording;
00215 int min_x;
00216 int max_x;
00217 int min_y;
00218 int max_y;
00219 size_t max_points;
00220 size_t min_points;
00221 size_t max_sequence;
00222 int scale_ratio;
00223 float bin_percent;
00224 MythGestureEvent::Gesture last_gesture;
00225 QList <QPoint> points;
00226
00227 MythGesturePrivate *p;
00228 };
00229
00230 #endif
00231