From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/modules/kjofol-skin/kjequalizer.cpp | 129 +++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 noatun/modules/kjofol-skin/kjequalizer.cpp (limited to 'noatun/modules/kjofol-skin/kjequalizer.cpp') diff --git a/noatun/modules/kjofol-skin/kjequalizer.cpp b/noatun/modules/kjofol-skin/kjequalizer.cpp new file mode 100644 index 00000000..3f0716e4 --- /dev/null +++ b/noatun/modules/kjofol-skin/kjequalizer.cpp @@ -0,0 +1,129 @@ +/*************************************************************************** + kjequalizer.cpp - links noatun VEqualizer and KJofol + -------------------------------------- + Maintainer: Stefan Gehn + + ***************************************************************************/ + +#include "kjequalizer.h" +#include "kjequalizer.moc" + +#include +#include + +#include +#include + +#include + +KJEqualizer::KJEqualizer(const QStringList &l, KJLoader *p) + : QObject(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 + QPixmap tmp = p->pixmap(p->item("backgroundimage")[1]); + mBack = new KPixmap ( QSize(xs,ys) ); + bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP ); + + // buffer for view + mView = new QPixmap ( 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(), SIGNAL(changed()), this, SLOT(slotUpdateBuffer())); + + slotUpdateBuffer(); // fill mView pixmap with valid data +} + +KJEqualizer::~KJEqualizer(void) +{ + delete mInterpEq; + delete mView; + delete mBack; +} + +int KJEqualizer::barNum(const QPoint &pos) const +{ + int x = pos.x(); + x = x / mXSpace; + return mInterpEq->bands() * x / mBands; +} + +int KJEqualizer::level(const QPoint &pos) const +{ + int y = ((-pos.y()) + mBandHalfHeight+1) * (200/mBandHalfHeight); + return y; +} + +void KJEqualizer::paint(QPainter *p, const QRect &) +{ + QPixmap 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, QRect(0,0,-1,-1), Qt::CopyROP); +} + +void KJEqualizer::slotUpdateBuffer() +{ +// kdDebug(66666) << "[KJEqualizer] slotUpdateBuffer() called." << endl; + + QBitmap regionMask( rect().width(), rect().height(), true); // fully transparent mask + QPainter mask( ®ionMask ); + + QPoint destX = QPoint(0, 0); + + for (int band=0; bandlevel(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, QRect(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 += QPoint(mXSpace,0); + + } // for() + // whole thingy has been drawn, now set the mask + mView->setMask( regionMask ); + repaint(); +} + +void KJEqualizer::mouseMove(const QPoint &p, bool in) +{ + if (!in) return; + mousePress(p); +} + +bool KJEqualizer::mousePress(const QPoint &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; +} -- cgit v1.2.1