1 /* This file is part of KsirK.
2    Copyright (C) 2001-2007 Gael de Chalendar <kleag@free.fr>
3 
4    KsirK is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public
6    License as published by the Free Software Foundation, either version 2
7    of the License, or (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA
18 */
19 
20 /*  begin                : Wed Jul 18 2001  */
21 
22 #include "animsprite.h"
23 #include "skinSpritesData.h"
24 #include "backgnd.h"
25 #include "kgamewin.h"
26 #include "ksirksettings.h"
27 #include "GameLogic/nationality.h"
28 #include "GameLogic/country.h"
29 #include "GameLogic/gameautomaton.h"
30 #include "GameLogic/onu.h"
31 
32 #include <QPoint>
33 #include <QPixmap>
34 #include <QPixmapCache>
35 #include <QSvgRenderer>
36 
37 #include <KMessageBox>
38 #include <KLocalizedString>
39 #include "ksirk_debug.h"
40 
41 namespace Ksirk
42 {
43 
44 using namespace GameLogic;
45 
AnimSprite(const QString & svgid,unsigned int width,unsigned int height,unsigned int nbFrames,unsigned int nbDirs,double zoom,BackGnd * aBackGnd,unsigned int visibility)46 AnimSprite::AnimSprite(const QString &svgid,
47                         unsigned int width,
48                         unsigned int height,
49                         unsigned int nbFrames, unsigned int nbDirs,
50                         double zoom,
51                         BackGnd* aBackGnd,
52                         unsigned int visibility) :
53     QGraphicsPixmapItem(0),
54     m_animated(false), m_zoom(zoom), m_svgid(svgid),
55     look(right), nbVersions(nbDirs),
56     backGnd(aBackGnd), destination(0), destinationPoint(), frames(nbFrames), actFrame(0),
57     myState(NONE),
58     m_height(zoom*height),
59     m_width(zoom*width),
60     approachDestByLeft(false), approachDestByRight(false),
61     approachDestByTop(false), approachDestByBottom(false),
62     m_frames(),
63     m_renderer(const_cast<ONU*>(aBackGnd->onu())->renderer()),
64     m_numberOfShots(0),
65     m_timer(this),
66     m_skin(backGnd->onu()->skin())
67 {
68    aBackGnd-> scene()->addItem(this);
69 //   qCDebug(KSIRK_LOG) << svgid << nbFrames;
70   setNone();
71 
72   sequenceConstruction();
73   setZValue(visibility);
74   show();
75 
76   /// @note uncomment here if you want to try sprites animation by connection to a timer
77 //   connect(GameAutomaton::changeable().game()->frame()->timer(),SIGNAL(timeout()),this,SLOT(animate()));
78   connect(&m_timer,&QTimer::timeout,this,&AnimSprite::animate);
79 //   m_timer.setSingleShot(true);
80   if (frames > 1)
81   {
82     m_timer.start(200);
83   }
84 }
85 
~AnimSprite()86 AnimSprite::~AnimSprite()
87 {
88 //   qCDebug(KSIRK_LOG) << (void*)this ;
89   m_timer.stop();
90   disconnect(&m_timer,&QTimer::timeout,this,&AnimSprite::animate);
91   setStatic();
92 }
93 
repaint()94 void AnimSprite::repaint()
95 {
96   update();
97 }
98 
setLook(TDir newLook)99 void AnimSprite::setLook(TDir newLook)
100 {
101 //   qCDebug(KSIRK_LOG);
102   if (newLook != look)
103   {
104 //        qCDebug(KSIRK_LOG)<<"setLook : " << newLook << ")";
105     look=newLook;
106     setFrame(0);
107     update();
108   }
109 }
110 
111 /**
112  * updates the sequence of images used by the underlying QGraphicsPixmapItem
113  * with the ones taken from the image found at imgPath. It is function of the
114  * direction of the look and the geometry of the sprite
115  */
sequenceConstruction()116 void AnimSprite::sequenceConstruction()
117 {
118   QList<QPixmap> list;
119 
120   QPixmap allpm;
121   QString allpmCacheId = m_skin+m_svgid+QString::number(m_width*frames)+"x"+QString::number(m_height*nbVersions);
122   if (!QPixmapCache::find(allpmCacheId, &allpm))
123   {
124     // Pixmap isn't in the cache, create it and insert to cache
125     QSize size((int)(m_width*frames), (int)(m_height*nbVersions));
126     QImage image(size, QImage::Format_ARGB32_Premultiplied);
127     image.fill(0);
128     QPainter p(&image);
129     m_renderer->render(&p, m_svgid);
130     allpm = QPixmap::fromImage(image);
131 
132     QPixmapCache::insert(allpmCacheId, allpm);
133   }
134 
135   for (unsigned int l = 0; l<nbVersions;l++)
136   {
137     for (unsigned int i = 0; i<frames;i++)
138     {
139 //       qCDebug(KSIRK_LOG)<< "constr s : "<<m_width<<" "<<m_height<<" "<<look-1;
140       QPixmap pm;
141       QString pmCacheId = m_skin+m_svgid+QString::number(m_width*frames)+"x"+QString::number(m_height*nbVersions)+"-"+QString::number(i)+":"+QString::number(l);
142       if (!QPixmapCache::find(pmCacheId, &pm))
143       {
144         // Pixmap isn't in the cache, create it and insert to cache
145         pm = allpm.copy((int)(m_width*i), (int)(m_height*l),
146                    (int)(m_width), (int)(m_height));
147 
148         QPixmapCache::insert(pmCacheId, pm);
149       }
150 
151       list.push_back(pm);
152     }
153   }
154   m_frames = list;
155 
156   setFrame(0);
157 }
158 
changeSequence(const QString & id)159 void AnimSprite::changeSequence(const QString &id)
160 {
161   qCDebug(KSIRK_LOG) << (void*)this << id;
162   changeSequence(
163           id,
164           Sprites::SkinSpritesData::single().intData(id+"-width"),
165           Sprites::SkinSpritesData::single().intData(id+"-height"),
166           Sprites::SkinSpritesData::single().intData(id+"-frames"),
167           Sprites::SkinSpritesData::single().intData(id+"-versions"));
168 }
changeSequence(const QString & svgid,unsigned int width,unsigned int height,unsigned int newNbFrames,unsigned int nbDirs)169 void AnimSprite::changeSequence(const QString &svgid,
170                                  unsigned int width,
171                                  unsigned int height,
172                                  unsigned int newNbFrames,
173                                  unsigned int nbDirs)
174 {
175   qCDebug(KSIRK_LOG) << (void*)this << svgid;
176   m_svgid = svgid;
177   m_width = width*m_zoom;
178   m_height = height*m_zoom;
179   frames = newNbFrames;
180   actFrame = 0;
181   nbVersions = nbDirs;
182 
183   sequenceConstruction();
184   update();
185   //    qCDebug(KSIRK_LOG)<<"OUT";
186 }
187 
nextFrame()188 void AnimSprite::nextFrame()
189 {
190   if (frames <= 1)
191   {
192     return;
193   }
194   actFrame++;    // next image
195 
196   if (actFrame > (frames-1))
197   {
198     actFrame=0; // come back to start
199     if (m_numberOfShots == 1)
200     {
201       setStatic();
202       m_numberOfShots = std::numeric_limits<unsigned int>::max();
203       qCDebug(KSIRK_LOG) << "Emiting animationFinished";
204       emit animationFinished(this);
205     }
206     else if (m_numberOfShots != std::numeric_limits<unsigned int>::max())
207     {
208       m_numberOfShots--;
209       qCDebug(KSIRK_LOG) << "numberOfShots is now " << m_numberOfShots ;
210     }
211   }
212   setFrame(actFrame);
213 }
214 
setFrame(unsigned int numFrame)215 void AnimSprite::setFrame(unsigned int numFrame)
216 {
217 //   qCDebug(KSIRK_LOG) << " " << numFrame << " look=" << look <<" ; frames="
218 //           <<frames<<" ; m_frames size="<<m_frames.size();
219   if (numFrame < (unsigned int)m_frames.size())
220   {
221     setPixmap(m_frames[(look-1)*frames+numFrame]);
222   }
223 }
224 
moveIt()225 void AnimSprite::moveIt()
226 {
227 //   qCDebug(KSIRK_LOG) << "Position of " << (void*)this << " is: "
228 //     << pos() << " (destination point is: " << destinationPoint << ")";
229   qreal delta = 5*m_zoom;
230   switch (KsirkSettings::spritesSpeed())
231   {
232     case 0:
233       delta = 2*m_zoom;
234       break;
235     case 1:
236       delta = 5*m_zoom;
237       break;
238     case 2:
239       delta = 10*m_zoom;
240       break;
241     case 3:
242       setPos(destinationPoint);
243       destinationPoint = QPointF();
244       emit atDestination(this);
245       return;
246       break;
247     default:
248       delta = 5*m_zoom;
249   }
250   delta=delta<1.0?1.0:delta;
251 
252 //   qCDebug(KSIRK_LOG) << "delta="<<delta;
253   if (getApproachDestByLeft())
254   {
255     setLook(right);
256     if (x() < destinationPoint.x())
257     {
258       if (destinationPoint.x() - x() > delta) setPos(pos() + QPointF(delta,0)) ;
259       else if (destinationPoint.x() - x() <= 1) setPos(destinationPoint.x(),y());
260       else /*if (destinationPoint.x() - x() <= delta)*/ setPos(pos() + QPointF(1,0));
261     }
262     if (x() > destinationPoint.x())
263     {
264       if (getMaxX() - x() > delta) setPos(pos()+QPointF(delta,0));
265       if (getMaxX() - x() <= delta) setPos(QPointF(destinationPoint.x()<0?destinationPoint.x():0,y()));
266     }
267   }
268   else if (getApproachDestByRight())
269   {
270     setLook(left);
271     if (x() < destinationPoint.x())
272     {
273       if (x() > delta) setPos(pos()+QPointF(-delta,0));
274       if (x() <= delta) setPos(QPointF(getMaxX(),y()));
275     }
276     if (x() > destinationPoint.x())
277     {
278       if ( x() - destinationPoint.x() > delta) setPos(pos()+QPointF(-delta,0));
279       else if ( x() - destinationPoint.x() <= 1) setPos(destinationPoint.x(),y());
280       else /*if ( x() - destinationPoint.x() <= delta)*/ setPos(pos()+QPointF(-1,0));
281     }
282   }
283   else
284   {
285     if (x() < destinationPoint.x())
286     {
287       setLook(right);
288       if (destinationPoint.x() - x() > delta) setPos(pos()+QPointF(delta,0));
289       if (destinationPoint.x() - x() <= 1) setPos(destinationPoint.x(),y());
290       else /*if (destinationPoint.x() - x() <= delta)*/ setPos(pos()+QPointF(1,0));
291     }
292     if (x() > destinationPoint.x())
293     {
294       setLook(left);
295       if (x() - destinationPoint.x() > delta) setPos(pos()+QPointF(-delta,0));
296       else if (x() - destinationPoint.x() <= 1) setPos(destinationPoint.x(),y());
297       else /*if (x() - destinationPoint.x() <= delta)*/ setPos(pos()+QPointF(-1,0));
298     }
299   }
300 //   qCDebug(KSIRK_LOG) << "After x, position is: " << pos();
301   if (getApproachDestByTop())
302   {
303     if (y() < destinationPoint.y())
304     {
305       if (destinationPoint.y() - y() > delta) setPos(pos()+QPointF(0,delta));
306       else if (destinationPoint.y() - y() <= delta) setPos(x(),destinationPoint.y());
307       else /*if (destinationPoint.y() - y() <= delta)*/ setPos(pos()+QPointF(0,1));
308     }
309     if (y() > destinationPoint.y())
310     {
311       if (getMaxY() - y() > delta) setPos(pos()+QPointF(0,delta));
312       if (getMaxY() - y() <= delta) setPos(x(),destinationPoint.y()<0?destinationPoint.y():0);
313     }
314   }
315   else if (getApproachDestByBottom())
316   {
317     if (y() < destinationPoint.y())
318     {
319       if (destinationPoint.y() - y() > delta) setPos(pos()+QPointF(0,-delta));
320       if (destinationPoint.y() - y() <= delta) setPos(x(), getMaxY() );
321     }
322     if (y() > destinationPoint.y())
323     {
324       if ( y() - destinationPoint.y() > delta) setPos(pos()+QPointF(0,-delta));
325       else if ( y() - destinationPoint.y() <= 1) setPos(x(),destinationPoint.y());
326       else /*if ( y() - destinationPoint.y() <= delta)*/ setPos(pos()+QPointF(0,-1));
327     }
328   }
329   else
330   {
331     if (y() < destinationPoint.y())
332     {
333       if (destinationPoint.y() - y() > delta) setPos(pos()+QPointF(0,delta));
334       else if (destinationPoint.y() - y() <= 1) setPos(x(),destinationPoint.y());
335       else /*if (destinationPoint.y() - y() <= delta)*/ setPos(pos()+QPointF(0,1));
336     }
337     if (y() > destinationPoint.y())
338     {
339       if (y() - destinationPoint.y() > delta) setPos(pos()+QPointF(0,-delta));
340       else if (y() - destinationPoint.y() <= 1) setPos(x(), destinationPoint.y());
341       else /*if (y() - destinationPoint.y() <= delta)*/ setPos(pos()+QPointF(0,-1));
342     }
343   }
344 //   qCDebug(KSIRK_LOG) << "New position of " << (void*)this << " is: " << pos();
345   nextFrame();
346   if (pos() == destinationPoint)
347   {
348     setStatic();
349     destinationPoint = QPointF();
350     emit atDestination(this);
351   }
352 }
353 
isLastFrame() const354 bool AnimSprite::isLastFrame() const
355 {
356 //    qCDebug(KSIRK_LOG)<<"AnimSprite::isLastFrame actFrame = "<<actFrame<<" frames = "<<frames-1;
357     return (actFrame == (frames - 1));
358 }
359 
setDestinationPoint(const QPointF & point)360 void AnimSprite::setDestinationPoint(const QPointF &point)
361 {
362 
363     destinationPoint = point;
364 }
365 
getDestinationPoint() const366 const QPointF& AnimSprite::getDestinationPoint() const
367 {
368     return  destinationPoint;
369 }
370 
operator ==(const AnimSprite & Arg) const371 int AnimSprite::operator==(const AnimSprite& Arg) const
372 {
373     return (memcmp(this,&Arg,sizeof(AnimSprite)));
374 }
375 
setDestination(Country * country)376 void AnimSprite::setDestination(Country* country)
377 {
378     destination = country;
379 }
380 
getDestination()381 Country* AnimSprite::getDestination()
382 {
383     return destination;
384 }
385 
turnTowardDestination()386 void AnimSprite::turnTowardDestination()
387 {
388     if (x() <= destinationPoint.x())
389         setLook(right);
390     else setLook(left);
391 }
392 
isAttacker() const393 bool AnimSprite::isAttacker() const
394 {
395     return (isMyState( ATTACKER ));
396 }
397 
setAttacker()398 void AnimSprite::setAttacker()
399 {
400     setState ( ATTACKER );
401 }
402 
isDefendant() const403 bool AnimSprite::isDefendant() const
404 {
405     return (isMyState(DEFENDANT));
406 }
407 
setDefendant()408 void AnimSprite::setDefendant()
409 {
410     setState (DEFENDANT);
411 }
412 
isNone() const413 bool AnimSprite::isNone() const
414 {
415     return (isMyState(NONE));
416 }
417 
setNone()418 void AnimSprite::setNone()
419 {
420     setState (NONE );
421 }
422 
423 /** turn the sprite towards left */
setLookLeft()424 void AnimSprite::setLookLeft()
425 {
426   qCDebug(KSIRK_LOG);
427   setLook(left);
428 }
429 
430 /** tourne le sprite vers la droite */
setLookRight()431 void AnimSprite::setLookRight()
432 {
433   qCDebug(KSIRK_LOG);
434   setLook(right);
435 }
436 /** No descriptions */
looksToLeft() const437 bool AnimSprite::looksToLeft() const
438 {
439     return (look == left);
440 }
441 /** No descriptions */
looksToRight() const442 bool AnimSprite::looksToRight() const
443 {
444     return (look == right);
445 }
446 
447 /** Read property of bool approachDestByRight. */
getApproachDestByRight() const448 bool AnimSprite::getApproachDestByRight() const
449 {
450     return approachDestByRight;
451 }
452 
453 /** Write property of bool approachDestByRight. */
setApproachDestByRight(const bool & _newVal)454 void AnimSprite::setApproachDestByRight( const bool& _newVal)
455 {
456   //    qCDebug(KSIRK_LOG);
457     approachDestByRight = _newVal;
458     if (_newVal) setApproachDestByLeft(false);
459 }
460 
461 /** Read property of bool approachDestByLeft . */
getApproachDestByLeft() const462 bool AnimSprite::getApproachDestByLeft () const
463 {
464     return approachDestByLeft ;
465 }
466 
467 /** Write property of bool approachDestByLeft . */
setApproachDestByLeft(const bool & _newVal)468 void AnimSprite::setApproachDestByLeft ( const bool& _newVal)
469 {
470   //    qCDebug(KSIRK_LOG);
471     approachDestByLeft  = _newVal;
472     if (_newVal) setApproachDestByRight(false);
473 }
474 
475 /** Read property of bool approachDestByTop. */
getApproachDestByTop() const476 bool AnimSprite::getApproachDestByTop() const
477 {
478     return approachDestByTop;
479 }
480 
481 /** Write property of bool approachDestByTop. */
setApproachDestByTop(const bool & _newVal)482 void AnimSprite::setApproachDestByTop( const bool& _newVal)
483 {
484     approachDestByTop = _newVal;
485     if (_newVal) setApproachDestByBottom(false);
486 }
487 
488 /** Read property of bool approachDestByBottom . */
getApproachDestByBottom() const489 bool AnimSprite::getApproachDestByBottom () const
490 {
491     return approachDestByBottom ;
492 }
493 
494 /** Write property of bool approachDestByBottom . */
setApproachDestByBottom(const bool & _newVal)495 void AnimSprite::setApproachDestByBottom ( const bool& _newVal)
496 {
497     approachDestByBottom  = _newVal;
498     if (_newVal) setApproachDestByTop(false);
499 }
500 
501 /** Return the maximum value for x for this sprite by looking to its including
502   * background. Necessary for directed approaches.
503   * Quit with error if there is no background
504   */
getMaxX() const505 qreal AnimSprite::getMaxX() const
506 {
507     if (backGnd)
508         return backGnd-> pixmap().width();
509     else
510     {
511         KMessageBox::error(0, i18n("Cannot find Max X for sprite: no background!"), i18n("Error!"));
512         exit(2);
513     }
514 }
515 
516 /** Return the maximum value for y for this sprite by looking to its including
517   * background. Necessary for directed approaches.
518   * Quit with error if there is no background
519   */
getMaxY() const520 qreal AnimSprite::getMaxY() const
521 {
522     if (backGnd)
523         return backGnd-> pixmap().height();
524     else
525     {
526         KMessageBox::error(0, i18n("Cannot find Max Y for sprite: no background!"), i18n("Error!"));
527         exit(2);
528     }
529 }
530 
setupTravel(Country * src,Country * dest,const QPointF * dpi)531 void AnimSprite::setupTravel(Country* src, Country* dest, const QPointF* dpi)
532 {
533   qCDebug(KSIRK_LOG) << src->name() << dest->name() << *dpi << (dpi==0?QPointF():*dpi);
534   if (dpi ==0) AnimSprite::setupTravel(src, dest, src->centralPoint(), dest-> centralPoint());
535   else AnimSprite::setupTravel(src, dest, src->centralPoint(), *dpi);
536 }
537 
538 /**
539   * This function chooses the approach mode of a sprite towards its destination:
540   * if the distance between the origin and the destination is higher than half
541   * the size of the map and if the origin and destination countries comunicate,
542   * then the sprite should choose an approach by left or right, through the
543   * edge of the map.
544   * This protected method will be called by three public functions specialized
545   * using as source point, respectivly, the infantryman point, the cavalryman
546   * point and the cannon point.
547   */
setupTravel(Country * src,Country * dest,const QPointF & srcPoint,const QPointF & destPoint)548 void AnimSprite::setupTravel(
549         Country* src,
550         Country* dest,
551         const QPointF& srcPoint,
552         const QPointF& destPoint)
553 {
554    qCDebug(KSIRK_LOG) << src->name() << srcPoint << ", " << dest->name() << destPoint ;
555 
556   setDestination(dest);
557   setDestinationPoint(destPoint);
558   setPos(srcPoint);
559 
560   if (!src-> communicateWith(dest))
561   {
562       qCCritical(KSIRK_LOG) << "Error in AnimSprite::setupTravel: " << src-> name() << "  and "
563               << dest-> name() << " do not communicate!\n";
564       exit(2);
565   }
566 
567   if ( (qAbs(srcPoint.x() - destPoint.x())) > ((backGnd-> boundingRect().width())/2) && !backGnd->bgIsArena())
568   {
569       // src is at the right of dest, approch dest by left
570       if (srcPoint.x() > destPoint.x()) setApproachDestByLeft(true);
571       // src is at the left of dest, approch dest by right
572       if (srcPoint.x() < destPoint.x()) setApproachDestByRight(true);
573   }
574   else
575   {
576       // src is at the right of dest, approch dest by left
577       if (srcPoint.x() > destPoint.x()) setApproachDestByRight(true);
578       // src is at the left of dest, approch dest by right
579       if (srcPoint.x() < destPoint.x()) setApproachDestByLeft(true);
580   }
581 
582   if ( ((qAbs(srcPoint.y() - destPoint.y())) > ((backGnd-> boundingRect().height())/2)) && !backGnd->bgIsArena())
583   {
584       // src is under the dest, approch dest by top
585       if (srcPoint.y() > destPoint.y()) setApproachDestByTop(true);
586       // src is up to the dest, approch dest by botto
587       if (srcPoint. y() < destPoint.y()) setApproachDestByBottom(true);
588   }
589   else
590   {
591       // src is under the dest, approch dest by bottom
592       if (srcPoint.y() > destPoint.y()) setApproachDestByBottom(true);
593       // src is up to the dest, approch dest by top
594       if (srcPoint. y() < destPoint.y()) setApproachDestByTop(true);
595   }
596   if (src->pointFlag().x() < dest-> pointFlag().x()) {
597     setLookRight();
598   } else {
599     setLookLeft();
600   }
601   setAnimated();
602   qCDebug(KSIRK_LOG) << "Done";
603 }
604 
arrival()605 void AnimSprite::arrival()
606 {
607   qCDebug(KSIRK_LOG)<< "at " << destinationPoint ;
608   if (!backGnd->bgIsArena())
609   {
610     qCDebug(KSIRK_LOG)<< "x=" << x() << "pf=" << getDestination()->pointFlag().x();
611     if (x() < getDestination()-> pointFlag().x())
612       setLookRight();
613     else
614       setLookLeft();
615   }
616   repaint();
617 }
618 
619 /** Return true if the state of the sprite is the argument; false otherwise */
isMyState(State state) const620 bool AnimSprite::isMyState(State state) const
621 {
622     return myState == state;
623 }
624 
625 /**
626   * returns the current state of the sprite
627   */
getState() const628 AnimSprite::State AnimSprite::getState() const
629 {
630 //    qCDebug(KSIRK_LOG) << "I'm a sprite; my state is : " << myState ;
631     return myState;
632 }
633 
634 /** sets the new state of the game */
setState(AnimSprite::State newState)635 void AnimSprite::setState(AnimSprite::State newState)
636 {
637 //    qCDebug(KSIRK_LOG) << "Setting sprite's state to : " << newState << " (was : " << myState << ")";
638     myState = newState;
639 }
640 
saveXml(QTextStream &)641 void AnimSprite::saveXml(QTextStream& /*xmlStream*/)
642 {
643 }
644 
image(unsigned int numFrame) const645 QPixmap AnimSprite::image(unsigned int numFrame) const
646 {
647 //   qCDebug(KSIRK_LOG) << "image(" << numFrame << ") / " << m_frames.size();
648   if (numFrame >= (unsigned int)m_frames.size())
649   {
650     return QPixmap();
651   }
652   else
653   {
654     return m_frames[(look-1)*frames+numFrame];
655   }
656 }
657 
animate()658 void AnimSprite::animate()
659 {
660   //   qCDebug(KSIRK_LOG) << (void*)this ;
661   if (!destinationPoint.isNull() && pos() != destinationPoint)
662   {
663     moveIt();
664   }
665   else if (m_animated && frames > 1)
666   {
667     nextFrame();
668   }
669   //   qCDebug(KSIRK_LOG) <<"finished for " << (void*)this ;
670 }
671 
setAnimated(unsigned int numberOfShots)672 void AnimSprite::setAnimated(unsigned int numberOfShots)
673 {
674   m_numberOfShots = numberOfShots;
675   m_animated = true;
676   if (!m_timer.isActive())
677   {
678     m_timer.start(200);
679   }
680 //   AnimSpritePool::changeable().addSprite(this);
681 }
682 
setStatic()683 void AnimSprite::setStatic()
684 {
685   m_animated = false;
686   m_timer.stop();
687 //   AnimSpritePool::changeable().removeSprite(this);
688 }
689 
applyZoomFactor(qreal zoomFactor)690 void AnimSprite::applyZoomFactor(qreal zoomFactor)
691 {
692   qCDebug(KSIRK_LOG) << "old zoom=" << m_zoom ;
693   m_zoom *= zoomFactor;
694   m_width *= m_zoom;
695   m_height *= m_zoom;
696 
697   sequenceConstruction();
698   update();
699 }
700 
addDecoration(const QString & svgid,const QRectF & geometry)701 void AnimSprite::addDecoration(const QString& svgid, const QRectF& geometry)
702 {
703   QSize size(geometry.size().toSize());
704   QImage image(size, QImage::Format_ARGB32_Premultiplied);
705   image.fill(0);
706   QPainter p(&image);
707   m_renderer->render(&p, svgid);
708   QPixmap pm = QPixmap::fromImage(image);
709   QGraphicsPixmapItem* item = new QGraphicsPixmapItem(pm,this);
710   item->setPos(geometry.topLeft());
711   item->show();
712 }
713 
714 } // closing namespace Ksirk
715 
716 
717