qdeclarativesparticlespainter.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "qdeclarativesparticlespainter.h"
  2. #include "qdeclarativesparticles.h"
  3. QDeclarativeSParticlesPainter::QDeclarativeSParticlesPainter(QDeclarativeSParticlesPrivate *p, QDeclarativeItem* parent)
  4. : QDeclarativeItem(parent), d(p)
  5. {
  6. setFlag(QGraphicsItem::ItemHasNoContents, false);
  7. // maxX = minX = maxY = minY = 0;
  8. }
  9. void QDeclarativeSParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
  10. {
  11. // if (d->image.isNull() || d->particles.isEmpty())
  12. // return;
  13. // const int myX = x() + parentItem()->x();
  14. // const int myY = y() + parentItem()->y();
  15. // QVarLengthArray<QPainter::PixmapFragment, 256> pixmapData;
  16. // pixmapData.resize(d->particles.count());
  17. // const QRectF sourceRect = d->image.rect();
  18. // qreal halfPWidth = sourceRect.width()/2.;
  19. // qreal halfPHeight = sourceRect.height()/2.;
  20. // for (int i = 0; i < d->particles.count(); ++i) {
  21. // const QDeclarativeParticle &particle = d->particles.at(i);
  22. // pixmapData[i].x = particle.x - myX + halfPWidth;
  23. // pixmapData[i].y = particle.y - myY + halfPHeight;
  24. // pixmapData[i].opacity = particle.opacity;
  25. // //these never change
  26. // pixmapData[i].rotation = 0;
  27. // pixmapData[i].scaleX = 1;
  28. // pixmapData[i].scaleY = 1;
  29. // pixmapData[i].sourceLeft = sourceRect.left();
  30. // pixmapData[i].sourceTop = sourceRect.top();
  31. // pixmapData[i].width = sourceRect.width();
  32. // pixmapData[i].height = sourceRect.height();
  33. // }
  34. // p->drawPixmapFragments(pixmapData.data(), d->particles.count(), d->image);
  35. }
  36. void QDeclarativeSParticlesPainter::updateSize()
  37. {
  38. if (!d->componentComplete)
  39. return;
  40. // const int parentX = parentItem()->x();
  41. // const int parentY = parentItem()->y();
  42. // for (int i = 0; i < d->particles.count(); ++i) {
  43. // const QDeclarativeParticle &particle = d->particles.at(i);
  44. // if(particle.x > maxX)
  45. // maxX = particle.x;
  46. // if(particle.x < minX)
  47. // minX = particle.x;
  48. // if(particle.y > maxY)
  49. // maxY = particle.y;
  50. // if(particle.y < minY)
  51. // minY = particle.y;
  52. // }
  53. // int myWidth = (int)(maxX-minX+0.5)+d->image.width();
  54. // int myX = (int)(minX - parentX);
  55. // int myHeight = (int)(maxY-minY+0.5)+d->image.height();
  56. // int myY = (int)(minY - parentY);
  57. // setWidth(myWidth);
  58. // setHeight(myHeight);
  59. // setX(myX);
  60. // setY(myY);
  61. }