QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraphic.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_GRAPHIC_H
7#define QSK_GRAPHIC_H
8
9#include "QskGlobal.h"
10
11#include <qmetatype.h>
12#include <qflags.h>
13#include <qpaintdevice.h>
14#include <qshareddata.h>
15
17class QskColorFilter;
19class QImage;
20class QPixmap;
21class QPainterPath;
22class QPaintEngine;
23class QPaintEngineState;
24class QTransform;
25class QDebug;
26
27class QSK_EXPORT QskGraphic : public QPaintDevice
28{
29 Q_GADGET
30
31 Q_PROPERTY( qreal aspectRatio READ aspectRatio )
32 Q_PROPERTY( QRectF viewBox READ viewBox WRITE setViewBox )
33 Q_PROPERTY( QRectF boundingRect READ boundingRect )
34 Q_PROPERTY( QRectF controlPointRect READ controlPointRect )
35 Q_PROPERTY( QSizeF defaultSize READ defaultSize )
36 Q_PROPERTY( quint64 modificationId READ modificationId )
37
38 using Inherited = QPaintDevice;
39
40 public:
41 enum RenderHint
42 {
43 RenderPensUnscaled = 0x1
44 };
45
46 typedef QFlags< RenderHint > RenderHints;
47
48 enum CommandType
49 {
50 VectorData = 1 << 0,
51 RasterData = 1 << 1,
52 Transformation = 1 << 2
53 };
54
55 typedef QFlags< CommandType > CommandTypes;
56
57 QskGraphic();
58 QskGraphic( const QskGraphic& );
60
61 ~QskGraphic() override;
62
63 QskGraphic& operator=( const QskGraphic& );
64 QskGraphic& operator=( QskGraphic&& );
65
66 bool operator==( const QskGraphic& ) const;
67 bool operator!=( const QskGraphic& ) const;
68
69 void reset();
70
71 bool isNull() const;
72 bool isEmpty() const;
73
74 CommandTypes commandTypes() const;
75
76 void render( QPainter* ) const;
77 void render( QPainter*, const QskColorFilter&,
78 QTransform* initialTransform = nullptr ) const;
79
80 void render( QPainter*, const QSizeF&,
81 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
82
83 void render( QPainter*, const QPointF&,
84 Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const;
85
86 void render( QPainter*, const QRectF&,
87 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
88
89 void render( QPainter*, const QRectF&, const QskColorFilter&,
90 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
91
92 QPixmap toPixmap( qreal devicePixelRatio = 0.0 ) const;
93
94 QPixmap toPixmap( const QSize&,
95 Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
96 qreal devicePixelRatio = 0.0 ) const;
97
98 QImage toImage( qreal devicePixelRatio = 0.0 ) const;
99
100 QImage toImage( const QSize&,
101 Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
102 qreal devicePixelRatio = 0.0 ) const;
103
104 QRectF scaledBoundingRect( qreal sx, qreal sy ) const;
105
106 QRectF boundingRect() const;
107 QRectF controlPointRect() const;
108
109 const QVector< QskPainterCommand >& commands() const;
110 void setCommands( const QVector< QskPainterCommand >& );
111
112 QSizeF defaultSize() const;
113
114 void setViewBox( const QRectF& );
115 QRectF viewBox() const;
116
117 qreal aspectRatio() const;
118
119 qreal heightForWidth( qreal width ) const;
120 qreal widthForHeight( qreal height ) const;
121
122 void setRenderHint( RenderHint, bool on = true );
123 bool testRenderHint( RenderHint ) const;
124
125 RenderHints renderHints() const;
126
127 QPaintEngine* paintEngine() const override;
128 int metric( PaintDeviceMetric metric ) const override;
129
130 static QskGraphic fromImage( const QImage& );
131 static QskGraphic fromPixmap( const QPixmap& );
132 static QskGraphic fromPixmapAsImage( const QPixmap& );
133 static QskGraphic fromGraphic( const QskGraphic&, const QskColorFilter& );
134
135 quint64 modificationId() const;
136 QskHashValue hash( QskHashValue seed ) const;
137
138 protected:
139 virtual QSize sizeMetrics() const;
140
141 virtual void drawPath( const QPainterPath& );
142
143 virtual void drawPixmap( const QRectF&,
144 const QPixmap&, const QRectF& );
145
146 virtual void drawImage( const QRectF&,
147 const QImage&, const QRectF&, Qt::ImageConversionFlags );
148
149 virtual void updateState( const QPaintEngineState& state );
150
151 private:
152 void updateBoundingRect( const QRectF& );
153 void updateControlPointRect( const QRectF& );
154
155 class PrivateData;
156 QSharedDataPointer< PrivateData > m_data;
157
158 friend class QskGraphicPaintEngine;
159 mutable QskGraphicPaintEngine* m_paintEngine;
160};
161
162inline bool QskGraphic::operator!=( const QskGraphic& other ) const
163{
164 return !( *this == other );
165}
166
167#ifndef QT_NO_DEBUG_STREAM
168QSK_EXPORT QDebug operator<<( QDebug, const QskGraphic& );
169#endif
170
171Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::RenderHints )
172Q_DECLARE_OPERATORS_FOR_FLAGS( QskGraphic::CommandTypes )
173Q_DECLARE_METATYPE( QskGraphic )
174
175#endif
A paint device for scalable graphics.
Definition QskGraphic.h:28