AudioSpectrumDrawer.cpp 1.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * AudioSpectrumDrawer.cpp: Audio Spectrum Drawing Widget
 *****************************************************************************
 * Copyright (C) 2008-2011 VideoLAN
 *
 * Authors: Geoffroy Lacarriere <geoffroylaca@gmail.com>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24 25 26 27 28 29 30 31
#include "AudioSpectrumDrawer.h"

AudioSpectrumDrawer::AudioSpectrumDrawer( QPainter* painter, int height, int width, QList<int>* audioValueList )
    : m_painter( painter ), m_height( height ), m_width( width ), m_audioValueList( audioValueList )
{
    m_painter->setRenderHint( QPainter::Antialiasing, true );
    m_painter->setPen( QPen( QColor( 79, 106, 25 ), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ) );
}

32 33
void
AudioSpectrumDrawer::run()
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
{
    qreal max = 0;
    for( int i = 0; i < m_audioValueList->count(); i++ )
        if ( m_audioValueList->at(i) > max )
            max = m_audioValueList->at(i);

    for( int x = 0; x < m_audioValueList->count(); x++ )
    {
        if ( x <= m_height )
        {
            qreal y = ( (qreal)m_audioValueList->at(x) / max ) * 500;
            y -= 365;
            m_path.lineTo( x, y );
        }
    }
    m_painter->drawPath( m_path );
}