Example #1
0
void BarsPainter::paint()
{
    //Create a new painter
    QPainter qpN(m_widget);
    //Draw grid and BG
    drawBackground(qpN);
    drawGrid(qpN);

    //Set a white color for the main rectangle
    qpN.setPen(QColor(255,255,255,255));


    //Compute size of the data and step size
    int size = m_cache.size();
    if (size <= 0)
    {
        std::cout<<"ERROR : NO DATA PROVIDED, CACHE SIZE IS 0"<<std::endl;
        return;
    }
    float steps = (m_width-size ) / (size);

    int subSize = m_cache[0].size();
    //Lets loop for each bar needed to be drawn
    for(int i = 0 ; i < size;i++)
    {
        //Let set the background color (zero alpha is transparent)
        qpN.setBrush(QColor(100,100,100,0));

        //Lets draw the container rectangle
        qpN.drawRoundedRect((steps*(i))+(i*2) ,0,(steps),m_height-1,
                         3,3,Qt::AbsoluteSize);

        //Lets theck if the size is big enough to contain the percentage value
        //Then lets draw the actual rectangle
        if (steps > 80)
            painterUtils::drawRectangleBar(qpN ,i*steps+3 + i*2,steps,
                                           m_height,m_cache[i].values()[subSize-1], true,
                                           m_color1,
                                           m_color2);
        else
            painterUtils::drawRectangleBar(qpN ,i*steps+3 + i*2,steps,
                                           m_height,m_cache[i].values()[subSize-1], false,
                                           m_color1,
                                           m_color2);
    }
}
void GraphMultiColorPainter::paint()
{

    //checkColors
    checkColors();


    QColor m_back = QColor(0,180,0,0);

    //Create a new painter
    QPainter qpN(m_widget);
    //Draw gird and BG
    drawBackground(qpN);
    drawGrid(qpN);
    //Compute size of the data and step size
    int size = m_cache.size();
    qpN.setBrush(m_back);
    qpN.drawRoundedRect(0 ,0,m_width -2 ,m_height-1,
                     3,3,Qt::AbsoluteSize);

    bool legendOnOff = (MIN_LEGEND_WIDTH * size) <= m_width;


    for(int i = 0 ; i < (size);i++)
    {
       //lets use our utils to draw the graph
       m_back = m_colors[size-i-1];
       m_back.setAlpha(80);
       painterUtils:: drawRectangleGraph(qpN,0,
                                         m_width,m_height,m_cache[size-i-1],
                                         m_colors[size-i-1],m_back);

       //paint legend
       if (legendOnOff )
       {
                QString text = QString("#") + QString::number(size-i-1);
                qpN.drawText(MIN_LEGEND_WIDTH *(size-i-1) +5,15,text);



       }
    }


}
void GraphPainter::paint()
{
    //Create a new painter
    QPainter qpN(m_widget);
    //Draw gird and BG
    drawBackground(qpN);
    drawGrid(qpN);

    //Set a white color for the main rectangle
    qpN.setPen(QColor(255,255,255,255));

    //Compute size of the data and step size
    int size = m_cache.size();
    int sizeLess  = size -1;

    if (sizeLess <= 0)
    {
        sizeLess = 1;

    }
    float steps = (m_width- m_cache.size() ) / (size);
    for(int i = 0 ; i < (size);i++)
    {
        //Let set needed colors for the background and borer
        qpN.setPen(QColor(244,244,244,255));
        qpN.setBrush(QColor(100,100,100,0));
        qpN.drawRoundedRect((steps*(i))+(i*2) ,0,(steps),m_height-1,
                         3,3,Qt::AbsoluteSize);

       //lets use our utils to draw the graph
       painterUtils:: drawRectangleGraph(qpN,(steps*(i))+(i*2)-1,
                                         steps,m_height,m_cache[i],
                                         m_color1,m_color2);


        }


}