/*******************************************
 * KJEqualizer IS NOT WORKING, TODO and FIXME :)
 *******************************************/

#include "kjequalizer.h"
#include <qpainter.h>

#include <noatun/equalizer.h>

KJEqualizer::KJEqualizer(const QStringList &l, KJLoader *parent)
	: QObject(0), KJWidget(parent)
{
	int x=l[1].toInt();
	int y=l[2].toInt();
	int xs=l[3].toInt()-x;
	int ys=l[4].toInt()-y;
	setRect(x,y,xs,ys);

	mBars=parent->pixmap(parser()["equalizerbmp"][3]);

	mBands=l[6].toInt();
	mXSpace=l[7].toInt();
	mBuffer.resize(rect().size());

	mXSize=parser()["EqualizerBmp"][1].toInt();
	mNumber=parser()["EqualizerBmp"][2].toInt();
}

int KJEqualizer::barNum(const QPoint &pos) const
{
	int x=pos.x();
	x = x/ mXSpace;
	return napp->equalizer()->bandCount()*x / mBands;
}

int KJEqualizer::level(const QPoint &pos) const
{
	int y=-pos.y();
	y+=rect().height()/2;
	y*=200/(rect().height()/2);
	return y;
}

void KJEqualizer::paint(QPainter *, const QRect &)
{

}

void KJEqualizer::updateBuffer()
{
	QPainter paint(&mBuffer);
	for (int band=0; band< mBands; band++)
	{


	}

}

void KJEqualizer::mouseMove(const QPoint &pos, bool in)
{
	if (!in) return;

	napp->equalizer()->band(barNum(pos))->setLevel(level(pos));
}

bool KJEqualizer::mousePress(const QPoint &p)
{
	mouseMove(p, true);
	return true;
}

#include "kjequalizer.moc"
