#include "cctrlstatic.h"
#include <QPainter>
CCtrlStatic::CCtrlStatic(QWidget *parent) : CMWidget(parent)
{
    m_iTimerInterval=0;
    m_BKColor=Qt::transparent;
    m_iAlignFlag=Qt::AlignLeft|Qt::AlignVCenter;
    m_text=QString::fromUtf8("N/A");
    setMinimumHeight(30);
}


void CCtrlStatic::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.drawPixmap(2,2,m_Pixmap);
}

void CCtrlStatic::refreshPixmap()
{
    QSize sizeFrame=size();
    sizeFrame.rheight()-=4;
    sizeFrame.rwidth()-=4;
    m_Pixmap=QPixmap(sizeFrame);
    m_Pixmap.fill(m_BKColor);

    QPainter painter(&m_Pixmap);
    if(!painter.isActive()) return;
    painter.initFrom(this);

    QRect  rectFrame=rect();
    rectFrame.adjust(5,0,-5,0);
    painter.drawText(rectFrame,m_iAlignFlag,m_text);
}

void CCtrlStatic::setText(const QString &text, int iAlignFlag)
{
    m_text=text;
    m_iAlignFlag=iAlignFlag;
    refreshPixmap();
    update();
}

void CCtrlStatic::setNum(int n, int iAlignFlag)
{
    setText(QString::number(n),  iAlignFlag);
}

void CCtrlStatic::setNum(double d, int iAlignFlag)
{
    setText(QString::number(d),  iAlignFlag);
}

void CCtrlStatic::showEvent(QShowEvent *)
{
    refreshPixmap();
}
