/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * 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 "vumeter.h" #include #include #include #include vuMeter::vuMeter( QWidget *parent, const char *name, WFlags f ): QFrame( parent, name, f ), total_steps( 100 ),progress_val( -1 ),percentage( -1 ) { setFrameStyle(QFrame::Panel | QFrame::Sunken); setLineWidth( 4); Needle=FALSE; } vuMeter::vuMeter( int totalSteps,QWidget *parent, const char *name, WFlags f ) : QFrame( parent, name, f ),total_steps( totalSteps ),progress_val( -1 ),percentage( -1 ) { setFrameStyle(QFrame::Panel | QFrame::Sunken); setLineWidth( 4 ); } void vuMeter::reset() { progress_val = -1; percentage = -1; update(); } void vuMeter::setTotalSteps( int totalSteps ) { total_steps = totalSteps; if ( isVisible() ) { repaint( FALSE ); } } void vuMeter::setProgress( int progress ) { if ( progress == progress_val ) return; progress_val = progress; if ( isVisible() ) { repaint( FALSE ); } } void vuMeter::show() { setFrameStyle(QFrame::Panel | QFrame::Sunken); setLineWidth( 4 ); QFrame::show(); } void vuMeter::drawContents( QPainter *p ) { int pw=0; int ph=0; const QRect bar = contentsRect(); if (!Needle) { if (bar.width()>bar.height()) { pw = bar.width() * progress_val / total_steps; p->setClipRect( bar.x(), bar.y(), pw,bar.height()); } else { ph = bar.height() * progress_val / total_steps; p->setClipRect( bar.x(), bar.height()-ph,bar.width(), ph ); } p->fillRect(bar,colorGroup().foreground()); if (bar.width()>bar.height()) { p->setClipRect( bar.x()+pw, bar.y(), bar.width()-pw, bar.height()); } else { p->setClipRect( bar.x(), bar.y(), bar.width(), bar.height()-ph); } p->fillRect(bar,colorGroup().background()); } else { p->setClipRect( bar.x(), bar.y(), bar.width(), bar.height()); p->fillRect(bar,colorGroup().background()); pw = bar.height() * progress_val / total_steps; p->setClipRect( bar.x(), bar.y()+bar.height()-pw-2, bar.width(),4); p->fillRect(bar,colorGroup().foreground()); } }