File: cpupiemarker.cpp

package info (click to toggle)
libqwt 4.2.0-4.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 66
file content (44 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <qpainter.h>
#include "cpuplot.h"
#include "cpupiemarker.h"

CpuPieMarker::CpuPieMarker(CpuPlot *plot):
    QwtPlotMarker(plot)
{
}

void CpuPieMarker::draw(QPainter *p, int, int, const QRect &rect)
{
    const CpuPlot *plot = (CpuPlot *)parentPlot();

    const QwtDiMap yMap = plot->canvasMap(QwtPlot::yLeft);

    const int margin = 5;
    
    QRect pieRect;
    pieRect.setX(rect.x() + margin);
    pieRect.setY(rect.y() + margin);
    pieRect.setHeight(yMap.transform(80.0));
    pieRect.setWidth(pieRect.height());
    
    const int dataType[] = { CpuPlot::User, CpuPlot::System, CpuPlot::Idle };

    int angle = (int)(5760 * 0.75);
    for ( unsigned int i = 0; 
        i < sizeof(dataType) / sizeof(dataType[0]); i++ )
    {
        const QwtPlotCurve *curve = plot->cpuCurve(dataType[i]);
        if ( curve->dataSize() > 0 )
        {
            const int value = (int)(5760 * curve->y(0) / 100.0);

            p->save();
            p->setBrush(QBrush(curve->pen().color(), Qt::SolidPattern));
            p->drawPie(pieRect, -angle, -value);
            p->restore();

            angle += value;
        }
    }
}