From 31b6eb581be7c57eeb8482d35fe1983c175259bd Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sun, 31 Mar 2024 09:27:41 +0700 Subject: [PATCH] Add classes documentation --- src/core/drawingcanvas.h | 83 +++++++++++++++++++++++++++++++++ src/core/drawingtemplatemodel.h | 14 ++++++ 2 files changed, 97 insertions(+) diff --git a/src/core/drawingcanvas.h b/src/core/drawingcanvas.h index a25b866e1b..e55c4e5762 100644 --- a/src/core/drawingcanvas.h +++ b/src/core/drawingcanvas.h @@ -25,10 +25,32 @@ class DrawingCanvas : public QQuickPaintedItem { Q_OBJECT + /** + * This property is set to TRUE when no canvas has been created or a previously + * created canvas has been cleared. + */ Q_PROPERTY( bool isEmpty READ isEmpty NOTIFY isEmptyChanged ) + + /** + * This property is set to TRUE when a created canvas has been modified. + */ Q_PROPERTY( bool isDirty READ isDirty NOTIFY isDirtyChanged ) + + /** + * This property holds the color of the canvas frame. + */ Q_PROPERTY( QColor frameColor READ frameColor WRITE setFrameColor NOTIFY frameColorChanged ) + + /** + * 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). + */ Q_PROPERTY( double zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged ) + + /** + * This property holds the offset from the center of the canvas as a result of + * panning operations. + */ Q_PROPERTY( QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged ) public: @@ -37,34 +59,95 @@ class DrawingCanvas : public QQuickPaintedItem void paint( QPainter *painter ) override; + //! \copydoc DrawingCanvas::isEmpty bool isEmpty() const; + + //! \copydoc DrawingCanvas::isEmpty void setIsEmpty( bool empty ); + //! \copydoc DrawingCanvas::isDirty bool isDirty() const; + + //! \copydoc DrawingCanvas::isDirty void setIsDirty( bool dirty ); + //! \copydoc DrawingCanvas::frameColor QColor frameColor() const; + + //! \copydoc DrawingCanvas::frameColor void setFrameColor( const QColor &color ); + //! \copydoc DrawingCanvas::zoomFactor double zoomFactor() const; + + //! \copydoc DrawingCanvas::zoomFactor void setZoomFactor( double factor ); + //! \copydoc DrawingCanvas::offset QPointF offset() const; + + //! \copydoc DrawingCanvas::offset void setOffset( const QPointF &offset ); + /** + * Creates a blank drawing canvas. + * \param width the width of the canvas. + * \param height the height of the canvas. + * \param backgroundColor the background color of the canvas. + */ Q_INVOKABLE void createBlankCanvas( int width, int height, QColor backgroundColor = QColor( 255, 255, 255 ) ); + + /** + * Creates a drawing canvas from a given image which will be the background on which + * the drawing will be overlayed. + * \param path the image path. + */ Q_INVOKABLE void createCanvasFromImage( const QString &path ); + + /** + * Clears the drawing canvas. + * \see isEmpty() + */ Q_INVOKABLE void clear(); + /** + * Saves the drawing canvas to a temporary location. + * \returns the temporary file path of the saved image. + */ Q_INVOKABLE QString save() const; + /** + * Fits the drawing canvas to match available width and height. + */ Q_INVOKABLE void fitCanvas(); + /** + * Pans the drawing canvas by the distance between two points. + */ Q_INVOKABLE void pan( const QPointF &oldPosition, const QPointF &newPosition ); + + /** + * Zooms the drawing canvas by the provided \a scale value. + */ Q_INVOKABLE void zoom( double scale ); + /** + * Begins a stroke operation. + * \param point the first point of the stroke + * \param color the color of the stroke + */ Q_INVOKABLE void strokeBegin( const QPointF &point, const QColor color = QColor( 0, 0, 0 ) ); + + /** + * Adds a new \a point to the current stroke path. + * \note The function strokeBegin must have been called prior to this function. + */ Q_INVOKABLE void strokeMove( const QPointF &point ); + + /** + * Ends the current stroke with a final \a point added to the stroke path. + * \note The function strokeBegin must have been called prior to this function. + */ Q_INVOKABLE void strokeEnd( const QPointF &point ); signals: diff --git a/src/core/drawingtemplatemodel.h b/src/core/drawingtemplatemodel.h index 86b60061bb..3a0c071cf5 100644 --- a/src/core/drawingtemplatemodel.h +++ b/src/core/drawingtemplatemodel.h @@ -22,7 +22,14 @@ class DrawingTemplateModel : public QAbstractListModel { Q_OBJECT + /** + * This property holds the project file path where project templates will be looked for. + */ Q_PROPERTY( QString projectFilePath READ projectFilePath WRITE setProjectFilePath NOTIFY projectFilePathChanged ) + + /** + * This property holds whether the model contains project templates. + */ Q_PROPERTY( bool hasProjectTemplate READ hasProjectTemplate NOTIFY hasProjectTemplateChanged ) public: @@ -42,9 +49,13 @@ class DrawingTemplateModel : public QAbstractListModel explicit DrawingTemplateModel( QObject *parent = nullptr ); + //! \copydoc DrawingTemplateModel::projectFilePath QString projectFilePath() const; + + //! \copydoc DrawingTemplateModel::projectFilePath void setProjectFilePath( const QString &path ); + //! \copydoc DrawingTemplateModel::hasProjectTemplate bool hasProjectTemplate() const; QHash roleNames() const override; @@ -52,6 +63,9 @@ class DrawingTemplateModel : public QAbstractListModel int rowCount( const QModelIndex &parent ) const override; QVariant data( const QModelIndex &index, int role ) const override; + /** + * Reloads the drawing template model. + */ Q_INVOKABLE void reloadModel(); signals: