1 /* This file is part of KsirK.
2    Copyright (C) 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                : Thu Feb 22 2007  */
21 
22 #include "animspritesgroup.h"
23 
24 #include "ksirk_debug.h"
25 
26 namespace Ksirk
27 {
28 
AnimSpritesGroup(QObject * target,const char * slot,QObject * parent)29 AnimSpritesGroup::AnimSpritesGroup(QObject* target, const char* slot, QObject* parent):
30   QObject(parent), AnimSpritesList<AnimSprite>(),
31   m_numberArrived(0), m_target(target), m_slot(slot)
32 {
33   qCDebug(KSIRK_LOG);
34   connect (this,SIGNAL(arrived(AnimSpritesGroup*)),target,slot);
35 }
36 
~AnimSpritesGroup()37 AnimSpritesGroup::~AnimSpritesGroup()
38 {
39 }
40 
changeTarget(QObject * target,const char * slot)41 void AnimSpritesGroup::changeTarget(QObject* target, const char* slot)
42 {
43   qCDebug(KSIRK_LOG) << (void*)target << slot;
44   if (m_target != 0)
45   {
46     disconnect(this,SIGNAL(arrived(AnimSpritesGroup*)),m_target,m_slot);
47   }
48   m_target = target;
49   m_slot = slot;
50   connect (this,SIGNAL(arrived(AnimSpritesGroup*)),target,slot);
51 }
52 
clear()53 void AnimSpritesGroup::clear()
54 {
55   qCDebug(KSIRK_LOG) << size();
56   disconnect(this,SIGNAL(arrived(AnimSpritesGroup*)),m_target,m_slot);
57   m_target = 0;
58   m_slot = 0;
59   m_numberArrived = 0;
60   hideAndRemoveAll();
61   AnimSpritesList<AnimSprite>::clear();
62 }
63 
64 
addSprite(AnimSprite * sprite)65 void AnimSpritesGroup::addSprite(AnimSprite* sprite)
66 {
67   push_back(sprite);
68   qCDebug(KSIRK_LOG) << "now" << size();
69   connect(sprite, &AnimSprite::atDestination,this,&AnimSpritesGroup::oneArrived);
70   connect(sprite, &AnimSprite::animationFinished,this,&AnimSpritesGroup::oneArrived);
71 }
72 
oneArrived(AnimSprite * sprite)73 void AnimSpritesGroup::oneArrived(AnimSprite* sprite)
74 {
75   m_numberArrived++;
76   qCDebug(KSIRK_LOG) << (void*)sprite << ":" << m_numberArrived << " on " << AnimSpritesList<AnimSprite>::size();
77   // if 0 is given, then one is count as arrived whithout action. Useful for
78   // non-animated sprites of the group, but ugly solution...
79   if (sprite != 0)
80   {
81     sprite->arrival();
82   }
83   if (m_numberArrived == (unsigned int)AnimSpritesList<AnimSprite>::size())
84   {
85     emit arrived(this);
86     m_numberArrived = 0;
87   }
88 }
89 
90 }
91 
92 
93