-
Notifications
You must be signed in to change notification settings - Fork 0
/
pietgraphicsscene.h
79 lines (58 loc) · 1.79 KB
/
pietgraphicsscene.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
#ifndef PIETGRAPHICSSCENE_H
#define PIETGRAPHICSSCENE_H
#include <QGraphicsScene>
#include <QVector>
#include <QImage>
enum class EditMode {PAINT, FILL, SELECT};
class PietGraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit PietGraphicsScene(QObject *parent = nullptr);
QImage getImage(int codelSize = 1) const;
void addRow();
void addColumn();
void removeRow();
void removeColumn();
void removeColumns(int amount);
void removeRows(int amount);
void loadFromImage(QImage img);
void setSize(int newRowsAmount, int newColsAmount);
void setRowsAmount(int newRowsAmount);
void setColsAmount(int newColsAmount);
void setEditMode(EditMode newEditMode);
void setSquareSize(int newSquareSize);
int getRowsAmount() const;
int getColsAmount() const;
public slots:
void pickColor(QColor color);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
private:
void selectSquare(int row, int col);
void addGridItems();
void addGridRow(int row);
void addGridCol(int col);
void resetGrid();
void resetChecks();
void fillSquare(int row, int col, const QColor &color);
QGraphicsRectItem *getRect(int row, int col);
QVector <QGraphicsRectItem*> getRectRow(int row);
QColor getRectColor(int row, int col) const;
bool isRectSelected(int row, int col);
bool isRowValid(int row) const;
bool isColValid(int col) const;
private:
EditMode editMode;
int rowsAmount;
int colsAmount;
int squareSize;
QColor pickedColor;
QColor baseColor;
QColor selectColor;
QColor lineColor;
QVector <QVector <QGraphicsRectItem *>> grid;
QVector <QVector <bool>> checks;
};
#endif // PIETGRAPHICSSCENE_H