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 
MythGestureEvent::Down
@ Down
Definition: mythgesture.h:50
MythGestureEvent::LeftThenUp
@ LeftThenUp
Definition: mythgesture.h:65
MythGestureEvent::GetPosition
QPoint GetPosition() const
Definition: mythgesture.h:118
MythGestureEvent::DownThenLeft
@ DownThenLeft
Definition: mythgesture.h:63
MythGesture::m_scaleRatio
int m_scaleRatio
Definition: mythgesture.h:229
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythGestureEvent::UpRight
@ UpRight
Definition: mythgesture.h:56
MythGestureEvent::Up
@ Up
Definition: mythgesture.h:49
MythGesture::m_points
QList< QPoint > m_points
Definition: mythgesture.h:232
MythGesture::p
MythGesturePrivate * p
Definition: mythgesture.h:234
MythGestureEvent::Gesture
Gesture
The types of gestures supported by myth.
Definition: mythgesture.h:45
MythGestureEvent::RightThenDown
@ RightThenDown
Definition: mythgesture.h:68
MythGesture::m_maxPoints
size_t m_maxPoints
Definition: mythgesture.h:226
MythGestureEvent::m_gesture
Gesture m_gesture
Definition: mythgesture.h:126
MythGestureEvent::NoButton
@ NoButton
Definition: mythgesture.h:82
MythGestureEvent::MaxGesture
@ MaxGesture
Definition: mythgesture.h:78
MythGestureEvent::MiddleButton
@ MiddleButton
Definition: mythgesture.h:85
MythGestureEvent::SetPosition
void SetPosition(QPoint position)
Definition: mythgesture.h:117
MythGesture::m_minPoints
size_t m_minPoints
Definition: mythgesture.h:227
MythGestureEvent::LeftButton
@ LeftButton
Definition: mythgesture.h:83
MythGestureEvent::UpThenLeft
@ UpThenLeft
Definition: mythgesture.h:61
MythGestureEvent::DownThenUp
@ DownThenUp
Definition: mythgesture.h:72
MythGesture
Contains the points in a stroke, and translates them into gestures.
Definition: mythgesture.h:147
MythGesture::MythGesture
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:62
MythGestureEvent::MythGestureEvent
MythGestureEvent(Gesture gesture, Button button=LeftButton)
Create a MythGesture.
Definition: mythgesture.h:95
MythGesture::m_recording
bool m_recording
Definition: mythgesture.h:221
MythGestureEvent::RightButton
@ RightButton
Definition: mythgesture.h:84
MythGesture::m_maxX
int m_maxX
Definition: mythgesture.h:223
MythGestureEvent::Button
Button
Definition: mythgesture.h:81
MythGestureEvent::gesture
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:109
MythGesture::m_lastGesture
MythGestureEvent::Gesture m_lastGesture
Definition: mythgesture.h:231
MythGesture::start
void start(void)
Start recording.
Definition: mythgesture.cpp:127
MythGesture::recording
bool recording(void) const
Determine if the stroke is being recorded.
Definition: mythgesture.cpp:118
MythGesture::m_binPercent
float m_binPercent
Definition: mythgesture.h:230
MythGesture::m_minX
int m_minX
Definition: mythgesture.h:222
MythGestureEvent::Right
@ Right
Definition: mythgesture.h:52
MythGesture::gesture
MythGestureEvent * gesture(void) const
Complete the gesture event of the last completed stroke.
Definition: mythgesture.cpp:153
MythGestureEvent::Aux1Button
@ Aux1Button
Definition: mythgesture.h:86
MythGestureEvent::UpLeft
@ UpLeft
Definition: mythgesture.h:55
MythGesture::stop
void stop(void)
Stop recording.
Definition: mythgesture.cpp:135
MythGestureEvent::Unknown
@ Unknown
Definition: mythgesture.h:46
MythGestureEvent::DownThenRight
@ DownThenRight
Definition: mythgesture.h:64
MythGesture::m_minY
int m_minY
Definition: mythgesture.h:224
MythGestureEvent::m_button
Button m_button
Definition: mythgesture.h:128
MythGestureEvent::Click
@ Click
Definition: mythgesture.h:75
MythGesture::hasMinimumPoints
bool hasMinimumPoints(void) const
Determine if the stroke has the minimum required points.
Definition: mythgesture.h:199
uint
unsigned int uint
Definition: compat.h:140
MythGestureEvent::Left
@ Left
Definition: mythgesture.h:51
MythGestureEvent::m_position
QPoint m_position
Definition: mythgesture.h:127
MythGestureEvent::GetButton
Button GetButton(void) const
Definition: mythgesture.h:121
MythGestureEvent::UpThenDown
@ UpThenDown
Definition: mythgesture.h:71
MythGesture::adjustExtremes
void adjustExtremes(int x, int y)
Adjust horizontal and vertical extremes.
Definition: mythgesture.cpp:110
MythGesture::~MythGesture
~MythGesture()
Definition: mythgesture.cpp:104
MythGestureEvent::LeftThenDown
@ LeftThenDown
Definition: mythgesture.h:66
MythGestureEvent::SetButton
void SetButton(Button button)
Definition: mythgesture.h:120
MythGestureEvent::kEventType
static Type kEventType
Definition: mythgesture.h:123
MythGesture::m_maxY
int m_maxY
Definition: mythgesture.h:225
MythGestureEvent::DownLeft
@ DownLeft
Definition: mythgesture.h:57
MythGesture::translate
QString translate(void)
Translate the stroke into a sequence.
Definition: mythgesture.cpp:175
MythGestureEvent::UpThenRight
@ UpThenRight
Definition: mythgesture.h:62
MythGestureEvent
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
MythGesture::record
bool record(const QPoint &p)
Record a point.
Definition: mythgesture.cpp:275
MythGestureEvent::RightThenLeft
@ RightThenLeft
Definition: mythgesture.h:69
MythGesturePrivate
Private information used only by a stroke class.
Definition: mythgesture.cpp:52
MythGesture::m_maxSequence
size_t m_maxSequence
Definition: mythgesture.h:228
MythGestureEvent::RightThenUp
@ RightThenUp
Definition: mythgesture.h:67
MythGestureEvent::DownRight
@ DownRight
Definition: mythgesture.h:58
MythGestureEvent::LeftThenRight
@ LeftThenRight
Definition: mythgesture.h:70
mythuiexp.h