summaryrefslogtreecommitdiffstats
path: root/noatun/modules/kjofol-skin/kjequalizer.cpp
blob: 51d50e976bfccc0d0cfc968839a4876100e6b514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***************************************************************************
	kjequalizer.cpp  -  links noatun VEqualizer and KJofol
	--------------------------------------
	Maintainer: Stefan Gehn <sgehn@gmx.net>

 ***************************************************************************/

#include "kjequalizer.h"
#include "kjequalizer.moc"

#include <tqpainter.h>
#include <tqtimer.h>

#include <kdebug.h>
#include <kpixmap.h>

#include <noatun/vequalizer.h>

KJEqualizer::KJEqualizer(const TQStringList &l, KJLoader *p)
	: TQObject(0), KJWidget(p), mBack(0), mView(0), mInterpEq(0)
{
	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 = p->pixmap(parser()["equalizerbmp"][3]);

	mBands = l[6].toInt();
	mXSpace = l[7].toInt();

	// background under equalizer
	// needed to only blit onto screen ONCE and not for every band
	TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
	mBack = new KPixmap ( TQSize(xs,ys) );
	bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP );

	// buffer for view
	mView = new TQPixmap ( xs, ys );

	mBandWidth=parser()["EqualizerBmp"][1].toInt();
	mBandHalfHeight=parser()["EqualizerBmp"][2].toInt();
	
	kdDebug(66666) << "[KJEqualizer] mBands=" << mBands << ", mXSpace=" << mXSpace << ", mBandWidth=" << mBandWidth << ", mBandHalfHeight=" <<  mBandHalfHeight << "." << endl;

	kdDebug(66666) << "[KJEqualizer] creating VInterpolation for " << mBands << " bands..." << endl;
	mInterpEq = new VInterpolation(mBands);
//	napp->vequalizer()->setBands(mBands); // FIXME: hack because spline sucks :P
	connect(napp->vequalizer(), TQT_SIGNAL(changed()), this, TQT_SLOT(slotUpdateBuffer()));

	slotUpdateBuffer(); // fill mView pixmap with valid data
}

KJEqualizer::~KJEqualizer(void)
{
	delete mInterpEq;
	delete mView;
	delete mBack;
}

int KJEqualizer::barNum(const TQPoint &pos) const
{
	int x = pos.x();
	x = x / mXSpace;
	return mInterpEq->bands() * x / mBands;
}

int KJEqualizer::level(const TQPoint &pos) const
{
	int y = ((-pos.y()) + mBandHalfHeight+1) * (200/mBandHalfHeight);
	return y;
}

void KJEqualizer::paint(TQPainter *p, const TQRect &)
{
	TQPixmap temp(rect().width(), rect().height());
	// draw background into buffer
	bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, Qt::CopyROP );
	// draw band sliders into buffer
	bitBlt( &temp, 0, 0, mView, 0, 0, rect().width(), rect().height(), Qt::CopyROP);
	// and draw it on screen
	bitBlt(p->device(), rect().topLeft(), &temp, TQRect(0,0,-1,-1), Qt::CopyROP);
}

void KJEqualizer::slotUpdateBuffer()
{
//	kdDebug(66666) << "[KJEqualizer] slotUpdateBuffer() called." << endl;

	TQBitmap regionMask( rect().width(), rect().height(), true); // fully transparent mask
	TQPainter mask( &regionMask );

	TQPoint destX = TQPoint(0, 0);

	for (int band=0; band<mBands; band++)
	{
		int level = mInterpEq->level(band);
		if (level>200) level=200;
		if (level<-200) level=-200;
		int picNum = ((int)(level+200)*(mBandHalfHeight-1) / 400) + 1;
		int xPos = (picNum * mBandWidth) - mBandWidth;

//		kdDebug(66666) << "[KJEqualizer] band=" << band << ", level=" << level << ", picNum=" << picNum << " @ xpos=" << xPos << "." << endl;

		bitBlt(mView, destX, &mBars, TQRect(xPos,0,mBandWidth,rect().height()), Qt::CopyROP);
		// make slider opaque in mask so you see something on screen
		mask.fillRect ( destX.x(), 0, mBandWidth, rect().height(), Qt::color1 );
		destX += TQPoint(mXSpace,0);

	} // for()
	// whole thingy has been drawn, now set the mask
	mView->setMask( regionMask );
	repaint();
}

void KJEqualizer::mouseMove(const TQPoint &p, bool in)
{
	if (!in) return;
	mousePress(p);
}

bool KJEqualizer::mousePress(const TQPoint &p)
{
	kdDebug(66666) << "[KJEqualizer] setting band " << mBands << "/" << barNum(p)+1 << " to level " << level(p) << endl;
	VBand b = mInterpEq->band( barNum(p) );
	b.setLevel( level(p) );
//	mouseMove(p, true);
	return true;
}