Exemplo n.º 1
0
void IntervalProgressDisplay::LinearPaintStrategy::paint(QPainter &p, const PaintContext &context, const PaintColors &colors)
{

    font.setPointSizeF(context.fontSize);

    qreal initialXPos = context.elementsSize / 2.0 + 1;
    qreal xSpace = getHorizontalSpace(context.width, context.elementsSize, context.beatsPerInterval, initialXPos+1);
    qreal yPos = context.height/2.0;

    // draw the background line
    p.setPen(QPen(colors.linesColor, 0.9f));
    p.drawLine(initialXPos + (xSpace * context.currentBeat), yPos, initialXPos + (context.beatsPerInterval - 1) * xSpace, yPos);

    qreal xPos = initialXPos;
    // draw all backgrounds first
    int size = (int)(context.elementsSize * 0.5f);
    for (int i = 0; i < context.beatsPerInterval; i++) {
        bool canDraw = i >= context.currentBeat && (xSpace >= (context.elementsSize * 0.5) || (i % 2 == 0));
        if (canDraw) {
            drawPoint(xPos, yPos, size, p, (i + 1), colors.secondaryBeat, true);
        }
        xPos += xSpace;
    }

    // draw accents
    if (context.showingAccents) {
        xPos = initialXPos;
        qreal size = context.elementsSize * 0.6f;
        for (int i = 0; i < context.beatsPerInterval; i++) {
            if (i > context.currentBeat && context.accentBeats.contains(i)) {
                drawPoint(xPos, yPos, size, p, (i + 1), colors.accentBeat, true);
            }
            xPos += xSpace;
        }
    }
    // draw current beat
    xPos = initialXPos + (context.currentBeat * xSpace);
    QBrush bgPaint(colors.currentBeat);
    bool isIntervalFirstBeat = context.currentBeat == 0;
    bool isMeasureAccentBeat = context.accentBeats.contains(context.currentBeat);
    if (isIntervalFirstBeat || (context.showingAccents && isMeasureAccentBeat )) {
        bgPaint = colors.currentAccentBeat;// QColor(Qt::green);
    }
    drawPoint(xPos, yPos, context.elementsSize, p, (context.currentBeat + 1), bgPaint, false);
}
Exemplo n.º 2
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);


}