QskGraphic

A paint device for scalable graphics. More…

#include <QskGraphic.h>

Inherits from QPaintDevice

Public Types

  Name
enum RenderHint { RenderPensUnscaled = 0x1}
enum CommandType { VectorData = 1 « 0, RasterData = 1 « 1, Transformation = 1 « 2}
typedef QFlags< RenderHint > RenderHints
typedef QFlags< CommandType > CommandTypes

Public Functions

  Name  
  QskGraphic()  
  QskGraphic(const QskGraphic & other)  
  QskGraphic(QskGraphic && other)  
  ~QskGraphic() override  
QskGraphic & operator=(const QskGraphic & other)  
QskGraphic & operator=(QskGraphic && other)  
bool operator==(const QskGraphic & other) const  
bool operator!=(const QskGraphic & other) const  
void reset()  
bool isNull() const  
bool isEmpty() const  
CommandTypes commandTypes() const  
void render(QPainter * painter) const  
void render(QPainter * painter, const QskColorFilter & colorFilter, QTransform * initialTransform =nullptr) const  
void render(QPainter * painter, const QSizeF & size, Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio) const  
void render(QPainter * painter, const QPointF & pos, Qt::Alignment alignment =Qt::AlignTop Qt::AlignLeft) const
void render(QPainter * painter, const QRectF & rect, Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio) const  
void render(QPainter * painter, const QRectF & rect, const QskColorFilter & colorFilter, Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio) const  
QPixmap toPixmap(qreal devicePixelRatio =0.0) const  
QPixmap toPixmap(const QSize & size, Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio, qreal devicePixelRatio =0.0) const  
QImage toImage(qreal devicePixelRatio =0.0) const  
QImage toImage(const QSize & size, Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio, qreal devicePixelRatio =0.0) const  
QRectF scaledBoundingRect(qreal sx, qreal sy) const  
QRectF boundingRect() const  
QRectF controlPointRect() const  
const QVector< QskPainterCommand > & commands() const  
void setCommands(const QVector< QskPainterCommand > & commands)  
void setDefaultSize(const QSizeF & size)  
QSizeF defaultSize() const  
qreal heightForWidth(qreal width) const  
qreal widthForHeight(qreal height) const  
void setRenderHint(RenderHint hint, bool on =true)  
bool testRenderHint(RenderHint hint) const  
RenderHints renderHints() const  
QPaintEngine * paintEngine() const override  
int metric(PaintDeviceMetric metric) const override  
quint64 modificationId() const  
uint hash(uint seed) const  
QskGraphic fromImage(const QImage & image)  
QskGraphic fromPixmap(const QPixmap & pixmap)  
QskGraphic fromPixmapAsImage(const QPixmap & pixmap)  

Protected Functions

  Name
virtual QSize sizeMetrics() const
virtual void drawPath(const QPainterPath & path)
virtual void drawPixmap(const QRectF & rect, const QPixmap & pixmap, const QRectF & subRect)
virtual void drawImage(const QRectF & rect, const QImage & image, const QRectF & subRect, Qt::ImageConversionFlags flags)
virtual void updateState(const QPaintEngineState & state)

Friends

  Name
class QskGraphicPaintEngine

Detailed Description

class QskGraphic;

A paint device for scalable graphics.

QskGraphic is the representation of a graphic that is tailored for scalability. Like QPicture it will be initialized by QPainter operations and can be replayed later to any target paint device. It can be stored and loaded from disk using the operators from QskGraphicIO. Together with QSvgRenderer it can be used to implement a simple SVG compiler.

QskGraphic maps all scalable drawing primitives to a QPainterPath and stores them together with the painter state changes ( pen, brush, transformation … ) in a list of QskPainterCommand. For being a complete QPaintDevice it also stores pixmaps or images, what is somehow against the idea of the class, because these objects can’t be scaled without a loss in quality.

The main issue about scaling a QskGraphic object are the pens used for drawing the outlines of the painter paths. While non cosmetic pens ( QPen::isCosmetic() ) are scaled with the same ratio as the path, cosmetic pens have a fixed width. A graphic might have paths with different pens - cosmetic and non-cosmetic.

QskGraphic caches 2 different rectangles:

The control point rectangle is the bounding rectangle of all control point rectangles of the painter paths, or the target rectangle of the pixmaps/images.

The bounding rectangle extends the control point rectangle by what is needed for rendering the outline with an unscaled pen. Because the offset for drawing the outline depends on the shape of the painter path ( the peak of a triangle is different than the flat side ) scaling with a fixed aspect ratio always needs to be calculated from the control point rectangle.

Public Types Documentation

enum RenderHint

Enumerator Value Description
RenderPensUnscaled 0x1  

enum CommandType

Enumerator Value Description
VectorData 1 « 0  
RasterData 1 « 1  
Transformation 1 « 2  

typedef RenderHints

typedef QFlags< RenderHint > QskGraphic::RenderHints;

typedef CommandTypes

typedef QFlags< CommandType > QskGraphic::CommandTypes;

Public Functions Documentation

function QskGraphic

QskGraphic()

function QskGraphic

QskGraphic(
    const QskGraphic & other
)

function QskGraphic

QskGraphic(
    QskGraphic && other
)

function ~QskGraphic

~QskGraphic() override

function operator=

QskGraphic & operator=(
    const QskGraphic & other
)

function operator=

QskGraphic & operator=(
    QskGraphic && other
)

function operator==

bool operator==(
    const QskGraphic & other
) const

function operator!=

inline bool operator!=(
    const QskGraphic & other
) const

function reset

void reset()

function isNull

bool isNull() const

function isEmpty

bool isEmpty() const

function commandTypes

CommandTypes commandTypes() const

function render

void render(
    QPainter * painter
) const

function render

void render(
    QPainter * painter,
    const QskColorFilter & colorFilter,
    QTransform * initialTransform =nullptr
) const

function render

void render(
    QPainter * painter,
    const QSizeF & size,
    Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio
) const

function render

void render(
    QPainter * painter,
    const QPointF & pos,
    Qt::Alignment alignment =Qt::AlignTop|Qt::AlignLeft
) const

function render

void render(
    QPainter * painter,
    const QRectF & rect,
    Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio
) const

function render

void render(
    QPainter * painter,
    const QRectF & rect,
    const QskColorFilter & colorFilter,
    Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio
) const

function toPixmap

QPixmap toPixmap(
    qreal devicePixelRatio =0.0
) const

function toPixmap

QPixmap toPixmap(
    const QSize & size,
    Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio,
    qreal devicePixelRatio =0.0
) const

function toImage

QImage toImage(
    qreal devicePixelRatio =0.0
) const

function toImage

QImage toImage(
    const QSize & size,
    Qt::AspectRatioMode aspectRatioMode =Qt::IgnoreAspectRatio,
    qreal devicePixelRatio =0.0
) const

function scaledBoundingRect

QRectF scaledBoundingRect(
    qreal sx,
    qreal sy
) const

function boundingRect

QRectF boundingRect() const

function controlPointRect

QRectF controlPointRect() const

function commands

const QVector< QskPainterCommand > & commands() const

function setCommands

void setCommands(
    const QVector< QskPainterCommand > & commands
)

function setDefaultSize

void setDefaultSize(
    const QSizeF & size
)

function defaultSize

QSizeF defaultSize() const

function heightForWidth

qreal heightForWidth(
    qreal width
) const

function widthForHeight

qreal widthForHeight(
    qreal height
) const

function setRenderHint

void setRenderHint(
    RenderHint hint,
    bool on =true
)

function testRenderHint

bool testRenderHint(
    RenderHint hint
) const

function renderHints

RenderHints renderHints() const

function paintEngine

QPaintEngine * paintEngine() const override

function metric

int metric(
    PaintDeviceMetric metric
) const override

function modificationId

quint64 modificationId() const

function hash

uint hash(
    uint seed
) const

function fromImage

static QskGraphic fromImage(
    const QImage & image
)

function fromPixmap

static QskGraphic fromPixmap(
    const QPixmap & pixmap
)

function fromPixmapAsImage

static QskGraphic fromPixmapAsImage(
    const QPixmap & pixmap
)

Protected Functions Documentation

function sizeMetrics

virtual QSize sizeMetrics() const

function drawPath

virtual void drawPath(
    const QPainterPath & path
)

function drawPixmap

virtual void drawPixmap(
    const QRectF & rect,
    const QPixmap & pixmap,
    const QRectF & subRect
)

function drawImage

virtual void drawImage(
    const QRectF & rect,
    const QImage & image,
    const QRectF & subRect,
    Qt::ImageConversionFlags flags
)

function updateState

virtual void updateState(
    const QPaintEngineState & state
)

Friends

friend QskGraphicPaintEngine

friend class QskGraphicPaintEngine(
    QskGraphicPaintEngine 
);

Updated on 28 July 2023 at 14:02:29 CEST