QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraphic Class Reference

#include <QskGraphic.h>

Detailed Description

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:

  • control point rectangle
    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.
  • bounding rectangle
    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.

Definition at line 27 of file QskGraphic.h.

Inheritance diagram for QskGraphic:

Public Types

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

Properties

qreal aspectRatio
 
QRectF viewBox
 
QRectF boundingRect
 
QRectF controlPointRect
 
QSizeF defaultSize
 
quint64 modificationId
 

Public Member Functions

 QskGraphic (const QskGraphic &)
 
 QskGraphic (QskGraphic &&)
 
QskGraphicoperator= (const QskGraphic &)
 
QskGraphicoperator= (QskGraphic &&)
 
bool operator== (const QskGraphic &) const
 
bool operator!= (const QskGraphic &) const
 
void reset ()
 
bool isNull () const
 
bool isEmpty () const
 
CommandTypes commandTypes () const
 
void render (QPainter *) const
 
void render (QPainter *, const QskColorFilter &, QTransform *initialTransform=nullptr) const
 
void render (QPainter *, const QSizeF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const
 
void render (QPainter *, const QPointF &, Qt::Alignment=Qt::AlignTop|Qt::AlignLeft) const
 
void render (QPainter *, const QRectF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const
 
void render (QPainter *, const QRectF &, const QskColorFilter &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const
 
QPixmap toPixmap (qreal devicePixelRatio=0.0) const
 
QPixmap toPixmap (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) const
 
QImage toImage (qreal devicePixelRatio=0.0) const
 
QImage toImage (const QSize &, Qt::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 > &)
 
QSizeF defaultSize () const
 
void setViewBox (const QRectF &)
 
QRectF viewBox () const
 
qreal aspectRatio () const
 
qreal heightForWidth (qreal width) const
 
qreal widthForHeight (qreal height) const
 
void setRenderHint (RenderHint, bool on=true)
 
bool testRenderHint (RenderHint) const
 
RenderHints renderHints () const
 
QPaintEngine * paintEngine () const override
 
int metric (PaintDeviceMetric metric) const override
 
quint64 modificationId () const
 
QskHashValue hash (QskHashValue seed) const
 

Static Public Member Functions

static QskGraphic fromImage (const QImage &)
 
static QskGraphic fromPixmap (const QPixmap &)
 
static QskGraphic fromPixmapAsImage (const QPixmap &)
 
static QskGraphic fromGraphic (const QskGraphic &, const QskColorFilter &)
 

Protected Member Functions

virtual QSize sizeMetrics () const
 
virtual void drawPath (const QPainterPath &)
 
virtual void drawPixmap (const QRectF &, const QPixmap &, const QRectF &)
 
virtual void drawImage (const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
 
virtual void updateState (const QPaintEngineState &state)
 

Member Typedef Documentation

◆ CommandTypes

typedef QFlags< CommandType > QskGraphic::CommandTypes

Definition at line 55 of file QskGraphic.h.

◆ RenderHints

typedef QFlags< RenderHint > QskGraphic::RenderHints

Definition at line 46 of file QskGraphic.h.

Member Enumeration Documentation

◆ CommandType

enum QskGraphic::CommandType

Definition at line 48 of file QskGraphic.h.

◆ RenderHint

enum QskGraphic::RenderHint

Definition at line 41 of file QskGraphic.h.

Constructor & Destructor Documentation

◆ QskGraphic() [1/3]

QskGraphic::QskGraphic ( )

Definition at line 392 of file QskGraphic.cpp.

◆ QskGraphic() [2/3]

QskGraphic::QskGraphic ( const QskGraphic other)

Definition at line 398 of file QskGraphic.cpp.

◆ QskGraphic() [3/3]

QskGraphic::QskGraphic ( QskGraphic &&  other)

Definition at line 405 of file QskGraphic.cpp.

◆ ~QskGraphic()

QskGraphic::~QskGraphic ( )
override

Definition at line 411 of file QskGraphic.cpp.

Member Function Documentation

◆ aspectRatio()

qreal QskGraphic::aspectRatio ( ) const

Definition at line 633 of file QskGraphic.cpp.

◆ boundingRect()

QRectF QskGraphic::boundingRect ( ) const

Definition at line 557 of file QskGraphic.cpp.

◆ commands()

const QVector< QskPainterCommand > & QskGraphic::commands ( ) const

Definition at line 1012 of file QskGraphic.cpp.

◆ commandTypes()

QskGraphic::CommandTypes QskGraphic::commandTypes ( ) const

Definition at line 534 of file QskGraphic.cpp.

◆ controlPointRect()

QRectF QskGraphic::controlPointRect ( ) const

Definition at line 565 of file QskGraphic.cpp.

◆ defaultSize()

QSizeF QskGraphic::defaultSize ( ) const

Definition at line 607 of file QskGraphic.cpp.

◆ drawImage()

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

Definition at line 948 of file QskGraphic.cpp.

◆ drawPath()

void QskGraphic::drawPath ( const QPainterPath &  path)
protectedvirtual

Definition at line 903 of file QskGraphic.cpp.

◆ drawPixmap()

void QskGraphic::drawPixmap ( const QRectF &  rect,
const QPixmap &  pixmap,
const QRectF &  subRect 
)
protectedvirtual

Definition at line 933 of file QskGraphic.cpp.

◆ fromGraphic()

QskGraphic QskGraphic::fromGraphic ( const QskGraphic graphic,
const QskColorFilter colorFilter 
)
static

Definition at line 1102 of file QskGraphic.cpp.

◆ fromImage()

QskGraphic QskGraphic::fromImage ( const QImage &  image)
static

Definition at line 1057 of file QskGraphic.cpp.

◆ fromPixmap()

QskGraphic QskGraphic::fromPixmap ( const QPixmap &  pixmap)
static

Definition at line 1071 of file QskGraphic.cpp.

◆ fromPixmapAsImage()

QskGraphic QskGraphic::fromPixmapAsImage ( const QPixmap &  pixmap)
static

Definition at line 1085 of file QskGraphic.cpp.

◆ hash()

QskHashValue QskGraphic::hash ( QskHashValue  seed) const

Definition at line 1049 of file QskGraphic.cpp.

◆ heightForWidth()

qreal QskGraphic::heightForWidth ( qreal  width) const

Definition at line 615 of file QskGraphic.cpp.

◆ isEmpty()

bool QskGraphic::isEmpty ( ) const

Definition at line 529 of file QskGraphic.cpp.

◆ isNull()

bool QskGraphic::isNull ( ) const

Definition at line 524 of file QskGraphic.cpp.

◆ metric()

int QskGraphic::metric ( PaintDeviceMetric  metric) const
override

Definition at line 445 of file QskGraphic.cpp.

◆ modificationId()

quint64 QskGraphic::modificationId ( ) const

Definition at line 1044 of file QskGraphic.cpp.

◆ operator!=()

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

Definition at line 162 of file QskGraphic.h.

◆ operator=() [1/2]

QskGraphic & QskGraphic::operator= ( const QskGraphic other)

Definition at line 416 of file QskGraphic.cpp.

◆ operator=() [2/2]

QskGraphic & QskGraphic::operator= ( QskGraphic &&  other)

Definition at line 425 of file QskGraphic.cpp.

◆ operator==()

bool QskGraphic::operator== ( const QskGraphic other) const

Definition at line 432 of file QskGraphic.cpp.

◆ paintEngine()

QPaintEngine * QskGraphic::paintEngine ( ) const
override

Definition at line 437 of file QskGraphic.cpp.

◆ render() [1/6]

void QskGraphic::render ( QPainter *  painter) const

Definition at line 642 of file QskGraphic.cpp.

◆ render() [2/6]

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

Definition at line 773 of file QskGraphic.cpp.

◆ render() [3/6]

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

Definition at line 683 of file QskGraphic.cpp.

◆ render() [4/6]

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

Definition at line 677 of file QskGraphic.cpp.

◆ render() [5/6]

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

Definition at line 670 of file QskGraphic.cpp.

◆ render() [6/6]

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

Definition at line 647 of file QskGraphic.cpp.

◆ renderHints()

QskGraphic::RenderHints QskGraphic::renderHints ( ) const

Definition at line 552 of file QskGraphic.cpp.

◆ reset()

void QskGraphic::reset ( )

Definition at line 514 of file QskGraphic.cpp.

◆ scaledBoundingRect()

QRectF QskGraphic::scaledBoundingRect ( qreal  sx,
qreal  sy 
) const

Definition at line 573 of file QskGraphic.cpp.

◆ setCommands()

void QskGraphic::setCommands ( const QVector< QskPainterCommand > &  commands)

Definition at line 1017 of file QskGraphic.cpp.

◆ setRenderHint()

void QskGraphic::setRenderHint ( RenderHint  hint,
bool  on = true 
)

Definition at line 539 of file QskGraphic.cpp.

◆ setViewBox()

void QskGraphic::setViewBox ( const QRectF &  rect)

Definition at line 597 of file QskGraphic.cpp.

◆ sizeMetrics()

QSize QskGraphic::sizeMetrics ( ) const
protectedvirtual

Definition at line 591 of file QskGraphic.cpp.

◆ testRenderHint()

bool QskGraphic::testRenderHint ( RenderHint  hint) const

Definition at line 547 of file QskGraphic.cpp.

◆ toImage() [1/2]

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

Definition at line 855 of file QskGraphic.cpp.

◆ toImage() [2/2]

QImage QskGraphic::toImage ( qreal  devicePixelRatio = 0.0) const

Definition at line 877 of file QskGraphic.cpp.

◆ toPixmap() [1/2]

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

Definition at line 833 of file QskGraphic.cpp.

◆ toPixmap() [2/2]

QPixmap QskGraphic::toPixmap ( qreal  devicePixelRatio = 0.0) const

Definition at line 807 of file QskGraphic.cpp.

◆ updateState()

void QskGraphic::updateState ( const QPaintEngineState &  state)
protectedvirtual

Definition at line 964 of file QskGraphic.cpp.

◆ viewBox()

QRectF QskGraphic::viewBox ( ) const

Definition at line 602 of file QskGraphic.cpp.

◆ widthForHeight()

qreal QskGraphic::widthForHeight ( qreal  height) const

Definition at line 624 of file QskGraphic.cpp.

Property Documentation

◆ aspectRatio

qreal QskGraphic::aspectRatio
read

Definition at line 31 of file QskGraphic.h.

◆ boundingRect

QRectF QskGraphic::boundingRect
read

Definition at line 33 of file QskGraphic.h.

◆ controlPointRect

QRectF QskGraphic::controlPointRect
read

Definition at line 34 of file QskGraphic.h.

◆ defaultSize

QSizeF QskGraphic::defaultSize
read

Definition at line 35 of file QskGraphic.h.

◆ modificationId

quint64 QskGraphic::modificationId
read

Definition at line 36 of file QskGraphic.h.

◆ viewBox

QRectF QskGraphic::viewBox
readwrite

Definition at line 32 of file QskGraphic.h.