00001
00024 #ifndef MYTHGESTURE_H
00025 #define MYTHGESTURE_H
00026
00027 #include <sys/types.h>
00028
00029 #include <qpoint.h>
00030 #include <qvaluelist.h>
00031 #include <qevent.h>
00032
00033 const int MythGestureEventType = 24427;
00034
00039 class MythGestureEvent : public QCustomEvent
00040 {
00041 public:
00045 enum Gesture {
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
00081 inline MythGestureEvent(size_t gesture):QCustomEvent(MythGestureEventType)
00082 {
00083 (gesture >= MaxGesture) ? _gesture = MaxGesture : _gesture = gesture;
00084 }
00085
00091 inline int gesture(void) const { return this->_gesture; }
00092
00097 operator QString() const;
00098
00099 private:
00100
00101 size_t _gesture;
00102 };
00103
00104
00105 class MythGesturePrivate;
00106
00116 class MythGesture
00117 {
00118 public:
00119
00129 MythGesture(size_t max_points = 10000, size_t min_points = 50,
00130 size_t max_sequence = 20, size_t scale_ratio = 4,
00131 float bin_percent = 0.07);
00132 ~MythGesture();
00133
00137 void start(void);
00138
00145 void stop(void);
00146
00151 bool recording(void) const;
00152
00157 MythGestureEvent *gesture(void) const;
00158
00164 bool record(const QPoint &p);
00165
00170 bool hasMinimumPoints(void) const { return points.size() >= min_points; }
00171
00172 protected:
00173
00180 QString translate(void);
00181
00187 void adjustExtremes(int x, int y);
00188
00189 private:
00190
00191 bool m_recording;
00192 int min_x;
00193 int max_x;
00194 int min_y;
00195 int max_y;
00196 size_t max_points;
00197 size_t min_points;
00198 size_t max_sequence;
00199 int scale_ratio;
00200 float bin_percent;
00201 size_t last_gesture;
00202 QValueList <QPoint> points;
00203
00204 MythGesturePrivate *p;
00205 };
00206
00207 #endif
00208