forked from OpenShield/DudeShield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelmeter.cpp
55 lines (48 loc) · 1.12 KB
/
levelmeter.cpp
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
46
47
48
49
50
51
52
53
54
55
#include "levelmeter.h"
#include <QPainter>
LevelMeter::LevelMeter(QWidget *parent) :
QWidget(parent)
{
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
setMinimumHeight(10);
setMaximumHeight(10);
setMinimumWidth(200);
m_falloff_timer = new QTimer();
connect(m_falloff_timer, SIGNAL(timeout()), this, SLOT(process_falloff()));
m_falloff_timer->start(20);
}
void LevelMeter::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.setPen(Qt::black);
painter.drawRect(QRect(painter.viewport().left(),
painter.viewport().top(),
painter.viewport().right(),
painter.viewport().bottom()));
//if (m_level == 0.0)
//return;
int pos = ((painter.viewport().right())-(painter.viewport().left()+1))*m_level;
painter.fillRect(painter.viewport().left()+1,
painter.viewport().top()+1,
pos,
painter.viewport().height()-2,
QColor("steelblue"));
}
void LevelMeter::setLevel(qreal l)
{
if(l > m_level){
m_level = l;
}
update();
}
void LevelMeter::process_falloff()
{
if(m_level <= 0.0){
m_level = 0.0f;
}
else{
m_level -= 0.015f;
}
//update();
}