nsbaci 1.0
Loading...
Searching...
No Matches
drawingWidget.h
Go to the documentation of this file.
1
12
13#ifndef NSBACI_UI_DRAWINGWIDGET_H
14#define NSBACI_UI_DRAWINGWIDGET_H
15
16#include <QWidget>
17#include <QPainter>
18#include <QPixmap>
19#include <QColor>
20#include <QPoint>
21#include <vector>
22
23#include "drawingTypes.h"
24
29namespace nsbaci::ui {
30
39class DrawingWidget : public QWidget {
40 Q_OBJECT
41
42 public:
47 explicit DrawingWidget(QWidget* parent = nullptr);
48
52 ~DrawingWidget() override = default;
53
59
64 QSize minimumSizeHint() const override;
65
70 QSize sizeHint() const override;
71
72 public slots:
73 // ============== Drawing Command Slots ==============
74
79 void onDrawCommand(const nsbaci::types::DrawCommand& command);
80
85 void onDrawRequested(const nsbaci::types::Drawable& drawable);
86
91 void onClearRequested(const nsbaci::types::Color& color);
92
96 void onRefreshRequested();
97
103
104 // ============== Direct Drawing Slots ==============
105
109 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
110
114 void clear();
115
119 void drawCircle(int32_t centerX, int32_t centerY, int32_t radius,
120 bool filled = false);
121
125 void drawRectangle(int32_t x, int32_t y, int32_t width, int32_t height,
126 bool filled = false);
127
131 void drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
132 int32_t x3, int32_t y3, bool filled = false);
133
137 void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
138
142 void drawEllipse(int32_t centerX, int32_t centerY, int32_t radiusX,
143 int32_t radiusY, bool filled = false);
144
148 void drawPixel(int32_t x, int32_t y);
149
153 void drawText(int32_t x, int32_t y, const QString& text,
154 int32_t fontSize = 12);
155
159 void setLineWidth(int32_t width);
160
164 void reset();
165
166 protected:
171 void paintEvent(QPaintEvent* event) override;
172
177 void resizeEvent(QResizeEvent* event) override;
178
179 private:
185 void drawShapeInternal(const nsbaci::types::Shape& shape,
186 const nsbaci::types::Color& color);
187
191 static QColor toQColor(const nsbaci::types::Color& color);
192
196 void ensureCanvas();
197
198 QPixmap canvas_; // The drawing buffer
199 QColor currentColor_{Qt::black}; // Current drawing color
200 QColor backgroundColor_{Qt::white}; // Background color
201 int lineWidth_ = 1; // Current line width
202 nsbaci::types::Size canvasSize_{800, 600}; // Canvas dimensions
203};
204
205} // namespace nsbaci::ui
206
207#endif // NSBACI_UI_DRAWINGWIDGET_H
void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
Draw a line.
Definition drawingWidget.cpp:173
void drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, bool filled=false)
Draw a triangle.
Definition drawingWidget.cpp:151
void onClearRequested(const nsbaci::types::Color &color)
Clear the canvas with a specific color.
Definition drawingWidget.cpp:83
void onDrawRequested(const nsbaci::types::Drawable &drawable)
Handle a drawable object.
Definition drawingWidget.cpp:78
DrawingWidget(QWidget *parent=nullptr)
Constructs the drawing widget.
Definition drawingWidget.cpp:22
void drawEllipse(int32_t centerX, int32_t centerY, int32_t radiusX, int32_t radiusY, bool filled=false)
Draw an ellipse.
Definition drawingWidget.cpp:186
void drawPixel(int32_t x, int32_t y)
Draw a pixel.
Definition drawingWidget.cpp:207
void drawCircle(int32_t centerX, int32_t centerY, int32_t radius, bool filled=false)
Draw a circle.
Definition drawingWidget.cpp:111
void onRefreshRequested()
Refresh the canvas display.
Definition drawingWidget.cpp:88
~DrawingWidget() override=default
Destructor.
QSize minimumSizeHint() const override
Get the minimum size hint for the widget.
Definition drawingWidget.cpp:36
void paintEvent(QPaintEvent *event) override
Paint event handler.
Definition drawingWidget.cpp:243
void onDrawCommand(const nsbaci::types::DrawCommand &command)
Handle a drawing command.
Definition drawingWidget.cpp:46
void reset()
Reset the widget to initial state.
Definition drawingWidget.cpp:234
nsbaci::types::Size getCanvasSize() const
Get the current canvas size.
Definition drawingWidget.cpp:32
void setLineWidth(int32_t width)
Set the line width.
Definition drawingWidget.cpp:230
void drawText(int32_t x, int32_t y, const QString &text, int32_t fontSize=12)
Draw text.
Definition drawingWidget.cpp:215
void resizeEvent(QResizeEvent *event) override
Resize event handler.
Definition drawingWidget.cpp:251
void onCanvasSizeChanged(const nsbaci::types::Size &size)
Handle canvas size change.
Definition drawingWidget.cpp:92
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Set the current drawing color.
Definition drawingWidget.cpp:101
QSize sizeHint() const override
Get the size hint for the widget.
Definition drawingWidget.cpp:40
void clear()
Clear the canvas with the current background color.
Definition drawingWidget.cpp:105
void drawRectangle(int32_t x, int32_t y, int32_t width, int32_t height, bool filled=false)
Draw a rectangle.
Definition drawingWidget.cpp:131
Type definitions for drawing-related operations.
std::variant< Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText > Shape
Variant type for all drawable shapes.
Definition drawingTypes.h:203
User interface namespace for nsbaci.
Definition drawingWidget.cpp:18
RGB color representation with values from 0-255.
Definition drawingTypes.h:31
Represents a single drawing command to be executed.
Definition drawingTypes.h:240
Complete drawable object with shape, color, and visibility.
Definition drawingTypes.h:209
2D size representation.
Definition drawingTypes.h:93