3
#include <qfontmetrics.h>
6
#include "levelmeters.h"
8
PeakBar::PeakBar(QWidget *parent): LevelMeter(parent) {
10
displayMinPeak= false;
11
horizontalMode= false;
14
lastValues.setAutoDelete( TRUE );
16
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
17
setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
18
setBackgroundMode(NoBackground);
19
setMinimumSize(frameWidth()+7, 70);
22
void PeakBar::frameChanged() {
23
setMinimumSize(frameWidth()+7, 70);
24
QFrame::frameChanged();
27
QSize PeakBar::sizeHint() const {
28
return QSize(13, 250);
31
void PeakBar::checkMinMax() {
32
int mustRecheck= 0; // bool
35
while ((o= lastValues.first()) && o->time.elapsed() > peakMillis) {
36
lastValues.removeFirst();
44
for (QListIterator<Observation> it(lastValues); it.current(); ++it) {
45
float value= it.current()->value;
56
void PeakBar::drawContents(QPainter *p)
58
QRect size= contentsRect();
62
p->setBrush(clipped ? darkRed : darkBlue);
67
p->setBrush(clipped ? red : blue);
69
bar.setWidth((int)(bar.width()*currentValue));
71
int newHeight= (int)(bar.height()*currentValue);
72
bar.moveBy(0, bar.height()-newHeight);
73
bar.setHeight(newHeight);
78
// TODO: if (horizontalMode)
80
y= frameWidth()+size.height()-((int)(size.height()*minValue));
82
p->drawLine(frameWidth(), y, frameWidth()+size.width()-1, y);
84
y= frameWidth()+size.height()-((int)(size.height()*maxValue));
86
p->drawLine(frameWidth(), y, frameWidth()+size.width()-1, y);
89
void PeakBar::setValue(float f) {
96
if (displayMinPeak && (f<=minValue))
99
lastValues.append(new Observation(f));
104
// -------------------------------------------------------------
106
PeakLevelMeters::PeakLevelMeters(QWidget *parent):
107
StereoLevelMeter(parent), left(this), right(this), scaleView(this)
109
QBoxLayout *layout= new QHBoxLayout(this);
110
layout->addWidget(&left);
111
// layout->setStretchFactor(&left, 0);
112
layout->addWidget(&right);
113
// layout->setStretchFactor(&right, 0);
114
layout->addWidget(&scaleView);
115
// layout->setStretchFactor(&scaleView, 0);
116
left.setLineWidth(2);
117
right.setLineWidth(2);
118
scaleView.setScaleMargins(right.frameWidth());
119
setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
124
void PeakLevelMeters::setDbRange(int db) {
126
scaleView.setDbRange(db);
129
void PeakLevelMeters::setValues(float leftVal, float rightVal) {
130
float f= 1.0f+levelToDB(leftVal)/dbRange;
134
f= 1.0f+levelToDB(rightVal)/dbRange;
139
ScaleView::ScaleView(QWidget *parent): QFrame(parent) {
140
font.setPixelSize(10);
141
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
144
void ScaleView::setDbRange(int db) {
149
QSize ScaleView::sizeHint() const {
150
return QSize(QFontMetrics(font).width("-88")+8, 250);
153
void ScaleView::drawContents(QPainter *p) {
154
QRect size= contentsRect();
155
size.rTop()+= upperMargin;
156
size.rBottom()-= lowerMargin;
158
QFrame::drawContents(p); // clear background
161
while (dbRange/step*20>size.height())
164
/* float offset= ((float)size.height()*step)/dbRange, pos=0.f;
166
p->drawLine(0, (, size.width()*3/5, y);*/
171
for (int i=0; i<=dbRange; i++) {
172
int y= size.top()+(size.height()-1)*i/dbRange;
174
p->drawLine(0, y, 4, y);
176
p->drawText(8, y+5, numStr);
178
p->drawLine(0, y, 2, y);
182
// -------------------------------------------------------------
184
LedMeter::LedMeter(QWidget *parent, bool blueState) : LevelMeter(parent) {
185
setBackgroundColor(black);
186
QBoxLayout * l = new QVBoxLayout( this );
188
for(int i=0;i<12;i++) {
198
// put each led in its own frame, since it seems to be broken
199
QFrame *lframe = new QFrame(this);
200
QBoxLayout *lfl = new QVBoxLayout( lframe );
201
lfl->setAutoAdd(TRUE);
203
new KLed(c,KLed::Off, KLed::Sunken, KLed::Circular,lframe);
207
void LedMeter::setValue(float f)
209
//printf("value %f\n",f);
210
for(int i=11;i>=0;i--)
212
if(f > 0.06) leds[i]->setState(KLed::On);
213
else leds[i]->setState(KLed::Off);
218
// -------------------------------------------------------------
220
StereoLedMeters::StereoLedMeters(QWidget *parent)
221
: StereoLevelMeter(parent), left(this), right(this)
223
QBoxLayout *layout= new QHBoxLayout(this);
224
layout->addWidget(&left);
225
layout->addWidget(&right);
228
void StereoLedMeters::setValues(float leftVal, float rightVal) {
229
left.setValue(leftVal);
230
right.setValue(rightVal);
233
#include "levelmeters.moc"