File: DisplayLevel.cpp

package info (click to toggle)
hamfax 0.5.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 416 kB
  • ctags: 441
  • sloc: cpp: 3,188; sh: 197; makefile: 124
file content (45 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "DisplayLevel.hpp"
#include <qpainter.h>

DisplayLevel::DisplayLevel(QWidget* parent)
	: QFrame(parent), w(0)
{
	setMinimumHeight(20);
	setFrameStyle(QFrame::Panel|QFrame::Sunken);
	setMargin(2);
	m=margin();
}

void DisplayLevel::paintEvent(QPaintEvent* e)
{
	QFrame::paintEvent(e);
	QPainter paint;
	paint.begin(this);
	paint.setPen(Qt::blue);
	paint.setBrush(Qt::blue);
	paint.drawRect(m,m,w,height()-2*m);
	paint.end();
}

void DisplayLevel::setZero(void)
{
	w=0;
}

void DisplayLevel::samples(short* buffer, int n)
{
	short min=32767;
	short max=-32768;
	for(int i=0; i<n; i++) {
		short s=buffer[i];
		if(s>max) {
			max=s;
		}
		if(s<min) {
			min=s;
		}
	}
	double level=(max-min)/65536.0;
	w=static_cast<int>(level*(width()-2*m));
	update();
}