45 #include <private/qdeclarativeitem_p.h> 47 #include <private/qdeclarativepixmapcache_p.h> 48 #include <QtCore/QAbstractAnimation> 51 #include <QtGui/qdrawutil.h> 52 #include <QVarLengthArray> 58 #define M_PI 3.14159265358979323846 59 #define M_PI_2 (M_PI / 2.) 62 #define INT_MAX 2147483647 66 #define PI_SQR 9.8696044 73 qreal y = b * theta + c * theta *
qAbs(theta);
245 emit xattractorChanged();
253 emit yattractorChanged();
258 qreal scaledAccel = accel/1000000.0;
261 _accel = scaledAccel;
262 emit accelerationChanged();
267 qreal xdiff = _xAttr - p.
x;
268 qreal ydiff = _yAttr - p.
y;
272 qreal xcomp = xdiff / (absXdiff + absYdiff);
273 qreal ycomp = ydiff / (absXdiff + absYdiff);
348 if (_xvariance != 0.) {
358 if (_yvariance != 0.) {
360 if ((ydiff > d->
y_peak && d->
y_var > 0.0) || (ydiff < -d->y_peak && d->
y_var < 0.0)) {
392 qreal scaledVar = var / 1000.0;
395 _xvariance = scaledVar;
396 emit xvarianceChanged();
401 qreal scaledVar = var / 1000.0;
404 _yvariance = scaledVar;
405 emit yvarianceChanged();
410 qreal scaledPace = pace / 1000.0;
425 maxX = minX = maxY = minY = 0;
440 template<
class T,
void (T::*method)(
int)>
459 : count(1), emissionRate(-1), emissionVariance(0.5), lifeSpan(1000)
460 , lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300)
461 ,
angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.)
462 , addParticleTime(0), addParticleCount(0), lastAdvTime(0)
463 , motion(0), clock(this)
478 void createParticle(
int time);
514 int oldCount = particles.count();
516 int interval = time - lastAdvTime;
517 for (
int i = 0; i < particles.count(); ) {
522 motion->destroy(part);
525 updateOpacity(particle, age);
526 motion->advance(particle, interval);
531 if(emissionRate == -1)
532 while(removed-- && ((count == -1) || particles.count() < count))
533 createParticle(time);
535 if (!addParticleTime)
536 addParticleTime = time;
539 if (((count == -1) || particles.count() < count) && emissionRate
540 && !(count==-1 && emissionRate==-1)) {
541 int emissionCount = -1;
542 if (emissionRate != -1){
544 if (emissionVariance > 0.){
545 variance += (
qreal(
qrand())/RAND_MAX) * emissionVariance * (
qrand()%2?-1.:1.);
547 qreal emission = emissionRate * (
qreal(interval)/1000.);
548 emission = emission * variance + emissionCarry;
550 emissionCarry = modf(emission, &tmpDbl);
551 emissionCount = (int)tmpDbl;
552 emissionCount =
qMax(0,emissionCount);
554 while(((count == -1) || particles.count() < count) &&
555 (emissionRate==-1 || emissionCount--))
556 createParticle(time);
560 for(
int i=0; i<bursts.size(); i++){
562 if(bursts[i].second == -1){
563 emission = bursts[i].first;
566 if (emissionVariance > 0.){
567 variance += (
qreal(
qrand())/RAND_MAX) * emissionVariance * (
qrand()%2?-1.:1.);
569 qreal workingEmission = bursts[i].second * (
qreal(interval)/1000.);
570 workingEmission *= variance;
571 emission = (int)workingEmission;
572 emission =
qMax(emission, 0);
574 emission =
qMin(emission, bursts[i].first);
575 bursts[i].first -= emission;
577 createParticle(time);
579 for(
int i=bursts.size()-1; i>=0; i--)
580 if(bursts[i].first <= 0)
584 paintItem->updateSize();
586 if (!(oldCount || particles.count()) && (!count || !emissionRate) && bursts.isEmpty()) {
596 p.
x = q->x() + q->width() *
qreal(
qrand()) / RAND_MAX - image.width()/2.0;
597 p.
y = q->y() + q->height() *
qreal(
qrand()) / RAND_MAX - image.height()/2.0;
602 if (fadeInDur == 0.) {
608 a += angleDev/2 - angleDev *
qreal(
qrand()) / RAND_MAX;
613 v += velocityDev/2 - velocityDev *
qreal(
qrand()) / RAND_MAX;
617 motion->created(particles.last());
624 if (age <= fadeInDur) {
757 if (
d->image.isError())
759 d->paintItem->updateSize();
760 d->paintItem->update();
767 if ((
d->url.isEmpty() == name.
isEmpty()) && name ==
d->url)
772 d->image.clear(
this);
773 d->paintItem->updateSize();
774 d->paintItem->update();
779 if (
d->image.isLoading()) {
782 if (
d->image.isError())
785 d->paintItem->updateSize();
786 d->paintItem->update();
831 int oldCount =
d->count;
833 d->addParticleTime = 0;
834 d->addParticleCount =
d->particles.count();
838 d->paintItem->updateSize();
839 d->paintItem->update();
874 return d->emissionRate;
879 if(er ==
d->emissionRate)
881 d->emissionRate = er;
927 return d->emissionVariance;
933 if(
d->emissionVariance == ev)
935 d->emissionVariance = ev;
983 if(
d->lifeSpan == ls)
1013 return d->lifeSpanDev;
1019 if(
d->lifeSpanDev == dev)
1021 d->lifeSpanDev = dev;
1048 return d->fadeInDur;
1054 if (dur < 0.0 || dur == d->fadeInDur)
1072 return d->fadeOutDur;
1078 if (dur < 0.0 || d->fadeOutDur == dur)
1080 d->fadeOutDur = dur;
1118 return d->angle * 180.0 /
M_PI;
1125 if(radAngle ==
d->angle)
1127 d->angle = radAngle;
1155 return d->angleDev * 180.0 /
M_PI;
1162 if(radDev ==
d->angleDev)
1164 d->angleDev = radDev;
1202 return d->velocity * 1000.0;
1208 qreal realVel = velocity / 1000.0;
1209 if(realVel ==
d->velocity)
1211 d->velocity = realVel;
1239 return d->velocityDev * 1000.0;
1245 qreal realDev = velocity / 1000.0;
1246 if(realDev ==
d->velocityDev)
1248 d->velocityDev = realDev;
1288 if (motion ==
d->motion)
1329 for (
int i = 0; i <
d->particles.count(); ++i) {
1331 if(particle.
x > maxX)
1333 if(particle.
x < minX)
1335 if(particle.
y > maxY)
1337 if(particle.
y < minY)
1341 int myWidth = (int)(maxX-minX+0.5)+
d->image.width();
1342 int myX = (int)(minX - parentX);
1343 int myHeight = (int)(maxY-minY+0.5)+
d->image.height();
1344 int myY = (int)(minY - parentY);
1359 if (
d->image.isNull() ||
d->particles.isEmpty())
1366 pixmapData.
resize(
d->particles.count());
1368 const QRectF sourceRect =
d->image.rect();
1371 for (
int i = 0; i <
d->particles.count(); ++i) {
1373 pixmapData[i].x = particle.
x - myX + halfPWidth;
1374 pixmapData[i].y = particle.
y - myY + halfPHeight;
1375 pixmapData[i].opacity = particle.
opacity;
1378 pixmapData[i].rotation = 0;
1379 pixmapData[i].scaleX = 1;
1380 pixmapData[i].scaleY = 1;
1381 pixmapData[i].sourceLeft = sourceRect.
left();
1382 pixmapData[i].sourceTop = sourceRect.
top();
1383 pixmapData[i].width = sourceRect.
width();
1384 pixmapData[i].height = sourceRect.
height();
1393 if (
d->count &&
d->emissionRate) {
1394 d->paintItem->updateSize();
1397 if (
d->lifeSpanDev >
d->lifeSpan)
1398 d->lifeSpanDev =
d->lifeSpan;
QDeclarativeParticleMotion(QObject *parent=0)
Constructs a QDeclarativeParticleMotion with parent object parent.
The QPainter class performs low-level painting on widgets and other paint devices.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
QList< QDeclarativeParticle > particles
virtual void updateCurrentTime(int msec)
This pure virtual function is called every time the animation's currentTime changes.
void drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=0)
This function is used to draw pixmap, or a sub-rectangle of pixmap, at multiple positions with differ...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
QDeclarativeParserStatus ** d
TickAnimationProxy(T *p, QObject *parent=0)
The QDeclarativeParticleMotion class is the base class for particle motion.
void angleDeviationChanged()
void setXVariance(qreal var)
~QDeclarativeParticlesPrivate()
virtual void created(QDeclarativeParticle &)
The particle has just been created.
void setMotion(QDeclarativeParticleMotion *)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
qreal fastCos(qreal theta)
void setAngleDeviation(qreal)
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
long ASN1_INTEGER_get ASN1_INTEGER * a
The QUrl class provides a convenient interface for working with URLs.
T * qobject_cast(QObject *object)
Q_CORE_EXPORT int qrand()
Q_DECL_CONSTEXPR T qAbs(const T &t)
The QObject class is the base class of all Qt objects.
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
QDeclarativeParticles(QDeclarativeItem *parent=0)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
virtual void advance(QDeclarativeParticle &, int interval)
Move the particle to its new position.
QDeclarativeParticlesPainter * paintItem
virtual int duration() const
void setEmissionVariance(qreal)
void setAcceleration(qreal accel)
void createParticle(int time)
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
QDeclarativeParticleMotion * motion() const
qreal emissionVariance() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
QDeclarativeParticlesPrivate()
The QRectF class defines a rectangle in the plane using floating point precision. ...
void emissionRateChanged()
void fadeInDurationChanged()
The QDeclarativeItem class provides the most basic of all visual items in QML.
QList< QPair< int, int > > bursts
int fadeOutDuration() const
void fadeOutDurationChanged()
qreal height() const
Returns the height of the rectangle.
void setFadeOutDuration(int)
QDeclarativeParticle(int time)
void setFadeInDuration(int)
qreal width() const
Returns the width of the rectangle.
virtual void destroy(QDeclarativeParticle &)
The particle is about to be destroyed.
void setSource(const QUrl &)
virtual void destroy(QDeclarativeParticle &)
The particle is about to be destroyed.
The State element defines configurations of objects and properties.
The QAbstractAnimation class is the base of all animations.
void setX(qreal x)
Set's the x coordinate of the item's position.
void emissionVarianceChanged()
QDeclarativeParticlesPainter(QDeclarativeParticlesPrivate *p, QDeclarativeItem *parent)
void updateOpacity(QDeclarativeParticle &p, int age)
void setVelocityDeviation(qreal)
qreal angle(const QPointF &p1, const QPointF &p2)
void burst(int count, int emissionRate=-1)
#define Q_DECLARE_PUBLIC(Class)
qreal y() const
This convenience function is equivalent to calling pos().
QDeclarativeItem * parentItem() const
Returns the QDeclarativeItem parent of this item.
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
virtual void created(QDeclarativeParticle &)
The particle has just been created.
QObject * parent() const
Returns a pointer to the parent object.
qreal x() const
This convenience function is equivalent to calling pos().
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
void setY(qreal y)
Set's the y coordinate of the item's position.
virtual void advance(QDeclarativeParticle &, int interval)
Move the particle to its new position.
virtual void componentComplete()
void setEmissionRate(int)
if(void) toggleToolbarShown
virtual void componentComplete()
int fadeInDuration() const
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
void setYAttractor(qreal y)
virtual void advance(QDeclarativeParticle &, int interval)
Move the particle to its new position.
void setLifeSpanDeviation(int)
void lifeSpanDeviationChanged()
QDeclarativeParticlesPrivate * d
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
QDeclarativeInfo qmlInfo(const QObject *me)
qreal velocityDeviation() const
virtual void advance(QDeclarativeParticle &, int interval)
Move the particle to its new position.
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void setXAttractor(qreal x)
QDeclarativeParticleMotion * motion
qreal fastSin(qreal theta)
qreal angleDeviation() const
The QList class is a template class that provides lists.
TickAnimationProxy< QDeclarativeParticlesPrivate, &QDeclarativeParticlesPrivate::tick > clock
int lifeSpanDeviation() const
void setYVariance(qreal var)
void velocityDeviationChanged()