qskinny/src/graphic/QskGraphic.h

160 lines
4.2 KiB
C
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_GRAPHIC_H
#define QSK_GRAPHIC_H
#include "QskGlobal.h"
2018-07-19 12:10:48 +00:00
#include <qmetatype.h>
#include <qflags.h>
2018-08-03 06:15:28 +00:00
#include <qpaintdevice.h>
2018-07-19 12:10:48 +00:00
#include <qshareddata.h>
2017-07-21 16:21:34 +00:00
class QskPainterCommand;
class QskColorFilter;
2018-07-19 12:10:48 +00:00
class QskGraphicPaintEngine;
2017-07-21 16:21:34 +00:00
class QImage;
class QPixmap;
class QPainterPath;
2018-07-19 12:10:48 +00:00
class QPaintEngine;
class QPaintEngineState;
class QTransform;
2019-12-30 19:06:46 +00:00
class QDebug;
2017-07-21 16:21:34 +00:00
class QSK_EXPORT QskGraphic : public QPaintDevice
{
2018-08-03 06:15:28 +00:00
public:
2017-07-21 16:21:34 +00:00
enum RenderHint
{
RenderPensUnscaled = 0x1
};
typedef QFlags< RenderHint > RenderHints;
2019-12-04 17:33:30 +00:00
enum CommandType
{
VectorData = 1 << 0,
RasterData = 1 << 1,
Transformation = 1 << 2
};
typedef QFlags< CommandType > CommandTypes;
2017-07-21 16:21:34 +00:00
QskGraphic();
QskGraphic( const QskGraphic& );
QskGraphic( QskGraphic&& );
2018-07-31 15:32:25 +00:00
~QskGraphic() override;
2017-07-21 16:21:34 +00:00
QskGraphic& operator=( const QskGraphic& );
QskGraphic& operator=( QskGraphic&& );
bool operator==( const QskGraphic& ) const;
bool operator!=( const QskGraphic& ) const;
void reset();
bool isNull() const;
bool isEmpty() const;
2019-12-04 17:33:30 +00:00
CommandTypes commandTypes() const;
2017-07-21 16:21:34 +00:00
void render( QPainter* ) const;
void render( QPainter*, const QskColorFilter&,
2017-07-21 16:21:34 +00:00
QTransform* initialTransform = nullptr ) const;
void render( QPainter*, const QSizeF&,
2018-08-03 06:15:28 +00:00
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
2017-07-21 16:21:34 +00:00
void render( QPainter*, const QPointF&,
Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const;
void render( QPainter*, const QRectF&,
2018-08-03 06:15:28 +00:00
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
void render( QPainter*, const QRectF&, const QskColorFilter&,
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
2017-07-21 16:21:34 +00:00
QPixmap toPixmap( qreal devicePixelRatio = 0.0 ) const;
QPixmap toPixmap( const QSize&,
Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
2018-08-03 06:15:28 +00:00
qreal devicePixelRatio = 0.0 ) const;
2017-07-21 16:21:34 +00:00
QImage toImage( qreal devicePixelRatio = 0.0 ) const;
QImage toImage( const QSize&,
Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
2018-08-03 06:15:28 +00:00
qreal devicePixelRatio = 0.0 ) const;
2017-07-21 16:21:34 +00:00
QRectF scaledBoundingRect( qreal sx, qreal sy ) const;
QRectF boundingRect() const;
QRectF controlPointRect() const;
const QVector< QskPainterCommand >& commands() const;
void setCommands( const QVector< QskPainterCommand >& );
void setDefaultSize( const QSizeF& );
QSizeF defaultSize() const;
2018-10-18 13:41:33 +00:00
qreal heightForWidth( qreal width ) const;
qreal widthForHeight( qreal height ) const;
2017-07-21 16:21:34 +00:00
void setRenderHint( RenderHint, bool on = true );
bool testRenderHint( RenderHint ) const;
RenderHints renderHints() const;
2018-07-31 15:32:25 +00:00
QPaintEngine* paintEngine() const override;
int metric( PaintDeviceMetric metric ) const override;
2017-07-21 16:21:34 +00:00
static QskGraphic fromImage( const QImage& );
static QskGraphic fromPixmap( const QPixmap& );
2021-10-26 09:33:26 +00:00
static QskGraphic fromPixmapAsImage( const QPixmap& );
2017-07-21 16:21:34 +00:00
2021-02-05 12:21:35 +00:00
quint64 modificationId() const;
uint hash( uint seed ) const;
2018-08-03 06:15:28 +00:00
protected:
2017-07-21 16:21:34 +00:00
friend class QskGraphicPaintEngine;
2018-07-31 15:32:25 +00:00
2017-07-21 16:21:34 +00:00
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 );
2018-08-03 06:15:28 +00:00
private:
2017-07-21 16:21:34 +00:00
void updateBoundingRect( const QRectF& );
void updateControlPointRect( const QRectF& );
class PrivateData;
QSharedDataPointer< PrivateData > m_data;
mutable QskGraphicPaintEngine* m_paintEngine;
};
inline bool QskGraphic::operator!=( const QskGraphic& other ) const
{
return !( *this == other );
}
2019-12-30 19:06:46 +00:00
#ifndef QT_NO_DEBUG_STREAM
QSK_EXPORT QDebug operator<<( QDebug, const QskGraphic& );
#endif
2017-07-21 16:21:34 +00:00
Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::RenderHints )
2019-12-04 17:33:30 +00:00
Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::CommandTypes )
2017-07-21 16:21:34 +00:00
Q_DECLARE_METATYPE( QskGraphic )
#endif