* @brief QProgressIndicator::paintEvent draw the spinner. */
| 89 | * @brief QProgressIndicator::paintEvent draw the spinner. |
| 90 | */ |
| 91 | void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) { |
| 92 | if (!m_displayedWhenStopped && !isAnimated()) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | int width = qMin(this->width(), this->height()); |
| 97 | |
| 98 | QPainter p(this); |
| 99 | p.setRenderHint(QPainter::Antialiasing); |
| 100 | |
| 101 | auto outerRadius = int((width - 1) * 0.5); |
| 102 | auto innerRadius = int((width - 1) * 0.5 * 0.38); |
| 103 | |
| 104 | int capsuleHeight = outerRadius - innerRadius; |
| 105 | int capsuleWidth = |
| 106 | (width > 32) ? int(capsuleHeight * 0.23) : int(capsuleHeight * 0.35); |
| 107 | int capsuleRadius = capsuleWidth / 2; |
| 108 | |
| 109 | for (int i = 0; i < 12; ++i) { |
| 110 | QColor color = m_color.isValid() ? m_color : palette().windowText().color(); |
| 111 | color.setAlphaF(1.0f - (i / 12.0f)); |
| 112 | p.setPen(Qt::NoPen); |
| 113 | p.setBrush(color); |
| 114 | p.save(); |
| 115 | p.translate(rect().center()); |
| 116 | p.rotate(int(m_angle - i * 30.0f)); |
| 117 | p.drawRoundedRect(int(-capsuleWidth * 0.5), -(innerRadius + capsuleHeight), |
| 118 | capsuleWidth, capsuleHeight, capsuleRadius, |
| 119 | capsuleRadius); |
| 120 | p.restore(); |
| 121 | } |
| 122 | } |