-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignPad.h
More file actions
69 lines (56 loc) · 2.12 KB
/
SignPad.h
File metadata and controls
69 lines (56 loc) · 2.12 KB
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
#ifndef SIGNPAD_H
#define SIGNPAD_H
#include <QColor>
#include <QImage>
#include <QQuickPaintedItem>
typedef QList<QPoint> QPointList;
class SignPad : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor NOTIFY penColorChanged)
Q_PROPERTY(int penWidth READ penWidth WRITE setPenWidth NOTIFY penWidthChanged)
Q_PROPERTY(bool showBaseLine READ showBaseLine WRITE setShowBaseLine NOTIFY showBaseLineChanged)
Q_PROPERTY(bool redrawOnPenChange READ redrawOnPenChange WRITE setRedrawOnPenChange NOTIFY redrawOnPenChangeChanged)
public:
explicit SignPad(QQuickItem *parent = nullptr);
QColor penColor() const;
int penWidth() const;
bool showBaseLine() const;
bool redrawOnPenChange() const;
public slots:
void clear(bool clearCached = true);
void redraw();
bool saveImage(const QString &fileName, bool addBackground = false, bool saveCutted = true);
void setPenColor(const QColor &penColor);
void setPenWidth(int penWidth);
void setShowBaseLine(bool showBaseLine);
void setRedrawOnPenChange(bool redrawOnPenChange);
signals:
void penColorChanged(const QColor &penColor);
void penWidthChanged(int penWidth);
void showBaseLineChanged(bool showBaseLine);
void redrawOnPenChangeChanged(bool redrawOnPenChange);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void paint(QPainter *painter) override;
private:
void drawLineTo(const QPoint &endPoint, bool appendPoint = true);
void resizeImage(QImage *image, const QSizeF &newSize);
void addPoint(const QPoint &point);
/*!
* \brief cuttedImage can be used to generate actual signature with no background or margins
*/
QImage cuttedImage() const;
bool m_isScribbling = false;
QImage m_image;
QPoint m_lastPoint;
QPointList m_points;
QList<QPointList> m_series;
QColor m_penColor = Qt::blue;
int m_penWidth = 2;
bool m_showBaseLine = false;
bool m_redrawOnPenChange = true;
};
#endif // SIGNPAD_H