Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vumeter.cpp

Go to the documentation of this file.
00001 //
00002 // VUMeter class
00003 //
00004 
00005 // Copyright (c) 2001 Camilo Mesias
00006 // camilo@mesias.co.uk
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022 #include <stdio.h>
00023 #include "vumeter.h"
00024 #include <qpainter.h>
00025 
00026 #include <math.h>
00027 
00028 VUMeter::VUMeter(QWidget *parent, const char *name )
00029   : QWidget( parent, name ), Lannot("A"), Rannot("440 Hz")
00030 {
00031   //  setPalette( QPalette( QColor( 250, 250, 200) ) );
00032  
00033   vuvalue = 0;
00034 
00035   pix = 0;
00036   
00037 
00038 }
00039 
00040 VUMeter::~VUMeter()
00041 {
00042   delete(pix);
00043 }
00044 
00045 void VUMeter::paintEvent(QPaintEvent *){
00046 
00047   vupdate();
00048 }
00049 
00050 void VUMeter::bupdate(){
00051 
00052   if (!pix){
00053     pix = new QPixmap(rect().size());
00054   }
00055   // redraw whole background to buffer
00056 
00057   pix->fill(this, 0, 0);
00058 
00059   QPainter p( pix );
00060 
00061   p.setBrush(white);
00062   p.setPen(NoPen);
00063   
00064   p.drawRect( QRect(0, 0, width(), height()) );
00065 
00066   p.translate(width()/2, 0);
00067 
00068   p.setBrush(black);
00069   p.setPen(black);
00070 
00071   //  for (int i=-50;i<50;i+=4){
00072   //  p.drawLine((vuvalue), height()-10, vuvalue*2, 25);
00073   //  }
00074 
00075   p.drawText(-100,15,Lannot);
00076   p.drawText(65,15,Rannot);
00077 
00078   p.drawText(-100, height()-25, QString("-"));
00079   p.drawText(85, height()-25, QString("+"));
00080   p.drawText(-2, 20, QString("0"));
00081   p.end();
00082 
00083 }
00084 
00085 void VUMeter::vupdate(){
00086 
00087   if (!pix){
00088     bupdate();
00089   }
00090 
00091   // redraw line only
00092 
00093   QPixmap tmp_pix(rect().size());
00094 
00095   QPainter p( &tmp_pix );
00096   p.drawPixmap(QPoint(0,0), *pix);
00097 
00098   p.translate(width()/2, 0);
00099   p.drawLine((vuvalue), height()-10, vuvalue*2, 25);
00100   p.end();
00101   bitBlt(this, rect().topLeft(), &tmp_pix);
00102 }
00103 
00104 
00105 

Generated on Sat Nov 5 16:17:34 2005 for OPIE by  doxygen 1.4.2