Пример #1
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();
}
Пример #2
0
void myGauge2::drawTextRect(QPainter *painter)
{
    painter->save();
    qreal rectWidth=m_coverCircleRadius/5;

    QPointF topLeftPot(m_center.x()-1.5*rectWidth,m_center.y()+rectWidth*2);
    QPointF bottomRightPot(topLeftPot.x()+3*rectWidth,topLeftPot.y()+rectWidth*2);
    QRectF textRect(topLeftPot,bottomRightPot);

    painter->setPen(Qt::NoPen);
    painter->setBrush(QColor(0,170,255));
    painter->setOpacity(0.6);
    painter->drawRoundRect(textRect,ANGLE1,ANGLE1);

    qreal fontSize=textRect.height()/2;
    QFont font;
    font.setPointSize(fontSize);
    painter->setFont(font);

    painter->setOpacity(1.0);
    painter->setPen(Qt::black);
    QString strValue;
    strValue=tr("%1").arg(m_value);
    painter->drawText(textRect,Qt::AlignHCenter|Qt::AlignVCenter,strValue);
    painter->restore();
}
void PSV_CircularIndicatorItem::drawColorPie(int zValue)
{
    double colorCircleRadius = m_colorCircleRadiusRatio * m_outerRadius;
    QPointF topLeftPot(m_rect.center().x()-colorCircleRadius, m_rect.center().y()-colorCircleRadius);
    QPointF bottomRightPot(m_rect.center().x()+colorCircleRadius, m_rect.center().y()+colorCircleRadius);
    QRectF colorCircleRect=QRectF(topLeftPot, bottomRightPot);


    QMapIterator<double,QColor> iter(m_levelInfos);

    int startAngle = 225 * 16;
    double dValue = m_max -m_min;
    if(qAbs(dValue) < PSV_ZEOR)
    {
        dValue = 100;
        m_max = 100;
        m_min = 0;
    }
    int spanAngle = 0;
    int topAngle = 0;
    while(iter.hasNext())
    {
        iter.next();
        spanAngle = (int)(16 * 270 * iter.key()) - topAngle;
        topAngle += spanAngle;
        QGraphicsEllipseItem* item = new QGraphicsEllipseItem(this);
        item->setRect(colorCircleRect);
        item->setStartAngle(startAngle - spanAngle);
        item->setSpanAngle(spanAngle);
        item->setPen(QPen(Qt::NoPen));
        item->setBrush(QBrush(iter.value()));
        item->setZValue(zValue);
        startAngle = startAngle - spanAngle;
    }
}
void PSV_CircularIndicatorItem::drawTextRect(int zValue)
{
    qreal rectWidth = m_coverCircleRadiusRatio * m_outerRadius / 5;
    QPointF topLeftPot(m_rect.center().x()-1.5*rectWidth, m_rect.center().y()+rectWidth*2);
    QPointF bottomRightPot(topLeftPot.x()+3*rectWidth, topLeftPot.y()+rectWidth*2);
    QRectF textRect(topLeftPot, bottomRightPot);
    qreal fontSize=textRect.height()/2;
    QFont font;
    font.setPointSizeF(fontSize);
    QString strValue;
    strValue=QString("%1").arg(m_value);
    //    {
    //        QGraphicsRectItem *item = new QGraphicsRectItem(this);
    //        item->setRect(textRect);
    //        item->setPen(QPen(Qt::NoPen));
    //        item->setOpacity(0.6);
    //        item->setBrush(QColor(0, 170, 255));
    //        item->setZValue(zValue);
    //    }
    {
        m_textItem = new QGraphicsSimpleTextItem(strValue, this);
        m_textItem->setOpacity(1);
        m_textItem->setFont(m_valueFont);
        m_textItem->setZValue(zValue);
        QPointF pointF = m_textItem->boundingRect().center();
        //        m_textItem->moveBy(textRect.center().x() - pointF.x(), textRect.center().y() - pointF.y());
        m_textItem->moveBy(m_rect.center().x() - pointF.x(), m_rect.center().y() - pointF.y());
    }
}
Пример #5
0
void CIndicator::drawVariables(QPainter *painter)
{
    m_leftSpace=boundingRect().width()/10;
    m_topSpace=boundingRect().height()/25;
    m_lcdWidth=(boundingRect().width()-(boundingRect().width()/5))/3;
    m_lcdHeight=boundingRect().height()/12;

    QPointF topLeftPot(m_leftSpace,m_topSpace);
    m_rectTopLeft=topLeftPot;
    QPointF bottomRightPot(boundingRect().width()-m_leftSpace,boundingRect().height()-2*m_topSpace-m_lcdHeight);
    m_rectBottomRight=bottomRightPot;
}
Пример #6
0
void CIndicator::drawGraph(QPainter *painter)
{
    painter->save();
    painter->setPen(QPen(Qt::transparent,INDICATOR_PEN_WIDTH));

    QLinearGradient graphGradient(m_rectTopLeft,QPointF(m_rectTopLeft.x(),m_rectBottomRight.y()));
    graphGradient.setColorAt(0.0,forecolor);
    painter->setBrush(graphGradient);

    qreal dY=(qreal)(m_rectTopLeft.y()-m_rectBottomRight.y())/100;

    qreal yValue=dY*m_currValue;

    QPointF topLeftPot(m_rectTopLeft.x()+INDICATOR_PEN_WIDTH,m_rectBottomRight.y()+yValue);
    QPointF bottomRightPot(m_rectBottomRight.x()-INDICATOR_PEN_WIDTH,m_rectBottomRight.y());
    QRectF graphRect(topLeftPot,bottomRightPot);
    painter->drawRect(graphRect);

    QString strCurrValue;
    strCurrValue=tr("%1").arg((m_currValue));
    if(m_currValue<10)
    {
        lcd[0]->setValue(0);
        lcd[1]->setValue(0);
        lcd[2]->setValue(m_currValue);
    }
    else if(m_currValue < 100 && m_currValue >= 10)
    {
        lcd[0]->setValue(0);
        lcd[1]->setValue(strCurrValue.at(0).digitValue());
        lcd[2]->setValue(strCurrValue.at(1).digitValue());
    }
    else
    {
        lcd[0]->setValue(1);
        lcd[1]->setValue(0);
        lcd[2]->setValue(0);
    }
    painter->restore();
}
Пример #7
0
void myCoolBar::drawBar(QPainter *painter)
{
    m_increment=width()/(m_Max-m_Min);
    painter->save();
    qreal top=(qreal)(height()-BAR_HEIGHT)/2;
    qreal bottom=top+BAR_HEIGHT;
    QPointF topLeftPot(LEFT_WIDTH,top);
    QPointF bottomRightPot(width()-RIGHT_WIDTH,bottom);
    QRectF barRect(topLeftPot,bottomRightPot);
    m_barRect=barRect;

    QLinearGradient barGradient(barRect.topLeft(),barRect.bottomLeft());
    barGradient.setColorAt(0.0,QColor(230,230,230));
    barGradient.setColorAt(0.2,QColor(120,120,120));
    barGradient.setColorAt(0.5,QColor(230,230,230));
    barGradient.setColorAt(0.0,QColor(230,230,230));
    painter->setBrush(barGradient);

    painter->drawRoundedRect(barRect,RECT_RADIUS,RECT_RADIUS);

    painter->restore();
}
Пример #8
0
void CThermoMeterItem::drawGraph(QPainter *painter)
{
    painter->save();
    qreal bucketHeight=m_bucketRect.height();
    qreal increment=(qreal)bucketHeight/100;

    QPointF bottomRightPot(m_bucketRect.bottomRight());
    qreal currentY=m_currentValue*increment;

    QPointF topLeftPot(m_bucketRect.topLeft().x(),m_bucketRect.bottomLeft().y()-currentY);
    QRectF graphRect(topLeftPot,bottomRightPot);
    painter->setPen(Qt::NoPen);

    QLinearGradient graphGradient(graphRect.topLeft(),graphRect.topRight());
    painter->setOpacity(0.7);

    graphGradient.setColorAt(0.0,this->graphcolor);

    painter->setBrush(graphGradient);
    painter->drawRect(graphRect);
    painter->restore();
}
Пример #9
0
void myGauge1::drawTextRect(QPainter* painter)
{
    painter->save();
    qreal rectWidth=(m_colorPieRadius-m_coverCircleRadius)/2;

    painter->setOpacity(0.7);
    QPointF topLeftPot(m_center.x()-rectWidth,m_center.y()-rectWidth);
    QPointF bottomRightPot(m_center.x()+rectWidth,m_center.y()+rectWidth);
    QRectF textRect(topLeftPot,bottomRightPot);
    painter->setPen(Qt::NoPen);
    painter->setBrush(Qt::cyan);
    painter->drawRoundRect(textRect,rectWidth*2,rectWidth*2);

    painter->setOpacity(1.0);
    painter->setPen(Qt::black);
    qreal fontSize=rectWidth*0.75;
    QFont font;
    font.setPointSize(fontSize);
    painter->setFont(font);
    painter->drawText(textRect,Qt::AlignVCenter|Qt::AlignHCenter,tr("%1").arg(m_value));
    painter->restore();
}
Пример #10
0
void myGauge2::drawColorPie(QPainter *painter)
{
    painter->save();

    QPointF topLeftPot(m_center.x()-m_colorCircleRadius,m_center.y()-m_colorCircleRadius);
    QPointF bottomRightPot(m_center.x()+m_colorCircleRadius,m_center.y()+m_colorCircleRadius);
    m_colorCircleRect=QRectF(topLeftPot,bottomRightPot);
    painter->setPen(Qt::NoPen);

    QConicalGradient greenGradient(m_center,m_innerRadius);
    greenGradient.setColorAt(0.0,QColor(0,30,0));
    greenGradient.setColorAt(0.25,QColor(0,230,0));
    greenGradient.setColorAt(1.0,QColor(0,230,0));
    painter->setBrush(Qt::green);
    painter->drawPie(m_colorCircleRect,45*16,180*16);

    painter->setBrush(QColor(218,218,0));
    painter->drawPie(m_colorCircleRect,0*16,45*16);

    painter->setBrush(QColor(240,50,50));
    painter->drawPie(m_colorCircleRect,0,-45*16);

    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

}