-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvas.h
More file actions
118 lines (106 loc) · 3.78 KB
/
Copy pathcanvas.h
File metadata and controls
118 lines (106 loc) · 3.78 KB
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
#ifndef CANVAS_H
#define CANVAS_H
#include <QWidget>
#include "shape.h"
#include "shape_registry.h"
class Canvas : public QWidget {
Q_OBJECT
public:
explicit Canvas(ShapeRegistry* registry, QWidget* parent = nullptr);
const QVector<LayerData>& layers() const;
QString activeLayerId() const;
int selectedCount() const;
const Shape* primarySelectedShape() const;
ShapeStyle currentStyle() const;
QString currentToolId() const;
bool canUndo() const;
bool canRedo() const;
bool saveToFile(const QString& filePath, QString* errorMessage = nullptr) const;
bool loadFromFile(const QString& filePath, QStringList* skippedTypes = nullptr, QString* errorMessage = nullptr);
public slots:
void setSelectMode();
void setTool(const QString& typeId);
void setStrokeColor(const QColor& color);
void setFillColor(const QColor& color);
void setPenWidth(int width);
void setSelectionScale(qreal sx, qreal sy);
void setSelectionRotation(qreal degrees);
void rotateSelectionBy(qreal deltaDegrees);
void moveSelectionBy(int dx, int dy);
void deleteSelection();
void copySelection();
void clearAll();
void undo();
void redo();
void addLayer();
void removeActiveLayer();
void moveActiveLayerUp();
void moveActiveLayerDown();
void setActiveLayerById(const QString& layerId);
void moveSelectionToActiveLayer();
signals:
void documentStateChanged();
void selectionStateChanged();
void historyStateChanged(bool canUndo, bool canRedo);
void activeToolChanged(const QString& toolId);
protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
private:
enum class DragMode {
None,
DrawingDrag,
MovingSelection,
RubberBand
};
void initializeDocument();
void sanitizeDocument();
QString createLayerName();
LayerData* activeLayer();
const LayerData* activeLayer() const;
int activeLayerIndex() const;
Shape* findShapeById(const QString& id);
const Shape* findShapeById(const QString& id) const;
Shape* topShapeAt(const QPointF& scenePoint);
QVector<Shape*> selectedShapes();
QVector<const Shape*> selectedShapes() const;
QRectF selectionBounds() const;
void setSelection(const QSet<QString>& ids);
void selectOnly(const QString& id);
void clearSelection();
void pushUndoState(const DocumentState& before);
void emitHistorySignals();
void emitDocumentSignals();
void emitSelectionSignals();
void cancelDraft();
void finishPointDraft();
void moveSelectedByInternal(const QPointF& delta);
const IShapeDefinition* currentDefinition() const;
bool isSelectMode() const;
bool isPointTool() const;
bool isDragTool() const;
Shape createShape(const IShapeDefinition* definition, const ShapeSeed& seed) const;
QJsonObject serializeDocument() const;
bool deserializeDocument(const QJsonObject& object, QStringList* skippedTypes, QString* errorMessage);
ShapeRegistry* m_registry = nullptr;
DocumentState m_document;
QVector<DocumentState> m_undoStack;
QVector<DocumentState> m_redoStack;
QString m_currentToolId;
ShapeStyle m_currentStyle;
DragMode m_dragMode = DragMode::None;
QPointF m_dragStartScene;
QPointF m_lastScenePos;
QPointF m_previewScenePos;
QRectF m_rubberBandRect;
QVector<QPointF> m_draftPoints;
DocumentState m_pendingDocument;
bool m_hasPendingDocument = false;
bool m_interactionChanged = false;
int m_nextLayerNumber = 1;
};
#endif // CANVAS_H