2017-07-21 18:21:34 +02: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 14:10:48 +02:00
|
|
|
|
|
|
|
#include <qmetatype.h>
|
2019-12-05 10:08:11 +01:00
|
|
|
#include <qflags.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <qpaintdevice.h>
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qshareddata.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
class QskPainterCommand;
|
|
|
|
class QskColorFilter;
|
2018-07-19 14:10:48 +02:00
|
|
|
class QskGraphicPaintEngine;
|
2017-07-21 18:21:34 +02:00
|
|
|
class QImage;
|
|
|
|
class QPixmap;
|
|
|
|
class QPainterPath;
|
2018-07-19 14:10:48 +02:00
|
|
|
class QPaintEngine;
|
|
|
|
class QPaintEngineState;
|
2019-12-05 10:08:11 +01:00
|
|
|
class QTransform;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
class QSK_EXPORT QskGraphic : public QPaintDevice
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
enum RenderHint
|
|
|
|
{
|
|
|
|
RenderPensUnscaled = 0x1
|
|
|
|
};
|
|
|
|
|
2019-12-05 10:08:11 +01:00
|
|
|
typedef QFlags< RenderHint > RenderHints;
|
2019-12-04 18:33:30 +01:00
|
|
|
|
|
|
|
enum CommandType
|
|
|
|
{
|
|
|
|
VectorData = 1 << 0,
|
|
|
|
RasterData = 1 << 1,
|
|
|
|
Transformation = 1 << 2
|
|
|
|
};
|
|
|
|
|
2019-12-05 10:08:11 +01:00
|
|
|
typedef QFlags< CommandType > CommandTypes;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QskGraphic();
|
|
|
|
QskGraphic( const QskGraphic& );
|
|
|
|
QskGraphic( QskGraphic&& );
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
~QskGraphic() override;
|
2017-07-21 18:21:34 +02: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 18:33:30 +01:00
|
|
|
|
|
|
|
CommandTypes commandTypes() const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
void render( QPainter* ) const;
|
2019-12-05 10:08:11 +01:00
|
|
|
void render( QPainter*, const QskColorFilter&,
|
2017-07-21 18:21:34 +02:00
|
|
|
QTransform* initialTransform = nullptr ) const;
|
|
|
|
|
|
|
|
void render( QPainter*, const QSizeF&,
|
2018-08-03 08:15:28 +02:00
|
|
|
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
void render( QPainter*, const QPointF&,
|
|
|
|
Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const;
|
|
|
|
|
|
|
|
void render( QPainter*, const QRectF&,
|
2018-08-03 08:15:28 +02:00
|
|
|
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
void render( QPainter*, const QRectF&, const QskColorFilter&,
|
|
|
|
Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QPixmap toPixmap( qreal devicePixelRatio = 0.0 ) const;
|
|
|
|
|
|
|
|
QPixmap toPixmap( const QSize&,
|
|
|
|
Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
|
2018-08-03 08:15:28 +02:00
|
|
|
qreal devicePixelRatio = 0.0 ) const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QImage toImage( qreal devicePixelRatio = 0.0 ) const;
|
|
|
|
|
|
|
|
QImage toImage( const QSize&,
|
|
|
|
Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
|
2018-08-03 08:15:28 +02:00
|
|
|
qreal devicePixelRatio = 0.0 ) const;
|
2017-07-21 18:21:34 +02: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 15:41:33 +02:00
|
|
|
qreal heightForWidth( qreal width ) const;
|
|
|
|
qreal widthForHeight( qreal height ) const;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
void setRenderHint( RenderHint, bool on = true );
|
|
|
|
bool testRenderHint( RenderHint ) const;
|
|
|
|
|
|
|
|
RenderHints renderHints() const;
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
QPaintEngine* paintEngine() const override;
|
|
|
|
int metric( PaintDeviceMetric metric ) const override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
static QskGraphic fromImage( const QImage& );
|
|
|
|
static QskGraphic fromPixmap( const QPixmap& );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
protected:
|
2017-07-21 18:21:34 +02:00
|
|
|
friend class QskGraphicPaintEngine;
|
2018-07-31 17:32:25 +02:00
|
|
|
|
2017-07-21 18:21:34 +02: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 08:15:28 +02:00
|
|
|
private:
|
2017-07-21 18:21:34 +02: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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::RenderHints )
|
2019-12-04 18:33:30 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::CommandTypes )
|
2017-07-21 18:21:34 +02:00
|
|
|
Q_DECLARE_METATYPE( QskGraphic )
|
|
|
|
|
|
|
|
#endif
|