//****************************************************************************
//Copyright (C) 2005-2006 Beijing BlueDJ Technology Co.,Ltd. All rights reserved.

//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 (in the file LICENSE.GPL); if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

//Please visit http://www.bluedj.com for more infomation about us.
//Contact us at ggwizard@gmail.com or darkdong@gmail.com.
//****************************************************************************/

#ifndef DJSHOWVIEW_H
#define DJSHOWVIEW_H

#include <Qt3Support>
#include <QtGui>
#include <QtXml>
#include "DJBaseGlobal.h"

class DJMatrixCanvasText;
class DJMatrixCanvasImage;
class DJMatrixCanvasSprite;
class DJGameUser;
class DJShowView;

class DJ_BASE_EXPORT DJShowItem : public QObject
{
	Q_OBJECT
public:
	DJShowItem( DJShowView *showView, const QString& name, DJGameUser* user,
				double x, double y, double z, bool isAnimated,
				const QMatrix& innerMatrix = QMatrix() );
	virtual ~DJShowItem();
	
	void description();
	void createItem();
	void show();
	void hide();
	bool isReady() const;
	void setLifeTime( int second );
	void setAlignment( Qt::AlignmentFlag flag );
	//void canvasResized( const QSize& realSize, const QSize& newSize );
	void setInnerMatrix( const QMatrix& matrix );
	void setExternalMatrix( const QMatrix& matrix );
	//quint32 itemId() const { return m_itemId; }
	QString name() const { return m_name; }
	double x() const { return m_x; }
	double y() const { return m_y; }
	double z() const { return m_z; }
	bool isAnimated() const { return m_isAnimated; }
signals:
	void itemIsReady();
protected:
	virtual void timerEvent( QTimerEvent * event );
private slots:
	void showImageDone();
private:
	DJShowView	*m_showView;
	//quint32		m_itemId;
	QString		m_name;
	double		m_x;
	double		m_y;
	double		m_z;
	bool		m_isAnimated;
	QString		m_localImagePath;
	bool		m_hasStartedTimer;
	int			m_lifeTime;
	void		*m_item;
	QMatrix		m_innerMatrix;
};

class DJ_BASE_EXPORT DJShowView : public Q3CanvasView
{
    Q_OBJECT 
public:
    DJShowView( DJGameUser* user, QWidget* parent = 0 );
    virtual ~DJShowView();

	virtual QSize sizeHint() const;
	void setUser( DJGameUser* user );
	
	void setAlignment( Qt::Alignment flag );
	void matrimove( const QPoint& point );
	void matrimove( int x, int y );
	void move( const QPoint& point );
	void move( int x, int y );
	
	QSize	realSize() const { return m_realSize; }
	void setRealSize( const QSize& size );
	void setRealSize( int width, int height );
	QMatrix scaleMatrix() const;
	void setExternalMatrix( const QMatrix& matrix );
	void clearAllItems();
	
	void createDefaultItems();
	void showDefaultShow();
	void hideDefaultShow();
	
	void createCustomItems( const QString& xmlPath );
	void showCustomShow();
	void hideCustomShow();
	bool isAllCustomItemsReady();
	
	void addEffect( const QString& name, int second = 10 );
signals:
	void rightClicked( quint32 userId );
protected:   
	virtual void resizeEvent( QResizeEvent * event );
	virtual void contentsMouseReleaseEvent( QMouseEvent * e );
private slots:
	void showXmlDone( const QString& filePath );
	void customItemIsReady();
	
private:
	QHash<quint32,QString>	m_showXmls;
	DJGameUser			*m_user;
	QList<DJShowItem*>	m_defaultItems;
	QList<DJShowItem*>	m_customItems;
	QHash<QString, DJShowItem*>	m_effectItems;
	QSize				m_realSize;
	Qt::Alignment		m_alignment;
	QMatrix				m_externalMatrix;
	int					m_x,m_y;
};

#endif
