#ifndef Q2048TILE_H
#define Q2048TILE_H

#include <QGraphicsItemGroup>
//#include <QBrush>

class Q2048View;
class QGraphicsSimpleTextItem;
class QGraphicsRectItem;
class QParallelAnimationGroup;
class QAbstractAnimation;

class Q2048Tile : public QObject, public QGraphicsItemGroup
{
	Q_OBJECT
public:
	Q_PROPERTY(QPointF pos READ pos WRITE setPos)
	Q_PROPERTY(QColor brush READ brush WRITE setBrush)
	Q_PROPERTY(qreal scale READ scale WRITE setScale)

	Q2048Tile(int x, int y, Q2048View* v);
	virtual ~Q2048Tile();
	int value (void) const {return Value;}
	void shift(int dx, int dy);
	void grow (int v = -1);
	static Q2048Tile* getTile(int x, int y);
	//static Q2048Tile* getTile(int i);
	static int count();
	static void animate();
	typedef QMap <int, QColor> ColorMapT;
	static ColorMapT initColorMap();
	QColor brush(void) const;
	void setBrush(QColor);
	int getX(void) const {return X;}
	int getY(void) const {return Y;}
	void setZValue(qreal z);
	void removeTile(void);
private:
	void addAnimation(QAbstractAnimation* a);
	static QParallelAnimationGroup* Animation;
	static ColorMapT ColorMap;
	typedef QList <Q2048Tile*> TilesListT;
	static TilesListT Tiles;
	static const int AnimationDuration=100;
	int X;
	int Y;
	//int Index;
	int Value;
	Q2048View* View;
	QGraphicsSimpleTextItem* TextItem;
	QGraphicsRectItem* RectItem;
};

#endif // Q2048TILE_H
