~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/kjofol-skin/kjloader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qimage.h>
2
 
#include "kjloader.h"
3
 
#include <qbitmap.h>
4
 
#include <qpixmap.h>
5
 
#include <qcursor.h>
6
 
#include <qpainter.h>
7
 
#include <khelpmenu.h>
8
 
#include <kstdaction.h>
9
 
#include <noatunapp.h>
10
 
#include <kpopupmenu.h>
11
 
#include <kaction.h>
12
 
#include <klocale.h>
13
 
#include <player.h>
14
 
#include <kfiledialog.h>
15
 
#include <string.h>
16
 
#include <qvector.h>
17
 
#include <kconfig.h>
18
 
#include <kglobal.h>
19
 
#include <kstddirs.h>
20
 
#include <knotifyclient.h>
21
 
#include <qtooltip.h>
22
 
#include "kjprefs.h"
23
 
#include "equalizer.h"
24
 
#include <qdragobject.h>
25
 
#include <iostream.h>
26
 
#include <math.h>
27
 
#include <noatunstdaction.h>
28
 
#include <stdlib.h>
29
 
#include <unistd.h>
30
 
 
31
 
class KJToolTip : public QToolTip
32
 
{
33
 
public:
34
 
        KJToolTip(KJLoader *parent)
35
 
                : QToolTip(parent), mParent(parent)
36
 
        {}
37
 
 
38
 
protected:
39
 
        virtual void maybeTip(const QPoint &p)
40
 
        {
41
 
                QList<KJWidget> things=mParent->widgetsAt(p);
42
 
                for (KJWidget *i=things.first(); i!=0; i=things.next())
43
 
                {
44
 
                        QString string=i->tip();
45
 
                        if (string.length())
46
 
                        {
47
 
                                tip(i->rect(), string);
48
 
                                return;
49
 
                        }
50
 
                }
51
 
        }
52
 
 
53
 
private:
54
 
        KJLoader *mParent;
55
 
};
56
 
 
57
 
 
58
 
static int grayRgb(QRgb r)
59
 
{
60
 
        return qGray(qRed(r), qGreen(r), qBlue(r));
61
 
}
62
 
 
63
 
static int isGray(QRgb r)
64
 
{
65
 
        return (qRed(r)==qGreen(r)) &&
66
 
               (qRed(r) == qBlue(r));
67
 
}
68
 
 
69
 
KJLoader *KJLoader::kjofol=0;
70
 
 
71
 
KJLoader::KJLoader()
72
 
        : QWidget(0,"KJLoader", WType_TopLevel | WStyle_NoBorder |WRepaintNoErase),
73
 
          UserInterface(), moving(false), mClickedIn(0), mText(0), mNumbers(0)
74
 
{
75
 
        kjofol=this;
76
 
        
77
 
        mTooltips=new KJToolTip(this);
78
 
        setCaption("Noatun");
79
 
        
80
 
        subwidgets.setAutoDelete(true);
81
 
        
82
 
        KConfig *config=KGlobal::config();
83
 
        config->setGroup("KJofol-Skins");
84
 
        QString skin=config->readEntry("SkinResource", locate("data", "noatun/kjskins/kjofol/kjofol.rc"));
85
 
        if (QFile(skin).exists())
86
 
        {
87
 
                loadSkin(skin);
88
 
        }
89
 
        else
90
 
        {
91
 
                KNotifyClient::event("warning",
92
 
                        i18n("There was trouble loading skin %1. Please select another skin file.").arg(skin));
93
 
                napp->preferences();
94
 
        }
95
 
 
96
 
        setIcon(BarIcon("noatun"));
97
 
        setAcceptDrops(true);
98
 
        
99
 
        mHelpMenu =new KHelpMenu(this, kapp->aboutData());
100
 
        connect( napp->player(), SIGNAL(timeout()), this, SLOT(timeUpdate()));
101
 
        connect( napp->player(), SIGNAL(newSong()), this, SLOT(newSong()));
102
 
        connect( napp->player(), SIGNAL(hideYourself()), this, SLOT(hide()) );
103
 
        connect( napp->player(), SIGNAL(showYourself()), this, SLOT(show()) );
104
 
 
105
 
        new KJPrefs(this); 
106
 
        QApplication::restoreOverrideCursor();
107
 
        newSong();
108
 
}
109
 
 
110
 
QList<KJWidget> KJLoader::widgetsAt(const QPoint &pt) const
111
 
{
112
 
        QList<KJWidget> things;
113
 
        for (QListIterator<KJWidget> i(subwidgets); i.current(); ++i)
114
 
                if ((*i)->rect().contains(pt))
115
 
                        things.append((*i));
116
 
        return things;
117
 
                
118
 
}
119
 
 
120
 
void KJLoader::removeChild(KJWidget *c)
121
 
{
122
 
        if (mClickedIn==c) mClickedIn=0;
123
 
        if (subwidgets.findRef(c) != -1)
124
 
                subwidgets.take();
125
 
}
126
 
 
127
 
void KJLoader::addChild(KJWidget *c)
128
 
{
129
 
        subwidgets.append(c);
130
 
}
131
 
 
132
 
// GAMMA CORRECTION SUCKS!!! ROT IN HELL QIMAGEIO!!!
133
 
 
134
 
// just like gamma correction, this function is a stupid hack
135
 
bool KJLoader::cleanSkin(const QString &dir)
136
 
{
137
 
        // try to guess the current filetype:
138
 
        // BMP, JPEG, PNG
139
 
        
140
 
        QString ext;
141
 
        QDir d(dir);
142
 
        
143
 
        QStringList files=d.entryList();
144
 
        if (files.grep("png", false).count())
145
 
                return true;
146
 
        
147
 
        if (files.grep("bmp", false).count())
148
 
                ext="bmp";
149
 
        if (files.grep("jpeg", false).count())
150
 
                ext="jpeg";
151
 
        if (files.grep("jpg", false).count())
152
 
                ext="jpg";
153
 
 
154
 
        if (::access(dir.latin1(), W_OK)!=0) return false;
155
 
 
156
 
        QString command="/bin/sh "+::locate("exe", "noatun_kjofol_fixskin.sh");
157
 
        command+=" '"+dir+"' "+ext;
158
 
        ::system(command.latin1());
159
 
        return true;
160
 
}
161
 
 
162
 
QString KJLoader::guessRcFile(const QString &dir)
163
 
{
164
 
        QString path=dir;
165
 
        if (path[path.length()-1]=='/')
166
 
                path=path.left(path.length()-1);
167
 
 
168
 
        QString tests=path+"/";
169
 
        QString possible=path.mid(path.findRev("/")+1);
170
 
        tests+=possible+".rc";
171
 
        tests=filenameNoCase(tests);
172
 
        if (tests.length())
173
 
                return tests;
174
 
        
175
 
        QDir d(path, "*.rc");
176
 
        
177
 
        if (d.count()) return path+"/"+d[0];
178
 
 
179
 
        return "";
180
 
}
181
 
 
182
 
void KJLoader::loadSkin(const QString &file)
183
 
{
184
 
        if (file==mCurrentSkin) return;
185
 
        mCurrentSkin=file;
186
 
        unloadSkin();
187
 
        
188
 
        if (!cleanSkin(file.left(file.findRev("/"))))
189
 
        {
190
 
                KNotifyClient::event("warning",
191
 
                        i18n("There was trouble loading skin %1. Please select another skin file.").arg(file));
192
 
                napp->preferences();
193
 
                return;
194
 
        }
195
 
        
196
 
        Parser::open(filenameNoCase(file));
197
 
 
198
 
        
199
 
        mText = new KJFont("Font", this);
200
 
        mNumbers = new KJFont("TimeFont", this);
201
 
        
202
 
        subwidgets.append(new Background(this));
203
 
 
204
 
        if (exist("VolumeControlButton"))
205
 
                subwidgets.append(new KJVolumeBMP(item("VolumeControlButton"), this));
206
 
        if (exist("FilenameWindow"))
207
 
                subwidgets.append(new KJFilename(item("FilenameWindow"), this));
208
 
        if (exist("MP3TimeWindow"))
209
 
                subwidgets.append(new KJTime(item("MP3TimeWindow"), this));
210
 
        if (exist("AnalyzerWindow"))
211
 
                subwidgets.append(new KJVis(item("AnalyzerWindow"), this));
212
 
        QTimer::singleShot(0, this, SLOT(loadSeeker()));
213
 
//      subwidgets.append(new KJScope(item("AnalyzerWindow"), this));
214
 
//      subwidgets.append(new KJEqualizer(item("EqualizerWindow"), this));
215
 
        
216
 
        // all the regular buttons
217
 
        for (QDictIterator<QStringList> i(*this); i.current(); ++i)
218
 
        {
219
 
                QString d=i.currentKey();
220
 
                if(d.contains("Button") && (*i).count()==7)
221
 
                        subwidgets.append(new KJButton(*i, this)); 
222
 
                        
223
 
        }
224
 
        show();
225
 
        conserveMemory();
226
 
 
227
 
//      if (napp->player()->isPlaying())
228
 
//              newSong();
229
 
}
230
 
 
231
 
void KJLoader::loadSeeker()
232
 
{
233
 
        subwidgets.append(new KJSeeker(item("SeekRegion"), this));
234
 
}
235
 
 
236
 
void KJLoader::unloadSkin()
237
 
{
238
 
        subwidgets.clear();
239
 
        delete mText;
240
 
        delete mNumbers;        
241
 
}
242
 
 
243
 
void KJLoader::minimize()
244
 
{
245
 
//      setWFlags(WType_TopLevel);
246
 
        showMinimized();
247
 
}
248
 
 
249
 
void KJLoader::closeEvent(QCloseEvent*)
250
 
{
251
 
        unload();
252
 
}
253
 
 
254
 
void KJLoader::dragEnterEvent(QDragEnterEvent *event)
255
 
{
256
 
        // accept uri drops only
257
 
        event->accept(QUriDrag::canDecode(event));
258
 
}
259
 
 
260
 
void KJLoader::dropEvent(QDropEvent *event)
261
 
{
262
 
        QStrList uri;
263
 
        if (QUriDrag::decode(event, uri))
264
 
        {
265
 
                for (char *file=uri.first(); file != 0; file=uri.next() )
266
 
                        napp->player()->openFile(KURL(file), false);
267
 
        }
268
 
}
269
 
 
270
 
void KJLoader::wheelEvent(QWheelEvent *e)
271
 
{
272
 
        int delta=e->delta();
273
 
        napp->player()->setVolume(napp->player()->volume()+(delta/60));
274
 
}
275
 
 
276
 
KJLoader::~KJLoader()
277
 
{
278
 
        delete mHelpMenu;
279
 
        delete mTooltips;
280
 
}
281
 
 
282
 
void KJLoader::paintEvent(QPaintEvent *e)
283
 
{
284
 
        QPainter p(this);
285
 
        for (KJWidget* i=subwidgets.first(); i!=0; i=subwidgets.next())
286
 
                if (i->rect().intersects(e->rect()))
287
 
                        i->paint(&p, e->rect().intersect(i->rect()));
288
 
//      QWidget::paintEvent(e);
289
 
}
290
 
 
291
 
void KJLoader::mouseMoveEvent(QMouseEvent *e)
292
 
{
293
 
        if (moving)
294
 
                move(QCursor::pos()-mMousePoint);
295
 
        QWidget::mouseMoveEvent(e);
296
 
 
297
 
        if (!moving && mClickedIn && subwidgets.findRef(mClickedIn)!=-1)
298
 
                mClickedIn->mouseMove(e->pos()-mClickedIn->rect().topLeft(),
299
 
                                      mClickedIn->rect().contains(
300
 
                                              mapFromGlobal(QCursor::pos())));
301
 
}
302
 
 
303
 
void KJLoader::mousePressEvent(QMouseEvent *e)
304
 
{
305
 
        QWidget::mousePressEvent(e);
306
 
        raise();
307
 
        setActiveWindow();
308
 
        
309
 
        if (e->button()==RightButton)
310
 
                NoatunStdAction::ContextMenu::showContextMenu();
311
 
        else
312
 
        {
313
 
        
314
 
                mMousePoint=mapFromGlobal(QCursor::pos());
315
 
                // try to find a KJWidget that is here
316
 
                for (KJWidget* i=subwidgets.first(); i!=0; i=subwidgets.next())
317
 
                        if (i->rect().contains(mMousePoint))
318
 
                        {
319
 
                                if (i->mousePress(mMousePoint-i->rect().topLeft()))
320
 
                                {
321
 
                                        mClickedIn=i;
322
 
                                        return;
323
 
                                }
324
 
                        }
325
 
                
326
 
                // can't find it, so move the window    
327
 
                moving=true;
328
 
        }
329
 
}
330
 
 
331
 
void KJLoader::mouseReleaseEvent(QMouseEvent *e)
332
 
{
333
 
        QWidget::mouseReleaseEvent(e);
334
 
        
335
 
        if (!moving && mClickedIn && subwidgets.findRef(mClickedIn)!=-1)
336
 
        {
337
 
                mClickedIn->mouseRelease(mapFromGlobal(QCursor::pos())-
338
 
                                                       mClickedIn->rect().topLeft(),
339
 
                                         mClickedIn->rect().contains(
340
 
                                                 mapFromGlobal(QCursor::pos())));
341
 
                mClickedIn=0;
342
 
        }
343
 
 
344
 
        moving=false;
345
 
}
346
 
 
347
 
void KJLoader::timeUpdate()
348
 
{
349
 
        for (KJWidget* i=subwidgets.first(); i!=0; i=subwidgets.next())
350
 
                i->timeUpdate(napp->player()->getTime()/1000); // pass seconds to all Widgets
351
 
}
352
 
 
353
 
void KJLoader::newSong()
354
 
{
355
 
        if (!napp->player()->current()) return;
356
 
        for (KJWidget* i=subwidgets.first(); i!=0; i=subwidgets.next())
357
 
                i->newFile();
358
 
}
359
 
 
360
 
 
361
 
/*******************************************
362
 
 * KJWidget
363
 
 *******************************************/
364
 
 
365
 
KJWidget::KJWidget(KJLoader *p) : mParent(p)
366
 
{
367
 
}
368
 
 
369
 
// only works little endian
370
 
inline void setPixel1BPP(QImage &image, int x, int y, bool value)
371
 
{
372
 
        if (value)
373
 
                *(image.scanLine(y) + (x >> 3)) |= 1 << (x & 7);
374
 
        else
375
 
                *(image.scanLine(y) + (x >> 3)) &= ~(1 << (x & 7));     
376
 
}
377
 
 
378
 
 
379
 
QBitmap KJWidget::getMask(const QImage &_rect, register QRgb transparent)
380
 
{
381
 
 
382
 
        QImage result(_rect.width(), _rect.height(), 1,2, QImage::LittleEndian);
383
 
        result.setColor(0, qRgb(0,0,0));
384
 
        result.setColor(1, qRgb(255,255,255));
385
 
 
386
 
        for (int height=0;height<_rect.height(); height++)
387
 
        {
388
 
                for (int width=0; width<_rect.width(); width++)
389
 
                        setPixel1BPP(result, width, height,
390
 
                                     _rect.pixel(width, height)!=transparent);
391
 
        }
392
 
 
393
 
        QBitmap bm;
394
 
        bm.convertFromImage(result);
395
 
        return bm;
396
 
 
397
 
                /*
398
 
        register QRgb magenta=QColor(255,0,255).rgb();
399
 
        QImage rect=_rect.convertDepth(32);
400
 
        register int width=rect.width();
401
 
        register int height=rect.height();
402
 
 
403
 
        QImage result(width, height, 1,2, QImage::LittleEndian);
404
 
        result.setColor(0, qRgb(0,0,0));
405
 
        result.setColor(1, qRgb(255,255,255));
406
 
        
407
 
        for (register int cheight=height; cheight!=0; --cheight)
408
 
        {
409
 
                register QRgb *srcline=(QRgb*)rect.scanLine(cheight);
410
 
                register QRgb *resline=(QRgb*)result.scanLine(cheight);
411
 
                for (register int cwidth=width; cwidth!=0; --cwidth)
412
 
                        setPixel1BPP(result, cwidth, cheight,srcline[cwidth]==magenta);
413
 
        }               
414
 
                
415
 
        QBitmap bm;
416
 
        bm.convertFromImage(result);
417
 
        return bm;
418
 
*/
419
 
}
420
 
 
421
 
void KJWidget::repaint(bool me, const QRect &r, bool clear)
422
 
{
423
 
        QPainter p(parent());
424
 
        if (me)
425
 
                paint(&p, r.isValid() ? r : rect());
426
 
        else
427
 
                parent()->repaint(r.isValid() ? r : rect(), clear);             
428
 
}
429
 
 
430
 
QString KJWidget::backgroundPressed(const QString &bmp)
431
 
{
432
 
        return parser()["BackgroundImagePressed"+QString::number(bmp.mid(3).toInt())][1];
433
 
}
434
 
 
435
 
/*******************************************
436
 
 * Background
437
 
 *******************************************/
438
 
 
439
 
Background::Background(KJLoader *parent)
440
 
        : KJWidget(parent)
441
 
{
442
 
        QImage ibackground;
443
 
        mBackground=parent->pixmap(parser()["BackgroundImage"][1]);
444
 
        ibackground=parent->image(parser()["BackgroundImage"][1]);
445
 
        parent->setMask(getMask(ibackground));
446
 
        parent->setFixedSize(QSize(mBackground.width(), mBackground.height()));
447
 
 
448
 
        setRect(0,0,parent->width(),parent->height());
449
 
}
450
 
 
451
 
void Background::paint(QPainter *painter, const QRect &rect)
452
 
{
453
 
        QPaintDevice *dev=painter->device();
454
 
        bitBlt(dev, rect.topLeft(), &mBackground, rect, Qt::CopyROP);
455
 
//      bitBlt(dev, rect.topLeft(), parent()->pixmap("SeekImage", 1), rect, Qt::CopyROP);
456
 
}
457
 
 
458
 
/*******************************************
459
 
 * KJButton
460
 
 *******************************************/
461
 
 
462
 
KJButton::KJButton(const QStringList &i, KJLoader *parent)
463
 
        : KJWidget(parent), mTitle(i[0]), mShowPressed(false) 
464
 
{
465
 
        mPushedPixmap=(i.count()==7);
466
 
        
467
 
        // get the rectangle
468
 
        int x, y, xs, ys;
469
 
        x=i[1].toInt();
470
 
        y=i[2].toInt();
471
 
        xs=i[3].toInt()-x;
472
 
        ys=i[4].toInt()-y;
473
 
        setRect(x,y,xs,ys);
474
 
 
475
 
        mPressed=parent->pixmap(backgroundPressed(i[6]));
476
 
}
477
 
 
478
 
QString KJButton::tip()
479
 
{
480
 
        QString str;
481
 
        if (mTitle=="CloseButton")
482
 
                str=i18n("Close");
483
 
        else if (mTitle=="MinimizeButton")
484
 
                str=i18n("Minimize");
485
 
        else if (mTitle=="AboutButton")
486
 
                str=i18n("About");
487
 
        else if (mTitle=="StopButton")
488
 
                str=i18n("Stop");
489
 
        else if (mTitle=="PlayButton")
490
 
                str=i18n("Play");
491
 
        else if (mTitle=="PauseButton")
492
 
                str=i18n("Pause");
493
 
        else if (mTitle=="OpenFileButton")
494
 
                str=i18n("Open");
495
 
        else if (mTitle=="PlaylistButton")
496
 
                str=i18n("Playlist");
497
 
        else if (mTitle=="RepeatButton")
498
 
                str=i18n("Loop");
499
 
        else if (mTitle=="EqualizerButton")
500
 
                str="";
501
 
        else if (mTitle=="NextSongButton")
502
 
                str=i18n("Next");
503
 
        else if (mTitle=="PreviousSongButton")
504
 
                str=i18n("Previous");
505
 
        else if (mTitle=="PreferencesButton")
506
 
                str=i18n("Preferences");
507
 
        return str;
508
 
}
509
 
 
510
 
void KJButton::paint(QPainter *, const QRect &)
511
 
{
512
 
        if (mShowPressed)
513
 
                bitBlt(parent(), rect().topLeft(), &mPressed, rect(), Qt::CopyROP);
514
 
}
515
 
 
516
 
bool KJButton::mousePress(const QPoint &)
517
 
{
518
 
        bitBlt(parent(), rect().topLeft(), &mPressed, rect(), Qt::CopyROP);
519
 
        return true;
520
 
}
521
 
 
522
 
void KJButton::showPressed(bool b)
523
 
{
524
 
        mShowPressed=b;
525
 
        repaint();
526
 
}
527
 
 
528
 
void KJButton::mouseRelease(const QPoint &, bool in)
529
 
{
530
 
        repaint(false);
531
 
        if (!in)
532
 
                return;
533
 
 
534
 
        // now, find what widget I am and do the proper action
535
 
        if (mTitle=="CloseButton")
536
 
                parent()->close();
537
 
        else if (mTitle=="MinimizeButton")
538
 
                parent()->minimize();
539
 
        else if (mTitle=="AboutButton")
540
 
                parent()->helpMenu()->aboutApplication();
541
 
        else if (mTitle=="StopButton")
542
 
                napp->player()->stop();
543
 
        else if (mTitle=="PlayButton")
544
 
                napp->player()->play();
545
 
        else if (mTitle=="PauseButton")
546
 
                napp->player()->playpause();
547
 
        else if (mTitle=="OpenFileButton")
548
 
        {
549
 
                KURL file(KFileDialog::getOpenURL(0, napp->mimeTypes(), parent(),
550
 
                                                  i18n("Select a File to Play")));
551
 
                if (!file.isMalformed())
552
 
                        napp->player()->openFile(file);
553
 
        }
554
 
        else if (mTitle=="PlaylistButton")
555
 
                napp->player()->toggleListView();
556
 
        else if (mTitle=="RepeatButton")
557
 
        {
558
 
                napp->player()->loop(napp->player()->loopStyle()==Player::None
559
 
                                         ? Player::Song : Player::None);
560
 
                showPressed(napp->player()->loopStyle());
561
 
        }
562
 
        else if (mTitle=="EqualizerButton")
563
 
                ;
564
 
        else if (mTitle=="NextSongButton")
565
 
                napp->player()->fastForward();
566
 
        else if (mTitle=="PreviousSongButton")
567
 
                napp->player()->back();
568
 
        else if (mTitle=="PreferencesButton")
569
 
                napp->preferences();
570
 
}
571
 
 
572
 
 
573
 
KJSeeker::KJSeeker(const QStringList &i, KJLoader *l) : KJWidget(l), g(0)
574
 
{
575
 
        mActive=parent()->image(backgroundPressed("BMP1"));
576
 
        mScale=parent()->image(parser()["SeekImage"][1]);
577
 
        QImage pixmapNoPress=parent()->image(parser()["BackgroundImage"][1]);
578
 
 
579
 
        int x, y, xs, ys;
580
 
        x=i[1].toInt();
581
 
        y=i[2].toInt();
582
 
        xs=i[3].toInt()-x;
583
 
        ys=i[4].toInt()-y;
584
 
        setRect(x,y,xs,ys);
585
 
        QImage transmask(xs, ys, 1, 2, QImage::LittleEndian);
586
 
 
587
 
        transmask.setColor(0, qRgb(0,0,0));
588
 
        transmask.setColor(1, qRgb(255,255,255));
589
 
        
590
 
        
591
 
        QImage *barmodeImages[256];
592
 
        memset(barmodeImages, 0, 256*sizeof(QImage*));
593
 
        memset(barmode, 0, 256*sizeof(QPixmap*));
594
 
        // Now do the pixel f�king
595
 
        for (int iy=y;iy<y+ys; iy++)
596
 
                for (int ix=x;ix<x+xs; ix++)
597
 
                {
598
 
                        QRgb checkmScale=mScale.pixel(ix, iy);
599
 
                        // am I transparent?
600
 
                        if (!isGray(checkmScale))
601
 
                        {
602
 
                                setPixel1BPP(transmask, ix-x, iy-y, 0);
603
 
                                continue;
604
 
                        }
605
 
                        setPixel1BPP(transmask, ix-x, iy-y, 1);
606
 
 
607
 
                        // what is the level
608
 
                        int level=grayRgb(checkmScale)+1;
609
 
                        if (level>255) level=255;
610
 
                        // allocate the pixmap of the level proper
611
 
                        // copy the color to the surface proper
612
 
                        QRgb activeColor=mActive.pixel(ix,iy);
613
 
                        QRgb inactiveColor=pixmapNoPress.pixel(ix,iy);
614
 
                        // set this pixel and everything before it
615
 
                        for(int i=0; i<level; i++)
616
 
                        {
617
 
                                if (!barmodeImages[i])
618
 
                                        barmodeImages[i]=new QImage(xs,ys, 32);
619
 
                                QRgb *l=(QRgb*)barmodeImages[i]->scanLine(iy-y);
620
 
                                l[ix-x]=inactiveColor;
621
 
                        }
622
 
        
623
 
                        do
624
 
                        {
625
 
                                if (!barmodeImages[level])
626
 
                                        barmodeImages[level]=new QImage(xs,ys, 32);
627
 
                                QRgb *l=(QRgb*)barmodeImages[level]->scanLine(iy-y);
628
 
                                l[ix-x]=activeColor;
629
 
                        }
630
 
                        while (level++<255);
631
 
                        napp->processEvents();
632
 
                }
633
 
 
634
 
        for (int i=1; i<256; i++)
635
 
        {
636
 
                if (!barmodeImages[i])
637
 
                        continue;
638
 
                barmode[i]=new QPixmap(xs,ys);
639
 
                barmode[i]->convertFromImage(*barmodeImages[i]);
640
 
                delete barmodeImages[i];
641
 
                napp->processEvents();
642
 
        }
643
 
        // create the blank one
644
 
        barmode[0]=new QPixmap(xs, ys);
645
 
        QPixmap px=parent()->pixmap(parser()["BackgroundImage"][1]);
646
 
        bitBlt(barmode[0], 0, 0, &px, x, y, xs, ys, Qt::CopyROP);
647
 
        
648
 
        px.convertFromImage(transmask);
649
 
        barModeMask=px;
650
 
}
651
 
 
652
 
KJSeeker::~KJSeeker()
653
 
{
654
 
        for (int i=0; i<256; i++)
655
 
                if (barmode[i])
656
 
                        delete barmode[i];
657
 
}
658
 
 
659
 
void KJSeeker::paint(QPainter *p, const QRect &)
660
 
{
661
 
        closest();
662
 
        barmode[g]->setMask(barModeMask);
663
 
        bitBlt(p->device(), rect().topLeft().x(), rect().topLeft().y(), barmode[g], 0, 0, rect().width(), rect().height(), Qt::CopyROP);
664
 
}
665
 
 
666
 
bool KJSeeker::mousePress(const QPoint &pos)
667
 
{
668
 
        return (isGray(mScale.pixel(rect().topLeft().x()+pos.x(), rect().topLeft().y()+pos.y())));
669
 
}
670
 
 
671
 
void KJSeeker::mouseRelease(const QPoint &pos, bool in)
672
 
{
673
 
        QRgb color=mScale.pixel(rect().topLeft().x()+pos.x(), 
674
 
                                                 rect().topLeft().y()+pos.y());
675
 
        if (!isGray(color) || !in)
676
 
                return;
677
 
        
678
 
        g=grayRgb(color);
679
 
        repaint();
680
 
 
681
 
        napp->player()->skipTo(g*napp->player()->getLength()/255);
682
 
        return;
683
 
 
684
 
}
685
 
 
686
 
void KJSeeker::timeUpdate(int sec)
687
 
{
688
 
        int length = napp->player()->getLength() / 1000;
689
 
        if (length<1)
690
 
                length=1;
691
 
 
692
 
        if (sec > length)
693
 
                sec = length;
694
 
        else if ( sec < 0 )
695
 
                sec=0;
696
 
 
697
 
        g = sec * 255 / length;
698
 
//      fprintf(stderr,"sec: %d, len: %d, g: %d\n", sec, length, g);
699
 
        QPainter p(parent());
700
 
        paint(&p, rect());
701
 
}
702
 
 
703
 
void KJSeeker::closest()
704
 
{
705
 
        int south=g, north=g;
706
 
        bool southtried=false, northtried=false;
707
 
        while (!barmode[south] && !barmode[north])
708
 
        {
709
 
                if (southtried && northtried) { g=0; return; }
710
 
                south--;
711
 
                north++;
712
 
                if (north>255) {northtried=true; north=g;}
713
 
                if (south<0) {southtried=true; south=g;}
714
 
        }
715
 
        if (barmode[south])
716
 
                g=south;
717
 
        else if (barmode[north])
718
 
                g=north;
719
 
}
720
 
 
721
 
KJVolumeBMP::KJVolumeBMP(const QStringList &i, KJLoader *p)
722
 
        : KJWidget(p), mVolume(0)
723
 
{
724
 
        int x, y, xs, ys;
725
 
        x=i[1].toInt();
726
 
        y=i[2].toInt();
727
 
        xs=i[3].toInt()-x;
728
 
        ys=i[4].toInt()-y;
729
 
        setRect(x,y,xs,ys);
730
 
 
731
 
        mWidth=parser()["VolumeControlImageXSize"][1].toInt();
732
 
        mCount=parser()["VolumeControlImageNb"][1].toInt()-1;
733
 
 
734
 
        mImages=parent()->pixmap(parser()["VolumeControlImage"][1]);
735
 
        mPos=parent()->image(parser()["VolumeControlImagePosition"][1]);
736
 
}
737
 
 
738
 
QString KJVolumeBMP::tip()
739
 
{
740
 
        return i18n("Volume");
741
 
}
742
 
 
743
 
void KJVolumeBMP::paint(QPainter *p, const QRect &)
744
 
{
745
 
        QRect from(mVolume*mCount/100*mWidth, 0, mWidth, mImages.height());
746
 
        bitBlt(p->device(), rect().topLeft(), &mImages, from, Qt::CopyROP);
747
 
}
748
 
 
749
 
bool KJVolumeBMP::mousePress(const QPoint &pos)
750
 
{
751
 
        QRgb color=mPos.pixel(rect().topLeft().x()+pos.x(),
752
 
                               rect().topLeft().y()+pos.y());
753
 
        if (!isGray(color))
754
 
                return false;
755
 
                 
756
 
        mVolume=grayRgb(color)*100/255;
757
 
        napp->player()->setVolume(mVolume);
758
 
 
759
 
        repaint();
760
 
        return true;
761
 
}
762
 
 
763
 
void KJVolumeBMP::mouseRelease(const QPoint &, bool)
764
 
{}
765
 
 
766
 
void KJVolumeBMP::mouseMove(const QPoint &pos, bool in)
767
 
{
768
 
        if (!in) return;
769
 
        mousePress(pos);
770
 
}
771
 
 
772
 
void KJVolumeBMP::timeUpdate(int)
773
 
{
774
 
        mVolume=napp->player()->volume();
775
 
        repaint();
776
 
}
777
 
 
778
 
 
779
 
KJFont::KJFont(const QString &prefix, KJLoader *parent)
780
 
{
781
 
        if (prefix=="TimeFont")
782
 
        {
783
 
                mString[0]="0123456789: ";
784
 
                mString[1]=mString[2]=0;
785
 
                mNullChar=' ';
786
 
        }
787
 
        else
788
 
        {
789
 
                mString[0]="abcdefghijklmnopqrstuvwxyz\"@";
790
 
                mString[1]="0123456789;_:()-'!_+\\/[]*&%.=$#";
791
 
                mString[2]="���?*,                          ";
792
 
                mNullChar=' ';
793
 
        }
794
 
        
795
 
        mText=parent->pixmap(parent->item(prefix+"Image")[1]);
796
 
        mWidth=parent->item(prefix+"Size")[1].toInt();
797
 
        mHeight=parent->item(prefix+"Size")[2].toInt();
798
 
        mSpacing=parent->item(prefix+"Spacing")[1].toInt();
799
 
        mTransparent=(bool)parent->item(prefix+"Transparent")[1].toInt();
800
 
}
801
 
 
802
 
QPixmap KJFont::draw(const QCString &str, int wide, const QPoint &pos) const
803
 
{
804
 
        QPoint to(pos);
805
 
        QCString string=str.lower();
806
 
        QPixmap region(
807
 
                (string.length()*mWidth+string.length()*mSpacing > (unsigned int)wide
808
 
                        ? string.length()*mWidth+string.length()*mSpacing : wide),
809
 
                mHeight);
810
 
        
811
 
        for (unsigned int len=0; len<string.length(); len++)
812
 
        {
813
 
                char c=string[len];
814
 
                drawCharacter(&region, to, c);
815
 
                
816
 
                to+=QPoint(mWidth, 0);
817
 
                // draw according to "spacing"
818
 
                QPoint p=charSource(' ');
819
 
                bitBlt(&region, to, &mText, QRect(p.x(), p.y(), mSpacing, mHeight), Qt::CopyROP);
820
 
                to+=QPoint(mSpacing, 0);
821
 
        }
822
 
        for (; to.x()<=wide; to+=QPoint(mWidth, 0))
823
 
                drawCharacter(&region, to, ' ');
824
 
 
825
 
        return region;
826
 
}
827
 
 
828
 
void KJFont::drawCharacter(QPixmap *dev, const QPoint &to, char c) const
829
 
{
830
 
        QPoint src=charSource(c);
831
 
        int x=src.x();
832
 
        int y=src.y();
833
 
        int xs=mWidth;
834
 
        int ys=mHeight;
835
 
        
836
 
        bitBlt(dev, to, &mText, QRect(x,y,xs,ys), Qt::CopyROP);
837
 
 
838
 
}
839
 
 
840
 
#include <string.h>
841
 
 
842
 
QPoint KJFont::charSource(char c) const
843
 
{
844
 
        for (int i=0; i<3; i++)
845
 
        {
846
 
                const char *pos=strchr(mString[i], c);
847
 
                
848
 
                if (!pos) continue;
849
 
                return QPoint(mWidth*((int)(pos-mString[i])), mHeight*i);
850
 
        }
851
 
 
852
 
        return charSource(mNullChar);
853
 
}
854
 
 
855
 
KJFilename::KJFilename(const QStringList &l, KJLoader *p)
856
 
        : QObject(0), KJWidget(p)
857
 
{
858
 
        int x=l[1].toInt();
859
 
        int y=l[2].toInt();
860
 
        int xs=l[3].toInt()-x;
861
 
        int ys=l[4].toInt()-y;
862
 
        setRect(x,y,xs,ys);
863
 
 
864
 
        mDistance=2; // how far it moves per cycle
865
 
        
866
 
        prepareString(i18n("No File").latin1());
867
 
        killTimers();
868
 
}
869
 
 
870
 
void KJFilename::paint(QPainter *p, const QRect &)
871
 
{
872
 
        bitBlt(p->device(), rect().topLeft(), &mView, 
873
 
               QRect(0,0, rect().width(), rect().height()), Qt::CopyROP);
874
 
}
875
 
 
876
 
void KJFilename::timerEvent(QTimerEvent *)
877
 
{
878
 
        int height=mView.height();
879
 
        int width=mView.width();
880
 
        QPixmap cycle(1, height);
881
 
        bitBlt(&cycle, 0,0, &mView, 0,0, 1, height, Qt::CopyROP);
882
 
        bitBlt(&mView, 0,0, &mView, 1, 0, width-1, height, Qt::CopyROP);
883
 
        bitBlt(&mView, width-1, 0, &cycle, 0,0, 1, height, Qt::CopyROP);
884
 
        repaint();
885
 
}
886
 
 
887
 
bool KJFilename::mousePress(const QPoint &)
888
 
{
889
 
        return true;
890
 
}
891
 
 
892
 
void KJFilename::prepareString(const QCString &str)
893
 
{
894
 
        killTimers();
895
 
        mView=textFont().draw(str, rect().width());
896
 
        startTimer(100);
897
 
}
898
 
 
899
 
void KJFilename::newFile()
900
 
{
901
 
        QCString timestring=napp->player()->lengthString().latin1();
902
 
        timestring=timestring.mid(timestring.find('/')+1);
903
 
        prepareString(QCString(napp->player()->current()->title().latin1())
904
 
                      + " (" + timestring + ")   ");
905
 
}
906
 
 
907
 
KJTime::KJTime(const QStringList &l, KJLoader *p)
908
 
        : KJWidget(p)
909
 
{
910
 
        int x=l[1].toInt();
911
 
        int y=l[2].toInt();
912
 
        int xs=l[3].toInt()-x;
913
 
        int ys=l[4].toInt()-y;
914
 
        setRect(x,y,xs,ys);
915
 
 
916
 
        prepareString("00:00");
917
 
}
918
 
 
919
 
void KJTime::paint(QPainter *p, const QRect &)
920
 
{
921
 
        bitBlt(p->device(), rect().topLeft(), &mTime, 
922
 
               QRect(0,0, rect().width(), rect().height()), Qt::CopyROP);
923
 
}
924
 
 
925
 
bool KJTime::mousePress(const QPoint &)
926
 
{
927
 
        return true;
928
 
}
929
 
 
930
 
void KJTime::timeUpdate(int)
931
 
{
932
 
        if (!napp->player()->current())
933
 
                return;
934
 
        QCString time=napp->player()->lengthString().latin1();
935
 
        time=time.left(time.find('/'));
936
 
 
937
 
        prepareString(time);
938
 
}
939
 
 
940
 
void KJTime::prepareString(const QCString &str)
941
 
{
942
 
        if (str==mCurrentStr) return;
943
 
        mTime=timeFont().draw(str, rect().width());
944
 
        repaint();
945
 
        mCurrentStr=str;
946
 
}
947
 
 
948
 
void KJVisScope::swapScope(Visuals newOne)
949
 
{
950
 
        QStringList line=parent()->item("AnalyzerWindow");
951
 
        KJLoader *p=parent();
952
 
        p->removeChild(this);
953
 
        delete this;
954
 
        
955
 
        KJWidget *w;
956
 
        switch (newOne)
957
 
        {
958
 
        case Null:
959
 
                w=new KJNullScope(line, p);
960
 
                break;
961
 
        case FFT:
962
 
                w=new KJVis(line, p);
963
 
                break;
964
 
        case Mono:
965
 
                w=new KJScope(line, p);
966
 
        };
967
 
 
968
 
        p->addChild(w);
969
 
}
970
 
 
971
 
KJNullScope::KJNullScope(const QStringList &l, KJLoader *parent)
972
 
        : KJVisScope(parent)
973
 
{
974
 
        int x=l[1].toInt();
975
 
        int y=l[2].toInt();
976
 
        int xs=l[3].toInt()-x;
977
 
        int ys=l[4].toInt()-y;
978
 
        setRect(x,y,xs,ys);
979
 
}
980
 
 
981
 
bool KJNullScope::mousePress(const QPoint &)
982
 
{
983
 
        parent()->repaint(rect(), false);
984
 
        swapScope(FFT);
985
 
        
986
 
        return true;
987
 
}
988
 
 
989
 
KJVis::KJVis(const QStringList &l, KJLoader *parent)
990
 
        : KJVisScope(parent), MonoFFTScope(100)
991
 
{
992
 
        int x=l[1].toInt();
993
 
        int y=l[2].toInt();
994
 
        int xs=l[3].toInt()-x;
995
 
        int ys=l[4].toInt()-y;
996
 
        QStringList &col=parser()["AnalyzerColor"];
997
 
        mColor.setRgb(col[1].toInt(), col[2].toInt(), col[3].toInt());  
998
 
 
999
 
        start();
1000
 
        
1001
 
        int w=bands();
1002
 
        int wmult=w;
1003
 
        while (w<xs)
1004
 
                w+=wmult;
1005
 
 
1006
 
        // center the difference
1007
 
        x+=(xs-w)/2;
1008
 
        xs=w;
1009
 
        
1010
 
        mMultiples=w/wmult;
1011
 
        setRect(x,y,xs,ys);
1012
 
 
1013
 
}
1014
 
 
1015
 
void KJVis::scopeEvent(float *d, int size)
1016
 
{
1017
 
        QPainter p(parent());
1018
 
        int x=rect().x();
1019
 
        int y=rect().y();
1020
 
        int height=rect().height();
1021
 
        float *start=d;
1022
 
        float *end=d+size;
1023
 
        float fheight=(float)height;
1024
 
        parent()->repaint(rect(), false);
1025
 
        for ( ; start<end; ++start)
1026
 
        {
1027
 
                // d[i]     amp
1028
 
                // 1.5  =  height
1029
 
                float n=(*start)+1.0;
1030
 
                n=log(n)*fheight*8;
1031
 
                int amp=(int)n;
1032
 
                if (amp<0) amp=0;
1033
 
                if (amp>height) amp=height;
1034
 
                p.fillRect(x, y+(height-amp), mMultiples, amp, mColor);
1035
 
                x+=mMultiples;
1036
 
 
1037
 
        }
1038
 
}
1039
 
 
1040
 
bool KJVis::mousePress(const QPoint &)
1041
 
{
1042
 
        parent()->repaint(rect(), false);
1043
 
        swapScope(Mono);
1044
 
        
1045
 
        return true;
1046
 
}
1047
 
 
1048
 
KJScope::KJScope(const QStringList &l, KJLoader *parent)
1049
 
        : KJVisScope(parent), MonoScope(100)
1050
 
{
1051
 
        int x=l[1].toInt();
1052
 
        int y=l[2].toInt();
1053
 
        int xs=mWidth=l[3].toInt()-x;
1054
 
        int ys=mHeight=l[4].toInt()-y;
1055
 
        QStringList &col=parser()["AnalyzerColor"];
1056
 
        mColor.setRgb(col[1].toInt(), col[2].toInt(), col[3].toInt());  
1057
 
        setRect(x,y, xs, ys);
1058
 
 
1059
 
        start();
1060
 
        // set the samplewidth to the largest integer divisible by mWidth
1061
 
        setSamples(mWidth-1);
1062
 
}
1063
 
 
1064
 
void KJScope::scopeEvent(float *d, int size)
1065
 
{
1066
 
        QPainter p(parent());
1067
 
        p.setPen(mColor);
1068
 
        float *end=d+size;
1069
 
        parent()->repaint(rect(), false);
1070
 
        int x=rect().x();
1071
 
        int y=rect().y();
1072
 
        int heightHalf=mHeight/2;
1073
 
        y+=heightHalf;
1074
 
 
1075
 
        while (d<end)
1076
 
        {
1077
 
                // clip
1078
 
                float n=*d;
1079
 
        
1080
 
                n *= heightHalf*1.5;
1081
 
                int amp=(int)n;
1082
 
                if (amp>heightHalf) amp=heightHalf;
1083
 
                else if (amp<-heightHalf) amp=-heightHalf;
1084
 
 
1085
 
                p.drawLine(x, y, x, y+amp);
1086
 
                d++;
1087
 
                x++;
1088
 
        }
1089
 
}
1090
 
 
1091
 
 
1092
 
bool KJScope::mousePress(const QPoint &)
1093
 
{
1094
 
        parent()->repaint(rect(), false);
1095
 
        swapScope(Null);
1096
 
        return true;
1097
 
}
1098
 
 
1099
 
KJEqualizer::KJEqualizer(const QStringList &l, KJLoader *parent)
1100
 
        : QObject(0), KJWidget(parent)
1101
 
{
1102
 
        int x=l[1].toInt();
1103
 
        int y=l[2].toInt();
1104
 
        int xs=l[3].toInt()-x;
1105
 
        int ys=l[4].toInt()-y;
1106
 
        setRect(x,y,xs,ys);
1107
 
 
1108
 
        mBars=parent->pixmap(parser()["EqualizerBmp"][3]);
1109
 
 
1110
 
        mBands=l[6].toInt();
1111
 
        mXSpace=l[7].toInt();
1112
 
        mBuffer.resize(rect().size());
1113
 
 
1114
 
        mXSize=parser()["EqualizerBmp"][1].toInt();
1115
 
        mNumber=parser()["EqualizerBmp"][2].toInt();
1116
 
 
1117
 
}
1118
 
 
1119
 
int KJEqualizer::barNum(const QPoint &pos) const
1120
 
{
1121
 
        int x=pos.x();
1122
 
        x = x/ mXSpace;
1123
 
        return napp->equalizer()->bandCount()*x / mBands;
1124
 
}
1125
 
 
1126
 
int KJEqualizer::level(const QPoint &pos) const
1127
 
{
1128
 
        int y=-pos.y();
1129
 
        y+=rect().height()/2;
1130
 
        y*=200/(rect().height()/2);
1131
 
        return y;
1132
 
}
1133
 
 
1134
 
void KJEqualizer::paint(QPainter *, const QRect &)
1135
 
{
1136
 
        
1137
 
}
1138
 
 
1139
 
void KJEqualizer::updateBuffer()
1140
 
{
1141
 
        QPainter paint(&mBuffer);
1142
 
        for (int band=0; band< mBands; band++)
1143
 
        {
1144
 
                
1145
 
                
1146
 
        }
1147
 
                
1148
 
}
1149
 
 
1150
 
void KJEqualizer::mouseMove(const QPoint &pos, bool in)
1151
 
{
1152
 
        if (!in) return;
1153
 
 
1154
 
        napp->equalizer()->band(barNum(pos))->setLevel(level(pos));
1155
 
}
1156
 
 
1157
 
bool KJEqualizer::mousePress(const QPoint &p)
1158
 
{
1159
 
        mouseMove(p, true);
1160
 
        return true;
1161
 
}
1162
 
 
1163
 
 
1164
 
#include "kjloader.moc"
1165