49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#include "ringsprogressbar.h"
|
|
#include <QPainter>
|
|
#include <QFont>
|
|
|
|
#include "../../common/mydefine.h"
|
|
|
|
RingsProgressbar::RingsProgressbar(QWidget *parent) :
|
|
QWidget(parent)
|
|
{}
|
|
|
|
RingsProgressbar::~RingsProgressbar()
|
|
{}
|
|
|
|
void RingsProgressbar::paintEvent(QPaintEvent *)
|
|
{
|
|
QPainter p(this);
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
m_rotateAngle = 360*m_persent/100;
|
|
|
|
int side = qMin(width(), height());
|
|
QRectF outRect(0, 0, side, side);
|
|
QRectF inRect(10, 10, side - 20, side - 20);
|
|
QString valueStr = QString("%1%").arg(QString::number(m_persent));
|
|
|
|
//画外圆
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(QBrush(QColor(COLOR_LIGHT_BLUE)));
|
|
p.drawEllipse(outRect);
|
|
p.setBrush(QBrush(QColor(COLOR_BLUE)));
|
|
p.drawPie(QRectF(5 , 5, side - 10, side - 10), (90-m_rotateAngle)*16, m_rotateAngle*16);
|
|
//画遮罩
|
|
p.setBrush(palette().window().color());
|
|
p.drawEllipse(inRect);
|
|
//画文字
|
|
QFont f = this->font();
|
|
f.setBold(true);
|
|
f.setPixelSize(25);
|
|
p.setFont(f);
|
|
p.setPen(QColor(COLOR_BLUE));
|
|
p.drawText(inRect, Qt::AlignCenter, valueStr);
|
|
}
|
|
|
|
void RingsProgressbar::setPersent(int persent)
|
|
{
|
|
m_persent = persent;
|
|
repaint();
|
|
}
|