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

Led::Led(QWidget* parent): QWidget(parent)
{
	setMinimumSize(QSize(40,40));
	setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
}

bool Led::lit() const
{
	return lit_;
}

void Led::setLit(bool lit)
{
	if(lit != lit_)
	{
		lit_ = lit;
		stateChanged(lit_);
		update();
	}
}

void Led::paintEvent(QPaintEvent* event)
{
	Q_UNUSED(event)
	QPainter ledPainter(this);
	ledPainter.setRenderHint(QPainter::Antialiasing, true);
	ledPainter.setPen(Qt::black);
	if(lit_)
		ledPainter.setBrush(Qt::green);
	else
		ledPainter.setBrush(Qt::red);
	ledPainter.drawEllipse(rect().adjusted(0, 0, -1, -1));
}
