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

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

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

// KDE
#include <kdebug.h>

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

FillAttribute::~FillAttribute()
{
  delete m_ref;
  delete m_color;
  delete m_fillOpacity;
}

/**
 * Overloaded = Operator
 * Note that the m_parentElement Attr won't be copied
 */
FillAttribute& FillAttribute::operator=(const FillAttribute &other)
{
  Attribute::operator=(other);
  *m_ref = other.ref();
  *m_fillOpacity = other.fillOpacity();
  m_fillType = other.fillType();
  *m_color = other.color();

  return *this;
}

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

void FillAttribute::init( )
{
  m_fillType = FILL_UNSPECIFIED;
  m_ref = new URIReference(m_parentElement,false);
  m_color = new AnimatedColor();
  m_fillOpacity = new AnimatedNumber();
  m_fillOpacity->baseVal().setValue(1.0);   // Spec default
}

const QString FillAttribute::readableFillType( ) const
{
  switch(m_fillType)
  {
  case FILL_UNSPECIFIED:
    return "Unspecified";
    break;
  case FILL_NONE:
    return "None";
    break;
  case FILL_SOLID:
    return "Solid";
    break;
  case FILL_REF:
    return "PaintServer";
    break;
    /*  case FILL_GRADIENT:
        return "Gradient";
        break;
      case FILL_PATTERN:
        return "Pattern";
        break;*/
  case FILL_UNKNOWN:
    return "Unknown";
    break;
  default:
    return QString::null;
    break;
  }
}

void FillAttribute::setFillType( unsigned int t )
{
  m_fillType = t;
  setValid();
}

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