/***************************************************************************
 *   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.             *
 ***************************************************************************/
#ifndef ELEMENT_H
#define ELEMENT_H

#include <qobject.h>
#include <qstring.h>

#include <kcanvas/KCanvasTypes.h> // for BBOXFLAGS

class QPoint;
class QRect;
class Visitor;
class Attribute;
/**
Base interface for all Elements
 
@author Hans Oischinger
*/
class Element : public QObject
{
  Q_OBJECT
public:

  enum State {
    undefined     , /// see parent for State
    normal        , /// visible, not active
    normal_locked , /// visible, but locked (r/o)
    hidden        , /// hidden
    hidden_locked , /// hidden and locked (r/o)
    deleted       , /// deleted, nearly dead

    // shape specific states:
    /*
        Now in isSelected():
        selected      = 5,	/// visible, active and can be manipulated by tools
        edit          = 6	/// visible, active and is currently manipulated by a tool*/
  };

  enum Hit { NOHIT, PATHHIT, FILLHIT };


  Element( const QString & name = "", unsigned int state = undefined );
  Element( const Element & );
  virtual ~Element();

  Element &operator=(const Element &);

  /* TODO:
    virtual const QRect& boundingBox() const = 0;
  virtual VStroke* stroke() const { return m_stroke; }
  virtual VFill* fill() const { return m_fill; }

  virtual void setStroke( const VStroke& stroke );
  virtual void setFill( const VFill& fill );
  */

  virtual QString name() const { return m_name; }
  virtual void setName( const QString & name ) { m_name = name; }

  virtual QString readAbleType() { return className(); }

  virtual QString id() const { return m_id; } // The same as SVG's ID attribute
  virtual void setId( const QString & id ) { m_id = id; }

  virtual void setState( unsigned int state ) { m_state = state; }
  virtual unsigned int getState() const { return m_state; }

  virtual void setSelected( bool b ) { m_selected = b; }
  virtual bool isSelected() const { return m_selected; }

  virtual Element::Hit hits( const QPoint & ) = 0;
  // Returns an unscaled bounding box for this vector path
  virtual QRect bbox(KCBBoxFlags flags = BBOX_DEFAULT) const = 0;

  // Returns an attibute for the given name and 0 if none exists
  virtual Attribute* getAttrByName( const QString& name );

  // Accept a VVisitor.
  virtual void accept( Visitor& ) = 0;

  double isContextDirty() const { return m_contextDirty; }
  void setDirty( bool dirty = true ) { m_contextDirty = dirty; }

  const QString& desc() const { return m_desc; }
  void setDesc( const QString& desc ) { m_desc = desc; }
  const QString& title() const { return m_title; }
  void setTitle( const QString& title ) { m_title = title; }

protected:
  QString m_name;
  QString m_id;
  QString m_desc;
  QString m_title;
  unsigned int m_state;
  bool m_selected;

  bool m_contextDirty; // some visual attribute has been changed and we need a render update
};

#endif
