ImageMaskEditor.h
Go to the documentation of this file.
1#pragma once
2
3#include <QColor>
4#include <QImage>
5#include <QPoint>
6#include <QWidget>
7
8class ImageMaskEditor : public QWidget
9{
10 Q_OBJECT
11
12public:
13 ImageMaskEditor(QSize size, QWidget* parent = nullptr);
14
15 ImageMaskEditor(int width = 64, int height = 64, QWidget* parent = nullptr);
16
17 bool openMaskImage(const QString& fileName);
18 bool openBackgroundImage(const QString& fileName);
19
20 bool saveMaskImage(const QString& fileName, const char* fileFormat);
21 bool saveBackgroundImage(const QString& fileName, const char* fileFormat);
22
23 const QColor& maskColor() const;
24 const QColor& transparentColor() const;
25 int penWidth() const;
26
27 const QImage& backgroundImage() const;
28 QImage maskImage() const;
29
30 QSize imageSize() const;
31
32 QSize sizeHint() const override;
33
34public slots:
35 void setMaskColor(const QColor& newColor);
36 void setMaskColor(int r, int g, int b);
37 void setMaskColor(qreal r, qreal g, qreal b);
38 void setTransparentColor(const QColor& newColor);
39 void setTransparentColor(int r, int g, int b);
40 void setTransparentColor(qreal r, qreal g, qreal b);
41 void clearMaskImage();
42 void setPenWidth(int newWidth);
43 void setMaskAlpha(int newAlpha);
44 void setImageSize(QSize size, bool doNotShrink = false);
45 void resizeImage(QSize size, bool doNotShrink = false);
46 void setMaskImage(const QImage& i);
47 void setBackgroundImage(const QImage& i);
48 void setPenCircleVisible(bool b = true);
49
50signals:
53 void arrowDrawn(const QPoint& arrowStart, const QPoint& arrowEnd);
54
55protected:
56 void mousePressEvent(QMouseEvent* event) override;
57 void mouseMoveEvent(QMouseEvent* event) override;
58 void mouseReleaseEvent(QMouseEvent* event) override;
59 void paintEvent(QPaintEvent* event) override;
60
61private:
62 void drawOnMask(const QPoint& endPoint);
63 void resizeImage(QImage* image, const QSize& newSize, const QColor& fillcolor);
64
65 bool _drawing{false};
66 bool _maskModified{false};
67 bool _drawPenCircle{false};
68
69 int _penWidth{1};
70 QColor _penColor{Qt::red};
71
72 QColor _maskTransparentColor{Qt::black};
73 QImage _maskImage;
74 int _maskAlpha{0};
75
76 QImage _backgroundImage;
77
78 QPoint _lastPoint;
79};
void maskUpdateFinished()
bool saveMaskImage(const QString &fileName, const char *fileFormat)
void setMaskAlpha(int newAlpha)
void setMaskColor(const QColor &newColor)
void arrowDrawn(const QPoint &arrowStart, const QPoint &arrowEnd)
const QColor & transparentColor() const
QSize imageSize() const
QSize sizeHint() const override
void mouseReleaseEvent(QMouseEvent *event) override
QImage maskImage() const
void mouseMoveEvent(QMouseEvent *event) override
void setBackgroundImage(const QImage &i)
void setImageSize(QSize size, bool doNotShrink=false)
void mousePressEvent(QMouseEvent *event) override
void setMaskImage(const QImage &i)
void setPenWidth(int newWidth)
void setPenCircleVisible(bool b=true)
void paintEvent(QPaintEvent *event) override
void resizeImage(QSize size, bool doNotShrink=false)
bool openMaskImage(const QString &fileName)
const QImage & backgroundImage() const
bool saveBackgroundImage(const QString &fileName, const char *fileFormat)
ImageMaskEditor(QSize size, QWidget *parent=nullptr)
void setTransparentColor(const QColor &newColor)
bool openBackgroundImage(const QString &fileName)
const QColor & maskColor() const