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

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

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

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

CZT2EquipmentWidget::CZT2EquipmentWidget(QGraphicsItem *Parent)
{
	setParentItem(Parent);
    setGeometry(0,0,200,180);

    QFont LabelFont;
    LabelFont.setPointSize(20);
    mZT2Label = new QGraphicsTextItem(this);
    mZT2Label->setFont(LabelFont);
    mZT2Label->setPlainText("ZT2 - Arrière Gare");
    mZT2Label->setPos(boundingRect().x()+(boundingRect().width()/2 - mZT2Label->boundingRect().width()/2),boundingRect().bottom()+10);

    mS1Activated = mPPEActivated = mPPIActivated = false;
    mZT2Active = false;

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

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

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

void CZT2EquipmentWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(option)
	Q_UNUSED(widget)

    if(mZT2Active == false)
	{
		painter->fillRect(mS1Rect,*mHashedBrush);
		painter->fillRect(mPPERect,*mHashedBrush);
		painter->fillRect(mPPIRect,*mHashedBrush);
        painter->fillRect(mRailRect1,*mHashedBrush);
        painter->fillRect(mRailRect2,*mHashedBrush);
	}
	else
	{
		QBrush *brush;

        painter->fillRect(mRailRect1,*mGreenBrush);
        painter->fillRect(mRailRect2,*mGreenBrush);

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

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

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

	}
}

unsigned int CZT2EquipmentWidget::SetState(bool S1,bool PPI, bool PPE)
{
	mS1Activated = S1;
	mPPIActivated = PPI;
	mPPEActivated = PPE;

	update();

	return RET_OK;
}

unsigned int CZT2EquipmentWidget::SetActivation(bool IsActive)
{
    mZT2Active = IsActive;
	update();
    return RET_OK;
}
