#ifndef SIGNALS_H
#define SIGNALS_H
#include <QPixmap>
#include <QColor>
//显示信号强度的图标
//模拟类似手机的信号强度图标的绘制,比较简单,欢迎参考
//程序编程人员:Jason's.Alex QQ:531401335
//QT社区群:167304303
//日期:2012/2/10
class Signals : public QPixmap
{
public:
explicit Signals();
QPixmap GetPixmap(const int ping);
private:
QColor GetColor(const int ping);//获取颜色
int GetLineNum(const int ping);//获取线条数量
QPixmap GetSignalPixmap(const QColor &color,const int lineNum);//获取信号位图
};
#endif // SIGNALS_H
#include "signals.h"
#include <QPainter>
//显示信号强度的图标
//模拟类似手机的信号强度图标的绘制,比较简单,欢迎参考
//程序编程人员:Jason's.Alex QQ:531401335
//QT社区群:167304303
//日期:2012/2/10
Signals::Signals()
{
}
QPixmap Signals::GetPixmap(const int ping)
{
return GetSignalPixmap(GetColor(ping),GetLineNum(ping));
}
QColor Signals::GetColor(const int ping )//获取颜色
{
if(ping<=10)
return QColor(0x6a,0x6a,0xff);
else if(ping<=20)
return QColor(0x28,0x94,0xff);
else if(ping<=30)
return QColor(0x00,0xff,0xff);
else if(ping<=40)
return QColor(0x9a,0xff,0x02);
else if(ping<=50)
return QColor(0xe1,0xe1,0x00);
else if(ping<=60)
return QColor(0xea,0xc1,0x00);
else if(ping<=70)
return QColor(0xe8,0x00,0xe8);
else if(ping<=80)
return QColor(0xff,0x00,0x80);
else
return QColor(0xea,0x00,0x00);
}
int Signals::GetLineNum(const int ping)//获取线条数量
{
if(ping<=20)
return 5;
else if(ping<=40)
return 4;
else if(ping<=60)
return 3;
else if(ping<=80)
return 2;
else
return 1;
}
QPixmap Signals::GetSignalPixmap(const QColor &color,const int linenum)//获取信号位图
{
QPixmap pixmap(20,30);
pixmap.fill(QColor(255,255,255,0));
QPainter painter(&pixmap);
painter.setPen(QPen(color,3));
for(int i=1,xpos=0;i<=linenum;++i,++xpos)
{
painter.drawLine(xpos*4,30,xpos*4,33-(i*6));
}
return pixmap;
}