/***************************************************************************
 *   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 "stopelement.h"

// Elements
#include "elements/animatednumber.h"
#include "elements/animatedcolorattr.h"
#include "elements/number.h"

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

// Qt
#include <qrect.h>

StopElement::StopElement()
    : ElementNode()
{
  init();
}

StopElement::~StopElement()
{
  delete m_offset;
  delete m_stopColor;
  delete m_stopOpacity;
}

StopElement::StopElement( const StopElement &other )
    : ElementNode()
{
  init();
  (*this) = other;
}

StopElement& StopElement::operator=(const StopElement &other)
{
  ElementNode::operator=(other);
  *m_offset = other.getOffset();
  *m_stopColor = other.getStopColor();
  *m_stopOpacity = other.getStopOpacity();

  return *this;
}

ElementNode* StopElement::clone()
{
  StopElement* retElem = new StopElement();
  *retElem = *this;
  return ( retElem );
}

void StopElement::init()
{
  m_offset = new AnimatedNumber();
  m_offset->baseVal().setValue(0);  // SVG default
  m_offset->baseVal().setValid(false);

  m_stopColor = new AnimatedColor();

  m_stopOpacity = new AnimatedNumber();
  m_stopOpacity->baseVal().setValue(1);  // SVG default
  m_stopOpacity->baseVal().setValid(false);
}

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

Attribute * StopElement::getAttrByName( const QString & name )
{
  if (name == "offset")
    return m_offset;
  else if (name == "stop-color")
    return m_stopColor;
  else if (name == "stop-opacity")
    return m_stopOpacity;
  else
    return 0;
}

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

#include "stopelement.moc"
