CCIMXDesktop
 
Loading...
Searching...
No Matches
SimpleDrawingScene.h
1#ifndef SIMPLEDRAWINGSCENE_H
2#define SIMPLEDRAWINGSCENE_H
3#include <QGraphicsScene>
4#include <QPainterPath>
5
13class SimpleDrawingScene : public QGraphicsScene {
14public:
19 enum class DrawingMode {
22 };
23
28 enum class SupportItemItem {
29 Line,
30 Rect,
31 Ellipse,
33 };
34
39 explicit SimpleDrawingScene(QObject* parent = nullptr);
40
41 // Property setters/getters
46 inline void setColor(const QColor& color) { currentColor = color; }
47
52 inline QColor getColor() const { return currentColor; }
53
58 inline void setPenWidth(const short penWidth) { this->penWidth = penWidth; }
59
64 inline short getPenWidth() const { return penWidth; }
65
70 inline void setItemType(const SupportItemItem i) { itemType = i; }
71
76 void setMode(const DrawingMode m);
77
82 QImage exportImage();
83
84public slots:
88 void undo();
89
93 void redo();
94
95protected:
99 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
100
104 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
105
109 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
110
111private:
117 QGraphicsItem* create_from_types(QPen& pen);
118
123 void process_drawing_moving(const QPointF& currentPos);
124
126 QPainterPath currentPath;
127
129 QGraphicsPathItem* pathItem = nullptr;
130
132 QColor currentColor;
133
135 short penWidth;
136
138 QGraphicsItem* tempItem { nullptr };
139
141 QPointF startPos {};
142
145
148
150 QList<QGraphicsItem*> itemsStack;
151
153 QList<QGraphicsItem*> redoStack;
154};
155
156#endif // SIMPLEDRAWINGSCENE_H
A QGraphicsScene subclass that provides simple drawing capabilities.
Definition SimpleDrawingScene.h:13
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse press events for drawing.
Definition SimpleDrawingScene.cpp:40
short getPenWidth() const
Gets the current pen width.
Definition SimpleDrawingScene.h:64
void setPenWidth(const short penWidth)
Sets the pen width for drawing.
Definition SimpleDrawingScene.h:58
void redo()
Redoes the last undone operation.
Definition SimpleDrawingScene.cpp:161
QImage exportImage()
Exports the current scene as an image.
Definition SimpleDrawingScene.cpp:30
void setColor(const QColor &color)
Sets the current drawing color.
Definition SimpleDrawingScene.h:46
void setMode(const DrawingMode m)
Sets the interaction mode.
Definition SimpleDrawingScene.cpp:14
DrawingMode
Defines the interaction modes for the scene.
Definition SimpleDrawingScene.h:19
@ DrawingMode
Default mode for creating new items.
@ EditMode
Mode for selecting and modifying existing items.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse release events for drawing.
Definition SimpleDrawingScene.cpp:76
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse move events for drawing.
Definition SimpleDrawingScene.cpp:62
QColor getColor() const
Gets the current drawing color.
Definition SimpleDrawingScene.h:52
void undo()
Undoes the last drawing operation.
Definition SimpleDrawingScene.cpp:153
void setItemType(const SupportItemItem i)
Sets the current drawing item type.
Definition SimpleDrawingScene.h:70
SupportItemItem
The types of drawable shapes supported by the scene.
Definition SimpleDrawingScene.h:28
@ FreeHand
Free-form drawing with mouse movement.
@ Ellipse
Ellipse or circle shape.
@ Line
Straight line between two points.