nsbaci 1.0
Loading...
Searching...
No Matches
nsbaci::ui::DrawingWidget Class Reference

Qt widget that provides a drawing canvas. More...

#include <drawingWidget.h>

Inheritance diagram for nsbaci::ui::DrawingWidget:
Collaboration diagram for nsbaci::ui::DrawingWidget:

Public Slots

void onDrawCommand (const nsbaci::types::DrawCommand &command)
 Handle a drawing command.
void onDrawRequested (const nsbaci::types::Drawable &drawable)
 Handle a drawable object.
void onClearRequested (const nsbaci::types::Color &color)
 Clear the canvas with a specific color.
void onRefreshRequested ()
 Refresh the canvas display.
void onCanvasSizeChanged (const nsbaci::types::Size &size)
 Handle canvas size change.
void setColor (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the current drawing color.
void clear ()
 Clear the canvas with the current background color.
void drawCircle (int32_t centerX, int32_t centerY, int32_t radius, bool filled=false)
 Draw a circle.
void drawRectangle (int32_t x, int32_t y, int32_t width, int32_t height, bool filled=false)
 Draw a rectangle.
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.
void drawLine (int32_t x1, int32_t y1, int32_t x2, int32_t y2)
 Draw a line.
void drawEllipse (int32_t centerX, int32_t centerY, int32_t radiusX, int32_t radiusY, bool filled=false)
 Draw an ellipse.
void drawPixel (int32_t x, int32_t y)
 Draw a pixel.
void drawText (int32_t x, int32_t y, const QString &text, int32_t fontSize=12)
 Draw text.
void setLineWidth (int32_t width)
 Set the line width.
void reset ()
 Reset the widget to initial state.

Public Member Functions

 DrawingWidget (QWidget *parent=nullptr)
 Constructs the drawing widget.
 ~DrawingWidget () override=default
 Destructor.
nsbaci::types::Size getCanvasSize () const
 Get the current canvas size.
QSize minimumSizeHint () const override
 Get the minimum size hint for the widget.
QSize sizeHint () const override
 Get the size hint for the widget.

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 Paint event handler.
void resizeEvent (QResizeEvent *event) override
 Resize event handler.

Detailed Description

Qt widget that provides a drawing canvas.

The DrawingWidget maintains a pixel buffer (QPixmap) where all drawing operations are performed. It supports various shapes, colors, and provides a persistent canvas that preserves drawings between repaints.

Constructor & Destructor Documentation

◆ DrawingWidget()

nsbaci::ui::DrawingWidget::DrawingWidget ( QWidget * parent = nullptr)
explicit

Constructs the drawing widget.

Parameters
parentOptional parent widget.
Here is the call graph for this function:

Member Function Documentation

◆ getCanvasSize()

nsbaci::types::Size nsbaci::ui::DrawingWidget::getCanvasSize ( ) const

Get the current canvas size.

Returns
The canvas size.

◆ minimumSizeHint()

QSize nsbaci::ui::DrawingWidget::minimumSizeHint ( ) const
override

Get the minimum size hint for the widget.

Returns
The minimum size.

◆ onCanvasSizeChanged

void nsbaci::ui::DrawingWidget::onCanvasSizeChanged ( const nsbaci::types::Size & size)
slot

Handle canvas size change.

Parameters
sizeThe new canvas size.
Here is the call graph for this function:

◆ onClearRequested

void nsbaci::ui::DrawingWidget::onClearRequested ( const nsbaci::types::Color & color)
slot

Clear the canvas with a specific color.

Parameters
colorThe background color.
Here is the call graph for this function:

◆ onDrawCommand

void nsbaci::ui::DrawingWidget::onDrawCommand ( const nsbaci::types::DrawCommand & command)
slot

Handle a drawing command.

Parameters
commandThe command to execute.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onDrawRequested

void nsbaci::ui::DrawingWidget::onDrawRequested ( const nsbaci::types::Drawable & drawable)
slot

Handle a drawable object.

Parameters
drawableThe drawable to render.

◆ paintEvent()

void nsbaci::ui::DrawingWidget::paintEvent ( QPaintEvent * event)
overrideprotected

Paint event handler.

Parameters
eventThe paint event.

◆ resizeEvent()

void nsbaci::ui::DrawingWidget::resizeEvent ( QResizeEvent * event)
overrideprotected

Resize event handler.

Parameters
eventThe resize event.

◆ sizeHint()

QSize nsbaci::ui::DrawingWidget::sizeHint ( ) const
override

Get the size hint for the widget.

Returns
The preferred size.

The documentation for this class was generated from the following files: