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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskGraphicPaintEngine.h"
|
|
|
|
#include "QskGraphic.h"
|
|
|
|
|
|
|
|
static inline QskGraphic* qskGraphic( QskGraphicPaintEngine* engine )
|
|
|
|
{
|
|
|
|
if ( !engine->isActive() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return static_cast< QskGraphic* >( engine->paintDevice() );
|
|
|
|
}
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QskGraphicPaintEngine::QskGraphicPaintEngine()
|
|
|
|
: QPaintEngine( QPaintEngine::AllFeatures )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskGraphicPaintEngine::~QskGraphicPaintEngine()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskGraphicPaintEngine::begin( QPaintDevice* )
|
|
|
|
{
|
|
|
|
setActive( true );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskGraphicPaintEngine::end()
|
|
|
|
{
|
|
|
|
setActive( false );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QPaintEngine::Type QskGraphicPaintEngine::type() const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
return QPaintEngine::User;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGraphicPaintEngine::updateState( const QPaintEngineState& state )
|
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
graphic->updateState( state );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGraphicPaintEngine::drawPath( const QPainterPath& path )
|
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
graphic->drawPath( path );
|
|
|
|
}
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
void QskGraphicPaintEngine::drawPolygon(
|
|
|
|
const QPointF* points, int pointCount, PolygonDrawMode mode )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
if ( pointCount > 0 )
|
|
|
|
{
|
2018-08-03 06:15:28 +00:00
|
|
|
path.moveTo( points[ 0 ] );
|
2017-07-21 16:21:34 +00:00
|
|
|
for ( int i = 1; i < pointCount; i++ )
|
2018-08-03 06:15:28 +00:00
|
|
|
path.lineTo( points[ i ] );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
if ( mode != PolylineMode )
|
|
|
|
path.closeSubpath();
|
|
|
|
}
|
|
|
|
|
|
|
|
graphic->drawPath( path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
void QskGraphicPaintEngine::drawPolygon(
|
|
|
|
const QPoint* points, int pointCount, PolygonDrawMode mode )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
if ( pointCount > 0 )
|
|
|
|
{
|
2018-08-03 06:15:28 +00:00
|
|
|
path.moveTo( points[ 0 ] );
|
2017-07-21 16:21:34 +00:00
|
|
|
for ( int i = 1; i < pointCount; i++ )
|
2018-08-03 06:15:28 +00:00
|
|
|
path.lineTo( points[ i ] );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
if ( mode != PolylineMode )
|
|
|
|
path.closeSubpath();
|
|
|
|
}
|
|
|
|
|
|
|
|
graphic->drawPath( path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGraphicPaintEngine::drawPixmap(
|
|
|
|
const QRectF& rect, const QPixmap& pixmap, const QRectF& subRect )
|
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
graphic->drawPixmap( rect, pixmap, subRect );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGraphicPaintEngine::drawImage(
|
2018-08-03 06:15:28 +00:00
|
|
|
const QRectF& rect, const QImage& image,
|
|
|
|
const QRectF& subRect, Qt::ImageConversionFlags flags )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
QskGraphic* graphic = qskGraphic( this );
|
|
|
|
if ( graphic )
|
|
|
|
graphic->drawImage( rect, image, subRect, flags );
|
|
|
|
}
|