void IntervalProgressDisplay::setBeatsPerAccent(int beats)
{
    beatsPerAccent = beats;
    if (!isShowingAccents() && beatsPerAccent > 1)
        this->showAccents = true;
    update();
}
void IntervalProgressDisplay::paintEvent(QPaintEvent *e)
{
    Q_UNUSED(e);

    if (paintStrategy) {
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing, true);
        qreal elementsSize = getElementsSize(paintMode);
        qreal fontSize = getFontSize(paintMode);
        PaintContext paintContext(width(), height(), beatsPerInterval, currentBeat, isShowingAccents(), beatsPerAccent, elementsSize, fontSize);
        QColor currentBeatColor = usingLowContrastColors ? Qt::lightGray : Qt::white;
        QBrush textBrush = palette().text(); //using the color define in loaded stylesheet theme
        PaintColors paintColors(currentBeatColor, SECONDARY_BEATS_COLOR, ACCENT_COLOR, CURRENT_ACCENT_COLOR, DISABLED_BEATS_COLOR, textBrush);
        paintStrategy->paint(p, paintContext, paintColors);
    }
}
Ejemplo n.º 3
0
void IntervalProgressDisplay::drawPoints(QPainter* painter, int yPos, int startPoint, int totalPoinstToDraw) {
    int initialXPos = 0 + LINEAR_PAINT_MODE_OVAL_SIZE / 2 + 1;
    float xSpace = getHorizontalSpace(totalPoinstToDraw, initialXPos+1);

    //draw the background line
    painter->setPen(QPen(LINEAR_BORDER_COLOR,1));
    painter->drawLine(initialXPos + 1, yPos, (int) (initialXPos + (totalPoinstToDraw - 1) * xSpace), yPos);

    float xPos = initialXPos;
    //draw all backgrounds first
    for (int i = startPoint; i < totalPoinstToDraw; i++) {
        bool canDraw = xSpace >= LINEAR_PAINT_MODE_OVAL_SIZE || (i % 2 == 0);
        if (canDraw) {
            QColor border = LINEAR_BORDER_COLOR;// (isShowingAccents() && isMeasureFirstBeat) ? accentBorderColor : borderPaint;
            int size = (int) (LINEAR_PAINT_MODE_OVAL_SIZE * 0.7f);// (i < currentInterval) ? ((int) (OVAL_SIZE * 0.7)) : ((int) (OVAL_SIZE * 0.85));
            QColor bg = (i < currentBeat) ? LINEAR_BG_COLOR : LINEAR_BG_SECOND_COLOR;
            drawPoint((int) xPos, yPos, size, painter, (i + 1), bg, border, true);
        }
        xPos += xSpace;
    }

    //draw accents
    if (isShowingAccents()) {
        xPos = initialXPos;
        int size = (int)(LINEAR_PAINT_MODE_OVAL_SIZE * 0.9f);
        for (int i = 0; i < totalPoinstToDraw; i += beatsPerAccent) {
            QColor bg = (i < currentBeat) ? LINEAR_BG_COLOR : LINEAR_BG_SECOND_COLOR;
            drawPoint((int) xPos, yPos, size, painter, (i + 1), bg, LINEAR_ACCENT_BORDER_COLOR, true);
            xPos += xSpace * beatsPerAccent;
        }
    }
    //draw current beat
    xPos = initialXPos + (currentBeat * xSpace);
    QRadialGradient bgRadial(xPos-5, yPos-5, LINEAR_PAINT_MODE_OVAL_SIZE*2);//, new float[]{0.1f, 0.8f},
    bgRadial.setColorAt(0.1f, Qt::white);
    bgRadial.setColorAt(0.8f, Qt::black);
    drawPoint((int) xPos, yPos, LINEAR_PAINT_MODE_OVAL_SIZE, painter, (currentBeat + 1), bgRadial, Qt::darkGray, false);


}
Ejemplo n.º 4
0
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;

    }
}