10 #include <QPainterPath>
17 #define DESIRED_SAMPLES 800
32 timer =
new QTimer(
this);
49 int sampleCount = samples.size();
54 for(
int i = 0; i < sampleCount; ++i) {
56 int y =
YMARGIN + h - (int)(h * samples.at(i) /
fMax);
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++) {
105 painter.setRenderHint(QPainter::Antialiasing);
109 painter.fillPath(p, QColor(0, 255, 0, 128));
110 painter.setPen(Qt::green);
116 painter.fillPath(p, QColor(255, 0, 0, 128));
117 painter.setPen(Qt::red);
128 float in_rate_kilobytes_per_sec =
static_cast<float>(bytesIn -
nLastBytesIn) /
timer->interval();
129 float out_rate_kilobytes_per_sec =
static_cast<float>(bytesOut -
nLastBytesOut) /
timer->interval();
130 vSamplesIn.push_front(in_rate_kilobytes_per_sec);
131 vSamplesOut.push_front(out_rate_kilobytes_per_sec);
144 if(f > tmax) tmax = f;
147 if(f > tmax) tmax = f;
156 const auto msecs_per_sample{std::chrono::duration_cast<std::chrono::milliseconds>(
m_range) /
DESIRED_SAMPLES};
158 timer->setInterval(msecs_per_sample);