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
/
sketcheditor.h
154 lines (110 loc) · 3.53 KB
/
sketcheditor.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 SKETCHEDITOR_H
#define SKETCHEDITOR_H
#include <QObject>
#include <QString>
#include <QStack>
#include <QImage>
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <QDeclarativeItem>
class SketchEditor : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(int mode READ mode WRITE setMode)
Q_PROPERTY(int helperSize READ helperSize WRITE setHelperSize)
Q_PROPERTY(int radius READ radius WRITE setRadius)
Q_PROPERTY(bool changed READ changed)
Q_ENUMS(Mode)
Q_ENUMS(MouseState)
public:
explicit SketchEditor(QDeclarativeItem *parent = 0);
virtual ~SketchEditor();
int mode() const;
void setMode(const int &mode);
int helperSize() const;
void setHelperSize(const int &size);
int radius() const;
void setRadius(const int &radius);
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, GaussianRadius;
QImage LoadedImage, OriginalImage, EffectedImage, CurrentImage;
QStack<QImage> UndoStack;
};
class SketchPreviewGenerator : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(int radius READ radius WRITE setRadius)
public:
explicit SketchPreviewGenerator(QDeclarativeItem *parent = 0);
virtual ~SketchPreviewGenerator();
int radius() const;
void setRadius(const int &radius);
Q_INVOKABLE void openImage(const QString &image_url);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*);
public slots:
void sketchImageReady(const QImage &sketch_image);
signals:
void imageOpened();
void imageOpenFailed();
void generationStarted();
void generationFinished();
private:
void StartSketchGenerator();
static const qreal IMAGE_MPIX_LIMIT = 0.2;
bool SketchGeneratorRunning, RestartSketchGenerator;
int GaussianRadius;
QImage LoadedImage, SketchImage;
};
class SketchImageGenerator : public QObject
{
Q_OBJECT
public:
explicit SketchImageGenerator(QObject *parent = 0);
virtual ~SketchImageGenerator();
void setGaussianRadius(const int &radius);
void setInput(const QImage &input_image);
public slots:
void start();
signals:
void imageReady(const QImage &output_image);
void finished();
private:
int GaussianRadius;
QImage InputImage;
};
#endif // SKETCHEDITOR_H