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 
8 class ImageMaskEditor : public QWidget
9 {
10  Q_OBJECT
11 
12 public:
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 
34 public 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 
50 signals:
51  void maskUpdated();
52  void maskUpdateFinished();
53  void arrowDrawn(const QPoint& arrowStart, const QPoint& arrowEnd);
54 
55 protected:
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 
61 private:
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 };
ImageMaskEditor::imageSize
QSize imageSize() const
Definition: ImageMaskEditor.cpp:108
ImageMaskEditor::ImageMaskEditor
ImageMaskEditor(QSize size, QWidget *parent=nullptr)
Definition: ImageMaskEditor.cpp:9
ImageMaskEditor::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event) override
Definition: ImageMaskEditor.cpp:237
ImageMaskEditor::backgroundImage
const QImage & backgroundImage() const
Definition: ImageMaskEditor.cpp:81
ImageMaskEditor::openMaskImage
bool openMaskImage(const QString &fileName)
Definition: ImageMaskEditor.cpp:20
ImageMaskEditor::maskColor
const QColor & maskColor() const
Definition: ImageMaskEditor.cpp:66
ImageMaskEditor::setPenWidth
void setPenWidth(int newWidth)
Definition: ImageMaskEditor.cpp:169
ImageMaskEditor::maskImage
QImage maskImage() const
Definition: ImageMaskEditor.cpp:86
ImageMaskEditor::setBackgroundImage
void setBackgroundImage(const QImage &i)
Definition: ImageMaskEditor.cpp:205
ImageMaskEditor::saveBackgroundImage
bool saveBackgroundImage(const QString &fileName, const char *fileFormat)
Definition: ImageMaskEditor.cpp:54
ImageMaskEditor::maskUpdateFinished
void maskUpdateFinished()
ImageMaskEditor::saveMaskImage
bool saveMaskImage(const QString &fileName, const char *fileFormat)
Definition: ImageMaskEditor.cpp:42
ImageMaskEditor::openBackgroundImage
bool openBackgroundImage(const QString &fileName)
Definition: ImageMaskEditor.cpp:31
ImageMaskEditor::setMaskImage
void setMaskImage(const QImage &i)
Definition: ImageMaskEditor.cpp:198
ImageMaskEditor::clearMaskImage
void clearMaskImage()
Definition: ImageMaskEditor.cpp:163
ImageMaskEditor::setImageSize
void setImageSize(QSize size, bool doNotShrink=false)
Definition: ImageMaskEditor.cpp:180
ImageMaskEditor::transparentColor
const QColor & transparentColor() const
Definition: ImageMaskEditor.cpp:71
ImageMaskEditor::maskUpdated
void maskUpdated()
ImageMaskEditor
Definition: ImageMaskEditor.h:8
ImageMaskEditor::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event) override
Definition: ImageMaskEditor.cpp:223
ImageMaskEditor::resizeImage
void resizeImage(QSize size, bool doNotShrink=false)
Definition: ImageMaskEditor.cpp:193
armarx::red
QColor red()
Definition: StyleSheets.h:76
ImageMaskEditor::setTransparentColor
void setTransparentColor(const QColor &newColor)
Definition: ImageMaskEditor.cpp:141
ImageMaskEditor::sizeHint
QSize sizeHint() const override
Definition: ImageMaskEditor.cpp:113
ImageMaskEditor::paintEvent
void paintEvent(QPaintEvent *event) override
Definition: ImageMaskEditor.cpp:246
ImageMaskEditor::setMaskColor
void setMaskColor(const QColor &newColor)
Definition: ImageMaskEditor.cpp:118
ImageMaskEditor::setPenCircleVisible
void setPenCircleVisible(bool b=true)
Definition: ImageMaskEditor.cpp:359
ImageMaskEditor::penWidth
int penWidth() const
Definition: ImageMaskEditor.cpp:76
ImageMaskEditor::setMaskAlpha
void setMaskAlpha(int newAlpha)
Definition: ImageMaskEditor.cpp:174
ImageMaskEditor::arrowDrawn
void arrowDrawn(const QPoint &arrowStart, const QPoint &arrowEnd)
ImageMaskEditor::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Definition: ImageMaskEditor.cpp:213