ZT/sources/GuiElements/LedWidget.cpp

78 lines
2.3 KiB
C++

/*******************************************************************************
* *
* Société de Transports de Montréal. *
* 2013 *
* *
* Projet Zones Tests *
* *
* *
* *
*******************************************************************************/
/*
Description:
Affiche un bitmap d'une DEL verte (allumée ou éteinte).
*/
/* ************************************************************************** */
/* Revision:
### 20131024 JFM
Verision d'origine.
### YYYYMMDD Description du besoin ou du bug
Description du changement.
*/
#include "LedWidget.h"
#include <QFontMetrics>
CLedWidget::CLedWidget(QString Label,QGraphicsItem *Parent)
{
setParentItem(Parent);
mLabel = new QGraphicsTextItem(this);
mLedOnPixmap = new QGraphicsPixmapItem(this);
mLedONImage.load("./Images/green-led-on-md.png");
mLedOffPixmap = new QGraphicsPixmapItem(this);
mLedOFFImage.load("./Images/green-led-off-md.png");
mLabel->setPlainText(Label);
mLabel->adjustSize();
LedOFF();
resize(25,25);
}
void CLedWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
{
Q_UNUSED(event)
mLedOnPixmap->setPixmap(QPixmap().fromImage(mLedONImage).scaled(boundingRect().width(),boundingRect().height()));
mLedOffPixmap->setPixmap(QPixmap().fromImage(mLedOFFImage).scaled(boundingRect().width(),boundingRect().height()));
mLabel->setPos((boundingRect().width()/2) - ((QFontMetrics(mLabel->font()).width(mLabel->toPlainText()))/2),boundingRect().height());
}
void CLedWidget::LedOFF()
{
mLedOnPixmap->hide();
mLedOffPixmap->show();
}
void CLedWidget::LedON()
{
mLedOnPixmap->show();
mLedOffPixmap->hide();
}
void CLedWidget::SetLed(bool ON)
{
if(ON == true)
LedON();
else
LedOFF();
}