summaryrefslogtreecommitdiffstats
path: root/noatun/modules/kaiman/style.cpp
blob: 2c31815425c2c85364aaa10f3e57bc96f0ca534c (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
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
/*
   Copyright (c) 2000 Stefan Schimanski (1Stein@gmx.de)
                 1999-2000 Christian Esken (esken@kde.org)

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


#include <tdeapplication.h>
#include <kstandarddirs.h>
#include <tdemessagebox.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqpainter.h>
#include <tqdropsite.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <kurldrag.h>
#include <tqtimer.h>

#include <stdlib.h>
#include <unistd.h>

#include "style.h"
#include "userinterface.h"
#include <noatun/app.h>
#include <noatun/stdaction.h>

const bool KaimanStyleSlider::optionVertical = 1;
const bool KaimanStyleSlider::optionReversed = 2;
const bool KaimanStyleText::optionExtended = 1;

KaimanStyleElement::KaimanStyleElement(TQWidget *parent, const char *name)
    : TQWidget(parent, name)
{
    // Initialize everything to default values
    filename = "";
    element  = "";
    upperLeft.setX(0);
    upperLeft.setY(0);
    dimension.setWidth(0);
    dimension.setHeight(0);
    optionPrelight = optionStatuslight = false;
    options[0] = options[1] = options[2] = false;
    _currentPixmap = 0;
    digits = -1;
    pixmapLines = 1;
    pixmapColumns = 1;

    setAcceptDrops(true);
    pixmaps.setAutoDelete(true);

    setBackgroundMode( NoBackground );
}


KaimanStyleElement::~KaimanStyleElement()
{
}


void KaimanStyleElement::loadPixmaps(TQString &val_s_filename)
{
    TQPixmap pixmap;

    bool i_b_ret = pixmap.load(val_s_filename);
    pixmapNum = pixmapLines*pixmapColumns;

    pixmaps.resize(pixmapNum);

    if ( i_b_ret )  {
        if(pixmapNum) {
            int firstWidth, firstHeight, width, height, sourcex = 0, sourcey = 0;

            // first bitmap may be with different size
            if ( dimension.width()!=0 )
            {
                firstWidth = dimension.width();
                if ( pixmapColumns>1 )
                    width = (pixmap.width()-firstWidth) / (pixmapColumns-1);
                else
                    width = 0;
            } else
                firstWidth = width = pixmap.width() / pixmapColumns;

            if ( dimension.height()!=0 )
            {
                firstHeight = dimension.height();
                if ( pixmapLines>1 )
                    height = (pixmap.height()-firstHeight) / (pixmapLines-1);
                else
                    height = 0;
            } else
                firstHeight = height = pixmap.height() / pixmapLines;

            // create single pixmaps
            int i=0;
            sourcey = 0;
            for( int y=0; y<pixmapLines; y++ )
            {
                int h = (y==0) ? firstHeight : height;
                sourcex = 0;

                for( int x=0; x<pixmapColumns; x++ )
                {
                    int w = (x==0) ? firstWidth : width;

                    TQPixmap *part = new TQPixmap(w,h,pixmap.depth());
                    part->fill(TQt::black);
                    bitBlt(part,0,0,&pixmap,sourcex,sourcey,w,h);
                    pixmaps.insert(i,part);

                    if(pixmap.mask())
                    {
                        TQBitmap maskpart(w,h);
                        bitBlt(&maskpart,0,0,pixmap.mask(),sourcex,sourcey,w,h);
                        part->setMask(maskpart);
                    }

                    i++;
                    sourcex += w;
                }

                sourcey += h;
            }
        }
    } else {
        kdDebug() << "Cannot load pixmap " <<  val_s_filename << endl;

        for ( int i=0; i<pixmapNum; i++ )
        {
            TQPixmap *pm = new TQPixmap(10, 10);
            pm->fill(TQt::black);
            pixmaps.insert( i, pm );
        }
    }

    if ( dimension.width()==0 ) dimension.setWidth( pixmaps[0]->width() );
    if ( dimension.height()==0 ) dimension.setHeight( pixmaps[0]->height() );
    setGeometry( TQRect(upperLeft, dimension) );
}

void KaimanStyleElement::setPixmap( int num )
{
    if ( num!=_currentPixmap )
    {
        if ( num>pixmapNum-1 ) num = pixmapNum-1;
        if ( num<0 ) num = 0;

        _currentPixmap = num;
        repaint( FALSE );
    }
}

void KaimanStyleElement::paintEvent ( TQPaintEvent */*qpe*/ )
{
    TQPixmap *pm = pixmaps[_currentPixmap];
    if ( pm )
        bitBlt(this, 0, 0, pm );
    else
        kdDebug() << "Invalid pixmap" << endl;

/*    TQPainter p( this );
    p.setBrush( NoBrush );
    p.setPen( TQColor(255,255,255) );
    p.drawRect( 0, 0, width(), height() );
    p.drawText( 2, 16, name() ); */
}

void KaimanStyleElement::dragEnterEvent( TQDragEnterEvent *event )
{
    event->accept( KURLDrag::canDecode(event) );
}

void KaimanStyleElement::dropEvent( TQDropEvent *event )
{
    ((Kaiman*)(parentWidget()->parentWidget()))->doDropEvent(event);
}

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


KaimanStyleButton::KaimanStyleButton(TQWidget *parent, const char *name)
    : KaimanStyleMasked(parent, name)
{
    i_b_lit = i_b_prelit = i_b_down = false;
    i_i_currentState = NormalUp;

    I_pmIndex.resize( StateListEND );

    for (int i=0; i<StateListEND; i++) {
        // Set pixmap index of all states to 0 (the default pixmap)
        I_pmIndex.insert( i, new int(0));
    }
}

KaimanStyleButton::~KaimanStyleButton()
{
}

void KaimanStyleButton::mousePressEvent(TQMouseEvent *qme)
{
    // We deactivate prelight, because the user presses the button.
    // So it is now down, but there is no PrelitDown icon (BTW: would
    // make no real sense anyhow).
    setPrelight(false);
    setDown(true);
    grabMouse();

    KaimanStyleMasked::mousePressEvent( qme );
}

void KaimanStyleButton::mouseReleaseEvent(TQMouseEvent *qme)
{
    releaseMouse ();

    if (down())
    {
        setDown(false);
        emit clicked();
    }

    KaimanStyleMasked::mouseReleaseEvent( qme );
}


/* paint prelight */
void KaimanStyleButton::enterEvent ( TQEvent * e )
{
    if ( !down() )
        setPrelight(true);

    KaimanStyleMasked::enterEvent( e );
}

/* unpaint prelight */
void KaimanStyleButton::leaveEvent ( TQEvent * e )
{
    if (!down())
        setPrelight(false);

    KaimanStyleMasked::leaveEvent( e );
}

bool KaimanStyleButton::lit()
{
    return i_b_lit;
}

void KaimanStyleButton::setLit(bool val_b_lit)
{
    i_b_lit = val_b_lit;
    updateButtonState();
}

bool KaimanStyleButton::prelit()
{
    return i_b_prelit;
}

void KaimanStyleButton::setPrelight(bool val_b_prelit)
{
    i_b_prelit = val_b_prelit;
    updateButtonState();
}

bool KaimanStyleButton::down()
{
    return i_b_down;
}

void KaimanStyleButton::setDown(bool val_b_down)
{
    i_b_down = val_b_down;
    updateButtonState();
}

void KaimanStyleButton::updateButtonState() {

    if ( i_b_prelit ) {
        if ( i_b_lit ) {
            // Prelit and Lit
            i_i_currentState = PrelightLitUp;
        }
        else {
            // Prelit and not Lit
            i_i_currentState = PrelightUp;
        }
    }

    else if ( i_b_lit ) {
        if ( i_b_down ) {
            // Lit and Down
            i_i_currentState = LitDown;
        } else {
            // Lit and not Down
            i_i_currentState = LitUp;
        }
    }
    else {
        if ( i_b_down ) {
            // Normal and Down
            i_i_currentState = NormalDown;
        }
        else {
            // Normal and not Down
            i_i_currentState = NormalUp;
        }
    }

    setPixmap( *I_pmIndex[i_i_currentState] );
    repaint();
}


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

KaimanStyleSlider::KaimanStyleSlider(int min, int max, TQWidget *parent, const char *name)
    : KaimanStyleMasked( parent, name )
{
    _min = min;
    _max = max;
    _down = false;
    _lit = false;

    setValue( _min );
}


KaimanStyleSlider::~KaimanStyleSlider()
{
}


void KaimanStyleSlider::setValue( int value )
{
    if (value>_max) value=_max;
    if (value<_min) value=_min;
    _value = value;
    repaint();
}


void KaimanStyleSlider::setValue( int value, int min, int max )
{
    if ( value!=_value || min!=_min || max!=_max ) {
        _min = min;
        _max = max;
        setValue( value );
        repaint();
    }
}

int KaimanStyleSlider::pos2value( int x, int y )
{
    int p;
    int v;
    if ( options[optionVertical] ) {
        p = y;
        v = p*(_max-_min)/height();
    } else {
        p = x;
        v = p*(_max-_min)/width();
    }

    if ( options[optionReversed] ) v = (_max-_min) - v;
    return _min + v;
}


void KaimanStyleSlider::mouseMoveEvent(TQMouseEvent *qme)
{
    KaimanStyleMasked::mouseMoveEvent( qme );

    if ( _down )
    {
        setValue( pos2value(qme->x(), qme->y()) );
        emit newValue( value() );
    }
}

void KaimanStyleSlider::mousePressEvent(TQMouseEvent *qme)
{
    if ( !_down )
    {
        grabMouse();
        _down = true;

        setValue( pos2value(qme->x(), qme->y()) );
        emit newValueDrag( value() );
        emit newValue( value() );
    }

    KaimanStyleMasked::mousePressEvent( qme );
}


void KaimanStyleSlider::mouseReleaseEvent(TQMouseEvent *qme)
{
    if ( _down )
    {
        _down = false;
        releaseMouse();
        repaint();

        setValue( pos2value(qme->x(), qme->y()) );
        emit newValue( value() );
        emit newValueDrop( value() );
    }

    KaimanStyleMasked::mouseReleaseEvent( qme );
}


void KaimanStyleSlider::paintEvent(TQPaintEvent */*qpe*/)
{
    // draw background
    bitBlt( this, 0, 0, pixmaps[0] );

    // draw optional handle
    TQPixmap *handle;
    if ( _down )
        handle = pixmaps[2];
    else
    {
        if ( _lit && optionPrelight )
            handle = pixmaps[3];
        else
            handle = pixmaps[1];
    }

    if ( handle && handle->width() )
    {
        int x = 0;
        int y = 0;

        if ( _max-_min ) {
            int v = _value-_min;
            if ( options[optionReversed] ) v = (_max-_min) - v;

            if ( options[optionVertical] )
                y = ( height()-handle->height() ) * v / (_max-_min);
            else
                x = ( width()-handle->width() ) * v / (_max-_min);
        }

        bitBlt( this, x, y, handle );
    }
}

void KaimanStyleSlider::enterEvent ( TQEvent * e )
{
    if ( !_lit && optionPrelight )
    {
        _lit = true;
        repaint();
    }

    KaimanStyleMasked::enterEvent( e );
}

void KaimanStyleSlider::leaveEvent ( TQEvent * e )
{
    if ( _lit )
    {
        _lit = false;
        repaint();
    }

    KaimanStyleMasked::leaveEvent( e );
}


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


KaimanStyleBackground::KaimanStyleBackground(TQWidget *parent, const char *name)
    : KaimanStyleMasked( parent, name )
{
    i_b_move = false;
}

KaimanStyleBackground::~KaimanStyleBackground()
{
}

void KaimanStyleBackground::mouseReleaseEvent(TQMouseEvent *qme)
{
    i_b_move = false;
    KaimanStyleMasked::mouseReleaseEvent( qme );
}

void KaimanStyleBackground::mouseMoveEvent(TQMouseEvent *qme)
{
    TQPoint diff = qme->globalPos() - i_point_lastPos;
    if ( abs(diff.x()) > 10 || abs(diff.y()) > 10) {
        // Moving starts only, when passing a drag border
        i_b_move = true;
    }

    if ( i_b_move ) {
        TQWidget *p = parentWidget()->parentWidget();
        if ( !p ) p = parentWidget();

        p->move( qme->globalPos() - i_point_dragStart );
    }

    KaimanStyleMasked::mouseMoveEvent( qme );
}

void KaimanStyleBackground::mousePressEvent(TQMouseEvent *qme)
{
    // On the background we move the shaped toplevel around
    if (!i_b_move) {
        i_point_dragStart = qme->pos();
        i_point_lastPos = qme->globalPos();
    }

    KaimanStyleMasked::mousePressEvent( qme );
}

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

KaimanStyleValue::KaimanStyleValue(int min, int max, TQWidget *parent, const char *name)
    : KaimanStyleMasked( parent, name )
{
    _min = min;
    _max = max;
    _value = _min;

    setPixmap( 0 );
}

KaimanStyleValue::~KaimanStyleValue()
{
}

void KaimanStyleValue::setValue( int value )
{
    if (value>_max) value=_max;
    if (value<_min) value=_min;
    _value = value;

    int len = _max-_min;
    if ( len )
        setPixmap( (_value-_min)*pixmapNum/len );
    else
        setPixmap( 0 );
}

void KaimanStyleValue::setValue( int value, int min, int max )
{
    _min = min;
    _max = max;

    setValue( value );
}


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

KaimanStyleNumber::KaimanStyleNumber(TQWidget *parent, const char *name)
    : KaimanStyleElement( parent, name )
{
    //kdDebug(66666) << k_funcinfo << "name = '" << name << "'" << endl;
    _value = 0;
    if (TQCString(name) == "In_Rate_Number")
       digits = 3;
    else
       digits = 2;
}

KaimanStyleNumber::~KaimanStyleNumber()
{
}


void KaimanStyleNumber::loadPixmaps(TQString &val_s_filename)
{
    KaimanStyleElement::loadPixmaps( val_s_filename );
    resize( digits*pixmaps[0]->width(),pixmaps[0]->height() );
}


void KaimanStyleNumber::setValue( int value )
{
    if ( _value!=value )
    {
        _value = value;
        repaint();
    }
}

void KaimanStyleNumber::paintEvent(TQPaintEvent */*qpe*/)
{
    // check for overflow
    int v = _value;
    for ( int i=digits; i>0 && v>0; i-- )
        v /= 10;

    if ( v!=0 )
        v = 999999999; // overflow
    else
        v = _value;

    // draw number
    int x = width();
    do {
        x -= pixmaps[0]->width();
        bitBlt(this, x, 0, pixmaps[v%10] );

        v /= 10;
    } while ( v>0 );

    // draw right free space
    while ( x>0 )
    {
        x -= pixmaps[0]->width();
        bitBlt(this, x, 0, pixmaps[0] );
    }
/*
    TQPainter p( this );
    p.setBrush( NoBrush );
    p.setPen( TQColor(255,255,255) );
    p.drawRect( 0, 0, width(), height() );
    p.drawText( 2, 16, name() );*/
}

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

KaimanStyleText::KaimanStyleText(TQWidget *parent, const char *name)
    : KaimanStyleElement( parent, name )
{
    _pos = 0;
    _timer = new TQTimer( this );
    _delay = 500;
    connect( _timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeout()) );
}

KaimanStyleText::~KaimanStyleText()
{
}


void KaimanStyleText::loadPixmaps(TQString &val_s_filename)
{
    KaimanStyleElement::loadPixmaps( val_s_filename );
    resize( digits*pixmaps[0]->width(), pixmaps[0]->height() );
}


void KaimanStyleText::setValue( TQString value )
{
    if ( value!=_value ) {
        _pos = 0;
        _direction = 1;
        _value = value;
        repaint();
    }
}


void KaimanStyleText::startAnimation( int delay )
{
    _pos = 0;
    _direction = 1;
    _delay = delay;
    _timer->start( _delay, TRUE );
}


void KaimanStyleText::stopAnimation()
{
    _pos = 0;
    _timer->stop();
}


void KaimanStyleText::timeout()
{
    // reflect
    if ( _pos+_direction<0 || (int)_value.length()-(_pos+_direction)<digits ) {
        _direction = -_direction;
        _timer->start( _delay*5, TRUE );
    } else {
        // check new position
        if ( _pos+_direction>=0 && (int)_value.length()-(_pos+_direction)>=digits ) {
            _pos += _direction;
            repaint();
        }

        _timer->start( _delay, TRUE );
    }


}


void KaimanStyleText::paintEvent(TQPaintEvent */*qpe*/)
{
    // draw number
    int p;
    for (p=0; p<digits && p<(int)_value.length()-_pos; p++ )
    {
        int pmNum = _value[p+_pos].latin1() - ' ' ;
        if ( pmNum>=96 ) pmNum = '?' - ' ';
        if ( pmNum<0 ) pmNum = '?' - ' ';

        TQPixmap *pm = pixmaps[pmNum];
        if ( pm ) bitBlt(this, p*pixmaps[0]->width(), 0, pm );
    }

    TQPixmap *pm = pixmaps[0];
    for ( ; p<digits; p++ )
        bitBlt(this, p*pixmaps[0]->width(), 0, pm );

/*    TQPainter pnt( this );
    pnt.setBrush( NoBrush );
    pnt.setPen( TQColor(255,255,255) );
    pnt.drawRect( 0, 0, width(), height() );
    pnt.drawText( 2, 16, name() );*/
}

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

KaimanStyleAnimation::KaimanStyleAnimation(int delay, TQWidget *parent, const char *name)
    : KaimanStyleMasked( parent, name )
{
    _delay = delay;
    _frame = 0;
    _timer = new TQTimer( this );
    connect( _timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeout()) );
}

KaimanStyleAnimation::~KaimanStyleAnimation()
{
}

void KaimanStyleAnimation::start()
{
    _timer->start( _delay, FALSE );
}

void KaimanStyleAnimation::pause()
{
    _timer->stop();
}

void KaimanStyleAnimation::stop()
{
    _timer->stop();
    _frame = 0;
    setPixmap( _frame );
}

void KaimanStyleAnimation::timeout()
{
    _frame++;
    if ( _frame>=pixmapNum ) _frame = 1;
    setPixmap( _frame );
}

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

KaimanStyleState::KaimanStyleState(TQWidget *parent, const char *name)
    : KaimanStyleMasked( parent, name )
{
    _value = 0;
}

KaimanStyleState::~KaimanStyleState()
{
}

void KaimanStyleState::setValue( int value )
{
    _value = value;
    setPixmap( _value );
}

void KaimanStyleState::mousePressEvent(TQMouseEvent *qme)
{
    emit clicked();
    KaimanStyleMasked::mouseReleaseEvent( qme );
}

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


KaimanStyle::KaimanStyle( TQWidget *parent, const char *name )
    : TQWidget( parent, name )
{
    i_qw_parent = parent;
    i_eventSemaphore = false;
}


KaimanStyle::~KaimanStyle()
{
}


int KaimanStyle::parseStyleFile(TQString &l_s_tmpName)
{
    int l_i_ret = false;

    TQStringList l_s_tokens;

    TQFile l_fd(l_s_tmpName);
    if ( l_fd.open(IO_ReadOnly) ) {
        // file opened successfully
        TQTextStream l_ts_line( &l_fd );
        TQString l_s_textLine, l_s_token;
        while ( !l_ts_line.eof() ) {
            // Clear list of tokens (we are going to fill them now)
            l_s_tokens.clear();

            // Read a line
            l_s_textLine = l_ts_line.readLine();
            l_s_textLine = l_s_textLine.simplifyWhiteSpace();

            if ( l_s_textLine.left(1) != "#" ) {
                // OK, this is not a comment line
                if ( l_s_textLine.isNull())
                    l_s_textLine = "";
                while ( !l_s_textLine.isEmpty() ) {
                    l_s_token = getToken(l_s_textLine, ' ');
                    if ( ! l_s_token.isEmpty() ) {
                        // OK. There is a useful token. It is not NULL
                        if ( l_s_token.right(1) == ":" )
                            l_s_tokens.append(l_s_token.left(l_s_token.length() -1 ));
                        else
                            l_s_tokens.append(l_s_token);
                    } // -<- if it is a not-empty token
                } // -<- while there are tokens available

                interpretTokens(l_s_tokens);

            } // -<- if is not comment line
        } // -<- While not EOF on file

        l_i_ret = 0;
    } // -<- if file could be opened

    else {
        l_i_ret = KaimanStyle::FileNotFound;
    }
    return l_i_ret;
}



/*
  This function gets a list of tokens and inserts a new
  KaimanStyleElement in I_styleElem. */
void  KaimanStyle::interpretTokens(TQStringList& ref_s_tokens)
{
    if ( ref_s_tokens.count() < 1 ) {
        // A list with less than 1 item is useless to us
        return;
    }

    TQString l_s_tokenTypes;
    const TQString &l_s_elem = ref_s_tokens.first();
    bool l_vertPixmaps = false;
    int l_i_pmIndex[KaimanStyleButton::StateListEND];
    for (int i=0; i<KaimanStyleButton::StateListEND; i++) l_i_pmIndex[i]=0;

    enum { UnknownElement, BackgroundElement, MaskElement, ButtonElement, SliderElement,
           ValueElement, AnimationElement, StateElement, DigitElement, NumberElement,
           TextElement } l_elementType = UnknownElement;

    // Now determine the meaning of the following tokens
    // l_s_tokenTypes stores the meaning (e.g. x-Position, filename, ...)
    if ( l_s_elem == "Background" ) {
        l_s_tokenTypes = "f";
        l_elementType = BackgroundElement;
    }
    // ---
    else if ( l_s_elem == "Mask" ) {
        l_s_tokenTypes = "f";
        l_elementType = MaskElement;
    } else if ( l_s_elem=="Digit_Small" || l_s_elem=="Digit_Small_Default" ) {
        i_smallFont = ref_s_tokens[1];
        return;
    } else if ( l_s_elem=="Digit_Large" || l_s_elem=="Digit_Large_Default" ) {
        i_largeFont = ref_s_tokens[1];
        return;
    }
    // ---
    else if ( l_s_elem == "Title" ||
              l_s_elem == "Album"  ||
              l_s_elem == "Artist"  ||
              l_s_elem == "Genre" ) {
        // You can have an OPTIONAL argument, so lets see if it is there.
        if (ref_s_tokens.count() == 6 )
            l_s_tokenTypes = "fd1xy";
        else
            l_s_tokenTypes = "fdxy";
        l_elementType = TextElement;
    }
    // ---
    else if ( l_s_elem == "Play_Button" ||
              l_s_elem == "Pause_Button"  ||
              l_s_elem == "Stop_Button"  ||
              l_s_elem == "Shuffle_Button"  ||
              l_s_elem == "Repeat_Button" ) {
        l_s_tokenTypes = "fPSxy";
        l_i_pmIndex[KaimanStyleButton::NormalUp]     = 0;
        l_i_pmIndex[KaimanStyleButton::NormalDown]   = 1;
        l_i_pmIndex[KaimanStyleButton::LitUp]        = 2;
        l_i_pmIndex[KaimanStyleButton::LitDown]      = 3;
        l_i_pmIndex[KaimanStyleButton::PrelightUp]   = 4;
        l_i_pmIndex[KaimanStyleButton::PrelightLitUp] = 5;
        l_elementType = ButtonElement;
    }
    // ---
    else if ( l_s_elem == "Next_Button" ||
              l_s_elem == "Prev_Button"  ||
              l_s_elem == "FF"  ||
              l_s_elem == "RW"  ||
              l_s_elem == "Playlist_Button"  ||
              l_s_elem == "Config_Button"  ||
              l_s_elem == "Iconify_Button"  ||
              l_s_elem == "Mixer_Button"  ||
              l_s_elem == "Exit_Button"  ||
              l_s_elem == "Alt_Skin_Button"  ||
              l_s_elem == "Volume_Up_Button"  ||
              l_s_elem == "Volume_Down_Button"  ||
              l_s_elem == "Balance_Left_Button"  ||
              l_s_elem == "Balance_Right_Button" ) {
        l_i_pmIndex[KaimanStyleButton::NormalUp]     = 0;
        l_i_pmIndex[KaimanStyleButton::NormalDown]  = 1;
        l_i_pmIndex[KaimanStyleButton::PrelightUp]   = 2;
        l_s_tokenTypes = "fPxy";
        l_elementType = ButtonElement;
    }
    // ---
    else if ( l_s_elem == "Stereo_Item" ||
              l_s_elem == "Shuffle_Item"  ||
              l_s_elem == "Repeat_Item"  ||
              l_s_elem == "Mpegversion_Item"  ||
              l_s_elem == "Mpeglayer_Item"  ||
              l_s_elem == "Mpegmode_Item"  ||
              l_s_elem == "Status_Item" ) {
        l_s_tokenTypes = "Vfxy";
        l_elementType = StateElement;
    }
    // ---
    else if ( l_s_elem == "Hour_Number"  ||
              l_s_elem == "Minute_Number"  ||
              l_s_elem == "Second_Number"  ||
              l_s_elem == "Song_Number"  ||
              l_s_elem == "Total_Number"  ||
              l_s_elem == "In_Rate_Number"  ||
              l_s_elem == "In_Hz_Number"  ||
              l_s_elem == "Out_Bits"  ||
              l_s_elem == "Out_Hz"  ||
              l_s_elem == "Song_Minute"  ||
              l_s_elem == "Song_Second"  ||
              l_s_elem == "Frame"  ||
              l_s_elem == "Frame_Total"  ||
              l_s_elem == "CPU_Number"  ||
              l_s_elem == "Hour_Total"  ||
              l_s_elem == "Minute_Total"  ||
              l_s_elem == "Second_Total_Number" ) {
        // You can have an OPTIONAL argument, so lets see if it is there.
        if (ref_s_tokens.count() == 6 )
            l_s_tokenTypes = "fd1xy";
        else if (ref_s_tokens.count() == 5 )
            l_s_tokenTypes = "fdxy";
        else
            l_s_tokenTypes = "fxy";

        l_elementType = NumberElement;
    }
    // ---
    else if ( l_s_elem == "Position_Item" ||
              l_s_elem == "Volume_Item"  ||
              l_s_elem == "Balance_Item" ) {
        l_s_tokenTypes = "Vflxy";
        l_elementType = ValueElement;
    }
    // ---
    else if ( l_s_elem == "Load_Item" ) {
        l_s_tokenTypes = "Vflxy";
        l_elementType = AnimationElement;
    }
    // ---
    else if ( l_s_elem == "Position_Slider" ||
              l_s_elem == "Volume_Slider"  ||
              l_s_elem == "Balance_Slider" ) {

        if ( ref_s_tokens.count()==10 )
            l_s_tokenTypes = "VfP12wxyh";
        else
            l_s_tokenTypes = "VfP12sxy";
        l_elementType = SliderElement;
    }
    else {
        kdDebug() << l_s_elem << " not handled yet." << endl;
        l_s_tokenTypes = "f";
    }

    /* The above lines decode the meanings of the tokens. The rules for
       this are the SKIN-SPECS. So the decoder implements a syntactic
       analyser (parser).

       I now do know the type of each tokens, whether it represents a
       filename, the prelight parameter, the x position or what else. This
       information resides in l_s_tokenTypes, and will help in creating
       the kaiman style elements.

       I will now do two things:
       1) Create a new KaimanStyle*, that is inserted into I_styleElem.
       2) Fill the KaimanStyleElement structure, by interpreting the tokens.
    */
    TQStringList::Iterator li_s_tokens = ref_s_tokens.begin();
    ++ li_s_tokens; // Skip the name of the element

    // 1) Create a new KaimanStyleElement, that is inserted into I_styleElem.
    KaimanStyleElement *l_kse_elem = 0;
    KaimanStyleButton *but = 0;

    switch ( l_elementType )
    {
        case BackgroundElement:
            l_kse_elem = new KaimanStyleBackground(this, l_s_elem.latin1());
            l_kse_elem->show();
            break;

        case MaskElement:
            l_kse_elem = new KaimanStyleElement(this, l_s_elem.latin1());
            l_kse_elem->hide();
            break;

        case ButtonElement:
            l_kse_elem = new KaimanStyleButton(this, l_s_elem.latin1());
            but = static_cast<KaimanStyleButton*>(l_kse_elem);
            l_kse_elem->show();
            break;

        case SliderElement:
            l_kse_elem = new KaimanStyleSlider(0, 100, this, l_s_elem.latin1());
            i_sliders.append(l_kse_elem);
            l_kse_elem->show();
            break;

        case ValueElement:
            l_kse_elem = new KaimanStyleValue(0, 100, this, l_s_elem.latin1());
            break;

        case AnimationElement:
            l_kse_elem = new KaimanStyleAnimation(30, this, l_s_elem.latin1());
            break;

        case StateElement:
            l_kse_elem = new KaimanStyleState(this, l_s_elem.latin1());
            break;

        case NumberElement:
            l_kse_elem = new KaimanStyleNumber(this, l_s_elem.latin1());
            break;

        case TextElement:
            l_kse_elem = new KaimanStyleText(this, l_s_elem.latin1());
            break;

        default:
            break;
    }

    if ( !l_kse_elem )
    {
        kdDebug() << "Ignoring style element " << l_s_elem << endl;
        return;
    }

    // insert element into element list
    uint l_i_size = I_styleElem.size();
    I_styleElem.resize(l_i_size + 1);
    I_styleElem.insert(l_i_size, l_kse_elem);
    l_kse_elem->installEventFilter( this );

    // initialize element parameters
    l_kse_elem->element = l_s_elem;

    if (  l_s_tokenTypes.left(1) == "V" ) {
        //Qt::Vertical flag
        l_vertPixmaps = true;
        l_s_tokenTypes = l_s_tokenTypes.mid(1);
    }

    // initialize button parameters
    if ( but )
    {
        for (int i=0; i<KaimanStyleButton::StateListEND; i++)
            but->I_pmIndex.insert(i, new int(l_i_pmIndex[i]) );
    }

    // 2) Fill the KaimanStyleElement structure, by interpreting the tokens.
    while ( l_s_tokenTypes.length() != 0 ) {
        /* The skindata format allows omitting arguments if the parser
           can reconstruct without problems what you mean.  This is taken
           into account when writing the l_s_tokenTypes sting.

           Unfortunately, several skins do ship with a broken skindata file.
           Most common problem is that width and height is also given.

           Even worse examples leave out specified parametes and add others.
           For instance, the pause line is specified as "fPSxy". But in k9


           the line looks like

           Pause_Button: pause.jpg FALSE 91 148 116 173

           So the actual parameters are fPxywh. The parser has to be pretty
           smart now. It should "see" that S (status light) is not present,
           since that should be either TRUE or FALSE, and distribute the
           others accordingly. */

        bool skipOne;

        do {
            skipOne = false;

            // Take the first item from the l_s_tokenTypes;
            char l_c_type = (l_s_tokenTypes[0]).latin1();
            l_s_tokenTypes = l_s_tokenTypes.mid(1);
            TQString l_s_token = *li_s_tokens;
            switch(l_c_type) {
            case 'f':
                // filename
                l_kse_elem->filename = l_s_token;
                break;
            case 'P':
                // Prelight
                if ( l_s_token.upper() == "TRUE" )
                    l_kse_elem->optionPrelight = true;
                else
                {
                    l_kse_elem->optionPrelight = false;

                    // was that token really there?
                    skipOne = ( l_s_token.upper() != "FALSE" );
                }
                break;
            case 'S':
                // Statuslight
                if ( l_s_token.upper() == "TRUE" )
                    l_kse_elem->optionStatuslight = true;
                else
                {
                    l_kse_elem->optionStatuslight = false;

                    // was that token really there?
                    skipOne = ( l_s_token.upper() != "FALSE" );
                }
                break;
            case '1':
                // parameter 1
                if ( l_s_token.upper() == "TRUE" )
                    l_kse_elem->options[0] = true;
                else
                {
                    l_kse_elem->options[0] = false;

                    // was that token really there?
                    skipOne = ( l_s_token.upper() != "FALSE" );
                }
                break;
            case '2':
                // parameter 2
                if (  l_s_token.upper() == "TRUE" )
                    l_kse_elem->options[1] = true;
                else
                {
                    l_kse_elem->options[1] = false;

                    // was that token really there?
                    skipOne = ( l_s_token.upper() != "FALSE" );
                }
                break;
            case '3':
                // parameter 3
                if (  l_s_token.upper() == "TRUE" )
                    l_kse_elem->options[2] = true;
                else
                {
                    l_kse_elem->options[2] = false;

                    // was that token really there?
                    skipOne = ( l_s_token.upper() != "FALSE" );
                }
                break;
            case 'l':
                // length
                if ( l_vertPixmaps )
                    l_kse_elem->pixmapLines = l_s_token.toInt();
                else
                    l_kse_elem->pixmapColumns = l_s_token.toInt();
                break;
            case 'x':
                // x Position
                l_kse_elem->upperLeft.setX(l_s_token.toInt());
                break;
            case 'y':
                // y Position
                l_kse_elem->upperLeft.setY(l_s_token.toInt());
                break;
            case 's':
                // dimension
                if ( l_kse_elem->options[KaimanStyleSlider::optionVertical] )
                    l_kse_elem->dimension.setHeight(l_s_token.toInt());
                else
                    l_kse_elem->dimension.setWidth(l_s_token.toInt());
                break;
            case 'w':
                // width
                l_kse_elem->dimension.setWidth(l_s_token.toInt());
                break;
            case 'h':
                // height
                l_kse_elem->dimension.setHeight(l_s_token.toInt());
                break;
            case 'd':
                // number of digits
                l_kse_elem->digits = l_s_token.toInt();
                break;

            default:
                kdDebug() << "Element type '" << l_c_type << "' unknown" << endl;
            }

            if(skipOne) {
                kdDebug() << "Skipped one element '" << l_c_type << "'" << endl;
            }
        } while(skipOne && l_s_tokenTypes.length() != 0);

        // Next token.
        ++li_s_tokens;
        if (li_s_tokens == ref_s_tokens.end() ) {
            // End of token list
            break;
        }
    }

    /* Do some post-processing */

    if( l_elementType==ButtonElement ) {
        // <Normal button>
        if(but->optionPrelight) {
            // --- Has Prelight ---
            if(but->optionStatuslight)
                but->pixmapColumns = 6;
            else {
                but->pixmapColumns = 3;
                but->I_pmIndex.insert( KaimanStyleButton::LitUp,
                                       new int( *(but->I_pmIndex[KaimanStyleButton::NormalUp])));
                but->I_pmIndex.insert( KaimanStyleButton::LitDown,
                                       new int( *(but->I_pmIndex[KaimanStyleButton::NormalDown])));
            }
        } else {
            // --- Has No Prelight ---
            but->I_pmIndex.insert( KaimanStyleButton::PrelightUp,
                                   new int( *(but->I_pmIndex[KaimanStyleButton::NormalUp])));
            but->I_pmIndex.insert( KaimanStyleButton::PrelightLitUp,
                                   new int( *(but->I_pmIndex[KaimanStyleButton::LitUp])));
            if(l_kse_elem->optionStatuslight)
                but->pixmapColumns = 4;
            else {
                but->pixmapColumns = 2;
                but->I_pmIndex.insert( KaimanStyleButton::LitUp,
                                       new int( *(but->I_pmIndex[KaimanStyleButton::NormalUp])));
                but->I_pmIndex.insert( KaimanStyleButton::LitDown,
                                       new int( *(but->I_pmIndex[KaimanStyleButton::NormalDown])));
                but->I_pmIndex.insert( KaimanStyleButton::PrelightLitUp,
                                       new int( *(but->I_pmIndex[KaimanStyleButton::NormalUp])));
            }
        }
    } else if( l_elementType==NumberElement ) {
        // number items
        l_kse_elem->pixmapColumns = 11;
        if ( l_kse_elem->filename=="Small" ) l_kse_elem->filename = i_smallFont;
        else if ( l_kse_elem->filename=="Large" ) l_kse_elem->filename = i_largeFont;
    } else if( l_elementType==SliderElement ) {
        // slider items
        if ( l_kse_elem->options[KaimanStyleSlider::optionVertical] )
            l_kse_elem->pixmapLines = l_kse_elem->optionPrelight ? 4 : 3;
        else
            l_kse_elem->pixmapColumns = l_kse_elem->optionPrelight ? 4 : 3;
    } else if( l_elementType==TextElement ) {
        // text items
        l_kse_elem->pixmapColumns = 32;
        l_kse_elem->pixmapLines = l_kse_elem->options[KaimanStyleText::optionExtended] ? 6 : 3;
    } else {
        // <Not standard element>
        if(l_s_elem == "Stereo_Item")
            l_kse_elem->pixmapLines = 3;
        else if(l_s_elem == "Shuffle_Item")
            l_kse_elem->pixmapLines = 2;
        else if(l_s_elem == "Repeat_Item")
            l_kse_elem->pixmapLines = 2;
        else if(l_s_elem == "Mpegversion_Item")
            l_kse_elem->pixmapLines = 3;
        else if(l_s_elem == "Mpegversion_Item")
            l_kse_elem->pixmapLines = 4;
        else if(l_s_elem == "Mpegmode_Item")
            l_kse_elem->pixmapLines = 5;
        else if(l_s_elem == "Status_Item")
            l_kse_elem->pixmapLines = 3;
    } // </Not normal button>
}


TQString KaimanStyle::getToken(TQString &val_s_string, char val_c_separator)
{
    int l_i_pos;
    TQString l_s_token;

    // Find the first occurrence of the separator
    l_i_pos = val_s_string.find(val_c_separator, 0, false);
    if ( l_i_pos == -1 ) {
        // No sparator! Then the whole string is the token
        l_s_token = val_s_string;
        val_s_string = "";
    }
    else {
        // Separator found: Split the string at the separator position
        l_s_token = val_s_string.left(l_i_pos);
        val_s_string.remove(0,l_i_pos);
    }
    val_s_string = val_s_string.simplifyWhiteSpace();

    // Return the first token
    return l_s_token;
}



bool KaimanStyle::loadStyle(const TQString &styleName, const TQString &descFile)
{
    bool l_b_ret = true;
    int l_i_ret  = 0;
    TQString l_s_tmpName;

    i_skinName = styleName;
    this->i_s_styleName = styleName;
    i_s_styleBase = TQString("skins/kaiman/") + i_s_styleName + TQString("/");

    l_s_tmpName =  locate("appdata",  i_s_styleBase + descFile );
    if ( l_s_tmpName.isNull() ) {
        l_b_ret = false;
    }

    if ( l_b_ret) {
        // Skin description found. Now parse StyleFile.
        l_i_ret = parseStyleFile(l_s_tmpName);
        if (l_i_ret == 0) {
            // If parsiing OK, load the referenced pixmaps
            l_b_ret = loadPixmaps();

            kdDebug(66666) << "Found " << I_styleElem.count() << " elements." << endl;
        }
        else {
            if ( l_i_ret == KaimanStyle::FileNotFound ) {
                // File not found
                KMessageBox::error( 0, i18n("Cannot load style. Style not installed.") );
            }
            else {
                // Parsing not OK: Notify user
                KMessageBox::error( 0, i18n("Cannot load style. Unsupported or faulty style description.") );
            }
        }
    }

    return l_b_ret;
}

bool KaimanStyle::eventFilter( TQObject *o, TQEvent *e )
{
    /* HACK! HACK! HACK! */
    if ( !i_eventSemaphore )
        if ( e->type()==TQEvent::MouseMove || e->type()==TQEvent::MouseButtonPress ||
             e->type()==TQEvent::MouseButtonRelease )
        {
            TQMouseEvent *m = (TQMouseEvent*)e;

            // handle noatun context menu
            if (m->button()==Qt::RightButton) {
                NoatunStdAction::ContextMenu::showContextMenu();
                return true;
            }

            TQPoint mousePos( m->x()+TQT_TQWIDGET(o)->x(),
                             m->y()+TQT_TQWIDGET(o)->y() );
            TQWidget *slider = 0;

            /* find slider that is under the mouse position */
            for ( TQWidget *s = i_sliders.first(); s!=0; s=i_sliders.next() )
            {
                TQRect sliderRect( s->pos(), s->size() );
                if ( sliderRect.contains(mousePos) ) slider = s;
            }

            /* the slider the mouse events instead of the visible widget */
            if ( slider )
            {
                TQMouseEvent newMouseEvent( m->type(), mousePos-slider->pos(),
                                           m->globalPos(), m->button(), m->state() );

                i_eventSemaphore = true;
                bool ret = TQApplication::sendEvent( slider, &newMouseEvent );
                i_eventSemaphore = false;
                return ret;
            }
        }

    return TQWidget::eventFilter( o, e );    // standard event processing
}

bool KaimanStyle::loadPixmaps()
{
    TQString l_s_tmpName;
    TQPixmap *l_pixmap_Background = 0, *l_pixmap_Mask = 0;
    KaimanStyleElement *l_kse_elem;

    for ( uint l_i_elem = 0; l_i_elem<I_styleElem.count(); l_i_elem++) {
        l_kse_elem = I_styleElem[l_i_elem];

        l_s_tmpName =  locate("appdata", i_s_styleBase + l_kse_elem->filename );
        l_kse_elem->loadPixmaps(l_s_tmpName);
    }

    l_kse_elem = this->find("Background");
    if ( l_kse_elem != 0 ) {
        l_pixmap_Background = l_kse_elem->pixmaps[0];
    }
    l_kse_elem = this->find("Mask");
    if ( l_kse_elem != 0 ) {
        l_pixmap_Mask = l_kse_elem->pixmaps[0];
    }

    if ( (l_pixmap_Background != 0) && (l_pixmap_Mask != 0) ) {

        // OK, background and mask are defined. So now I can calculate the shape
        int l_i_width_Mask  = l_pixmap_Mask->width();
        int l_i_height_Mask = l_pixmap_Mask->height();

        TQImage l_image_MaskOrig = l_pixmap_Mask->convertToImage();

        TQImage l_image_Mask(l_i_width_Mask,l_i_height_Mask, 1, 2, TQImage::LittleEndian);
        l_image_Mask.setColor( 0, 0x00ffffff );
        l_image_Mask.setColor( 1, 0 );
        l_image_Mask.fill( 0xff );

        uchar *l_c_pixel;
        uint l_qcol_white = tqRgb(255,255,255);

        for (int l_i_x=0; l_i_x<l_i_width_Mask; l_i_x++) {
            for (int l_i_y=0; l_i_y < l_i_height_Mask; l_i_y++) {
                if ( ((*((TQRgb*)  l_image_MaskOrig.scanLine(l_i_y)+l_i_x) & 0x00ffffff)) != (l_qcol_white & 0x00ffffff) ) {
                    l_c_pixel = (uchar *)l_image_Mask.scanLine(l_i_y);
                    *(l_c_pixel + (l_i_x>>3)   )  &= ~(1 << (l_i_x & 7));
                }
            }
        }

        i_bitmap_Mask.convertFromImage(l_image_Mask);
        //  l_pixmap_Background.setMask(i_bitmap_Mask);
    }

    return true;
}


TQBitmap* KaimanStyle::Mask()
{
    return &i_bitmap_Mask;
}

KaimanStyleElement* KaimanStyle::find(const char *val_s_elemName)
{
    for (uint i=0; i< I_styleElem.count(); i++) {
        if ( I_styleElem[i]->element == TQString(val_s_elemName)) {
            return I_styleElem[i];
        }
    }
    return 0;
}
#include "style.moc"