/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2013                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    .

*/

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

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

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

#include "TxRxWidget.h"
#include <QPainter>
#define TXRX_WIDGET_SIZE 30

CTxRxWidget::CTxRxWidget(QString Label)
{
    mRxLedOffPixmap = new QGraphicsPixmapItem(QPixmap("./Images/green-led-off-md.png").scaled(TXRX_WIDGET_SIZE,TXRX_WIDGET_SIZE),this);
    mRxLedOnPixmap = new QGraphicsPixmapItem(QPixmap("./Images/green-led-on-md.png").scaled(TXRX_WIDGET_SIZE,TXRX_WIDGET_SIZE),this);
    mTxLedOffPixmap = new QGraphicsPixmapItem(QPixmap("./Images/red-led-off-md.png").scaled(TXRX_WIDGET_SIZE,TXRX_WIDGET_SIZE),this);
    mTxLedOnPixmap = new QGraphicsPixmapItem(QPixmap("./Images/red-led-on-md.png").scaled(TXRX_WIDGET_SIZE,TXRX_WIDGET_SIZE),this);

    mRxLedOffPixmap->setPos(0,20);
    mRxLedOnPixmap->setPos(0,20);
    mTxLedOffPixmap->setPos(30,20);
    mTxLedOnPixmap->setPos(30,20);

    mRxLedOnPixmap->hide();
    mTxLedOnPixmap->hide();

    mRxToggleTimer = new QTimer();
    connect(mRxToggleTimer, SIGNAL(timeout()), this, SLOT(ToggleRxLed()));
    mRxToggleTimer->setSingleShot(true);

    mTxToggleTimer = new QTimer();
    connect(mTxToggleTimer, SIGNAL(timeout()), this, SLOT(ToggleTxLed()));
    mTxToggleTimer->setSingleShot(true);

    mLabel = new QGraphicsTextItem(this);
    mLabel->setPlainText(Label);
    mLabel->setPos(5,0);



}

CTxRxWidget::~CTxRxWidget()
{
}

void CTxRxWidget::Receive()
{
    mRxLedOnPixmap->show();
    mRxLedOffPixmap->hide();
    mRxToggleTimer->start(100);
}

void CTxRxWidget::Transmit()
{
    mTxLedOnPixmap->show();
    mTxLedOffPixmap->hide();
    mTxToggleTimer->start(50);
}

void CTxRxWidget::ToggleRxLed()
{
    mRxLedOnPixmap->hide();
    mRxLedOffPixmap->show();

}
void CTxRxWidget::ToggleTxLed()
{
    mTxLedOnPixmap->hide();
    mTxLedOffPixmap->show();

}
