summaryrefslogtreecommitdiff
path: root/noncore/multimedia/powerchord/vumeter.cpp
blob: 0c174358daa18d425d99823143d8040e58bfc82a (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// VUMeter class
//

// Copyright (c) 2001 Camilo Mesias
// camilo@mesias.co.uk
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <stdio.h>
#include "vumeter.h"
#include <qpainter.h>

#include <math.h>

VUMeter::VUMeter(QWidget *parent, const char *name )
  : QWidget( parent, name ), Lannot("A"), Rannot("440 Hz")
{
  //  setPalette( QPalette( QColor( 250, 250, 200) ) );
 
  vuvalue = 0;

  pix = 0;
  

}

VUMeter::~VUMeter()
{
  delete(pix);
}

void VUMeter::paintEvent(QPaintEvent *){

  vupdate();
}

void VUMeter::bupdate(){

  if (!pix){
    pix = new QPixmap(rect().size());
  }
  // redraw whole background to buffer

  pix->fill(this, 0, 0);

  QPainter p( pix );

  p.setBrush(white);
  p.setPen(NoPen);
  
  p.drawRect( QRect(0, 0, width(), height()) );

  p.translate(width()/2, 0);

  p.setBrush(black);
  p.setPen(black);

  //  for (int i=-50;i<50;i+=4){
  //  p.drawLine((vuvalue), height()-10, vuvalue*2, 25);
  //  }

  p.drawText(-100,15,Lannot);
  p.drawText(65,15,Rannot);

  p.drawText(-100, height()-25, QString("-"));
  p.drawText(85, height()-25, QString("+"));
  p.drawText(-2, 20, QString("0"));
  p.end();

}

void VUMeter::vupdate(){

  if (!pix){
    bupdate();
  }

  // redraw line only

  QPixmap tmp_pix(rect().size());

  QPainter p( &tmp_pix );
  p.drawPixmap(QPoint(0,0), *pix);

  p.translate(width()/2, 0);
  p.drawLine((vuvalue), height()-10, vuvalue*2, 25);
  p.end();
  bitBlt(this, rect().topLeft(), &tmp_pix);
}