/***************************************************************************
 *   Copyright (C) 2004 by Hans Oischinger                                 *
 *   hans.oischinger@kdemail.net                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#include "animateelement.h"

// Visitors
#include "visitors/visitor.h"

// Elements
#include "attribute.h"
#include "urireference.h"
#include "transformlist.h"
#include "lengthattribute.h"
#include "timeattribute.h"

// Qt
#include <qrect.h>

// KDE
#include <kdebug.h>

AnimateElement::AnimateElement(URIReference& targetElem, const QString & name, State state)
    : ElementNode( name, state),
    m_ref(0),
    m_fill(0),
    m_begin(0),
    m_duration(0),
    m_additive(true)
{
  m_begin = new TimeAttribute();
  m_duration = new TimeAttribute();
  m_ref = new URIReference(this);
  *m_ref = targetElem;
}

AnimateElement::~AnimateElement()
{
  delete m_begin;
  delete m_duration;
  delete m_ref;
}

AnimateElement::AnimateElement( const AnimateElement &other )
    : ElementNode(),
    m_ref(0),
    m_fill(0)
{
  m_begin = new TimeAttribute();
  m_duration = new TimeAttribute();
  m_ref = new URIReference(this);
  (*this) = other;
}

AnimateElement& AnimateElement::operator=(const AnimateElement &other)
{
  ElementNode::operator=(other);
  *m_begin = other.getStartTime();
  *m_duration = other.getSimpleDuration();
  *m_ref=other.ref();
  m_fill = other.getFill();
  m_additive = other.isAdditive();
  return *this;
}

void AnimateElement::accept( Visitor& visitor )
{
  visitor.visit( *this );
}

QRect AnimateElement::bbox( KCBBoxFlags flags ) const
{
  return QRect();
}

Attribute * AnimateElement::getAttrByName( const QString & name )
{
  if ( name == "starttime" )
    return m_begin;
  else if ( name == "simpleduration" )
    return m_duration;
  else
    return 0;
}






AnimateTransformElement::AnimateTransformElement( URIReference& targetElem
    , AnimatedTransformList *targetAttr, const QString & name, State state )
    : AnimateElement(targetElem, name, state),
    m_targetAttr(targetAttr),
    m_from(0),
    m_by(0),
    m_to(0)
{
  init();
}

AnimateTransformElement::~ AnimateTransformElement( )
{}

AnimateTransformElement::AnimateTransformElement( const AnimateTransformElement &other )
    : AnimateElement(other.ref()),
    m_from(0),
    m_by(0),
    m_to(0)
{
  init();
}

AnimateTransformElement& AnimateTransformElement::operator =( const AnimateTransformElement &other )
{
  AnimateElement::operator=(other);
  m_targetAttr = other.targetAttribute();
  *m_from = other.fromAttribute();
  *m_by = other.byAttribute();
  *m_to = other.toAttribute();
  return *this;
}

ElementNode * AnimateTransformElement::clone( )
{
  AnimateTransformElement* retElem = new AnimateTransformElement(*m_ref, m_targetAttr);
  *retElem = *this;
  return ( retElem );
}

void AnimateTransformElement::accept( Visitor & visitor )
{
  visitor.visit( *this );
}

void AnimateTransformElement::init( )
{
  m_attrList = new QPtrList<TimekeyedTransform>();
  m_from = new Transform();
  m_by = new Transform();
  m_to = new Transform();
}

Attribute * AnimateTransformElement::getAttrByName( const QString & name )
{
  if ( name == "to" )
    return m_to;
  else if ( name == "from" )
    return m_from;
  else if ( name == "by" )
    return m_by;
  else
    return AnimateElement::getAttrByName(name);
}





AnimateLengthElement::AnimateLengthElement( URIReference & targetElem, AnimatedLength * targetAttr, const QString & name, State state )
    : AnimateElement(targetElem, name, state),
    m_targetAttr(targetAttr)
{
  m_from = new LengthAttribute();
  m_by = new LengthAttribute();
  m_to = new LengthAttribute();
}

AnimateLengthElement::~AnimateLengthElement( )
{}

AnimateLengthElement::AnimateLengthElement( const AnimateLengthElement &other )
    : AnimateElement(other.ref())
{
  m_from = new LengthAttribute();
  m_by = new LengthAttribute();
  m_to = new LengthAttribute();
  *this = other;
}

AnimateLengthElement& AnimateLengthElement::operator =( const AnimateLengthElement &other )
{
  AnimateElement::operator=(other);
  m_targetAttr = other.targetAttribute();
  *m_from = other.fromAttribute();
  *m_by = other.byAttribute();
  *m_to = other.toAttribute();
  return *this;
}

ElementNode * AnimateLengthElement::clone( )
{
  AnimateLengthElement* retElem = new AnimateLengthElement(*m_ref, m_targetAttr);
  *retElem = *this;
  return ( retElem );
}

void AnimateLengthElement::accept( Visitor & visitor )
{
  visitor.visit( *this );
}

Attribute * AnimateLengthElement::getAttrByName( const QString & name )
{
  if ( name == "to" )
    return m_to;
  else if ( name == "from" )
    return m_from;
  else if ( name == "by" )
    return m_by;
  else
    return AnimateElement::getAttrByName(name);
}





#include "number.h"
AnimateNumberElement::AnimateNumberElement( URIReference& targetElem, AnimatedNumber *targetAttr, const QString & name, State state )
    : AnimateElement(targetElem, name, state),
    m_targetAttr(targetAttr),
    m_from(0),
    m_by(0),
    m_to(0)
{
  m_from = new Number();
  m_by = new Number();
  m_to = new Number();
}

AnimateNumberElement::~AnimateNumberElement( )
{}

AnimateNumberElement::AnimateNumberElement( const AnimateNumberElement &other )
    : AnimateElement(other.ref()),
    m_from(0),
    m_by(0),
    m_to(0)
{
  m_from = new Number();
  m_by = new Number();
  m_to = new Number();
}

AnimateNumberElement& AnimateNumberElement::operator =( const AnimateNumberElement &other )
{
  AnimateElement::operator=(other);
  m_targetAttr = other.targetAttribute();
  *m_from = other.fromAttribute();
  *m_by = other.byAttribute();
  *m_to = other.toAttribute();
  return *this;
}

ElementNode * AnimateNumberElement::clone( )
{
  AnimateNumberElement* retElem = new AnimateNumberElement(*m_ref, m_targetAttr);
  *retElem = *this;
  return ( retElem );
}

void AnimateNumberElement::accept( Visitor & visitor )
{
  visitor.visit( *this );
}

Attribute * AnimateNumberElement::getAttrByName( const QString & name )
{
  if ( name == "to" )
    return m_to;
  else if ( name == "from" )
    return m_from;
  else if ( name == "by" )
    return m_by;
  else
    return AnimateElement::getAttrByName(name);
}










#include "colorattribute.h"

AnimateColorElement::AnimateColorElement( URIReference& targetElem, AnimatedColor *targetAttr, const QString & name, State state )
    : AnimateElement(targetElem, name, state),
    m_targetAttr(targetAttr),
    m_from(0),
    m_by(0),
    m_to(0)
{
  m_from = new ColorAttribute();
  m_by = new ColorAttribute();
  m_to = new ColorAttribute();
}

AnimateColorElement::~AnimateColorElement( )
{}

AnimateColorElement::AnimateColorElement( const AnimateColorElement &other )
    : AnimateElement(other.ref()),
    m_from(0),
    m_by(0),
    m_to(0)
{
  m_from = new ColorAttribute();
  m_by = new ColorAttribute();
  m_to = new ColorAttribute();
}

AnimateColorElement& AnimateColorElement::operator =( const AnimateColorElement &other )
{
  AnimateElement::operator=(other);
  m_targetAttr = other.targetAttribute();
  *m_from = other.fromAttribute();
  *m_by = other.byAttribute();
  *m_to = other.toAttribute();
  return *this;
}

ElementNode* AnimateColorElement::clone()
{
  AnimateColorElement* retElem = new AnimateColorElement(*m_ref, m_targetAttr);
  *retElem = *this;
  return ( retElem );
}

void AnimateColorElement::accept( Visitor & visitor )
{
  visitor.visit( *this );
}

Attribute * AnimateColorElement::getAttrByName( const QString & name )
{
  if ( name == "to" )
    return m_to;
  else if ( name == "from" )
    return m_from;
  else if ( name == "by" )
    return m_by;
  else
    return AnimateElement::getAttrByName(name);
}




#include "animateelement.moc"
