OpenCoverage

qquickimageparticle_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickimageparticle_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#ifndef ULTRAPARTICLE_H-
41#define ULTRAPARTICLE_H-
42-
43//-
44// W A R N I N G-
45// --------------
46//-
47// This file is not part of the Qt API. It exists purely as an-
48// implementation detail. This header file may change from version to-
49// version without notice, or even be removed.-
50//-
51// We mean it.-
52//-
53#include "qquickparticlepainter_p.h"-
54#include "qquickdirection_p.h"-
55#include <private/qquickpixmapcache_p.h>-
56#include <QQmlListProperty>-
57#include <QtQuick/qsgsimplematerial.h>-
58#include <QtGui/qcolor.h>-
59-
60QT_BEGIN_NAMESPACE-
61-
62class ImageMaterialData;-
63class QSGGeometryNode;-
64-
65class QQuickSprite;-
66class QQuickStochasticEngine;-
67-
68struct SimpleVertex {-
69 float x;-
70 float y;-
71 float t;-
72 float lifeSpan;-
73 float size;-
74 float endSize;-
75 float vx;-
76 float vy;-
77 float ax;-
78 float ay;-
79};-
80-
81struct ColoredVertex {-
82 float x;-
83 float y;-
84 float t;-
85 float lifeSpan;-
86 float size;-
87 float endSize;-
88 float vx;-
89 float vy;-
90 float ax;-
91 float ay;-
92 Color4ub color;-
93};-
94-
95struct DeformableVertex {-
96 float x;-
97 float y;-
98 float tx;-
99 float ty;-
100 float t;-
101 float lifeSpan;-
102 float size;-
103 float endSize;-
104 float vx;-
105 float vy;-
106 float ax;-
107 float ay;-
108 Color4ub color;-
109 float xx;-
110 float xy;-
111 float yx;-
112 float yy;-
113 float rotation;-
114 float rotationVelocity;-
115 float autoRotate;//Assumed that GPUs prefer floats to bools-
116};-
117-
118struct SpriteVertex {-
119 float x;-
120 float y;-
121 float tx;-
122 float ty;-
123 float t;-
124 float lifeSpan;-
125 float size;-
126 float endSize;-
127 float vx;-
128 float vy;-
129 float ax;-
130 float ay;-
131 Color4ub color;-
132 float xx;-
133 float xy;-
134 float yx;-
135 float yy;-
136 float rotation;-
137 float rotationVelocity;-
138 float autoRotate;//Assumed that GPUs prefer floats to bools-
139 float animW;-
140 float animH;-
141 float animProgress;-
142 float animX1;-
143 float animY1;-
144 float animX2;-
145 float animY2;-
146};-
147-
148template <typename Vertex>-
149struct Vertices {-
150 Vertex v1;-
151 Vertex v2;-
152 Vertex v3;-
153 Vertex v4;-
154};-
155-
156class QQuickImageParticle : public QQuickParticlePainter-
157{-
158 Q_OBJECT-
159 Q_PROPERTY(QUrl source READ image WRITE setImage NOTIFY imageChanged)-
160 Q_PROPERTY(QQmlListProperty<QQuickSprite> sprites READ sprites)-
161 Q_PROPERTY(Status status READ status NOTIFY statusChanged)-
162 //### Is it worth having progress like Image has?-
163 //Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)-
164-
165 Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)-
166 Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)-
167 Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)-
168-
169 //###Now just colorize - add a flag for 'solid' color particles(where the img is just a mask?)?-
170 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged RESET resetColor)-
171 //Stacks (added) with individual colorVariations-
172 Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged RESET resetColor)-
173 Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged RESET resetColor)-
174 Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged RESET resetColor)-
175 Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged RESET resetColor)-
176 //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)-
177 Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged RESET resetColor)-
178 Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged RESET resetColor)-
179-
180 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged RESET resetRotation)-
181 Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged RESET resetRotation)-
182 Q_PROPERTY(qreal rotationVelocity READ rotationVelocity WRITE setRotationVelocity NOTIFY rotationVelocityChanged RESET resetRotation)-
183 Q_PROPERTY(qreal rotationVelocityVariation READ rotationVelocityVariation WRITE setRotationVelocityVariation NOTIFY rotationVelocityVariationChanged RESET resetRotation)-
184 //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation-
185 //to 180 will lead to facing away from the direction of motion-
186 Q_PROPERTY(bool autoRotation READ autoRotation WRITE setAutoRotation NOTIFY autoRotationChanged RESET resetRotation)-
187-
188 //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size-
189 Q_PROPERTY(QQuickDirection* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged RESET resetDeformation)-
190 //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.-
191 Q_PROPERTY(QQuickDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged RESET resetDeformation)-
192 Q_PROPERTY(bool spritesInterpolate READ spritesInterpolate WRITE setSpritesInterpolate NOTIFY spritesInterpolateChanged)-
193-
194 Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged)-
195public:-
196 explicit QQuickImageParticle(QQuickItem *parent = 0);-
197 virtual ~QQuickImageParticle();-
198-
199 enum Status { Null, Ready, Loading, Error };-
200 Q_ENUM(Status)-
201-
202 QQmlListProperty<QQuickSprite> sprites();-
203 QQuickStochasticEngine* spriteEngine() {return m_spriteEngine;}
executed 22348 times by 1 test: return m_spriteEngine;
Executed by:
  • tst_qquickspritegoal
22348
204-
205 enum EntryEffect {-
206 None = 0,-
207 Fade = 1,-
208 Scale = 2-
209 };-
210 Q_ENUM(EntryEffect)-
211-
212 enum PerformanceLevel{//TODO: Expose?-
213 Unknown = 0,-
214 Simple,-
215 Colored,-
216 Deformable,-
217 Tabled,-
218 Sprites-
219 };-
220-
221 QUrl image() const { return m_image ? m_image->source : QUrl(); }
never executed: return m_image ? m_image->source : QUrl();
0
222 void setImage(const QUrl &image);-
223-
224 QUrl colortable() const { return m_colorTable ? m_colorTable->source : QUrl(); }
never executed: return m_colorTable ? m_colorTable->source : QUrl();
0
225 void setColortable(const QUrl &table);-
226-
227 QUrl sizetable() const { return m_sizeTable ? m_sizeTable->source : QUrl(); }
never executed: return m_sizeTable ? m_sizeTable->source : QUrl();
0
228 void setSizetable (const QUrl &table);-
229-
230 QUrl opacitytable() const { return m_opacityTable ? m_opacityTable->source : QUrl(); }
never executed: return m_opacityTable ? m_opacityTable->source : QUrl();
0
231 void setOpacitytable(const QUrl &table);-
232-
233 QColor color() const { return m_color; }
never executed: return m_color;
0
234 void setColor(const QColor &color);-
235-
236 qreal colorVariation() const { return m_color_variation; }
never executed: return m_color_variation;
0
237 void setColorVariation(qreal var);-
238-
239 qreal alphaVariation() const { return m_alphaVariation; }
never executed: return m_alphaVariation;
0
240-
241 qreal alpha() const { return m_alpha; }
never executed: return m_alpha;
0
242-
243 qreal redVariation() const { return m_redVariation; }
never executed: return m_redVariation;
0
244-
245 qreal greenVariation() const { return m_greenVariation; }
never executed: return m_greenVariation;
0
246-
247 qreal blueVariation() const { return m_blueVariation; }
never executed: return m_blueVariation;
0
248-
249 qreal rotation() const { return m_rotation; }
never executed: return m_rotation;
0
250-
251 qreal rotationVariation() const { return m_rotationVariation; }
never executed: return m_rotationVariation;
0
252-
253 qreal rotationVelocity() const { return m_rotationVelocity; }
never executed: return m_rotationVelocity;
0
254-
255 qreal rotationVelocityVariation() const { return m_rotationVelocityVariation; }
never executed: return m_rotationVelocityVariation;
0
256-
257 bool autoRotation() const { return m_autoRotation; }
never executed: return m_autoRotation;
0
258-
259 QQuickDirection* xVector() const { return m_xVector; }
never executed: return m_xVector;
0
260-
261 QQuickDirection* yVector() const { return m_yVector; }
never executed: return m_yVector;
0
262-
263 bool spritesInterpolate() const { return m_spritesInterpolate; }
never executed: return m_spritesInterpolate;
0
264-
265 bool bypassOptimizations() const { return m_bypassOptimizations; }
never executed: return m_bypassOptimizations;
0
266-
267 EntryEffect entryEffect() const { return m_entryEffect; }
never executed: return m_entryEffect;
0
268-
269 Status status() const { return m_status; }
never executed: return m_status;
0
270-
271 void resetColor();-
272 void resetRotation();-
273 void resetDeformation();-
274-
275Q_SIGNALS:-
276-
277 void imageChanged();-
278 void colortableChanged();-
279 void sizetableChanged();-
280 void opacitytableChanged();-
281-
282 void colorChanged();-
283 void colorVariationChanged();-
284-
285 void alphaVariationChanged(qreal arg);-
286-
287 void alphaChanged(qreal arg);-
288-
289 void redVariationChanged(qreal arg);-
290-
291 void greenVariationChanged(qreal arg);-
292-
293 void blueVariationChanged(qreal arg);-
294-
295 void rotationChanged(qreal arg);-
296-
297 void rotationVariationChanged(qreal arg);-
298-
299 void rotationVelocityChanged(qreal arg);-
300-
301 void rotationVelocityVariationChanged(qreal arg);-
302-
303 void autoRotationChanged(bool arg);-
304-
305 void xVectorChanged(QQuickDirection* arg);-
306-
307 void yVectorChanged(QQuickDirection* arg);-
308-
309 void spritesInterpolateChanged(bool arg);-
310-
311 void bypassOptimizationsChanged(bool arg);-
312-
313 void entryEffectChanged(EntryEffect arg);-
314-
315 void statusChanged(Status arg);-
316-
317public Q_SLOTS:-
318 void reloadColor(const Color4ub &c, QQuickParticleData* d);-
319 void setAlphaVariation(qreal arg);-
320-
321 void setAlpha(qreal arg);-
322-
323 void setRedVariation(qreal arg);-
324-
325 void setGreenVariation(qreal arg);-
326-
327 void setBlueVariation(qreal arg);-
328-
329 void setRotation(qreal arg);-
330-
331 void setRotationVariation(qreal arg);-
332-
333 void setRotationVelocity(qreal arg);-
334-
335 void setRotationVelocityVariation(qreal arg);-
336-
337 void setAutoRotation(bool arg);-
338-
339 void setXVector(QQuickDirection* arg);-
340-
341 void setYVector(QQuickDirection* arg);-
342-
343 void setSpritesInterpolate(bool arg);-
344-
345 void setBypassOptimizations(bool arg);-
346-
347 void setEntryEffect(EntryEffect arg);-
348-
349protected:-
350 void reset() override;-
351 void initialize(int gIdx, int pIdx) override;-
352 void commit(int gIdx, int pIdx) override;-
353-
354 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;-
355 void prepareNextFrame(QSGNode**);-
356 void buildParticleNodes(QSGNode**);-
357-
358 void sceneGraphInvalidated() override;-
359-
360private Q_SLOTS:-
361 void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty-
362-
363 void spriteAdvance(int spriteIndex);-
364 void spritesUpdate(qreal time = 0 );-
365 void mainThreadFetchImageData();-
366 void finishBuildParticleNodes(QSGNode **n);-
367private:-
368 struct ImageData {-
369 QUrl source;-
370 QQuickPixmap pix;-
371 };-
372 QScopedPointer<ImageData> m_image;-
373 QScopedPointer<ImageData> m_colorTable;-
374 QScopedPointer<ImageData> m_sizeTable;-
375 QScopedPointer<ImageData> m_opacityTable;-
376 bool loadingSomething();-
377-
378-
379 QColor m_color;-
380 qreal m_color_variation;-
381-
382 QHash<int, QSGGeometryNode *> m_nodes;-
383 QHash<int, int> m_idxStarts;//TODO: Proper resizing will lead to needing a spriteEngine per particle - do this after sprite engine gains transparent sharing?-
384 QList<QPair<int, int> > m_startsIdx;//Same data, optimized for alternate retrieval-
385-
386 int m_lastIdxStart;-
387 QSGMaterial *m_material;-
388-
389 // derived values...-
390-
391 qreal m_alphaVariation;-
392 qreal m_alpha;-
393 qreal m_redVariation;-
394 qreal m_greenVariation;-
395 qreal m_blueVariation;-
396 qreal m_rotation;-
397 qreal m_rotationVariation;-
398 qreal m_rotationVelocity;-
399 qreal m_rotationVelocityVariation;-
400 bool m_autoRotation;-
401 QQuickDirection* m_xVector;-
402 QQuickDirection* m_yVector;-
403-
404 QList<QQuickSprite*> m_sprites;-
405 QQuickSpriteEngine* m_spriteEngine;-
406 bool m_spritesInterpolate;-
407-
408 bool m_explicitColor;-
409 bool m_explicitRotation;-
410 bool m_explicitDeformation;-
411 bool m_explicitAnimation;-
412 QHash<int, QVector<QQuickParticleData*> > m_shadowData;-
413 void clearShadows();-
414 QQuickParticleData* getShadowDatum(QQuickParticleData* datum);-
415-
416 bool m_bypassOptimizations;-
417 PerformanceLevel perfLevel;-
418-
419 PerformanceLevel m_lastLevel;-
420 bool m_debugMode;-
421-
422 template<class Vertex>-
423 void initTexCoords(Vertex* v, int count){-
424 Vertex* end = v + count;-
425 while (v < end){
v < endDescription
TRUEevaluated 6000 times by 3 tests
Evaluated by:
  • tst_qquickcustomaffector
  • tst_qquickimageparticle
  • tst_qquickspritegoal
FALSEevaluated 12 times by 3 tests
Evaluated by:
  • tst_qquickcustomaffector
  • tst_qquickimageparticle
  • tst_qquickspritegoal
12-6000
426 v[0].tx = 0;-
427 v[0].ty = 0;-
428-
429 v[1].tx = 1;-
430 v[1].ty = 0;-
431-
432 v[2].tx = 0;-
433 v[2].ty = 1;-
434-
435 v[3].tx = 1;-
436 v[3].ty = 1;-
437-
438 v += 4;-
439 }
executed 6000 times by 3 tests: end of block
Executed by:
  • tst_qquickcustomaffector
  • tst_qquickimageparticle
  • tst_qquickspritegoal
6000
440 }
executed 12 times by 3 tests: end of block
Executed by:
  • tst_qquickcustomaffector
  • tst_qquickimageparticle
  • tst_qquickspritegoal
12
441-
442 template<class MaterialData>-
443 static MaterialData* getState(QSGMaterial* m) {-
444 return static_cast<QSGSimpleMaterial<MaterialData> *>(m)->state();
executed 139729 times by 21 tests: return static_cast<QSGSimpleMaterial<MaterialData> *>(m)->state();
Executed by:
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
139729
445 }-
446 EntryEffect m_entryEffect;-
447 Status m_status;-
448 int m_startedImageLoading;-
449};-
450-
451QT_END_NAMESPACE-
452#endif // ULTRAPARTICLE_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0