Bandwidth meter: Bytes -> bits, number formatting (colors, digits, aligment) on dialog

This commit is contained in:
tosh 2013-07-01 10:28:17 +02:00
parent fdf9f10e82
commit 98589adef5
2 changed files with 19 additions and 7 deletions

View file

@ -23,7 +23,7 @@ namespace { // .cpp-local
char const* CAPTION_OUT = "OUT";
char const* CAPTION_UNIT = "Mbps";
double const UNIT_SCALE = 1000.0 / (1024.0 * 1024.0); // Bytes/ms -> Mbps
double const UNIT_SCALE = 8000.0 / (1024.0 * 1024.0); // Bytes/ms -> Mbps
int const INITIAL_SCALE_MAXIMUM_INDEX = 250; // / 9: exponent, % 9: mantissa - 2, 0 o--o 2 * 10^-10
int SPACING_RIGHT_CAPTION_IN_OUT = 4;
@ -38,9 +38,9 @@ namespace { // .cpp-local
}
BandwidthMeter::ChannelInfo BandwidthMeter::_DEFAULT_CHANNELS[] = {
{ "Audio" , "Kbps", 1000.0 / 1024.0, 0x40ff40d0 },
{ "Avatars" , "Kbps", 1000.0 / 1024.0, 0xffef40c0 },
{ "Voxels" , "Kbps", 1000.0 / 1024.0, 0xd0d0d0a0 }
{ "Audio" , "Kbps", 8000.0 / 1024.0, 0x40ff40d0 },
{ "Avatars" , "Kbps", 8000.0 / 1024.0, 0xffef40c0 },
{ "Voxels" , "Kbps", 8000.0 / 1024.0, 0xd0d0d0a0 }
};
BandwidthMeter::BandwidthMeter() :

View file

@ -4,6 +4,9 @@
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QPalette>
#include <QColor>
#include "Log.h"
BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) :
@ -23,8 +26,17 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) :
int chIdx = i / 2;
bool input = i % 2 == 0;
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(chIdx);
QLabel* label = _labels[i] = new QLabel();
snprintf(strBuf, sizeof(strBuf), "%s %s Bandwidth:", input ? "Input" : "Output", ch.caption);
QLabel* label = _labels[i] = new QLabel();
label->setAlignment(Qt::AlignRight);
// Set foreground color to 62.5% brightness of the meter (otherwise will be hard to read on the bright background)
QPalette palette = label->palette();
unsigned rgb = ch.colorRGBA >> 8;
rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3);
palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb));
label->setPalette(palette);
snprintf(strBuf, sizeof(strBuf), " %s %s Bandwidth:", input ? "Input" : "Output", ch.caption);
form->addRow(strBuf, label);
}
}
@ -39,7 +51,7 @@ void BandwidthDialog::paintEvent(QPaintEvent* event) {
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(chIdx);
BandwidthMeter::Stream& s = input ? _model->inputStream(chIdx) : _model->outputStream(chIdx);
QLabel* label = _labels[i];
snprintf(strBuf, sizeof(strBuf), "%010.5f%s", s.getValue() * ch.unitScale, ch.unitCaption);
snprintf(strBuf, sizeof(strBuf), "%0.2f %s", s.getValue() * ch.unitScale, ch.unitCaption);
label->setText(strBuf);
}