Пример #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 myCoolBar::drawIndicator(QPainter *painter)
{
    painter->save();

   if(m_firstRun)
    {
        m_indicatorY=m_barRect.center().y();
        m_indicatorX=m_barRect.topLeft().x()+m_indicatorPos+INDICATOR_RADIUS;
        QPointF indicatorCenter(m_indicatorX,m_indicatorY);
        m_lastPot=indicatorCenter;
        m_firstRun=false;
    }
    m_lastPot.setY(m_barRect.center().y());

    QPointF indicatorTopLeftPot(m_lastPot.x()-INDICATOR_RADIUS,m_lastPot.y()-INDICATOR_RADIUS);
    QPointF indicatorBottomRightPot(m_lastPot.x()+INDICATOR_RADIUS,m_lastPot.y()+INDICATOR_RADIUS);

    QRectF indicatorRect(indicatorTopLeftPot,indicatorBottomRightPot);
    m_indicatorRect=indicatorRect;

    QLinearGradient indicatorGradient(indicatorRect.topLeft(),indicatorRect.bottomRight());
    indicatorGradient.setColorAt(0.0,QColor(230,230,230));
    indicatorGradient.setColorAt(0.4,QColor(120,120,120));
    indicatorGradient.setColorAt(1.0,QColor(230,230,230));
    painter->setBrush(indicatorGradient);
    painter->drawEllipse(indicatorRect.center(),INDICATOR_RADIUS,INDICATOR_RADIUS);

   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

}