| 77 | } |
| 78 | |
| 79 | void WaitingSpinnerWidget::paintEvent(QPaintEvent *) { |
| 80 | updatePosition(); |
| 81 | QPainter painter(this); |
| 82 | painter.fillRect(this->rect(), Qt::transparent); |
| 83 | painter.setRenderHint(QPainter::Antialiasing, true); |
| 84 | |
| 85 | if (_currentCounter >= _numberOfLines) { |
| 86 | _currentCounter = 0; |
| 87 | } |
| 88 | |
| 89 | painter.setPen(Qt::NoPen); |
| 90 | for (int i = 0; i < _numberOfLines; ++i) { |
| 91 | painter.save(); |
| 92 | painter.translate(_innerRadius + _lineLength, |
| 93 | _innerRadius + _lineLength); |
| 94 | qreal rotateAngle = |
| 95 | static_cast<qreal>(360 * i) / static_cast<qreal>(_numberOfLines); |
| 96 | painter.rotate(rotateAngle); |
| 97 | painter.translate(_innerRadius, 0); |
| 98 | int distance = |
| 99 | lineCountDistanceFromPrimary(i, _currentCounter, _numberOfLines); |
| 100 | QColor color = |
| 101 | currentLineColor(distance, _numberOfLines, _trailFadePercentage, |
| 102 | _minimumTrailOpacity, _color); |
| 103 | painter.setBrush(color); |
| 104 | // TODO improve the way rounded rect is painted |
| 105 | painter.drawRoundedRect( |
| 106 | QRect(0, -_lineWidth / 2, _lineLength, _lineWidth), _roundness, |
| 107 | _roundness, Qt::RelativeSize); |
| 108 | painter.restore(); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void WaitingSpinnerWidget::start() { |
| 113 | updatePosition(); |