/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
	Page affichant la liste des passages de train.

*/

/* ************************************************************************** */
/* Revision:
### 20131021 JFM
    Verision d'origine.

### YYYMMDD Description du besoin ou du bug
    Description du changement.
 */

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


#include "RemoteZTPage.h"
#include <QGraphicsProxyWidget>
#include "OutilZT.h"
#include <QString>
#include <QTextCodec>
#include <QHeaderView>
#include <QTextStream>


CRemoteZTPage::~CRemoteZTPage()
{
//    delete mListParsingTimer;
}

CRemoteZTPage::CRemoteZTPage(QGraphicsWidget *Parent)
{
//    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
	setParentItem(Parent);
	mProgramHandle = 0;

    QFont font;
    font.setPointSize(20);
    font.setBold(true);
    mStationName = new QGraphicsTextItem(this);
    mStationName->setPlainText("Non connecté");
    mStationName->setFont(font);
    mStationName->setPos(20,10);

    font.setPointSize(15);
    font.setBold(false);
    mRemoteZTStatus = new QGraphicsTextItem(this);
    mRemoteZTStatus->setPlainText("Status de la ZT:");
    mRemoteZTStatus->setFont(font);
    mRemoteZTStatus->setPos(20,60);

}

void CRemoteZTPage::SetRemoteZTName(QString Name)
{
    mStationName->setPlainText(Name);
}

void CRemoteZTPage::SetRemoteZTStatus(const CTCPZTStatus *status)
{
 //   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QString StatString;
    QTextStream stream(&StatString,QIODevice::ReadWrite);
    StatString.clear();
    stream.seek(0);
    stream.setAutoDetectUnicode(true);

    StatString.append("Status de la ZT:\n");
    StatString.append("ZT1: ");
    switch(status->mZT1Status)
    {
        case SB_ZT_ACTIVE_STATUS:
        {
            StatString.append("ACTIVÉE");
            break;
        }
        case SB_ZT_INACTIVE_STATUS:
        {
            StatString.append("DÉSACTIVÉE");
            break;
        }
        case SB_ZT_NOT_PRESENT_STATUS:
        {
            StatString.append("ABSENTE (!?)");
            break;
        }
        case SB_ZT_DISABLED_STATUS:
        {
            StatString.append("HORS-SERVICE");
            break;
        }
    }
    StatString.append("\n");
    StatString.append("ZT2: ");
    switch(status->mZT2Status)
    {
        case SB_ZT_ACTIVE_STATUS:
        {
            StatString.append("ACTIVÉE");
            break;
        }
        case SB_ZT_INACTIVE_STATUS:
        {
            StatString.append("DÉSACTIVÉE");
            break;
        }
        case SB_ZT_NOT_PRESENT_STATUS:
        {
            StatString.append("ABSENTE");
            break;
        }
        case SB_ZT_DISABLED_STATUS:
        {
            StatString.append("HORS-SERVICE");
            break;
        }
    }
    StatString.append("\n");

    StatString.append(QString("Nombre de passages: %1\n").arg(status->mNbPass));
    StatString.append(QString("Nombre de déclenchements: %1\n").arg(status->mNbTrigs));
    StatString.append(QString("Date de démarrage de la ZT: %1\n").arg(status->mZTStartDateTime.toString("yyyy/MM/dd - hh:mm")));
    StatString.append(QString("Date actuelle de la ZT: %1\n").arg(status->mActualDateTime.toString("yyyy/MM/dd - hh:mm")));
    StatString.append(QString("Seuil du pneu de guidage: %1\n").arg(status->mPGTreshold));
    StatString.append(QString( "Mode Maintenance activé: %1\n").arg(status->mModeMaintenanceON));
    StatString.append(QString("Mode calibration activé: %1\n").arg(status->mCalibModeON));
    StatString.append(QString("Clef USB connectée: %1\n").arg(status->mUSBKeyConnected));
    StatString.append(QString("Frotteur négatif: TK=[%1] - Analyse=[%2]\n").arg(status->mFNTKActive).arg(status->mFNAnalysisActive));
    StatString.append(QString("Pneu de guidage: TK=[%1] - Analyse=[%2]\n").arg(status->mPGTKActive).arg(status->mPGAnalysisActive));
    StatString.append(QString("Pneu porteur: TK=[%1] - Analyse=[%2]\n").arg(status->mPP1TKActive).arg(status->mPP1AnalysisActive));
    StatString.append(QString("Pneu porteur ZT2: TK=[%1] - Analyse=[%2]\n").arg(status->mPP2TKActive).arg(status->mPP2AnalysisActive));
    StatString.append(QString("ZT1: TK=[%1] - Analyse=[%2]\n").arg(status->mZT1TKActive).arg(status->mZT1AnalysisActive));
    StatString.append(QString("ZT2: TK=[%1] - Analyse=[%2]\n").arg(status->mZT2TKActive).arg(status->mZT2AnalysisActive));


    mRemoteZTStatus->setPlainText(StatString);

}

void CRemoteZTPage::resizeEvent(QGraphicsSceneResizeEvent *event)
{
	Q_UNUSED(event)
//	mBackgroundRect->setRect(boundingRect());
}

void CRemoteZTPage::ButtonClicked(CTextButtonWidget *BtnPtr)
{

}

void CRemoteZTPage::NetworkZTConnected(int ID)
{

}
void CRemoteZTPage::NetworkZTDisconnected(int ID)
{
    mStationName->setPlainText("Non connecté");
    mRemoteZTStatus->setPlainText("Status de la ZT:");
}

//Grab the mouse if the user clicks outside buttons
void CRemoteZTPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//    qDebug("CRemoteZTPage");
	Q_UNUSED(event)
}
void CRemoteZTPage::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	Q_UNUSED(event)
}
