Use three colors in volume meter
This commit is contained in:
parent
d947c525c6
commit
60b927a412
1 changed files with 20 additions and 6 deletions
|
|
@ -52,6 +52,7 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
namespace SpeexWebRTCTest {
|
namespace SpeexWebRTCTest {
|
||||||
|
|
||||||
|
|
@ -75,14 +76,27 @@ void AudioLevel::paintEvent(QPaintEvent* event)
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
||||||
const float maxLevel = 0;
|
const float maxLevel = 0;
|
||||||
const float minLevel = -60;
|
const float minLevel = -50;
|
||||||
|
const float redLevel = -1;
|
||||||
|
const float yellowLevel = -6;
|
||||||
|
|
||||||
|
const QColor greenColor = QColor(42, 168, 43);
|
||||||
|
const QColor yellowColor = "yellow";
|
||||||
|
const QColor redColor = "red";
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
// draw level
|
|
||||||
qreal heightLevel = (level_ - minLevel) / (maxLevel - minLevel) * height();
|
auto drawArea = [&](float min, float max, const QColor& color)
|
||||||
painter.fillRect(0, height() - heightLevel, width(), heightLevel, QColor(42, 168, 43));
|
{
|
||||||
// clear the rest of the control
|
int maxHeight = std::floor((max - minLevel) / (maxLevel - minLevel) * height());
|
||||||
painter.fillRect(0, 0, width(), height() - heightLevel, Qt::black);
|
int minHeight = std::floor((min - minLevel) / (maxLevel - minLevel) * height());
|
||||||
|
painter.fillRect(0, height() - maxHeight, width(), maxHeight - minHeight, color);
|
||||||
|
};
|
||||||
|
|
||||||
|
drawArea(minLevel, level_, greenColor);
|
||||||
|
drawArea(yellowLevel, level_, yellowColor);
|
||||||
|
drawArea(redLevel, level_, redColor);
|
||||||
|
drawArea(level_, maxLevel, Qt::black);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace SpeexWebRTCTest
|
} // namespace SpeexWebRTCTest
|
||||||
|
|
|
||||||
Reference in a new issue