-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScribbleArea.h
130 lines (92 loc) · 3.22 KB
/
ScribbleArea.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef _SCRIBBLE_AREA_H_
#define _SCRIBBLE_AREA_H_
#include <QList>
#include <QColor>
#include <QPoint>
#include <QQueue>
#include <QPixmap>
#include <QTouchEvent>
#include <QMediaPlayer>
#include <QQuickPaintedItem>
class QMouseEvent;
class QTouchEvent;
class QMediaPlayer;
class ScribbleArea : public QQuickPaintedItem
{
Q_OBJECT
public:
ScribbleArea(QQuickItem* parent = nullptr);
// QWidget interface
protected:
inline QPoint tr(const QPoint& p) const { return p + QPoint(m_offsetX, 0); }
inline QPoint tr(const QPointF& p) const { return p.toPoint() + QPoint(m_offsetX, 0); }
inline QRect tr(const QRect& r) const { return r.adjusted(m_offsetX, 0, m_offsetX, 0); }
// bool event(QEvent* event);
void touchEvent(QTouchEvent* event);
#if not defined(Q_OS_IOS)
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
#endif
// void paintEvent(QPaintEvent* event);
void paint(QPainter* painter);
// void resizeEvent(QResizeEvent* event);
void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
void drawLineTo(const QPoint& startPoint, const QPoint& endPoint);
void drawPattern(const QPoint& point);
void resizeImage(QPixmap& image, const QSize& newSize);
void changePen(const QColor& c, double size, qreal opacity);
void animatePen();
void reset();
protected slots:
void onFrame();
void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
public slots:
void restart();
void stop();
void clear();
protected:
QTimer* m_timer;
double m_penWidth;
QColor m_penColor;
double m_penOpacity;
QPixmap m_penPattern;
int m_speed;
int m_frameID;
bool m_paused;
int m_offsetX;
QList<QPoint> m_touchPoints;
QPixmap m_image;
QMediaPlayer * m_player;
struct Gradient{
int m_tStart;
QColor m_cStart;
double m_wStart;
int m_pStart;
int m_tEnd;
QColor m_cEnd;
double m_wEnd;
int m_pEnd;
Gradient()
: m_tStart(0), m_cStart(Qt::white), m_wStart(0), m_pStart(0)
, m_tEnd(0), m_cEnd(Qt::white), m_wEnd(0), m_pEnd(0)
{
return;
}
Gradient(int tStart, const QColor& cStart, double wStart, int pStart
, int tEnd, const QColor& cEnd, double wEnd, int pEnd)
: m_tStart(tStart), m_cStart(cStart), m_wStart(wStart), m_pStart(pStart)
, m_tEnd(tEnd), m_cEnd(cEnd), m_wEnd(wEnd), m_pEnd(pEnd)
{
return;
}
};
QQueue<Gradient> m_gradients;
public:
Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
bool isPaused() const { return m_paused; }
void setPaused(bool paused) { m_paused = paused; }
signals:
void pausedChanged();
};
#endif // _SCRIBBLE_AREA_H_