102 lines
2.1 KiB
C++
102 lines
2.1 KiB
C++
#include "LoadingWidget.h"
|
|
|
|
#include <QTimer>
|
|
#include <QtMath>
|
|
#include <QPainter>
|
|
#include <QDebug>
|
|
|
|
LoadingWidget::LoadingWidget(QWidget* aParent)
|
|
: QWidget(aParent)
|
|
, mTimer(new QTimer(this))
|
|
, mColor(QColor(Qt::white))
|
|
, mCount(12)
|
|
, mMaxDiameter(30)
|
|
, mMinDiameter(5)
|
|
{
|
|
connect(mTimer,&QTimer::timeout,this,QOverload<>::of(&QWidget::repaint));
|
|
initPaintArea();
|
|
}
|
|
|
|
LoadingWidget::~LoadingWidget()
|
|
{
|
|
|
|
}
|
|
|
|
void LoadingWidget::setMaxDiameter(const int aValue)
|
|
{
|
|
mMaxDiameter = aValue;
|
|
}
|
|
|
|
void LoadingWidget::setMinDiameter(const int aValue)
|
|
{
|
|
mMinDiameter = aValue;
|
|
}
|
|
|
|
void LoadingWidget::setColor(const QColor& aColor)
|
|
{
|
|
mColor = aColor;
|
|
}
|
|
|
|
void LoadingWidget::setCount(const int aCount)
|
|
{
|
|
mCount = aCount;
|
|
}
|
|
|
|
void LoadingWidget::resizeEvent(QResizeEvent *aEvent)
|
|
{
|
|
QWidget::resizeEvent(aEvent);
|
|
initPaintArea();
|
|
}
|
|
|
|
void LoadingWidget::showEvent(QShowEvent *aEvent)
|
|
{
|
|
QWidget::showEvent(aEvent);
|
|
mTimer->start(60);
|
|
}
|
|
|
|
void LoadingWidget::hideEvent(QHideEvent *aEvent)
|
|
{
|
|
QWidget::hideEvent(aEvent);
|
|
mTimer->stop();
|
|
}
|
|
|
|
void LoadingWidget::initPaintArea()
|
|
{
|
|
double halfWidth = width() /2;
|
|
double halfHeight = height() /2;
|
|
double half = qMin(width(),height())/2;
|
|
double distance = half - mMaxDiameter/2 - 1;
|
|
|
|
double gap = (mMaxDiameter - mMinDiameter)/(mCount-1)/2;
|
|
double angleGap = 360/mCount;
|
|
|
|
mPointList.clear();
|
|
mRadiusList.clear();
|
|
|
|
for(int i=0;i<mCount;i++)
|
|
{
|
|
mRadiusList << mMaxDiameter/2-i*gap;
|
|
double radian = qDegreesToRadians(angleGap*i);
|
|
mPointList.append(QPointF(halfWidth + distance*qCos(radian),halfHeight - distance*qSin(radian)));
|
|
}
|
|
}
|
|
|
|
void LoadingWidget::paintEvent(QPaintEvent *aEvent)
|
|
{
|
|
if(mStatus == mCount)
|
|
{
|
|
mStatus = 0;
|
|
}
|
|
QWidget::paintEvent(aEvent);
|
|
QPainter painter(this);
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
painter.setPen(mColor);
|
|
painter.setBrush(mColor);
|
|
for(int i=0;i<mCount;i++)
|
|
{
|
|
double radius= mRadiusList.at((mStatus + i)%mCount);
|
|
painter.drawEllipse(mPointList.at(i),radius,radius);
|
|
}
|
|
++mStatus;
|
|
}
|