File indexing completed on 2024-04-21 04:04:45

0001 /* This file is part of KsirK.
0002    Copyright (C) 2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KsirK is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, either version 2
0007    of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; if not, write to the Free Software
0016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017    02110-1301, USA
0018 */
0019 
0020 /*  begin                : Thu Feb 22 2007  */
0021 
0022 #include "animspritesgroup.h"
0023 
0024 #include "ksirk_debug.h"
0025 
0026 namespace Ksirk
0027 {
0028 
0029 AnimSpritesGroup::AnimSpritesGroup(QObject* target, const char* slot, QObject* parent):
0030   QObject(parent), AnimSpritesList<AnimSprite>(),
0031   m_numberArrived(0), m_target(target), m_slot(slot)
0032 {
0033   qCDebug(KSIRK_LOG);
0034   connect (this,SIGNAL(arrived(AnimSpritesGroup*)),target,slot);
0035 }
0036 
0037 AnimSpritesGroup::~AnimSpritesGroup() 
0038 {
0039 }
0040 
0041 void AnimSpritesGroup::changeTarget(QObject* target, const char* slot)
0042 {
0043   qCDebug(KSIRK_LOG) << (void*)target << slot;
0044   if (m_target != nullptr)
0045   {
0046     disconnect(this,SIGNAL(arrived(AnimSpritesGroup*)),m_target,m_slot);
0047   }
0048   m_target = target;
0049   m_slot = slot;
0050   connect (this,SIGNAL(arrived(AnimSpritesGroup*)),target,slot);
0051 }
0052 
0053 void AnimSpritesGroup::clear()
0054 {
0055   qCDebug(KSIRK_LOG) << size();
0056   disconnect(this,SIGNAL(arrived(AnimSpritesGroup*)),m_target,m_slot);
0057   m_target = nullptr; 
0058   m_slot = nullptr;
0059   m_numberArrived = 0;
0060   hideAndRemoveAll();
0061   AnimSpritesList<AnimSprite>::clear();
0062 }
0063 
0064 
0065 void AnimSpritesGroup::addSprite(AnimSprite* sprite)
0066 {
0067   push_back(sprite);
0068   qCDebug(KSIRK_LOG) << "now" << size();
0069   connect(sprite, &AnimSprite::atDestination,this,&AnimSpritesGroup::oneArrived);
0070   connect(sprite, &AnimSprite::animationFinished,this,&AnimSpritesGroup::oneArrived);
0071 }
0072 
0073 void AnimSpritesGroup::oneArrived(AnimSprite* sprite)
0074 {
0075   m_numberArrived++;
0076   qCDebug(KSIRK_LOG) << (void*)sprite << ":" << m_numberArrived << " on " << AnimSpritesList<AnimSprite>::size();
0077   // if 0 is given, then one is count as arrived whithout action. Useful for 
0078   // non-animated sprites of the group, but ugly solution...
0079   if (sprite != nullptr)
0080   {
0081     sprite->arrival();
0082   }
0083   if (m_numberArrived == (unsigned int)AnimSpritesList<AnimSprite>::size())
0084   {
0085     emit arrived(this);
0086     m_numberArrived = 0;
0087   }
0088 }
0089 
0090 }
0091 
0092 #include "moc_animspritesgroup.cpp"