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  explicit 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 
102  ~MythGestureEvent() override;
103 
109  inline Gesture gesture(void) const { return m_gesture; }
110 
115  explicit operator QString() const;
116 
117  void SetPosition(QPoint position) { m_position = position; }
118  QPoint GetPosition() const { return m_position; }
119 
120  void SetButton(Button button) { m_button = button; }
121  Button GetButton(void) const { return m_button; }
122 
123  static Type kEventType;
124 
125  private:
127  QPoint m_position;
129 
130 };
131 
132 /* forward declaration of private information */
133 class MythGesturePrivate;
134 
147 {
148  public:
158  explicit MythGesture(size_t max_points = 10000, size_t min_points = 50,
159  size_t max_sequence = 20, size_t scale_ratio = 4,
160  float bin_percent = 0.07);
161  ~MythGesture();
162 
166  void start(void);
167 
174  void stop(void);
175 
180  bool recording(void) const;
181 
186  MythGestureEvent *gesture(void) const;
187 
193  bool record(const QPoint &p);
194 
199  bool hasMinimumPoints(void) const
200  { return (uint)m_points.size() >= m_minPoints; }
201 
202  protected:
203 
210  QString translate(void);
211 
217  void adjustExtremes(int x, int y);
218 
219  private:
220 
221  bool m_recording {false};
222  int m_minX {10000};
223  int m_maxX {-1};
224  int m_minY {10000};
225  int m_maxY {-1};
226  size_t m_maxPoints {10000};
227  size_t m_minPoints {50};
228  size_t m_maxSequence {20};
229  int m_scaleRatio {4};
230  float m_binPercent {0.07F};
232  QList <QPoint> m_points;
233 
234  MythGesturePrivate *p {nullptr}; // NOLINT(readability-identifier-naming)
235 };
236 
237 #endif /* MYTHGESTURE_H */
238 
bool record(const QPoint &p)
Record a point.
size_t m_minPoints
Definition: mythgesture.h:227
QString translate(void)
Translate the stroke into a sequence.
void SetPosition(QPoint position)
Definition: mythgesture.h:117
MythGestureEvent::Gesture m_lastGesture
Definition: mythgesture.h:231
int m_scaleRatio
Definition: mythgesture.h:229
bool recording(void) const
Determine if the stroke is being recorded.
float m_binPercent
Definition: mythgesture.h:230
void stop(void)
Stop recording.
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:109
bool hasMinimumPoints(void) const
Determine if the stroke has the minimum required points.
Definition: mythgesture.h:199
MythGesturePrivate * p
Definition: mythgesture.h:234
Private information used only by a stroke class.
Definition: mythgesture.cpp:49
MythGestureEvent * gesture(void) const
Complete the gesture event of the last completed stroke.
MythGestureEvent(Gesture gesture, Button button=LeftButton)
Create a MythGesture.
Definition: mythgesture.h:95
bool m_recording
Definition: mythgesture.h:221
unsigned int uint
Definition: compat.h:140
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:59
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
void start(void)
Start recording.
Button GetButton(void) const
Definition: mythgesture.h:121
static Type kEventType
Definition: mythgesture.h:123
#define MUI_PUBLIC
Definition: mythuiexp.h:9
size_t m_maxSequence
Definition: mythgesture.h:228
void adjustExtremes(int x, int y)
Adjust horizontal and vertical extremes.
QList< QPoint > m_points
Definition: mythgesture.h:232
Contains the points in a stroke, and translates them into gestures.
Definition: mythgesture.h:146
void SetButton(Button button)
Definition: mythgesture.h:120
size_t m_maxPoints
Definition: mythgesture.h:226
QPoint GetPosition() const
Definition: mythgesture.h:118
Gesture
The types of gestures supported by myth.
Definition: mythgesture.h:45