From 98589adef50d5a05735ccc203c1020755a953f28 Mon Sep 17 00:00:00 2001 From: tosh Date: Mon, 1 Jul 2013 10:28:17 +0200 Subject: [PATCH] Bandwidth meter: Bytes -> bits, number formatting (colors, digits, aligment) on dialog --- interface/src/BandwidthMeter.cpp | 8 ++++---- interface/src/ui/BandwidthDialog.cpp | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/interface/src/BandwidthMeter.cpp b/interface/src/BandwidthMeter.cpp index 69a80c19e8..01e708866e 100644 --- a/interface/src/BandwidthMeter.cpp +++ b/interface/src/BandwidthMeter.cpp @@ -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() : diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 300788e004..f2e6ca2377 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include + #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); }