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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
/***************************************************************************
kjtexdisplay.cpp
---------------------------------------------
Displays for time and other things
using fonts provided by KJFont
---------------------------------------------
Maintainer: Stefan Gehn <sgehn@gmx.net>
***************************************************************************/
// local includes
#include "kjtextdisplay.h"
#include "kjfont.h"
#include "kjprefs.h"
// kde includes
#include <klocale.h>
#include <kdebug.h>
#include <kpixmap.h>
#include <kurl.h>
#include <krun.h>
#include <kmimemagic.h>
// arts-includes, needed for pitch
#include <artsmodules.h>
#include <arts/reference.h>
#include <arts/soundserver.h>
#include <arts/kmedia2.h>
// noatun includes
#include <noatun/player.h>
#include <noatun/engine.h>
/*******************************************
* KJFilename
*******************************************/
KJFilename::KJFilename(const TQStringList &l, KJLoader *p)
: TQObject(0), KJWidget(p), mBack(0)
{
int x = l[1].toInt();
int y = l[2].toInt();
int xs = l[3].toInt() - x;
int ys = l[4].toInt() - y;
// fix for all those weird skins where the filenamewindow has more
// height than needed for the font
// ( ... usually resulting in garbage on-screen )
if ( ys > (textFont().fontHeight()) )
ys = textFont().fontHeight();
// background under filename-scroller
TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
mBack = new KPixmap ( TQSize(xs,ys) );
bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, TQt::CopyROP );
setRect(x,y,xs,ys);
// how far it moves per cycle
// TODO: make that configurable for the user
//mDistance = 1;
// mDistance = (int)(textFont().fontWidth()/2);
readConfig();
prepareString(i18n("Welcome to Noatun").local8Bit());
killTimers();
}
KJFilename::~KJFilename()
{
delete mBack;
}
void KJFilename::paint(TQPainter *p, const TQRect &)
{
TQPixmap temp ( rect().width(), rect().height() );
// draw background into buffer
bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, TQt::CopyROP );
// draw font into buffer
bitBlt( &temp, 0, 0, &mView, 0, 0, rect().width(), rect().height(), TQt::CopyROP);
// and draw it on screen
bitBlt(p->device(), rect().topLeft(), &temp,
TQRect(0,0,-1,-1), TQt::CopyROP);
}
void KJFilename::timerEvent(TQTimerEvent *)
{
int height = mView.height();
int width = mView.width();
TQBitmap cycleMask ( mDistance, height ); // temporary-space for moving parts of the tqmask
TQPixmap cycle ( mDistance, height ); // temporary-space for moving parts of the pixmap
TQBitmap newMask ( *mView.tqmask() ); // save old tqmask
// copy tqmask like the same way we're doing it with the pixmap
// a tqmask does not get copied on a bitblt automatically, we have to do
// it "by hand"
bitBlt(&cycleMask, 0,0, &newMask, 0,0, mDistance, height, TQt::CopyROP);
bitBlt(&newMask, 0,0, &newMask, mDistance, 0, width-mDistance, height, TQt::CopyROP);
bitBlt(&newMask, width-mDistance, 0, &cycleMask, 0,0, mDistance, height, TQt::CopyROP);
bitBlt(&cycle, 0,0, &mView, 0,0, mDistance, height, TQt::CopyROP);
bitBlt(&mView, 0,0, &mView, mDistance, 0, width-mDistance, height, TQt::CopyROP);
bitBlt(&mView, width-mDistance, 0, &cycle, 0,0, mDistance, height, TQt::CopyROP);
// apply the newly created tqmask
mView.setMask(newMask);
tqrepaint();
}
bool KJFilename::mousePress(const TQPoint &)
{
return true;
}
void KJFilename::mouseRelease(const TQPoint &, bool in)
{
if (!in) // only do something if users is still inside the button
return;
if ( !napp->player()->current() )
return;
KURL dirURL = napp->player()->current().url().upURL();
KMimeMagicResult *result = KMimeMagic::self()->findFileType( dirURL.path() );
// TODO: Maybe test for protocol type?
// if ( napp->player()->current().url().protocol() == "file" )
if ( result->isValid() )
KRun::runURL ( dirURL, result->mimeType() );
}
void KJFilename::readConfig()
{
kdDebug(66666) << "KJFilename::readConfig()" << endl;
mDistance = (int)( textFont().fontWidth() * KJLoader::kjofol->prefs()->titleMovingDistance() );
if ( mDistance <= 0 )
mDistance = 1;
mTimerUpdates = KJLoader::kjofol->prefs()->titleMovingUpdates();
textFont().recalcSysFont();
mLastTitle=""; // tqinvalidate title so it gets tqrepainted on next timeUpdate()
}
void KJFilename::prepareString(const TQCString &str)
{
killTimers(); // i.e. stop timers
mView = textFont().draw(str, rect().width());
startTimer(mTimerUpdates);
}
void KJFilename::timeUpdate(int)
{
if ( !napp->player()->current() ) // just for safety
return;
TQCString title = TQCString( napp->player()->current().title().local8Bit() );
if ( title == mLastTitle )
return;
mLastTitle = title;
TQCString timestring = napp->player()->lengthString().local8Bit();
timestring = timestring.mid(timestring.tqfind('/')+1);
prepareString ( title + " (" + timestring + ") ");
}
TQString KJFilename::tip()
{
if ( !napp->player()->current() ) // just for safety
return i18n("Filename");
else
return napp->player()->current().url().prettyURL();
}
/*******************************************
* KJTime
*******************************************/
KJTime::KJTime(const TQStringList &l, KJLoader *p)
: KJWidget(p), mBack(0)
{
int x = l[1].toInt();
int y = l[2].toInt();
int xs = l[3].toInt() - x;
int ys = l[4].toInt() - y;
// fix for all those weird skins where the timewindow
// has more space than needed for the font
int maxNeededHeight = timeFont().fontHeight();
if ( ys > maxNeededHeight )
ys = maxNeededHeight;
// five digits + spacing between them
int maxNeededWidth = ( 5 *timeFont().fontWidth() ) + ( 4 * timeFont().fontSpacing() );
if ( xs > maxNeededWidth )
xs = maxNeededWidth;
// background under time-display
TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
mBack = new KPixmap ( TQSize(xs,ys) );
bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, TQt::CopyROP );
setRect(x,y,xs,ys);
readConfig();
prepareString("00:00");
}
KJTime::~KJTime()
{
delete mBack;
}
void KJTime::paint(TQPainter *p, const TQRect &)
{
// kdDebug(66666) << "KJTime::paint(TQPainter *p, const TQRect &)" << endl;
TQPixmap temp ( rect().width(), rect().height() );
// draw background into buffer
bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, TQt::CopyROP );
// draw time-display into buffer (that's a pixmap with a tqmask applied)
bitBlt( &temp, 0, 0, &mTime, 0, 0, rect().width(), rect().height(), TQt::CopyROP);
// and draw it on screen
bitBlt(p->device(), rect().topLeft(), &temp,
TQRect(0,0, rect().width(), rect().height()), TQt::CopyROP);
}
bool KJTime::mousePress(const TQPoint &)
{
return true;
}
void KJTime::mouseRelease(const TQPoint &, bool in)
{
if (!in) // only do something if users is still inside the button
return;
countDown = !countDown;
napp->setDisplayRemaining( countDown );
// KJLoader::kjofol->prefs()->setTimeCountMode( countDown );
}
void KJTime::readConfig()
{
// kdDebug(66666) << "KJTime::readConfig()" << endl;
countDown = napp->displayRemaining();
timeFont().recalcSysFont();
mLastTime=""; // tqinvalidate time so it gets tqrepainted on next timeUpdate()
}
TQString KJTime::lengthString ( void )
{
int pos = 0;
TQString posString;
int secs = 0,
seconds = 0,
minutes = 0,
hours = 0;
if ( countDown )
{ // current remaining time
pos = napp->player()->getLength() - napp->player()->getTime();
}
else
{ // current time
pos = napp->player()->getTime();
}
if ( pos < 0 )
{
posString = "00:00";
}
else
{ // get the position
secs = pos / 1000; // convert milliseconds -> seconds
seconds = secs % 60;
minutes = (secs - seconds) / 60;
hours = minutes / 60;
minutes %= 60; // remove the hours from minutes ;)
// cerr << " " << hours << ":" << minutes << ":" << seconds << endl;
// if ( hours > 0 ) // looks ugly :)
if ( (napp->player()->getLength()/1000) >= 3600 ) // displays hh:mm if file is long
{
posString.sprintf("%d:%.2d", hours, minutes);
}
else // displays mm:ss
{
posString.sprintf("%.2d:%.2d", minutes, seconds);
}
}
return posString;
}
void KJTime::timeUpdate(int)
{
// kdDebug(66666) << "START KJTime::timeUpdate(int)" << endl;
if (!napp->player()->current())
return;
prepareString( (lengthString()).latin1() );
// kdDebug(66666) << "END KJTime::timeUpdate(int)" << endl;
}
void KJTime::prepareString(const TQCString &str)
{
// kdDebug(66666) << "START KJTime::prepareString(const TQCString &str)" << endl;
if ( str == mLastTime )
return;
mLastTime = str;
mTime = timeFont().draw(str, rect().width());
tqrepaint();
// kdDebug(66666) << "END KJTime::prepareString(const TQCString &str)" << endl;
}
TQString KJTime::tip()
{
if ( countDown )
return i18n("Play time left");
else
return i18n("Current play time");
}
/*******************************************
* KJVolumeText
*******************************************/
KJVolumeText::KJVolumeText(const TQStringList &l, KJLoader *p)
: KJWidget(p), mBack(0)
{
int x=l[1].toInt();
int y=l[2].toInt();
int xs=l[3].toInt()-x;
int ys=l[4].toInt()-y;
// fix for all those weird skins where the timewindow has more space than needed for the font
if ( ys > (volumeFont().fontHeight()) )
ys = volumeFont().fontHeight();
// 3 digits for volume (1-100)
// + spaces according to spacing
// + percentage letter (seems to be 1px wider than a normal char)
int tempWidth = (3*volumeFont().fontWidth()) + (2*volumeFont().fontSpacing()) + ((volumeFont().fontWidth()+1));
if ( xs > ( tempWidth ) )
xs = tempWidth;
// background under volumetext-display
TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
mBack = new KPixmap ( TQSize(xs,ys) );
bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, TQt::CopyROP );
setRect(x,y,xs,ys);
prepareString("100%");
}
KJVolumeText::~KJVolumeText()
{
delete mBack;
}
void KJVolumeText::paint(TQPainter *p, const TQRect &)
{
TQPixmap temp ( rect().width(), rect().height() );
// draw background into buffer
bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, TQt::CopyROP );
// draw time-display into buffer
bitBlt( &temp, 0, 0, &mVolume, 0, 0, rect().width(), rect().height(), TQt::CopyROP);
// and draw it on screen
bitBlt(p->device(), rect().topLeft(), &temp,
TQRect(0,0,-1,-1), TQt::CopyROP);
}
bool KJVolumeText::mousePress(const TQPoint &)
{
return false;
}
void KJVolumeText::readConfig()
{
volumeFont().recalcSysFont();
mLastVolume=""; // tqinvalidate value so it gets tqrepainted on next timeUpdate()
}
void KJVolumeText::timeUpdate(int)
{
TQCString volume;
if (!napp->player()->current())
return;
volume.sprintf("%d%%", napp->player()->volume() ); // FIXME: is sprintf safe to use?
prepareString(volume);
}
void KJVolumeText::prepareString(const TQCString &str)
{
if ( str == mLastVolume )
return;
mLastVolume = str;
mVolume = volumeFont().draw(str, rect().width());
tqrepaint();
}
TQString KJVolumeText::tip()
{
return i18n("Volume");
}
/*******************************************
* KJPitchText
*******************************************/
KJPitchText::KJPitchText(const TQStringList &l, KJLoader *p)
: KJWidget(p), mBack(0)
{
int x = l[1].toInt();
int y = l[2].toInt();
int xs = l[3].toInt() - x;
int ys = l[4].toInt() - y;
// fix for all those weird skins where the timewindow has more space than needed for the font
if ( ys > (pitchFont().fontHeight()) )
ys = pitchFont().fontHeight();
// 3 digits for volume (1-100), spaces according to spacing and percentage letter
int tempWidth = (3*pitchFont().fontWidth()) + (2*pitchFont().fontSpacing());
if ( xs > tempWidth )
xs = tempWidth;
// background under time-display
TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
mBack = new KPixmap ( TQSize(xs,ys) );
bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, TQt::CopyROP );
setRect(x,y,xs,ys);
prepareString("100");
}
KJPitchText::~KJPitchText()
{
delete mBack;
}
void KJPitchText::paint(TQPainter *p, const TQRect &)
{
TQPixmap temp ( rect().width(), rect().height() );
// draw background into buffer
bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, TQt::CopyROP );
// draw time-display into buffer
bitBlt( &temp, 0, 0, &mSpeed, 0, 0, rect().width(), rect().height(), TQt::CopyROP);
// and draw it on screen
bitBlt(p->device(), rect().topLeft(), &temp, TQRect(0,0,-1,-1), TQt::CopyROP);
}
bool KJPitchText::mousePress(const TQPoint &)
{
return true;
}
void KJPitchText::mouseRelease(const TQPoint &, bool in)
{
if (!in)
return;
Arts::PlayObject playobject = napp->player()->engine()->playObject();
Arts::PitchablePlayObject pitchable = Arts::DynamicCast(playobject);
if (pitchable.isNull())
return;
pitchable.speed( 1.00f ); // reset pitch
}
void KJPitchText::readConfig()
{
pitchFont().recalcSysFont();
mLastPitch=""; // tqinvalidate value so it gets tqrepainted on next timeUpdate()
}
void KJPitchText::timeUpdate(int)
{
TQCString speed;
if (!napp->player()->current())
return;
Arts::PlayObject playobject = napp->player()->engine()->playObject();
Arts::PitchablePlayObject pitchable = Arts::DynamicCast(playobject);
if (pitchable.isNull())
return;
speed.setNum ( (int) ((float)pitchable.speed()*(float)100) );
prepareString ( speed );
}
void KJPitchText::prepareString(const TQCString &str)
{
if ( str == mLastPitch )
return;
mLastPitch = str;
mSpeed = pitchFont().draw(str, rect().width());
tqrepaint();
}
TQString KJPitchText::tip()
{
return i18n("Pitch");
}
/*******************************************
* KJFileInfo
*******************************************/
KJFileInfo::KJFileInfo(const TQStringList &l, KJLoader *p)
: KJWidget(p), mBack(0)
{
mInfoType = l[0]; // type of info-display
int x = l[1].toInt();
int y = l[2].toInt();
int xs = l[3].toInt() - x;
int ys = l[4].toInt() - y;
// fix for all those weird skins where the timewindow
// has more space than needed for the font
int maxNeededHeight = timeFont().fontHeight();
if ( ys > maxNeededHeight )
ys = maxNeededHeight;
// five digits + spacing between them
int maxNeededWidth = ( 3 *timeFont().fontWidth() ) + ( 2 * timeFont().fontSpacing() );
if ( xs > maxNeededWidth )
xs = maxNeededWidth;
// background under info-display
TQPixmap tmp = p->pixmap(p->item("backgroundimage")[1]);
mBack = new KPixmap ( TQSize(xs,ys) );
bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, TQt::CopyROP );
setRect(x,y,xs,ys);
prepareString("");
}
KJFileInfo::~KJFileInfo()
{
delete mBack;
}
void KJFileInfo::paint(TQPainter *p, const TQRect &)
{
TQPixmap temp ( rect().width(), rect().height() );
// draw background into buffer
bitBlt ( &temp, 0, 0, mBack, 0, 0, -1, -1, TQt::CopyROP );
// draw time-display into buffer (that's a pixmap with a tqmask applied)
bitBlt( &temp, 0, 0, &mTime, 0, 0, rect().width(), rect().height(), TQt::CopyROP);
// and draw it on screen
bitBlt(p->device(), rect().topLeft(), &temp,
TQRect(0,0, rect().width(), rect().height()), TQt::CopyROP);
}
bool KJFileInfo::mousePress(const TQPoint &)
{
return false;
}
void KJFileInfo::readConfig()
{
textFont().recalcSysFont();
mLastTime=""; // tqinvalidate value so it gets tqrepainted on next timeUpdate()
}
void KJFileInfo::timeUpdate(int)
{
if (!napp->player()->current())
return;
const PlaylistItem &item = napp->player()->current();
TQString prop;
if ( mInfoType == "mp3khzwindow" )
{
prop = item.property("samplerate");
prop.truncate(2); // we just want 44 instead of 44100
}
else if ( mInfoType == "mp3kbpswindow" )
{
prop = item.property("bitrate");
}
else // for safety: no infoType we know of
return;
if (prop.isNull())
prop="";
prepareString( prop.latin1() );
}
void KJFileInfo::prepareString(const TQCString &str)
{
if ( str == mLastTime )
return;
mLastTime = str;
mTime = textFont().draw(str, rect().width());
tqrepaint();
}
TQString KJFileInfo::tip()
{
if ( mInfoType == "mp3khzwindow" )
return i18n("Sample rate in kHz");
else if ( mInfoType == "mp3kbpswindow" )
return i18n("Bitrate in kbps");
return TQString();
}
#include "kjtextdisplay.moc"
|