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

// Elements
#include "animatedtransformlist.h"

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

// Qt
#include <qrect.h>

// KCanvas
#include <kcanvas/KCanvasItem.h>

GroupElement::GroupElement()
    : Transformable(),
    m_context(0)
{}

GroupElement::~GroupElement()
{}

GroupElement::GroupElement( const GroupElement &other )
    : Transformable(),
    m_context(0)
{
  (*this) = other;
}

GroupElement& GroupElement::operator=(const GroupElement &other)
{
  Transformable::operator=(other);
  return *this;
}

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

Attribute* GroupElement::getAttrByName( const QString & name )
{
  return Transformable::getAttrByName( name );
}

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

Element::Hit GroupElement::hits( const QPoint &p )
{
  if ( !m_context )
  {
    return Element::NOHIT;
  }
  if ( m_context->strokeContains(p) )
    return Element::PATHHIT;
  else if ( m_context->fillContains(p) )
    return Element::FILLHIT;
  else
    return Element::NOHIT;
}

QRect GroupElement::bbox( KCBBoxFlags flags ) const
{
  if (!m_context)
    return QRect(0,0,10,10);
  return m_context->bbox(flags);
}

void GroupElement::setContext( KCanvasContainer* context )
{
  // kdDebug() << "Changing context from " << m_context << " to " << context << endl;
  m_context = context;
  if ( m_context )
    m_context->setUserData( this );
}



#include "groupelement.moc"
