96 lines
2.6 KiB
C++
96 lines
2.6 KiB
C++
/**
|
|
* @file PaiLabel.cpp
|
|
* @date 2011-10-17
|
|
*/
|
|
#include <QPainter>
|
|
|
|
#include "PaiLabel.h"
|
|
|
|
using namespace pai::gui;
|
|
|
|
PaiLabel::PaiLabel(QWidget *pParent) :
|
|
QLabel(pParent),
|
|
m_PromptType(PT_NO_STYLE)
|
|
{
|
|
// TODO Auto-generated constructor stub
|
|
}
|
|
|
|
PaiLabel::PaiLabel(const QString & text, QWidget *pParent) :
|
|
QLabel(text, pParent),
|
|
m_PromptType(PT_NO_STYLE)
|
|
{
|
|
// TODO Auto-generated constructor stub
|
|
}
|
|
|
|
PaiLabel::~PaiLabel()
|
|
{
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
void PaiLabel::ShowPromptMessge(PromptType type)
|
|
{
|
|
m_PromptType = type;
|
|
|
|
// 刷新提示区域
|
|
update();
|
|
}
|
|
|
|
void PaiLabel::paintEvent(QPaintEvent *pEvent)
|
|
{
|
|
QPainter painter(this);
|
|
|
|
QFontMetrics fontMetrics(font());
|
|
|
|
switch(m_PromptType)
|
|
{
|
|
case PT_Information:
|
|
{
|
|
painter.setPen(QColor("#829bb5"));
|
|
QString showText = fontMetrics.elidedText(text(), Qt::ElideRight, width());
|
|
painter.drawText(rect(), Qt::AlignVCenter | Qt::AlignLeft, showText);
|
|
break;
|
|
}
|
|
case PT_Question:
|
|
{
|
|
painter.setPen(QColor("#829bb5"));
|
|
QString showText = fontMetrics.elidedText(text(), Qt::ElideRight, width());
|
|
painter.drawText(rect(), Qt::AlignVCenter | Qt::AlignLeft, showText);
|
|
break;
|
|
}
|
|
case PT_Warning:
|
|
{
|
|
QPixmap warnPixmap(":/warn.png");
|
|
painter.drawPixmap(0, (this->height() - warnPixmap.height()) / 2, warnPixmap);
|
|
|
|
painter.setPen(QColor("#829bb5"));
|
|
QString showText = fontMetrics.elidedText(text(), Qt::ElideRight, width() - warnPixmap.width());
|
|
painter.drawText(rect().adjusted(warnPixmap.width(), 0, 0, 0), Qt::AlignVCenter | Qt::AlignLeft, showText);
|
|
break;
|
|
}
|
|
case PT_Error:
|
|
{
|
|
QPixmap errPixmap(":/error.png");
|
|
painter.drawPixmap(0, (this->height() - errPixmap.height()) / 2, errPixmap);
|
|
|
|
painter.setPen(Qt::red);
|
|
QString showText = fontMetrics.elidedText(text(), Qt::ElideRight, width() - errPixmap.width());
|
|
painter.drawText(rect().adjusted(errPixmap.width() + 3, 0, 0, 0), Qt::AlignVCenter | Qt::AlignLeft, showText);
|
|
}
|
|
break;
|
|
case PT_NO_STYLE_Text:
|
|
{
|
|
QString showText = fontMetrics.elidedText(text(), Qt::ElideRight, width());
|
|
painter.drawText(rect(), Qt::AlignVCenter | Qt::AlignLeft, showText);
|
|
break;
|
|
}
|
|
case PT_NO_STYLE:
|
|
{
|
|
QLabel::paintEvent(pEvent);
|
|
break;
|
|
}
|
|
default:
|
|
QLabel::paintEvent(pEvent);
|
|
break;
|
|
}
|
|
}
|