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
39class MUI_PUBLIC MythGestureEvent : public QEvent
40{
41 Q_GADGET
42
43 public:
44 enum Gesture : std::uint8_t
45 {
47
48 /* Horizontal and vertical lines */
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 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 const 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();
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
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
void SetPosition(QPoint Position)
Definition: mythgesture.h:86
~MythGestureEvent() override=default
static const Type kEventType
Definition: mythgesture.h:91
Gesture GetGesture() const
Definition: mythgesture.h:85
QPoint GetPosition() const
Definition: mythgesture.h:87
Qt::MouseButton GetButton() const
Definition: mythgesture.h:88
Contains the points in a stroke, and translates them into gestures.
Definition: mythgesture.h:100
float m_binPercent
Definition: mythgesture.h:128
QMutex m_lock
Definition: mythgesture.h:131
bool Record(QPoint Point, Qt::MouseButton Button)
Record a point.
bool HasMinimumPoints() const
Determine if the stroke has the minimum required points.
MythGestureEvent * GetGesture() const
Complete the gesture event of the last completed stroke.
bool Recording()
Determine if the stroke is being recorded.
size_t m_maxSequence
Definition: mythgesture.h:126
MythGestureEvent::Gesture m_lastGesture
Definition: mythgesture.h:129
size_t m_maxPoints
Definition: mythgesture.h:124
void Start()
Start recording.
static const std::map< QString, MythGestureEvent::Gesture > kSequences
Definition: mythgesture.h:132
size_t m_minPoints
Definition: mythgesture.h:125
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.
Qt::MouseButton m_lastButton
Definition: mythgesture.h:133
int m_scaleRatio
Definition: mythgesture.h:127
void Stop(bool Timeout=false)
Stop recording.
void AdjustExtremes(int X, int Y)
Adjust horizontal and vertical extremes.
QList< QPoint > m_points
Definition: mythgesture.h:130
QString Translate(bool Timeout)
Translate the stroke into a sequence.
bool m_recording
Definition: mythgesture.h:119
#define MUI_PUBLIC
Definition: mythuiexp.h:9