/***************************************************************************
                          qmetapicture.h  -  description
                             -------------------
    begin                : Fri Aug 22 2003
    copyright            : (C) 2003 by Armando Navarro-Vazquez
    email                : qoajnv@usc.es
 ***************************************************************************/

/***************************************************************************
 *   Copyright (C) 2003 by Armando Navarro-Vazquez                         *
 *   qoajnv@usc.es                                                         *
 *                                                                         *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the       *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to    *
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:                                             *
 *                                                                         *
 *   The above copyright notice and this permission notice shall be        *
 *   included in all copies or substantial portions of the Software.       *
 *                                                                         *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
 ***************************************************************************/

#ifndef QMETAPICTURE_H
#define QMETAPICTURE_H

#include <qobject.h>
//Added by qt3to4:
#include <QMouseEvent>
#include <list>


/**
  *@author Armando Navarro-Vazquez
  */



class QMouseEvent;
class QMatrix;
/** a class to manage drawing, translation and scaling of QPicture objects on a
  *  drawing surface */
class QMetaPicture : QObject {

  friend class QMetaPictureList;
  public:
  /** construct a QPicture from a data array of given size */ 
	  QMetaPicture(const char* data,unsigned int size);
    /** No descriptions */
    ~QMetaPicture();
    /** draw the QPicture contents */
    void draw(QPainter* p);
    /** Get the Bounding Rect of the QPicture */
    QRect getBoundingRect(); 
    /** return true if picture is currently selected*/
    bool isSelected() { return m_selected; }

  protected: // Protected methods
  /** return true is point is between bounding rect limits */
  bool contains(const QPoint& point);
  /** No descriptions */
  void drawRect(QPainter* p);
  /** No descriptions */
  void mousePressEvent(QMouseEvent* e);
  /** No descriptions */
  void mouseMoveEvent(QMouseEvent* e);
  private: // Private attributes

  Q3Picture* m_picture;
  bool m_selected;
  /** a bidimensional vector */
  template <class X> struct dvector
  { dvector() { x=0;  y=0;}
    X x;
    X y;
  };
  dvector<int> m_translate;
  dvector<float> m_scale;
  dvector<int> m_scaletranslation;

  QRect activerect[8];
  /**  */
  QPoint m_oldpoint;
  /**  */
  int m_movemode;

private: // Private methods
  /**  translate to transformed coordinates*/
  QPoint translatePoint(const QPoint&  point);
  /**  translate to transformed coordinates*/
  QRect translateRect(const QRect& rect);
  /** Get the transformation vectors*/
  void resolveVectors(int a, int b, const QPoint&,bool coord);
};

/** a stl based container for a list of QMetaPicture objects*/
class QMetaPictureList 
{
  public:
  QMetaPictureList();
  ~QMetaPictureList();
  /** select the first object containing point*/
  void select(const QPoint& point);
  /** returns a pointer to the QMetaPicture object currently selected*/
  QMetaPicture* getSelected();
  /** add a QMetaPicture object*/
  void  push_back(QMetaPicture* pic);
  /** draw the full list of QMetaPicture objects*/
  void  draw(QPainter* p);
  void mousePressEvent(QMouseEvent* e);
  void mouseMoveEvent(QMouseEvent* e);
  private:
  std::list<QMetaPicture*> list;

};
/** A class to pass QPicture data through the clipboard. It can return the data either
  * in QPicture native format or SVG format*/
class QPicMimeSource : public QMimeSource  {

  private: // Private attributes
  /** data of the picture , add at the beginning, more possibilities
  to be understood */
   char* m_data;
   /** size of data */
   unsigned int m_size;
  public:
    /** Pass a pointer to the QPicture object to be copied */
    QPicMimeSource(Q3Picture* picture);
	  ~QPicMimeSource();
    /** return data either in QPicture  or svg format. To request the SVG format
      * pass the image/x-svg+xml or image/x-svg MIME types. Any other string will
      return QPicture native data */
  QByteArray encodedData(const char* data) const;
  /** return availables formats. For the QPicture native format I have chosen
   * image/x-vnd.trolltech.qpicture and image/x-svg+xml for SVG format
   * representation*/
  virtual const char* format(int i=0) const;
  /** copy to the global clibpoard */
  void copy();
  /** true if requested format is provided. Currently image/x-vnd.trolltech.qpicture
   * and image/x-svg+xml */
  bool provides(const char* format);
  /**  Same fuction than provides(const char* format) provided
    * by convenience*/
  bool canDecode(const char* format);


};

#endif

