/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012 - 2013                                                                        *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
	Description:
	Élément graphique qui affiche les équipements de la ZT1.
	
*/

/* ************************************************************************** */
/* Revision:
### YYYMMDD JFM
	Verision d'origine.
	
### YYYYMMDD Description du besoin ou du bug
	Description du changement.
 */

/* ************************************************************************** */

#include "ZT1EquipmentWidget.h"
#include <QPainter>

CZT1EquipmentWidget::CZT1EquipmentWidget(QGraphicsItem *Parent)
{
	setParentItem(Parent);
    setGeometry(0,0,320,180);

    QFont LabelFont;
    LabelFont.setPointSize(20);
    mZT1Label = new QGraphicsTextItem(this);
    mZT1Label->setFont(LabelFont);
    mZT1Label->setPlainText("ZT1 - Avant Gare");
    mZT1Label->setPos(boundingRect().x()+(boundingRect().width()/2 - mZT1Label->boundingRect().width()/2),boundingRect().bottom()+10);


    mS1Activated = mS2Activated = mFNActivated = mPPEActivated = mPPIActivated = mPGEActivated = mPGIActivated = false;
	mZT1Active = true;

	mFNRect1.setRect(0,50,boundingRect().width(),10);
	mFNRect2.setRect(0,boundingRect().bottom()-50,boundingRect().width(),10);

    mPGERect.setRect(boundingRect().width()/2-10,10,20,20);
    mPGIRect.setRect(boundingRect().width()/2-10,boundingRect().bottom()-20,20,20);

	mPPERect.setRect(boundingRect().width()-50,65,10,20);
	mPPIRect.setRect(boundingRect().width()-50,boundingRect().bottom() - 75,10,20);

	mS1Rect.setRect(boundingRect().right()-30,boundingRect().bottom()-30,30,20);
	mS2Rect.setRect(0,boundingRect().bottom()-30,30,20);


	mRedBrush = new QBrush(Qt::red);
	mGreenBrush = new QBrush(Qt::darkGreen);
	mHashedBrush = new QBrush(Qt::darkGray/*,Qt::Dense2Pattern*/);
}

void CZT1EquipmentWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(option)
	Q_UNUSED(widget)
//		static int toto = 0;
//		qDebug("CZT1EquipmentWidget::paint %d",toto++);

	if(mZT1Active == false)
	{
		painter->fillRect(mFNRect1,*mHashedBrush);
		painter->fillRect(mFNRect2,*mHashedBrush);
		painter->fillRect(mPGERect,*mHashedBrush);
		painter->fillRect(mPGIRect,*mHashedBrush);
		painter->fillRect(mS1Rect,*mHashedBrush);
		painter->fillRect(mS2Rect,*mHashedBrush);
		painter->fillRect(mPPERect,*mHashedBrush);
		painter->fillRect(mPPIRect,*mHashedBrush);
	}
	else
	{
		QBrush *brush;

		if(mS1Activated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mS1Rect,*brush);

		if(mS2Activated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mS2Rect,*brush);

		if(mPGEActivated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mPGERect,*brush);

		if(mPGIActivated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mPGIRect,*brush);

		if(mPPEActivated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mPPERect,*brush);

		if(mPPIActivated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mPPIRect,*brush);

		if(mFNActivated)
			brush = mRedBrush;
		else
			brush = mGreenBrush;
		painter->fillRect(mFNRect1,*brush);
		painter->fillRect(mFNRect2,*brush);


	}
}

unsigned int CZT1EquipmentWidget::SetState(bool S1, bool S2, bool FN, bool PI, bool PE, bool PPI, bool PPE)
{
	mS1Activated = S1;
	mS2Activated = S2;
	mFNActivated = FN;
	mPGIActivated = PI;
	mPGEActivated = PE;
	mPPIActivated = PPI;
	mPPEActivated = PPE;

	update();

	return RET_OK;
}

unsigned int CZT1EquipmentWidget::SetActivation(bool IsActive)
{
	mZT1Active = IsActive;
	update();

    return RET_OK;
}
