10 #include <QPainterPath>
15 #define DESIRED_SAMPLES 800
30 timer =
new QTimer(
this);
51 int sampleCount = samples.size(), x =
XMARGIN + w, y;
52 if (sampleCount > 0) {
54 for (
int i = 0; i < sampleCount; ++i) {
65 QPainter painter(
this);
66 painter.fillRect(rect(), Qt::black);
68 if (
fMax <= 0.0f)
return;
70 QColor axisCol(Qt::gray);
72 painter.setPen(axisCol);
76 int base = floor(log10(
fMax));
77 float val = pow(10.0f, base);
79 const QString units = tr(
"KB/s");
80 const float yMarginText = 2.0;
83 painter.setPen(axisCol);
84 painter.drawText(
XMARGIN,
YMARGIN + h - h * val /
fMax - yMarginText, QString(
"%1 %2").arg(val).arg(units));
85 for (
float y = val; y <
fMax; y += val) {
90 if (
fMax / val <= 3.0f) {
91 axisCol = axisCol.darker();
92 val = pow(10.0f, base - 1);
93 painter.setPen(axisCol);
94 painter.drawText(
XMARGIN,
YMARGIN + h - h * val /
fMax - yMarginText, QString(
"%1 %2").arg(val).arg(units));
96 for (
float y = val; y <
fMax; y += val, count++) {
108 painter.fillPath(p, QColor(0, 255, 0, 128));
109 painter.setPen(Qt::green);
115 painter.fillPath(p, QColor(255, 0, 0, 128));
116 painter.setPen(Qt::red);
143 if (f > tmax) tmax = f;
146 if (f > tmax) tmax = f;
157 timer->setInterval(msecsPerSample);