/***************************************************************************
                           object.h
                           -------------------
    copyright            : (C) 2004 by Jos van den Oever
    email                : jos@vandenoever.info
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef OBJECT_H
#define OBJECT_H

#include <qwidget.h>
#include <qmatrix.h>
#include <qpixmap.h>
//Added by qt3to4:
#include <QResizeEvent>
#include <QMouseEvent>
#include <QList>
#include <QPaintEvent>
//#include <vector>
//#include <map>
//#include <list>

#include "side.h"
#include "matrix3d.h"

using namespace std;
class Q3Picture;

/* this class implements an object that can be rotate by dragging over it with
   the mouse */
class Object : public QWidget {
Q_OBJECT
public:
	explicit Object(QWidget *, const char *name="");
	void addSide(Side);
	Side &getSide(short i);
	const Side &getSide(short i) const;
	bool hasPicture(const Q3Picture *p1, short i) const;
	void reset();
	void saveOrientation();
	void animateToSavedOrientation();
	void stopAnimation();
	void setPicture(short i, const Q3Picture *p);
	void setOrient(double t, double p, double r);
public slots:
	void rotateX(double);
	void rotateY(double);
	void rotateZ(double);
private slots:
	void animationStep();
protected:
	void paintEvent(QPaintEvent *);
	void mouseMoveEvent ( QMouseEvent * e );
	void mousePressEvent(QMouseEvent *e);
	void mouseReleaseEvent(QMouseEvent *e);
	void resizeEvent ( QResizeEvent * );
	void updateMatrices();
private:
	short elements;
	int lastX, lastY;
	bool firstMouseEvent;
	bool changed;
	bool grabbing;
	bool movedSinceMousePress;
	double scaling;
	double maxdist;
	bool animate;
	int rotangle;
	int currentCursor;

	Matrix3D m;
	QPixmap buffer;
	QList<Side> sides;
	void updateCursor(int x, int w, bool onlyZ=false);
signals:
	void animationFinished();
	void rotatedX(double);
	void rotatedY(double);
	void rotatedZ(double);
	void rotated();
};

#endif
