MythTV  master
mythgesture.h
Go to the documentation of this file.
1 
22 #ifndef MYTHGESTURE_H
23 #define MYTHGESTURE_H
24 
25 // Qt
26 #include <QPoint>
27 #include <QList>
28 #include <QString>
29 #include <QEvent>
30 #include <QMutex>
31 
32 // MythTV
33 #include "mythuiexp.h"
34 
35 // Std
36 #include <sys/types.h>
37 #include <map>
38 
39 class MUI_PUBLIC MythGestureEvent : public QEvent
40 {
41  Q_GADGET
42 
43  public:
44  enum Gesture
45  {
47 
48  /* Horizontal and vertical lines */
49  Up,
53 
54  /* Diagonal lines */
59 
60  /* Two Lines */
73 
74  /* A click */
75  // NB LongClick before Click as MythMainWindow filters out otherwise
77  Click
78  };
79  Q_ENUM(Gesture)
80 
81  explicit MythGestureEvent(Gesture gesture, Qt::MouseButton Button);
82  ~MythGestureEvent() override = default;
83 
84  QString GetName () const;
85  inline Gesture GetGesture () const { return m_gesture; }
86  void SetPosition (QPoint Position) { m_position = Position; }
87  QPoint GetPosition () const { return m_position; }
88  Qt::MouseButton GetButton () const { return m_button; }
89  QString GetButtonName() const;
90 
91  static Type kEventType;
92 
93  private:
94  Gesture m_gesture { Unknown };
95  QPoint m_position;
96  Qt::MouseButton m_button { Qt::NoButton };
97 };
98 
100 {
101  public:
102  explicit MythGesture(size_t MaxPoints = 10000, size_t MinPoints = 50,
103  size_t MaxSequence = 20, int ScaleRatio = 4,
104  float BinPercent = 0.07F);
105 
106  void Start();
107  void Stop(bool Timeout = false);
108  bool Recording();
109  MythGestureEvent* GetGesture() const;
110  bool Record(QPoint Point, Qt::MouseButton Button);
111 
112  private:
113  Q_DISABLE_COPY(MythGesture)
114 
115  bool HasMinimumPoints() const;
116  QString Translate(bool Timeout);
117  void AdjustExtremes(int X, int Y);
118 
119  bool m_recording { false };
120  int m_minX { 10000 };
121  int m_maxX { -1 };
122  int m_minY { 10000 };
123  int m_maxY { -1 };
124  size_t m_maxPoints { 10000 };
125  size_t m_minPoints { 50 };
126  size_t m_maxSequence { 20 };
127  int m_scaleRatio { 4 };
128  float m_binPercent { 0.07F };
130  QList <QPoint> m_points;
131  QMutex m_lock;
132  static const std::map<QString, MythGestureEvent::Gesture> kSequences;
133  Qt::MouseButton m_lastButton { Qt::NoButton };
134 };
135 
136 #endif
137 
MythGestureEvent::Down
@ Down
Definition: mythgesture.h:50
MythGestureEvent::LeftThenUp
@ LeftThenUp
Definition: mythgesture.h:65
MythGestureEvent::GetPosition
QPoint GetPosition() const
Definition: mythgesture.h:87
MythGestureEvent::DownThenLeft
@ DownThenLeft
Definition: mythgesture.h:63
MythGesture::m_scaleRatio
int m_scaleRatio
Definition: mythgesture.h:127
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythGesture::AdjustExtremes
void AdjustExtremes(int X, int Y)
Adjust horizontal and vertical extremes.
Definition: mythgesture.cpp:131
MythGestureEvent::UpRight
@ UpRight
Definition: mythgesture.h:56
MythGestureEvent::GetGesture
Gesture GetGesture() const
Definition: mythgesture.h:85
MythGestureEvent::GetButton
Qt::MouseButton GetButton() const
Definition: mythgesture.h:88
MythGestureEvent::Up
@ Up
Definition: mythgesture.h:49
MythGesture::m_points
QList< QPoint > m_points
Definition: mythgesture.h:130
MythGesture::Recording
bool Recording()
Determine if the stroke is being recorded.
Definition: mythgesture.cpp:142
MythGesture::Start
void Start()
Start recording.
Definition: mythgesture.cpp:151
MythGestureEvent::Gesture
Gesture
Definition: mythgesture.h:45
MythGestureEvent::RightThenDown
@ RightThenDown
Definition: mythgesture.h:68
MythGesture::m_maxPoints
size_t m_maxPoints
Definition: mythgesture.h:124
MythGestureEvent::LongClick
@ LongClick
Definition: mythgesture.h:76
MythGesture::m_minPoints
size_t m_minPoints
Definition: mythgesture.h:125
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:100
MythGesture::Stop
void Stop(bool Timeout=false)
Stop recording.
Definition: mythgesture.cpp:163
MythGesture::m_recording
bool m_recording
Definition: mythgesture.h:119
MythGesture::m_maxX
int m_maxX
Definition: mythgesture.h:121
MythGesture::m_lastGesture
MythGestureEvent::Gesture m_lastGesture
Definition: mythgesture.h:129
MythGesture::Translate
QString Translate(bool Timeout)
Translate the stroke into a sequence.
Definition: mythgesture.cpp:217
MythGesture::m_binPercent
float m_binPercent
Definition: mythgesture.h:128
MythGesture::m_minX
int m_minX
Definition: mythgesture.h:120
MythGestureEvent::Right
@ Right
Definition: mythgesture.h:52
MythGesture::Record
bool Record(QPoint Point, Qt::MouseButton Button)
Record a point.
Definition: mythgesture.cpp:331
MythGesture::MythGesture
MythGesture(size_t MaxPoints=10000, size_t MinPoints=50, size_t MaxSequence=20, int ScaleRatio=4, float BinPercent=0.07F)
Create a new stroke, specifying tuning values.
Definition: mythgesture.cpp:116
MythGestureEvent::UpLeft
@ UpLeft
Definition: mythgesture.h:55
MythGestureEvent::Unknown
@ Unknown
Definition: mythgesture.h:46
MythGestureEvent::DownThenRight
@ DownThenRight
Definition: mythgesture.h:64
MythGesture::m_minY
int m_minY
Definition: mythgesture.h:122
MythGestureEvent::SetPosition
void SetPosition(QPoint Position)
Definition: mythgesture.h:86
MythGesture::kSequences
static const std::map< QString, MythGestureEvent::Gesture > kSequences
Definition: mythgesture.h:132
MythGestureEvent::Left
@ Left
Definition: mythgesture.h:51
MythGestureEvent::m_position
QPoint m_position
Definition: mythgesture.h:95
MythGestureEvent::UpThenDown
@ UpThenDown
Definition: mythgesture.h:71
MythGestureEvent::LeftThenDown
@ LeftThenDown
Definition: mythgesture.h:66
MythGestureEvent::~MythGestureEvent
~MythGestureEvent() override=default
MythGestureEvent::kEventType
static Type kEventType
Definition: mythgesture.h:91
MythGesture::m_maxY
int m_maxY
Definition: mythgesture.h:123
MythGesture::GetGesture
MythGestureEvent * GetGesture() const
Complete the gesture event of the last completed stroke.
Definition: mythgesture.cpp:190
MythGestureEvent::DownLeft
@ DownLeft
Definition: mythgesture.h:57
MythGestureEvent::UpThenRight
@ UpThenRight
Definition: mythgesture.h:62
MythGestureEvent
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
MythGesture::HasMinimumPoints
bool HasMinimumPoints() const
Determine if the stroke has the minimum required points.
Definition: mythgesture.cpp:322
MythGestureEvent::RightThenLeft
@ RightThenLeft
Definition: mythgesture.h:69
MythGesture::m_maxSequence
size_t m_maxSequence
Definition: mythgesture.h:126
MythGestureEvent::RightThenUp
@ RightThenUp
Definition: mythgesture.h:67
MythGestureEvent::DownRight
@ DownRight
Definition: mythgesture.h:58
MythGestureEvent::LeftThenRight
@ LeftThenRight
Definition: mythgesture.h:70
MythGesture::m_lastButton
Qt::MouseButton m_lastButton
Definition: mythgesture.h:133
mythuiexp.h
MythGesture::m_lock
QMutex m_lock
Definition: mythgesture.h:131