| 18 | } |
| 19 | |
| 20 | void SpinnerPainter::paint(QPainter &painter, const QColor &color, const QRect &rect) |
| 21 | { |
| 22 | painter.save(); |
| 23 | if (currentColor != color) { |
| 24 | currentColor = color; |
| 25 | indicatorColors.clear(); |
| 26 | } |
| 27 | |
| 28 | if (indicatorColors.isEmpty()) { |
| 29 | for (int i = 0; i < 3; ++i) |
| 30 | indicatorColors << createDefaultIndicatorColorList(color); |
| 31 | } |
| 32 | |
| 33 | painter.setRenderHints(QPainter::Antialiasing); |
| 34 | auto center = QRectF(rect).center(); |
| 35 | auto radius = qMin(rect.width(), rect.height()) / 2.0; |
| 36 | auto indicatorRadius = radius / 2 / 2 * 1.1; |
| 37 | auto indicatorDegreeDelta = 360 / indicatorColors.count(); |
| 38 | |
| 39 | for (int i = 0; i < indicatorColors.count(); ++i) { |
| 40 | auto colors = indicatorColors.value(i); |
| 41 | for (int j = 0; j < colors.count(); ++j) { |
| 42 | double degreeCurrent = currentDegree - j * indicatorShadowOffset + indicatorDegreeDelta * i; |
| 43 | auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent)); |
| 44 | auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent)); |
| 45 | |
| 46 | x = center.x() + x; |
| 47 | y = center.y() + y; |
| 48 | auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius); |
| 49 | QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2); |
| 50 | |
| 51 | QPainterPath path; |
| 52 | path.addEllipse(rf); |
| 53 | |
| 54 | painter.fillPath(path, colors.value(j)); |
| 55 | } |
| 56 | } |
| 57 | painter.restore(); |
| 58 | } |
| 59 | |
| 60 | void SpinnerPainter::setUpdateCallback(const UpdateCallback &cb) |
| 61 | { |