/***************************************************************************
 *   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 VECTORPATH_H
#define VECTORPATH_H

#include <kcanvas/KCanvasPath.h>  // FIXME: replace this with a wrapper or a pathSegment class
#include <qstring.h>

class AnimatedLength;
class QPoint;
class Attribute;
/**
Represents vector data as simple geometric objects (circle, rectangle,...) and Lists of PathSegments
 
@author Hans Oischinger
*/
class VectorPath
{
public:

  // All VectorPaths can be represented by one ofthe following
  // ShapeMetaType values.
  // This allows us to treat simple shapes as such but also as PathSegments
  // if we need those for vector editing
  enum ShapeMetaType
  {
    SHAPE_NONE,
    SHAPE_CIRCLE,
    SHAPE_RECT,
    SHAPE_RRECT,
    SHAPE_ELLIPSE,
    SHAPE_LINE,
    SHAPE_POLYLINE,
    SHAPE_POLYGON,
    SHAPE_PATH
  };

  VectorPath( ShapeMetaType type = SHAPE_NONE );
  virtual ~VectorPath();

  VectorPath( const VectorPath& );

  virtual VectorPath *clone();
  VectorPath &operator=(const VectorPath &);

  const ShapeMetaType shapeMetaType() const { return m_shapeMetaType; }
  void setShapeMetaType( ShapeMetaType metaType ) { m_shapeMetaType = metaType; }
  QString getReadeableShapeMetaType();

  virtual Attribute* getAttrByName( const QString& name );

  // getPathSegments() <- TODO: implement this according to Karbon's Subpath

  void moveTo(double x, double y, bool abs=true);
  void lineTo(double x, double y, bool abs=true);
  void lineToHorizontal(double x, bool abs = true);
  void lineToVertical(double y, bool abs = true);
  void curveTo(double x1, double y1, double x2, double y2, double x, double y, bool abs=true);
  void curveToCubicSmooth(double x2, double y2, double x, double y, bool abs=true);
  void curveToArc(double x, double y, double r1, double r2, double angle, bool largeArcFlag, bool sweepFlag, bool abs=true);
  void closePath();

  QPoint currentPoint();
  KCPathDataList* kcPathData() const { return m_pathData; }

  // MetaType Attributes
  AnimatedLength &getX1() const { return *m_x1; }
  AnimatedLength &getY1() const { return *m_y1; }
  AnimatedLength &getX2() const { return *m_x2; }
  AnimatedLength &getY2() const { return *m_y2; }
  AnimatedLength &getX3() const { return *m_x3; }
  AnimatedLength &getY3() const { return *m_y3; }
  // Convenience Functions
  AnimatedLength &getX() const { return *m_x1; }
  AnimatedLength &getY() const { return *m_y1; }
  // RECT
  AnimatedLength &getWidth() const { return *m_x2; }
  AnimatedLength &getHeight() const { return *m_y2; }
  // CIRCLE
  AnimatedLength &getRadius() const { return *m_x2; }
  // ELLIPSE
  AnimatedLength &getRadiusX() const { return *m_x3; }
  AnimatedLength &getRadiusY() const { return *m_y3; }
  // RRECT
  AnimatedLength &getRX() const { return *m_x3; }
  AnimatedLength &getRY() const { return *m_y3; }

private:
  ShapeMetaType m_shapeMetaType;
  KCPathDataList* m_pathData;

  // Attributes depending on metaType
  AnimatedLength *m_x1; // XPos
  AnimatedLength *m_y1; // YPos
  AnimatedLength *m_x2; // RECT(width), CIRCLE(radius), ELLIPSE(radiusx), LINE(X2)
  AnimatedLength *m_y2; // RECT(height), ELLIPSE(radiusy), LINE(Y2)
  AnimatedLength *m_x3; // RRECT(rx)
  AnimatedLength *m_y3; // RRECT(ry)
};

#endif
