This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixelateeditor.h
154 lines (110 loc) · 3.58 KB
/
pixelateeditor.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef PIXELATEEDITOR_H
#define PIXELATEEDITOR_H
#include <QObject>
#include <QString>
#include <QStack>
#include <QImage>
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <QDeclarativeItem>
class PixelateEditor : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(int mode READ mode WRITE setMode)
Q_PROPERTY(int helperSize READ helperSize WRITE setHelperSize)
Q_PROPERTY(int pixDenom READ pixDenom WRITE setPixDenom)
Q_PROPERTY(bool changed READ changed)
Q_ENUMS(Mode)
Q_ENUMS(MouseState)
public:
explicit PixelateEditor(QDeclarativeItem *parent = 0);
virtual ~PixelateEditor();
int mode() const;
void setMode(const int &mode);
int helperSize() const;
void setHelperSize(const int &size);
int pixDenom() const;
void setPixDenom(const int &pix_denom);
bool changed() const;
Q_INVOKABLE void openImage(const QString &image_url);
Q_INVOKABLE void saveImage(const QString &image_url);
Q_INVOKABLE void undo();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*);
enum Mode {
ModeScroll,
ModeOriginal,
ModeEffected
};
enum MouseState {
MousePressed,
MouseMoved,
MouseReleased
};
public slots:
void effectedImageReady(const QImage &effected_image);
signals:
void imageOpened();
void imageOpenFailed();
void imageSaved();
void imageSaveFailed();
void undoAvailabilityChanged(bool available);
void mouseEvent(int event_type, int x, int y);
void helperImageReady(const QImage &helper_image);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
void SaveUndoImage();
void ChangeImageAt(bool save_undo, int center_x, int center_y);
static const int UNDO_DEPTH = 4,
BRUSH_SIZE = 16;
static const qreal IMAGE_MPIX_LIMIT = 1.0;
bool IsChanged;
int CurrentMode, HelperSize, PixelDenom;
QImage LoadedImage, OriginalImage, EffectedImage, CurrentImage;
QStack<QImage> UndoStack;
};
class PixelatePreviewGenerator : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(int pixDenom READ pixDenom WRITE setPixDenom)
public:
explicit PixelatePreviewGenerator(QDeclarativeItem *parent = 0);
virtual ~PixelatePreviewGenerator();
int pixDenom() const;
void setPixDenom(const int &pix_denom);
Q_INVOKABLE void openImage(const QString &image_url);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*);
public slots:
void pixelatedImageReady(const QImage &pixelated_image);
signals:
void imageOpened();
void imageOpenFailed();
void generationStarted();
void generationFinished();
private:
void StartPixelateGenerator();
static const qreal IMAGE_MPIX_LIMIT = 0.2;
bool PixelateGeneratorRunning, RestartPixelateGenerator;
int PixelDenom;
QImage LoadedImage, PixelatedImage;
};
class PixelateImageGenerator : public QObject
{
Q_OBJECT
public:
explicit PixelateImageGenerator(QObject *parent = 0);
virtual ~PixelateImageGenerator();
void setPixelDenom(const int &pix_denom);
void setInput(const QImage &input_image);
public slots:
void start();
signals:
void imageReady(const QImage &output_image);
void finished();
private:
int PixelDenom;
QImage InputImage;
};
#endif // PIXELATEEDITOR_H