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

QBorderLabel::QBorderLabel(QWidget *parent)
    : QLabel(parent),
      active_(false)
{
}

QBorderLabel::~QBorderLabel()
{

}

void QBorderLabel::resizeEvent( QResizeEvent * )
{
    emit resize(this);
}

void QBorderLabel::SetActive( bool val )
{
    active_ = val;
    update(0,0,this->geometry().width()-1,1);
    update(0,this->geometry().height()-1,this->geometry().width()-1,1);
    update(0,0,1,this->geometry().height()-1);
    update(this->geometry().width()-1,0,1,this->geometry().height()-1);
}

void QBorderLabel::paintEvent( QPaintEvent * ev)
{
    QPainter painter(this);
    painter.setPen(Qt::SolidLine);
    if (active_)
    {
        painter.setPen(Qt::red);
    }
    else
    {
        painter.setPen(QColor(170, 170, 255));
    }
    painter.drawRect(QRect(0,0,this->geometry().width()-1,this->geometry().height()-1));
    //QLabel::paintEvent(ev);
}
