mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-05 23:30:46 +02:00
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
//
|
|
// BandwidthDialog.h
|
|
// interface
|
|
//
|
|
// Created by Tobias Schwinger on 6/21/13.
|
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#include <cstdio>
|
|
|
|
#include "ui/BandwidthDialog.h"
|
|
|
|
#include <QFormLayout>
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPalette>
|
|
#include <QColor>
|
|
|
|
BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) :
|
|
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint),
|
|
_model(model) {
|
|
|
|
char strBuf[64];
|
|
|
|
this->setWindowTitle("Bandwidth Details");
|
|
|
|
// Create layouter
|
|
QFormLayout* form = new QFormLayout();
|
|
this->QDialog::setLayout(form);
|
|
|
|
// Setup labels
|
|
for (size_t i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
|
|
bool input = i % 2 == 0;
|
|
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(BandwidthMeter::ChannelIndex(i / 2));
|
|
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);
|
|
}
|
|
}
|
|
|
|
BandwidthDialog::~BandwidthDialog() {
|
|
for (size_t i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
|
|
delete _labels[i];
|
|
}
|
|
}
|
|
|
|
void BandwidthDialog::paintEvent(QPaintEvent* event) {
|
|
|
|
// Update labels
|
|
char strBuf[64];
|
|
for (size_t i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
|
|
BandwidthMeter::ChannelIndex chIdx = BandwidthMeter::ChannelIndex(i / 2);
|
|
bool input = i % 2 == 0;
|
|
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(chIdx);
|
|
BandwidthMeter::Stream& s = input ? _model->inputStream(chIdx) : _model->outputStream(chIdx);
|
|
QLabel* label = _labels[i];
|
|
snprintf(strBuf, sizeof(strBuf), "%0.2f %s", s.getValue() * ch.unitScale, ch.unitCaption);
|
|
label->setText(strBuf);
|
|
}
|
|
|
|
this->QDialog::paintEvent(event);
|
|
this->setFixedSize(this->width(), this->height());
|
|
}
|
|
|
|
void BandwidthDialog::reject() {
|
|
|
|
// Just regularly close upon ESC
|
|
this->QDialog::close();
|
|
}
|
|
|
|
void BandwidthDialog::closeEvent(QCloseEvent* event) {
|
|
|
|
this->QDialog::closeEvent(event);
|
|
emit closed();
|
|
}
|
|
|