MythTV  master
mythgesture.h
Go to the documentation of this file.
1 /* -*- myth -*- */
23 #ifndef MYTHGESTURE_H
24 #define MYTHGESTURE_H
25 
26 #include <sys/types.h>
27 
28 #include <QPoint>
29 #include <QList>
30 #include <QString>
31 #include <QEvent>
32 
33 #include "mythuiexp.h"
34 
39 class MUI_PUBLIC MythGestureEvent : public QEvent
40 {
41  public:
45  enum Gesture {
47 
48  /* Horizontal and vertical lines */
49  Up,
53 
54  /* Diagonal lines */
59 
60  /* Two Lines */
73 
74  /* A click */
76 
77  /* This isn't real */
78  MaxGesture
79  };
80 
81  enum Button {
87  Aux2Button
88  };
89 
95  MythGestureEvent(Gesture gesture, Button button = LeftButton) :
96  QEvent(kEventType), m_gesture(Unknown)
97  {
98  m_button = button;
99  (gesture >= MaxGesture) ? m_gesture = MaxGesture : m_gesture = gesture;
100  }
101 
107  inline Gesture gesture(void) const { return m_gesture; }
108 
113  operator QString() const;
114 
115  void SetPosition(QPoint position) { m_position = position; }
116  QPoint GetPosition() const { return m_position; }
117 
118  void SetButton(Button button) { m_button = button; }
119  Button GetButton(void) const { return m_button; }
120 
121  static Type kEventType;
122 
123  private:
125  QPoint m_position;
127 
128 };
129 
130 /* forward declaration of private information */
131 class MythGesturePrivate;
132 
145 {
146  public:
156  explicit MythGesture(size_t max_points = 10000, size_t min_points = 50,
157  size_t max_sequence = 20, size_t scale_ratio = 4,
158  float bin_percent = 0.07);
159  ~MythGesture();
160 
164  void start(void);
165 
172  void stop(void);
173 
178  bool recording(void) const;
179 
184  MythGestureEvent *gesture(void) const;
185 
191  bool record(const QPoint &p);
192 
197  bool hasMinimumPoints(void) const
198  { return (uint)m_points.size() >= m_min_points; }
199 
200  protected:
201 
208  QString translate(void);
209 
215  void adjustExtremes(int x, int y);
216 
217  private:
218 
219  bool m_recording {false};
220  int m_min_x {10000};
221  int m_max_x {-1};
222  int m_min_y {10000};
223  int m_max_y {-1};
224  size_t m_max_points {10000};
225  size_t m_min_points {50};
226  size_t m_max_sequence {20};
227  int m_scale_ratio {4};
228  float m_bin_percent {0.07F};
230  QList <QPoint> m_points;
231 
232  MythGesturePrivate *p {nullptr};
233 };
234 
235 #endif /* MYTHGESTURE_H */
236 
bool record(const QPoint &p)
Record a point.
QString translate(void)
Translate the stroke into a sequence.
void SetPosition(QPoint position)
Definition: mythgesture.h:115
bool recording(void) const
Determine if the stroke is being recorded.
unsigned int uint
Definition: compat.h:140
void stop(void)
Stop recording.
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:107
bool hasMinimumPoints(void) const
Determine if the stroke has the minimum required points.
Definition: mythgesture.h:197
MythGesturePrivate * p
Definition: mythgesture.h:232
size_t m_max_points
Definition: mythgesture.h:224
Private information used only by a stroke class.
Definition: mythgesture.cpp:45
size_t m_max_sequence
Definition: mythgesture.h:226
MythGestureEvent * gesture(void) const
Complete the gesture event of the last completed stroke.
MythGestureEvent::Gesture m_last_gesture
Definition: mythgesture.h:229
MythGestureEvent(Gesture gesture, Button button=LeftButton)
Create a MythGesture.
Definition: mythgesture.h:95
bool m_recording
Definition: mythgesture.h:219
MythGesture(size_t max_points=10000, size_t min_points=50, size_t max_sequence=20, size_t scale_ratio=4, float bin_percent=0.07)
Create a new stroke, specifying tuning values.
Definition: mythgesture.cpp:55
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
void start(void)
Start recording.
Button GetButton(void) const
Definition: mythgesture.h:119
static Type kEventType
Definition: mythgesture.h:121
int m_scale_ratio
Definition: mythgesture.h:227
float m_bin_percent
Definition: mythgesture.h:228
#define MUI_PUBLIC
Definition: mythuiexp.h:9
void adjustExtremes(int x, int y)
Adjust horizontal and vertical extremes.
QList< QPoint > m_points
Definition: mythgesture.h:230
Contains the points in a stroke, and translates them into gestures.
Definition: mythgesture.h:144
void SetButton(Button button)
Definition: mythgesture.h:118
QPoint GetPosition() const
Definition: mythgesture.h:116
size_t m_min_points
Definition: mythgesture.h:225
Gesture
The types of gestures supported by myth.
Definition: mythgesture.h:45