void IntervalProgressDisplay::EllipticalPaintStrategy::drawCircles(QPainter &p, const QRectF &rect, const PaintContext &context, const PaintColors &colors, int beatsToDraw, int beatsToDrawOffset, bool drawPath) { if (drawPath) { paintEllipticalPath(p, rect, colors, context.currentBeat, beatsToDraw); } qreal angleIncrement = (2 * -PI) / beatsToDraw; double angle = -PI/2 + angleIncrement; qreal hRadius = rect.width()/2; qreal vRadius = rect.height()/2; qreal centerX = rect.center().x(); qreal centerY = rect.center().y(); for (int beat = beatsToDraw-1; beat >= 0; --beat) { // draw the current beat if (beat + beatsToDrawOffset >= context.currentBeat) { qreal x = centerX + ((hRadius) * std::cos(angle)); qreal y = centerY + ((vRadius) * std::sin(angle)); p.setBrush(getBrush(beat, beatsToDrawOffset, context, colors)); p.setPen(getPen(beat, beatsToDrawOffset, context)); qreal size = getCircleSize(beat, beatsToDrawOffset, context); p.drawEllipse(QPointF(x, y), size, size); } angle += angleIncrement; } }
void IntervalProgressDisplay::drawBeatCircles(QPainter& p, int hRadius, int vRadius, int beatCircles, int offset) { paintEllipticalPath(p, hRadius, vRadius); double angle = -PI / 2.0; const float FIRST_COLOR_POSITION = 0.0f; const float SECOND_COLOR_POSITION = 0.99f; //float hRadius = width()/2; //float vRadius = height()/2; for (int i = 0; i < beatCircles; i++) { int x = centerX + (hRadius * std::cos(angle));// - ovalSize /2; int y = (centerY + (vRadius * std::sin(angle))) + ovalSize/2; QRadialGradient brush(x + ovalSize/2, y, ovalSize*2); QPen pen(Qt::NoPen); //p->drawLine(0, centerY, width(), centerY); //beat not played yet brush.setColorAt(FIRST_COLOR_POSITION, Qt::gray); brush.setColorAt(SECOND_COLOR_POSITION, Qt::black); bool isIntervalFirstBeat = i + offset == 0; bool isMeasureFirstBeat = (i + offset) % beatsPerAccent == 0; if (i + offset == currentBeat && (isIntervalFirstBeat || isMeasureFirstBeat)) {//first beats if( isIntervalFirstBeat || isShowingAccents() ){ brush.setColorAt(FIRST_COLOR_POSITION, QColor(255, 100, 100));//accent beat colors brush.setColorAt(SECOND_COLOR_POSITION, Qt::red); } else{ brush.setColorAt(FIRST_COLOR_POSITION, Qt::green); //playing beat highlight colors brush.setColorAt(SECOND_COLOR_POSITION, Qt::darkGreen); } pen.setColor(Qt::darkGray); pen.setStyle(Qt::SolidLine); } else{ if((i + offset) % beatsPerAccent == 0 && (i+offset) > currentBeat){ if(isShowingAccents()){ brush.setColorAt(FIRST_COLOR_POSITION, Qt::white); //accent marks brush.setColorAt(SECOND_COLOR_POSITION, Qt::gray); pen.setColor(Qt::gray); pen.setStyle(Qt::SolidLine); } } else if ( (i + offset) <= currentBeat) { if(i + offset < currentBeat){ brush.setColorAt(FIRST_COLOR_POSITION, PLAYED_BEATS_FIRST_COLOR); //played beats brush.setColorAt(SECOND_COLOR_POSITION, PLAYED_BEATS_SECOND_COLOR); } else{//the current beat is highlighted brush.setColorAt(FIRST_COLOR_POSITION, Qt::green); //playing beat highlight colors brush.setColorAt(SECOND_COLOR_POSITION, Qt::darkGreen); pen.setColor(Qt::darkGreen); pen.setStyle(Qt::SolidLine); } } } p.setBrush(brush); p.setPen( pen ); int size = (i + offset) == currentBeat ? ovalSize + 1 : ovalSize; p.drawEllipse( QPoint(x, y), size, size); if(offset > 0 && currentBeat < offset){//is drawing the first circles? p.setBrush(QColor(255,255, 255, 200)); //the internal circles are drawed transparent p.drawEllipse( QPoint(x, y), size, size); } angle -= 2 * -PI / beatCircles; } }