Skip to content

Class DrawingCanvas

ClassList > DrawingCanvas

Inherits the following classes: QQuickPaintedItem

Public Properties

Type Name
property DrawingStroke currentStroke
property QColor frameColor
property bool isDirty
property bool isEmpty
property QPointF offset
property double zoomFactor

Public Signals

Type Name
signal void currentStrokeChanged
signal void frameColorChanged
signal void isDirtyChanged
signal void isEmptyChanged
signal void offsetChanged
signal void zoomFactorChanged

Public Functions

Type Name
DrawingCanvas (QQuickItem * parent=nullptr)
Q_INVOKABLE void clear ()
Q_INVOKABLE void createBlankCanvas (int width, int height, QColor backgroundColor=QColor(255, 255, 255))
Q_INVOKABLE void createCanvasFromImage (const QString & path)
DrawingStroke currentStroke () const
Q_INVOKABLE void fitCanvas ()
QColor frameColor () const
bool isDirty () const
bool isEmpty () const
QPointF offset () const
void paint (QPainter * painter) override
Q_INVOKABLE void pan (const QPointF & oldPosition, const QPointF & newPosition)
Q_INVOKABLE QString save () const
void setFrameColor (const QColor & color)
void setIsDirty (bool dirty)
void setIsEmpty (bool empty)
void setOffset (const QPointF & offset)
void setZoomFactor (double factor)
Q_INVOKABLE void strokeBegin (const QPointF & point, const QColor color=QColor(0, 0, 0))
Q_INVOKABLE void strokeEnd (const QPointF & point)
Q_INVOKABLE void strokeMove (const QPointF & point)
Q_INVOKABLE void undo ()
Q_INVOKABLE void zoom (double scale)
double zoomFactor () const
~DrawingCanvas () = default

Public Properties Documentation

property currentStroke [1/2]

DrawingStroke DrawingCanvas::currentStroke;

property frameColor [1/2]

QColor DrawingCanvas::frameColor;

This property holds the color of the canvas frame.


property isDirty [1/2]

bool DrawingCanvas::isDirty;

This property is set to TRUE when a created canvas has been modified.


property isEmpty [1/2]

bool DrawingCanvas::isEmpty;

This property is set to TRUE when no canvas has been created or a previously created canvas has been cleared.


property offset [1/2]

QPointF DrawingCanvas::offset;

This property holds the offset from the center of the canvas as a result of panning operations.


property zoomFactor [1/2]

double DrawingCanvas::zoomFactor;

This property holds the current zoom factor of the canvas. A value of 1.0 means the canvas is at native resolutio (i.e. one screen pixel represents one canvas pixel).


Public Signals Documentation

signal currentStrokeChanged

void DrawingCanvas::currentStrokeChanged;

signal frameColorChanged

void DrawingCanvas::frameColorChanged;

signal isDirtyChanged

void DrawingCanvas::isDirtyChanged;

signal isEmptyChanged

void DrawingCanvas::isEmptyChanged;

signal offsetChanged

void DrawingCanvas::offsetChanged;

signal zoomFactorChanged

void DrawingCanvas::zoomFactorChanged;

Public Functions Documentation

function DrawingCanvas

DrawingCanvas::DrawingCanvas (
    QQuickItem * parent=nullptr
) 

function clear

Q_INVOKABLE void DrawingCanvas::clear () 

Clears the drawing canvas.

See also: isEmpty()


function createBlankCanvas

Q_INVOKABLE void DrawingCanvas::createBlankCanvas (
    int width,
    int height,
    QColor backgroundColor=QColor(255, 255, 255)
) 

Creates a blank drawing canvas.

Parameters:

  • width the width of the canvas.
  • height the height of the canvas.
  • backgroundColor the background color of the canvas.

function createCanvasFromImage

Q_INVOKABLE void DrawingCanvas::createCanvasFromImage (
    const QString & path
) 

Creates a drawing canvas from a given image which will be the background on which the drawing will be overlayed.

Parameters:

  • path the image path.

function currentStroke [2/2]

DrawingStroke DrawingCanvas::currentStroke () const

function fitCanvas

Q_INVOKABLE void DrawingCanvas::fitCanvas () 

Fits the drawing canvas to match available width and height.


function frameColor [2/2]

QColor DrawingCanvas::frameColor () const

This property holds the color of the canvas frame.


function isDirty [2/2]

bool DrawingCanvas::isDirty () const

This property is set to TRUE when a created canvas has been modified.


function isEmpty [2/2]

bool DrawingCanvas::isEmpty () const

This property is set to TRUE when no canvas has been created or a previously created canvas has been cleared.


function offset [2/2]

QPointF DrawingCanvas::offset () const

This property holds the offset from the center of the canvas as a result of panning operations.


function paint

void DrawingCanvas::paint (
    QPainter * painter
) override

function pan

Q_INVOKABLE void DrawingCanvas::pan (
    const QPointF & oldPosition,
    const QPointF & newPosition
) 

Pans the drawing canvas by the distance between two points.


function save

Q_INVOKABLE QString DrawingCanvas::save () const

Saves the drawing canvas to a temporary location.

Returns:

the temporary file path of the saved image.


function setFrameColor

void DrawingCanvas::setFrameColor (
    const QColor & color
) 

This property holds the color of the canvas frame.


function setIsDirty

void DrawingCanvas::setIsDirty (
    bool dirty
) 

This property is set to TRUE when a created canvas has been modified.


function setIsEmpty

void DrawingCanvas::setIsEmpty (
    bool empty
) 

This property is set to TRUE when no canvas has been created or a previously created canvas has been cleared.


function setOffset

void DrawingCanvas::setOffset (
    const QPointF & offset
) 

This property holds the offset from the center of the canvas as a result of panning operations.


function setZoomFactor

void DrawingCanvas::setZoomFactor (
    double factor
) 

This property holds the current zoom factor of the canvas. A value of 1.0 means the canvas is at native resolutio (i.e. one screen pixel represents one canvas pixel).


function strokeBegin

Q_INVOKABLE void DrawingCanvas::strokeBegin (
    const QPointF & point,
    const QColor color=QColor(0, 0, 0)
) 

Begins a stroke operation.

Parameters:

  • point the first point of the stroke
  • color the color of the stroke

function strokeEnd

Q_INVOKABLE void DrawingCanvas::strokeEnd (
    const QPointF & point
) 

Ends the current stroke with a final point added to the stroke path.

Note:

The function strokeBegin must have been called prior to this function.


function strokeMove

Q_INVOKABLE void DrawingCanvas::strokeMove (
    const QPointF & point
) 

Adds a new point to the current stroke path.

Note:

The function strokeBegin must have been called prior to this function.


function undo

Q_INVOKABLE void DrawingCanvas::undo () 

Undos the last drawing operation.

See also: isDirty()


function zoom

Q_INVOKABLE void DrawingCanvas::zoom (
    double scale
) 

Zooms the drawing canvas by the provided scale value.


function zoomFactor [2/2]

double DrawingCanvas::zoomFactor () const

This property holds the current zoom factor of the canvas. A value of 1.0 means the canvas is at native resolutio (i.e. one screen pixel represents one canvas pixel).


function ~DrawingCanvas

DrawingCanvas::~DrawingCanvas () = default


The documentation for this class was generated from the following file src/core/drawingcanvas.h