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

#include "animatedcolorattr.h"
#include "animatednumber.h"
#include "number.h"
#include "urireference.h"

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

// KDE
#include <kdebug.h>

StrokeAttribute::StrokeAttribute( ElementNode* parent ) : Attribute(ATTR_STROKE),
    m_parentElement(parent)
{
  if (!parent)
    kdWarning() << "StrokeAttribute::StrokeAttribute() - NULL parent given. This won't work" << endl;
  init();
}

StrokeAttribute::StrokeAttribute( const StrokeAttribute &other ) : Attribute(ATTR_STROKE),
    m_parentElement(0)
{
  init();
  *this = other;
}

StrokeAttribute::~StrokeAttribute()
{
  delete m_color;
  delete m_strokeOpacity;
  delete m_strokeWidth;
}

/**
 * Overloaded = Operator
 * Note that the m_parentElement Attr won't be copied
 */
StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute &other)
{
  Attribute::operator=(other);
  *m_ref = other.ref();
  m_strokeType = other.strokeType();
  *m_strokeOpacity = other.strokeOpacity();
  *m_strokeWidth = other.strokeWidth();
  *m_color = other.color();
  return *this;
}

Attribute* StrokeAttribute::clone()
{
  StrokeAttribute* retElem = new StrokeAttribute(m_parentElement);
  *retElem = *this;
  return ( retElem );
}

void StrokeAttribute::init( )
{
  m_strokeType = STROKE_NONE; // Spec default
  m_ref = new URIReference(m_parentElement,false);
  m_color = new AnimatedColor();
  m_strokeOpacity = new AnimatedNumber();
  m_strokeOpacity->baseVal().setValue(1.0); // Spec default
  m_strokeWidth = new AnimatedNumber();
  m_strokeWidth->baseVal().setValue(1.0); // Spec default
}

const QString StrokeAttribute::readableStrokeType( ) const
{
  switch(m_strokeType)
  {
    case STROKE_UNSPECIFIED:
      return "Unspecified";
      break;
    case STROKE_NONE:
      return "None";
      break;
    case STROKE_SOLID:
      return "Solid";
      break;
    case STROKE_REF:
      return "PaintServer";
      break;
/*    case STROKE_GRADIENT:
      return "Gradient";
      break;
    case STROKE_PATTERN:
      return "Pattern";
      break;*/
    case STROKE_UNKNOWN:
      return "Unknown";
      break;
    default:
      return QString::null;
      break;
  }
}

void StrokeAttribute::setStrokeType( unsigned int t )
{
  m_strokeType = t;
  setValid();
}

void StrokeAttribute::accept( AVisitor &a )
{
  a.visit(*this);
}

