QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskPainterCommand.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskPainterCommand.h"
7
8QskPainterCommand::QskPainterCommand( const QPainterPath& path )
9 : m_type( Path )
10{
11 m_path = new QPainterPath( path );
12}
13
14QskPainterCommand::QskPainterCommand( const QRectF& rect,
15 const QPixmap& pixmap, const QRectF& subRect )
16 : m_type( Pixmap )
17{
18 m_pixmapData = new PixmapData();
19 m_pixmapData->rect = rect;
20 m_pixmapData->pixmap = pixmap;
21 m_pixmapData->subRect = subRect;
22}
23
24QskPainterCommand::QskPainterCommand( const QRectF& rect,
25 const QImage& image, const QRectF& subRect, Qt::ImageConversionFlags flags )
26 : m_type( Image )
27{
28 m_imageData = new ImageData();
29 m_imageData->rect = rect;
30 m_imageData->image = image;
31 m_imageData->subRect = subRect;
32 m_imageData->flags = flags;
33}
34
35QskPainterCommand::QskPainterCommand( const QskPainterCommand::StateData& data )
36 : m_type( State )
37{
38 m_stateData = new StateData( data );
39}
40
41QskPainterCommand::QskPainterCommand( const QPaintEngineState& state )
42 : m_type( State )
43{
44 m_stateData = new StateData();
45
46 m_stateData->flags = state.state();
47
48 if ( m_stateData->flags & QPaintEngine::DirtyPen )
49 m_stateData->pen = state.pen();
50
51 if ( m_stateData->flags & QPaintEngine::DirtyBrush )
52 m_stateData->brush = state.brush();
53
54 if ( m_stateData->flags & QPaintEngine::DirtyBrushOrigin )
55 m_stateData->brushOrigin = state.brushOrigin();
56
57 if ( m_stateData->flags & QPaintEngine::DirtyFont )
58 m_stateData->font = state.font();
59
60 if ( m_stateData->flags & QPaintEngine::DirtyBackground )
61 {
62 m_stateData->backgroundMode = state.backgroundMode();
63 m_stateData->backgroundBrush = state.backgroundBrush();
64 }
65
66 if ( m_stateData->flags & QPaintEngine::DirtyTransform )
67 m_stateData->transform = state.transform();
68
69 if ( m_stateData->flags & QPaintEngine::DirtyClipEnabled )
70 m_stateData->isClipEnabled = state.isClipEnabled();
71
72 if ( m_stateData->flags & QPaintEngine::DirtyClipRegion )
73 {
74 m_stateData->clipRegion = state.clipRegion();
75 m_stateData->clipOperation = state.clipOperation();
76 }
77
78 if ( m_stateData->flags & QPaintEngine::DirtyClipPath )
79 {
80 m_stateData->clipPath = state.clipPath();
81 m_stateData->clipOperation = state.clipOperation();
82 }
83
84 if ( m_stateData->flags & QPaintEngine::DirtyHints )
85 m_stateData->renderHints = state.renderHints();
86
87 if ( m_stateData->flags & QPaintEngine::DirtyCompositionMode )
88 m_stateData->compositionMode = state.compositionMode();
89
90 if ( m_stateData->flags & QPaintEngine::DirtyOpacity )
91 m_stateData->opacity = state.opacity();
92}
93
94QskPainterCommand::QskPainterCommand( const QskPainterCommand& other )
95{
96 copy( other );
97}
98
99QskPainterCommand::~QskPainterCommand()
100{
101 reset();
102}
103
104QskPainterCommand& QskPainterCommand::operator=( const QskPainterCommand& other )
105{
106 reset();
107 copy( other );
108
109 return *this;
110}
111
112bool QskPainterCommand::operator==( const QskPainterCommand& other ) const noexcept
113{
114 if ( m_type != other.m_type )
115 return false;
116
117 switch ( m_type )
118 {
119 case Path:
120 {
121 return ( m_path == other.m_path );
122 }
123 case Pixmap:
124 {
125 return ( m_pixmapData == other.m_pixmapData );
126 }
127 case Image:
128 {
129 return ( m_imageData == other.m_imageData );
130 }
131 case State:
132 {
133 const StateData& sd = *m_stateData;
134 const StateData& osd = *other.m_stateData;
135
136 if ( sd.flags != osd.flags )
137 return false;
138
139 if ( sd.flags & QPaintEngine::DirtyPen )
140 {
141 if ( sd.pen != osd.pen )
142 return false;
143 }
144
145 if ( sd.flags & QPaintEngine::DirtyBrush )
146 {
147 if ( sd.brush != osd.brush )
148 return false;
149 }
150
151 if ( sd.flags & QPaintEngine::DirtyBrushOrigin )
152 {
153 if ( sd.brushOrigin != osd.brushOrigin )
154 return false;
155 }
156
157 if ( sd.flags & QPaintEngine::DirtyFont )
158 {
159 if ( sd.font != osd.font )
160 return false;
161 }
162
163 if ( sd.flags & QPaintEngine::DirtyBackground )
164 {
165 if ( sd.backgroundMode != osd.backgroundMode ||
166 sd.backgroundBrush != osd.backgroundBrush )
167 {
168 return false;
169 }
170 }
171
172 if ( sd.flags & QPaintEngine::DirtyTransform )
173 {
174 if ( sd.transform != osd.transform )
175 return false;
176 }
177
178 if ( sd.flags & QPaintEngine::DirtyClipEnabled )
179 {
180 if ( sd.isClipEnabled != osd.isClipEnabled )
181 return false;
182 }
183
184 if ( sd.flags & QPaintEngine::DirtyClipRegion )
185 {
186 if ( sd.clipRegion != osd.clipRegion ||
187 sd.clipOperation != osd.clipOperation )
188 {
189 return false;
190 }
191 }
192
193 if ( sd.flags & QPaintEngine::DirtyClipPath )
194 {
195 if ( sd.clipPath != osd.clipPath ||
196 sd.clipOperation != osd.clipOperation )
197 {
198 return false;
199 }
200 }
201
202 if ( sd.flags & QPaintEngine::DirtyHints )
203 {
204 if ( sd.renderHints != osd.renderHints )
205 return false;
206 }
207
208 if ( sd.flags & QPaintEngine::DirtyCompositionMode )
209 {
210 if ( sd.compositionMode != osd.compositionMode )
211 return false;
212 }
213
214 if ( sd.flags & QPaintEngine::DirtyOpacity )
215 {
216 if ( sd.opacity != osd.opacity )
217 return false;
218 }
219
220 return true;
221 }
222 default:
223 break;
224 }
225
226 return true;
227}
228
229void QskPainterCommand::copy( const QskPainterCommand& other )
230{
231 m_type = other.m_type;
232
233 switch ( other.m_type )
234 {
235 case Path:
236 {
237 m_path = new QPainterPath( *other.m_path );
238 break;
239 }
240 case Pixmap:
241 {
242 m_pixmapData = new PixmapData( *other.m_pixmapData );
243 break;
244 }
245 case Image:
246 {
247 m_imageData = new ImageData( *other.m_imageData );
248 break;
249 }
250 case State:
251 {
252 m_stateData = new StateData( *other.m_stateData );
253 break;
254 }
255 default:
256 break;
257 }
258}
259
260void QskPainterCommand::reset()
261{
262 switch ( m_type )
263 {
264 case Path:
265 {
266 delete m_path;
267 break;
268 }
269 case Pixmap:
270 {
271 delete m_pixmapData;
272 break;
273 }
274 case Image:
275 {
276 delete m_imageData;
277 break;
278 }
279 case State:
280 {
281 delete m_stateData;
282 break;
283 }
284 default:
285 break;
286 }
287
288 m_type = Invalid;
289}
290
291QPainterPath* QskPainterCommand::path() noexcept
292{
293 return m_path;
294}
295
296QskPainterCommand::PixmapData* QskPainterCommand::pixmapData() noexcept
297{
298 return m_pixmapData;
299}
300
301QskPainterCommand::ImageData* QskPainterCommand::imageData() noexcept
302{
303 return m_imageData;
304}
305
306QskPainterCommand::StateData* QskPainterCommand::stateData() noexcept
307{
308 return m_stateData;
309}
@ Path
Draw a QPainterPath.
@ Image
Draw a QImage.
@ Pixmap
Draw a QPixmap.
@ Invalid
Invalid command.
@ State
QPainter state change.