Example #1
0
void myGauge1::drawMarkAndText(QPainter* painter)
{
    painter->save();
    painter->translate(m_center);

    int value=0;
    QString strValue;
    qreal startAngle=90;
    qreal increment=(qreal)180/100;

    for(int i=0;i<=100;i++)
    {
        painter->save();
        painter->rotate(startAngle);
        if(i%10==0)
        {
            painter->setPen(QColor(16,49,98));
            QPointF bottomPot(0,m_colorPieRadius+m_space);
            QPointF topPot(0,m_colorPieRadius+m_space+m_longHand);
            painter->drawLine(bottomPot,topPot);

            strValue=tr("%1").arg(value);
            qreal textWidth=fontMetrics().width(strValue);
            qreal textHeight=fontMetrics().height();
            QPointF textPot(-textWidth/2,m_colorPieRadius+2*m_space+m_longHand+textHeight);
            painter->save();
            painter->translate(textPot);
            painter->rotate(180);
            painter->drawText(QPointF(-textWidth,textHeight/2),strValue);
            painter->restore();
            value+=10;

        }
        else if(i%5==0)
        {

            painter->setPen(QColor(0,255,17));
            QPointF bottomPot(0,m_colorPieRadius+m_space);
            QPointF topPot(0,m_colorPieRadius+m_space+m_okHand);
            painter->drawLine(bottomPot,topPot);
        }
        else
        {

            painter->setPen(QColor(255,170,0));
            QPointF bottomPot(0,m_colorPieRadius+m_space);
            QPointF topPot(0,m_colorPieRadius+m_space+m_shortHand);
            painter->drawLine(bottomPot,topPot);
        }
        startAngle+=increment;
        painter->restore();
    }
    painter->restore();
}
Example #2
0
void myGauge2::drawMark(QPainter *painter)
{
    painter->save();
    painter->setPen(Qt::white);
    painter->translate(m_center);

    qreal dAngle=(qreal)270/100;
    qreal startAngle=45;
    int value=0;
    QString strValue;
    for(int i=0;i<=100;i++)
    {
        painter->save();
        painter->rotate(startAngle);

        if(i%10==0)
        {
            strValue=tr("%1").arg(value);
            qreal textWidth=fontMetrics().width(strValue);
            qreal textHeight=fontMetrics().height();
            QPointF bottomPot(0,m_colorCircleRadius+SPACE1);
            QPointF topPot(0,m_colorCircleRadius+SPACE1+LONG1);
            painter->drawLine(bottomPot,topPot);
            value+=10;

            painter->save();
            QPointF textPot(0-textWidth/2,m_colorCircleRadius+SPACE1+LONG1+SPACE1+textHeight);
            painter->translate(textPot);
            painter->rotate(180);
            painter->drawText(QPointF(-textWidth,textHeight/2),strValue);
            painter->restore();            
        }
        else if(i%5==0)
        {
            QPointF bottomPot(0,m_colorCircleRadius+SPACE1);
            QPointF topPot(0,m_colorCircleRadius+SPACE1+OK1);
            painter->drawLine(bottomPot,topPot);

        }
        else
        {
            QPointF bottomPot(0,m_colorCircleRadius+SPACE1);
            QPointF topPot(0,m_colorCircleRadius+SPACE1+SHORT1);
            painter->drawLine(bottomPot,topPot);
        }
        painter->restore();
        startAngle+=dAngle;
    }
    painter->restore();
}
Example #3
0
void PerfMon::drawFrame(QPainter *painter)
{
    painter->save();
    QPen framePen(m_frameClr);
    framePen.setStyle(Qt::DotLine);
    painter->setPen(framePen);
    painter->drawRect(rect());

    qreal yIncrement=(qreal)height()/10;
    qreal xIncrement=(qreal)width()/10;
    qreal startX=0;
    qreal startY=0;

    for(int i=0;i<10;i++)
    {

        // draw horizontal lines
        QPointF leftPot(0,startY);
        QPointF rightPot(width(),startY);
        startY+=yIncrement;
        painter->drawLine(leftPot,rightPot);

        // draw vertical lines
        QPointF topPot(startX,0);
        QPointF bottomPot(startX,height());
        startX+=xIncrement;
        painter->drawLine(topPot,bottomPot);
    }

    painter->restore();
}
Example #4
0
void myGauge2::drawIndicator(QPainter *painter)
{
    painter->save();

    painter->translate(m_center);
    qreal increment=(qreal)270/100;
    qreal changedAngle=45+increment*m_currentValue;
    painter->rotate(changedAngle);

    QPointF topPot(0,m_colorCircleRadius+LONG1);
    QPointF bottomLeftPot(-m_coverBallRadius/3,0);
    QPointF bottomRightPot(m_coverBallRadius/3,0);
    painter->setPen(Qt::NoPen);

    QLinearGradient indicatorGradient(topPot,bottomLeftPot);
    indicatorGradient.setColorAt(0.0,QColor(236,187,62));
    indicatorGradient.setColorAt(0.5,QColor(220,147,0));
    indicatorGradient.setColorAt(1.0,QColor(236,187,62));

    painter->setBrush(indicatorGradient);
    QVector<QPointF> potVec;
    potVec.push_back(topPot);
    potVec.push_back(bottomLeftPot);
    potVec.push_back(bottomRightPot);

    painter->drawPolygon(potVec);
    painter->restore();
}
Example #5
0
void ProgressBarColor::drawBar(QPainter *painter)
{
    painter->save();

    //自动计算文字字体大小
    QFont f(font());
    f.setPixelSize((width() / 10) * 0.35);
    painter->setFont(f);

    //计算进度值字符的宽度
    double currentValue = (double)(value - minValue) * 100 / (maxValue - minValue);
    QString strValue = QString("当前值:%1%").arg(currentValue, 0, 'f', precision);
    QString strMaxValue = QString("%1%").arg(maxValue, 0, 'f', precision);
    //字符的宽度取最大值字符的宽度 + 10
    int textWidth = painter->fontMetrics().width(strMaxValue) + 10;

    //绘制进度值背景
    QPointF textTopLeft(width() - space - textWidth, space);
    QPointF textBottomRight(width() - space, height() - space);
    QRectF textRect(textTopLeft, textBottomRight);
    painter->setPen(barBgColor);
    painter->setBrush(barBgColor);
    painter->drawRoundedRect(textRect, radius, radius);

    //绘制进度值
    painter->setPen(textColor);
    painter->drawText(textRect, Qt::AlignCenter, strValue);

    //绘制进度条背景
    QRectF barBgRect(QPointF(space, space), QPointF(width() - space * 2 - textWidth, height() - space));
    painter->setPen(Qt::NoPen);
    painter->setBrush(barBgColor);
    painter->drawRoundedRect(barBgRect, radius, radius);

    //绘制进度条
    double length = width() - space  - space * 2 - textWidth;
    //计算每一格移动多少
    double increment = length / (maxValue - minValue);
    QRectF barRect(QPointF(space, space), QPointF(space + increment * (value - minValue), height() - space));
    painter->setBrush(barColor);
    painter->drawRoundedRect(barRect, radius, radius);

    //绘制背景分割线条 每一格长度7
    painter->setPen(lineColor);
    int initX = 5;
    int lineCount = barBgRect.width() / step;
    double lineX = (double)barBgRect.width() / lineCount;

    //线条高度在进度条高度上 - 1
    while (lineCount > 0) {
        QPointF topPot(initX + lineX, space + 1);
        QPointF bottomPot(initX + lineX, height() - space - 1);
        painter->drawLine(topPot, bottomPot);
        initX += lineX;
        lineCount--;
    }

    painter->restore();
}
Example #6
0
void SliderRuler::drawRule(QPainter *painter)
{
    painter->save();
    painter->setPen(lineColor);

    //绘制横向标尺底部线,居中
    double initX = space;
    double initY = (double)height() / 2;
    lineLeftPot = QPointF(initX, initY);
    lineRightPot = QPointF(width() - initX, initY);
    painter->drawLine(lineLeftPot, lineRightPot);

    //绘制纵向标尺刻度
    double length = width() - 2 * space;
    //计算每一格移动多少
    double increment = length / (maxValue - minValue);

    //根据范围值绘制刻度值及刻度值
    for (int i = minValue; i <= maxValue; i = i + shortStep) {
        if (i % longStep == 0) {
            QPointF topPot(initX, initY - longLineHeight);
            QPointF bottomPot(initX, initY);
            painter->drawLine(topPot, bottomPot);

            QString strValue = QString("%1").arg((double)i, 0, 'f', precision);
            double textWidth = fontMetrics().width(strValue);
            double textHeight = fontMetrics().height();
            QPointF textPot(initX - textWidth / 2, initY + textHeight);
            painter->drawText(textPot, strValue);
        } else {
            QPointF topPot(initX, initY - shortLineHeight);
            QPointF bottomPot(initX, initY);
            painter->drawLine(topPot, bottomPot);
        }

        initX += increment * shortStep;
    }

    painter->restore();
}
Example #7
0
void CThermoMeterItem::drawMark(QPainter *painter)
{
    painter->save();

    qreal initY=m_topSpace;
    qreal initX=m_markSpace;
    qreal length=boundingRect().height()-2*m_topSpace;
    qreal increment=length/100;
    painter->setPen(m_markClr);

    // draw vertical line
    QPointF topPot(m_markSpace,m_topSpace);
    QPointF bottomPot(m_markSpace,boundingRect().height()-m_topSpace);
    painter->drawLine(topPot,bottomPot);

    int vvalue=100;
    QString strValue;
    for(int i=0;i<=100;i++)
    {
        if(i%10==0)
        {
            QPointF leftPot(initX+LONG3,initY);
            QPointF rightPot(initX,initY);
            painter->drawLine(leftPot,rightPot);

            strValue=tr("%1").arg(vvalue);
            qreal fontWidth=painter->fontMetrics().width(strValue);
            qreal fontHeight=painter->fontMetrics().height();

            QPointF textPot(initX-fontWidth-5,initY+fontHeight/2);
            painter->drawText(textPot,strValue);

            vvalue-=10;

        }
        else if(i%5==0 && i%10!=0)
        {
            QPointF leftPot(initX+OK3,initY);
            QPointF rightPot(initX,initY);
            painter->drawLine(leftPot,rightPot);
        }
        else
        {
            QPointF leftPot(initX+SHORT3,initY);
            QPointF rightPot(initX,initY);
            painter->drawLine(leftPot,rightPot);
        }
        initY+=increment;
    }
    painter->restore();
}
Example #8
0
void myGauge1::drawCoverLines(QPainter* painter)
{
    return ;
    painter->save();

    qreal startAngle=90;
    qreal dAngle=(qreal)180/5;
    painter->translate(m_center);
    painter->setPen(QColor(255,0,127));
    for(int i=0;i<=5;i++)
    {
        painter->save();
        painter->rotate(startAngle);
        QPointF topPot(0,m_colorPieRadius);
        QPointF bottomPot(0,m_coverCircleRadius);
        painter->drawLine(topPot,bottomPot);
        painter->restore();
        startAngle+=dAngle;
    }
    painter->restore();
}
void PSV_CircularIndicatorItem::drawIndicator(int zValue)
{
    QPointF center(0, 0);
    QPointF topPot(center.x(), center.y() - m_colorCircleRadiusRatio * m_outerRadius/*m_coverBallRadius*/);
    QPointF bottomLeftPot(center.x() - m_outerRadius * m_indicatorWidthRatio, center.y());
    QPointF bottomRightPot(center.x() + m_outerRadius * m_indicatorWidthRatio, center.y());

    QLinearGradient indicatorGradient(topPot, bottomLeftPot);
    indicatorGradient.setColorAt(0.0, QColor(236, 187, 62));
    indicatorGradient.setColorAt(0.5, QColor(220, 147, 0));
    indicatorGradient.setColorAt(1.0, QColor(236, 187, 62));

    QPolygonF polygon;
    polygon.append(topPot);
    polygon.append(bottomLeftPot);
    polygon.append(bottomRightPot);
    //    if(m_polygonItem == NULL)
    {
        QGraphicsLineItem *item = new QGraphicsLineItem(this);
        item->setPos(m_rect.center().x(), m_rect.center().y());
        item->setZValue(zValue);
        m_polygonItem = new QGraphicsPolygonItem(item);
    }
    m_polygonItem->setPolygon(polygon);
    m_polygonItem->setPen(QPen(Qt::NoPen));
    m_polygonItem->setBrush(indicatorGradient);
    m_polygonItem->setZValue(zValue);
    qreal angle = (m_value - m_min) / (m_max - m_min) * 270 - 135;
    PSV_Public::printMes(angle,"angle");
#if QT_VERSION > QT_VERSION_CHECK(4, 6, 0)
    m_polygonItem->setRotation(angle);
#else
    m_polygonItem->rotate((m_value - m_min) / (m_max - m_min) * 270 - 135);
#endif

}