QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraphicPaintEngine.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskGraphicPaintEngine.h"
7#include "QskGraphic.h"
8
9#include <qpainterpath.h>
10
11static inline QskGraphic* qskGraphic( QskGraphicPaintEngine* engine )
12{
13 if ( !engine->isActive() )
14 return nullptr;
15
16 return static_cast< QskGraphic* >( engine->paintDevice() );
17}
18
19QskGraphicPaintEngine::QskGraphicPaintEngine()
20 : QPaintEngine( QPaintEngine::AllFeatures )
21{
22}
23
24QskGraphicPaintEngine::~QskGraphicPaintEngine()
25{
26}
27
28bool QskGraphicPaintEngine::begin( QPaintDevice* )
29{
30 setActive( true );
31 return true;
32}
33
34bool QskGraphicPaintEngine::end()
35{
36 setActive( false );
37 return true;
38}
39
40QPaintEngine::Type QskGraphicPaintEngine::type() const
41{
42 return QPaintEngine::User;
43}
44
45void QskGraphicPaintEngine::updateState( const QPaintEngineState& state )
46{
47 if ( auto graphic = qskGraphic( this ) )
48 graphic->updateState( state );
49}
50
51void QskGraphicPaintEngine::drawPath( const QPainterPath& path )
52{
53 if ( auto graphic = qskGraphic( this ) )
54 graphic->drawPath( path );
55}
56
57void QskGraphicPaintEngine::drawPolygon(
58 const QPointF* points, int pointCount, PolygonDrawMode mode )
59{
60 if ( auto graphic = qskGraphic( this ) )
61 {
62 QPainterPath path;
63
64 if ( pointCount > 0 )
65 {
66 path.moveTo( points[ 0 ] );
67 for ( int i = 1; i < pointCount; i++ )
68 path.lineTo( points[ i ] );
69
70 if ( mode != PolylineMode )
71 path.closeSubpath();
72 }
73
74 graphic->drawPath( path );
75 }
76}
77
78void QskGraphicPaintEngine::drawPolygon(
79 const QPoint* points, int pointCount, PolygonDrawMode mode )
80{
81 if ( auto graphic = qskGraphic( this ) )
82 {
83 QPainterPath path;
84
85 if ( pointCount > 0 )
86 {
87 path.moveTo( points[ 0 ] );
88 for ( int i = 1; i < pointCount; i++ )
89 path.lineTo( points[ i ] );
90
91 if ( mode != PolylineMode )
92 path.closeSubpath();
93 }
94
95 graphic->drawPath( path );
96 }
97}
98
99void QskGraphicPaintEngine::drawPixmap(
100 const QRectF& rect, const QPixmap& pixmap, const QRectF& subRect )
101{
102 if ( auto graphic = qskGraphic( this ) )
103 graphic->drawPixmap( rect, pixmap, subRect );
104}
105
106void QskGraphicPaintEngine::drawImage(
107 const QRectF& rect, const QImage& image,
108 const QRectF& subRect, Qt::ImageConversionFlags flags )
109{
110 if ( auto graphic = qskGraphic( this ) )
111 graphic->drawImage( rect, image, subRect, flags );
112}
113
114void QskGraphicPaintEngine::drawTextItem(
115 const QPointF& position, const QTextItem& textItem )
116{
117 // TODO ...
118 QPaintEngine::drawTextItem( position, textItem );
119}
A paint device for scalable graphics.
Definition QskGraphic.h:28