Clementine-audio-player-Mac.../src/analyzers/sonogram.cpp

76 lines
1.4 KiB
C++
Raw Normal View History

2009-12-24 20:16:07 +01:00
//
//
// C++ Implementation: Sonogram
//
// Description:
//
//
// Author: Melchior FRANZ <mfranz@kde.org>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "sonogram.h"
2010-03-22 14:49:08 +01:00
#include <QPainter>
2010-03-21 18:22:05 +01:00
const char* Sonogram::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");
2009-12-24 20:16:07 +01:00
Sonogram::Sonogram(QWidget *parent) :
Analyzer::Base(parent)
2009-12-24 20:16:07 +01:00
{
}
Sonogram::~Sonogram()
{
}
void Sonogram::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
2010-03-21 18:22:05 +01:00
canvas_ = QPixmap(size());
canvas_.fill(palette().color(QPalette::Background));
2009-12-24 20:16:07 +01:00
}
2010-03-21 18:22:05 +01:00
void Sonogram::analyze(QPainter& p, const Scope &s)
2009-12-24 20:16:07 +01:00
{
int x = width() - 1;
QColor c;
2010-03-21 18:22:05 +01:00
QPainter canvas_painter(&canvas_);
canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, x, -1);
2009-12-24 20:16:07 +01:00
Scope::const_iterator it = s.begin(), end = s.end();
for (int y = height() - 1; y;) {
if (it >= end || *it < .005)
2010-03-21 18:22:05 +01:00
c = palette().color(QPalette::Background);
2009-12-24 20:16:07 +01:00
else if (*it < .05)
c.setHsv(95, 255, 255 - int(*it * 4000.0));
else if (*it < 1.0)
c.setHsv(95 - int(*it * 90.0), 255, 255);
else
c = Qt::red;
2010-03-21 18:22:05 +01:00
canvas_painter.setPen(c);
canvas_painter.drawPoint(x, y--);
2009-12-24 20:16:07 +01:00
if (it < end)
++it;
}
2010-03-21 18:22:05 +01:00
canvas_painter.end();
p.drawPixmap(0, 0, canvas_);
2009-12-24 20:16:07 +01:00
}
2010-03-21 18:22:05 +01:00
void Sonogram::demo(QPainter& p)
2009-12-24 20:16:07 +01:00
{
analyze(p, Scope(m_lastScope.size(), 0));
2009-12-24 20:16:07 +01:00
}