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

« back to all changes in this revision

Viewing changes to noatun/modules/winskin/waSkinModel.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
/*
 
2
  operations with skinset.
 
3
  Copyright (C) 1999  Martin Vogt
 
4
  Copyright (C) 2001  Ryan Cumming
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify
 
7
  it under the terms of the GNU General Public License as published by
 
8
  the Free Software Foundation.
 
9
 
 
10
  For more information look at the file COPYRIGHT in this package
 
11
 
 
12
 */
 
13
 
 
14
 
 
15
#include <config.h>
 
16
#include <qdir.h>
 
17
#include <qstringlist.h>
 
18
#include <qbitmap.h>
 
19
#include <kdebug.h>
 
20
#include <kstandarddirs.h>
 
21
 
 
22
#include "waSkinMapping.h"
 
23
#include "waShadeMapping.h"
 
24
 
 
25
#include "waSkinModel.h"
 
26
#include "waColor.h"
 
27
#include "waRegion.h"
 
28
#include "waSkin.h"
 
29
 
 
30
WaSkinModel *_waskinmodel_instance = NULL;
 
31
 
 
32
// Our current skin map
 
33
// Can switch between normal and windowshade maps
 
34
const SkinMap *mapToGui;
 
35
const SkinDesc *mapFromFile;
 
36
int digit_width;
 
37
int digit_height;
 
38
 
 
39
 
 
40
struct WaPixmapEntry {
 
41
    const char *filename;
 
42
    QPixmap *pixmap;
 
43
};
 
44
 
 
45
WaPixmapEntry waPixmapEntries[11] = {
 
46
                                      {"main.bmp", NULL},
 
47
                                      {"cbuttons.bmp", NULL},
 
48
                                      {"monoster.bmp", NULL},
 
49
                                      {"numbers.bmp", NULL},
 
50
                                      {"shufrep.bmp", NULL},
 
51
                                      {"text.bmp", NULL},
 
52
                                      {"volume.bmp", NULL},
 
53
                                      {"balance.bmp", NULL},
 
54
                                      {"posbar.bmp", NULL},
 
55
                                      {"playpaus.bmp", NULL},
 
56
                                      {"titlebar.bmp", NULL}
 
57
                                  };
 
58
 
 
59
WaSkinModel::WaSkinModel()
 
60
 
61
    for (int x = 0;x < 11;x++) 
 
62
        waPixmapEntries[x].pixmap = new QPixmap;    
 
63
 
 
64
    resetSkinModel();
 
65
    _waskinmodel_instance = this;
 
66
}
 
67
 
 
68
WaSkinModel::~WaSkinModel()
 
69
{
 
70
    for (int x = 0;x < 11;x++) 
 
71
        delete waPixmapEntries[x].pixmap;    
 
72
 
 
73
    delete windowRegion;
 
74
    delete colorScheme;
 
75
}
 
76
 
 
77
bool WaSkinModel::load(QString skinDir)
 
78
{
 
79
    bool success = true;
 
80
 
 
81
    QDir dir(skinDir);
 
82
 
 
83
    if (findFile(dir, "main.bmp").isEmpty()) {
 
84
        // Ack, our skin dir doesn't exist, fall back to the default
 
85
        dir = QDir(KGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + WaSkin::defaultSkin())[0]);
 
86
        success = false;
 
87
    }
 
88
 
 
89
    for (int x = 0;x < 11;x++) {
 
90
      getPixmap(dir, waPixmapEntries[x].filename, 
 
91
                waPixmapEntries[x].pixmap);
 
92
    }
 
93
 
 
94
    resetSkinModel();
 
95
 
 
96
    loadColors(dir);
 
97
    loadRegion(dir);
 
98
 
 
99
    emit(skinChanged());
 
100
 
 
101
    return success;
 
102
}
 
103
 
 
104
// Does a case-insenstive file search (like DOS/Windows)
 
105
// Filename -must- be lowercase, which is an nice optimization, since
 
106
// this is a private API, and all our filenames are internally lowercase
 
107
// anyway
 
108
QString WaSkinModel::findFile(const QDir &dir, const QString &filename) {
 
109
    QFileInfo fileInfo;
 
110
    QString ret = "";
 
111
 
 
112
    QStringList strList = dir.entryList();
 
113
 
 
114
    for (QStringList::iterator file = strList.begin(); file != strList.end(); file++) {
 
115
        QFileInfo fileInfo(*file);
 
116
 
 
117
        if (fileInfo.isDir()) 
 
118
            continue;
 
119
 
 
120
        if (fileInfo.filePath().lower() == filename) 
 
121
            return dir.absPath() + "/" + QString(fileInfo.filePath());
 
122
    }
 
123
 
 
124
    return "";
 
125
}
 
126
 
 
127
void WaSkinModel::loadColors(const QDir &dir) {
 
128
    QString colorFile = findFile(dir, "viscolor.txt");
 
129
 
 
130
    if (colorScheme) {
 
131
      delete colorScheme;
 
132
    }
 
133
 
 
134
    colorScheme = new WaColor(colorFile);
 
135
}
 
136
 
 
137
void WaSkinModel::loadRegion(const QDir &dir) {
 
138
    QString regionFile = findFile(dir, "region.txt");
 
139
 
 
140
    if (windowRegion) {
 
141
      delete windowRegion;
 
142
      windowRegion = 0;
 
143
    }
 
144
 
 
145
    windowRegion = new WaRegion(regionFile);
 
146
}
 
147
 
 
148
int WaSkinModel::getPixmap(const QDir &dir, QString fname,
 
149
                               QPixmap *target)
 
150
{
 
151
    QFileInfo fileInfo;
 
152
    QStringList strList = dir.entryList();
 
153
    QString abspath;
 
154
 
 
155
    abspath = findFile(dir, fname);
 
156
 
 
157
    if (!abspath.isEmpty()) {
 
158
        target->load(abspath);
 
159
        return true;
 
160
    }
 
161
 
 
162
    // now the filename mapping 1.8x -> 2.0
 
163
    if (fname == "volume.bmp") 
 
164
        return WaSkinModel::getPixmap(dir, QString("volbar.bmp"), target);
 
165
 
 
166
    if (fname == "numbers.bmp") 
 
167
        return WaSkinModel::getPixmap(dir, QString("nums_ex.bmp"), target);
 
168
 
 
169
    // Even 2.x themes can omit BALANCE, in which case we use VOLUME
 
170
    if (fname == "balance.bmp") 
 
171
        return WaSkinModel::getPixmap(dir, QString("volume.bmp"), target);
 
172
 
 
173
    return false;
 
174
}
 
175
 
 
176
 
 
177
QRect WaSkinModel::getGeometry(int id) {
 
178
  if ( (id < 0) || (id >= _WA_SKIN_ENTRIES) ) {
 
179
    kdDebug() << "Array index out of range. WaSkinModel::getGeometry"<<endl;
 
180
    exit(-1);
 
181
  }
 
182
  return QRect(mapFromFile[id].x, mapFromFile[id].y,
 
183
               mapFromFile[id].width, mapFromFile[id].height);
 
184
}
 
185
 
 
186
QRect WaSkinModel::getMapGeometry(int id) {
 
187
  if ( (id < 0) || (id >= _WA_MAPPING_ENTRIES) ) {
 
188
    kdDebug() << "Array index out of range. WaSkinModel::getMapGeometry"<<endl;
 
189
    exit(-1);
 
190
  }  
 
191
  return QRect(mapToGui[id].x, mapToGui[id].y,
 
192
               mapToGui[id].width, mapToGui[id].height);
 
193
}
 
194
 
 
195
void WaSkinModel::bltTo(int id, QPaintDevice *dest, int x, int y) {
 
196
    bitBlt(dest, x, y, waPixmapEntries[mapFromFile[id].fileId].pixmap,
 
197
           mapFromFile[id].x, mapFromFile[id].y,
 
198
           mapFromFile[id].width, mapFromFile[id].height);
 
199
}
 
200
 
 
201
void WaSkinModel::bltTo(int id, QPaintDevice *dest, int x, int y, int argument) {
 
202
  if (id == _WA_SKIN_VOLUME_BAR) {
 
203
    QPixmap *pix = waPixmapEntries[_WA_FILE_VOLUME].pixmap;
 
204
 
 
205
    int nBar = int((float)argument * 27.0 / 100.0);
 
206
    bitBlt(dest, x, y, pix, 0, 15 * nBar, 68, 13);
 
207
 
 
208
    return;
 
209
  }
 
210
 
 
211
  if (id == _WA_SKIN_BALANCE_BAR) {
 
212
    QPixmap *pix = waPixmapEntries[_WA_FILE_BALANCE].pixmap;
 
213
 
 
214
    argument = abs(argument);
 
215
 
 
216
    int nBar = int((float)argument * 27.0 / 100.0);
 
217
    bitBlt(dest, x, y, pix, 9, 15 * nBar, 38, 13);
 
218
 
 
219
    return;
 
220
  }
 
221
 
 
222
  bltTo(id, dest, x, y);
 
223
}
 
224
 
 
225
void WaSkinModel::getDigit(char number, QPaintDevice *dest, int x, int y) {
 
226
    if (number=='-') { 
 
227
      bltTo(_WA_SKIN_NUMBERS_MINUS, dest, x, y);
 
228
      return;
 
229
    }
 
230
 
 
231
    // empty number ?
 
232
    if (number == ' ') {
 
233
      bltTo(_WA_SKIN_NUMBERS_BLANK, dest, x, y);
 
234
      return;
 
235
    }
 
236
 
 
237
    // number
 
238
    QPixmap *pix = waPixmapEntries[mapFromFile[_WA_SKIN_NUMBERS].fileId].pixmap;
 
239
 
 
240
    // ordinary number:
 
241
    int index = number - '0';
 
242
    if ((index < 0) || (index > 9)) 
 
243
      return;
 
244
 
 
245
    bitBlt(dest, x, y, pix , (index * digit_width) + mapFromFile[_WA_SKIN_NUMBERS].x, mapFromFile[_WA_SKIN_NUMBERS].y, digit_width, digit_height);
 
246
 
 
247
    return;
 
248
}
 
249
 
 
250
void WaSkinModel::getText(char text, QPaintDevice * dest, int x, int y) {
 
251
  QPixmap *pix = waPixmapEntries[_WA_FILE_TEXT].pixmap;
 
252
 
 
253
  text = deaccent(text);
 
254
 
 
255
  if (('A' <= text) && (text <= 'Z')) {
 
256
    bitBlt(dest, x, y,pix,(text-'A')*5,0,5,6);
 
257
    return;
 
258
  }
 
259
  if (('a' <= text) && (text <= 'z')) {
 
260
    bitBlt(dest, x, y,pix,(text-'a')*5,0,5,6);
 
261
    return;
 
262
  }
 
263
  if (('0' <= text) && (text <= '9')) {
 
264
    bitBlt(dest, x, y,pix,(text-'0')*5,6,5,6);
 
265
    return;
 
266
  }
 
267
  if ('"' == text) {
 
268
    bitBlt(dest, x, y,pix,27*5,0,5,6);
 
269
    return;
 
270
  }
 
271
  if ('@' == text) {
 
272
    bitBlt(dest, x, y,pix,28*5,0,5,6);
 
273
    return;
 
274
  }
 
275
 
 
276
 
 
277
  if ('.' == text) {
 
278
    bitBlt(dest, x, y,pix,11*5,6,5,6);
 
279
    return;
 
280
  }
 
281
  if (':' == text) {
 
282
    bitBlt(dest, x, y,pix,12*5,6,5,6);
 
283
    return;
 
284
  }
 
285
  if (('(' == text) || ('<' == text) || ('{' == text)) {
 
286
    bitBlt(dest, x, y,pix,13*5,6,5,6);
 
287
    return;
 
288
  }
 
289
  if ((')' == text) || ('>' == text) || ('}' == text)) {
 
290
    bitBlt(dest, x, y,pix,14*5,6,5,6);
 
291
    return;
 
292
  }
 
293
  if ('-' == text) {
 
294
    bitBlt(dest, x, y,pix,15*5,6,5,6);
 
295
    return;
 
296
  }
 
297
  if (('`' == text) || ('\'' == text)) {
 
298
    bitBlt(dest, x, y,pix,16*5,6,5,6);
 
299
    return;
 
300
  }
 
301
  if ('!' == text) {
 
302
    bitBlt(dest, x, y,pix,17*5,6,5,6);
 
303
    return;
 
304
  }
 
305
  if ('_' == text) {
 
306
    bitBlt(dest, x, y,pix,18*5,6,5,6);
 
307
    return;
 
308
  }
 
309
  if ('+' == text) {
 
310
    bitBlt(dest, x, y,pix,19*5,6,5,6);
 
311
    return;
 
312
  }
 
313
  if ('\\' == text) {
 
314
    bitBlt(dest, x, y,pix,20*5,6,5,6);
 
315
    return;
 
316
  }
 
317
  if ('/' == text) {
 
318
    bitBlt(dest, x, y,pix,21*5,6,5,6);
 
319
    return;
 
320
  }
 
321
  if ('[' == text) {
 
322
    bitBlt(dest, x, y,pix,22*5,6,5,6);
 
323
    return;
 
324
  }
 
325
  if (']' == text) {
 
326
    bitBlt(dest, x, y,pix,23*5,6,5,6);
 
327
    return;
 
328
  }
 
329
  if ('^' == text) {
 
330
    bitBlt(dest, x, y,pix,24*5,6,5,6);
 
331
    return;
 
332
  }
 
333
  if ('&' == text) {
 
334
    bitBlt(dest, x, y,pix,25*5,6,5,6);
 
335
    return;
 
336
  }
 
337
  if ('%' == text) {
 
338
    bitBlt(dest, x, y,pix,26*5,6,5,6);
 
339
    return;
 
340
  }
 
341
  if (',' == text) {
 
342
    bitBlt(dest, x, y,pix,27*5,6,5,6);
 
343
    return;
 
344
  }
 
345
  if ('=' == text) {
 
346
    bitBlt(dest, x, y,pix,28*5,6,5,6);
 
347
    return;
 
348
  }
 
349
  if ('$' == text) {
 
350
    bitBlt(dest, x, y,pix,29*5,6,5,6);
 
351
    return;
 
352
  }
 
353
  if ('#' == text) {
 
354
    bitBlt(dest, x, y,pix,30*5,6,5,6);
 
355
    return;
 
356
  }
 
357
  if (('�' == text) || ('�' == text)) {
 
358
    bitBlt(dest, x, y,pix,0*5,12,5,6);
 
359
    return;
 
360
  }
 
361
  if (('�' == text) || ('�' == text)) {
 
362
    bitBlt(dest, x, y,pix,1*5,12,5,6);
 
363
    return;
 
364
  } 
 
365
  if (('�' == text) || ('�' == text)) {
 
366
    bitBlt(dest, x, y,pix,2*5,12,5,6);
 
367
    return;
 
368
  } 
 
369
  if ('?' == text) {
 
370
    bitBlt(dest, x, y,pix,3*5,12,5,6);
 
371
    return;
 
372
  }
 
373
  if ('*' == text) {
 
374
    bitBlt(dest, x, y,pix,4*5,12,5,6);
 
375
    return;
 
376
  }
 
377
  // default back is space char
 
378
  bitBlt(dest, x, y,pix,(10*5),12,5,6);
 
379
}
 
380
 
 
381
void WaSkinModel::paintBackgroundTo(int mapping, QPaintDevice *dest, int x, int y) 
 
382
{
 
383
    QPixmap *pix = waPixmapEntries[mapFromFile[_WA_SKIN_MAIN].fileId].pixmap;
 
384
    QRect main_rect = getGeometry(_WA_SKIN_MAIN);
 
385
    QRect dest_rect = getMapGeometry(mapping);
 
386
 
 
387
    int source_x = main_rect.x() + dest_rect.x() + x;
 
388
    int source_y = main_rect.y() + dest_rect.y() + y;
 
389
 
 
390
    int width = dest_rect.width() - x;
 
391
    int height = dest_rect.height() - y;
 
392
 
 
393
    bitBlt(dest, x, y, pix, source_x, source_y, width, height);
 
394
}
 
395
 
 
396
void WaSkinModel::setSkinModel(skin_models new_model) {
 
397
    if (new_model == WA_MODEL_NORMAL) {
 
398
        mapToGui = normalMapToGui;
 
399
        mapFromFile = normalMapFromFile;
 
400
        digit_width = 9;
 
401
        digit_height = 13;
 
402
    }
 
403
    else if (new_model == WA_MODEL_WINDOWSHADE) {
 
404
        mapToGui = shadeMapToGui;
 
405
        mapFromFile = shadeMapFromFile;
 
406
        digit_width = 5;
 
407
        digit_height = 6;
 
408
    }
 
409
 
 
410
    emit(skinChanged());
 
411
}
 
412
 
 
413
void WaSkinModel::resetSkinModel() {
 
414
    mapToGui = normalMapToGui;
 
415
    mapFromFile = normalMapFromFile;
 
416
    digit_width = 9;
 
417
    digit_height = 13;
 
418
}
 
419
 
 
420
 
 
421
QChar WaSkinModel::deaccent(QChar input) {
 
422
    if (QString("�").contains(input))
 
423
        return 'A';
 
424
 
 
425
    if (QString("��").contains(input))
 
426
        return 'E';
 
427
 
 
428
    if (QString("��").contains(input))
 
429
        return 'I';
 
430
 
 
431
    if (QString("��").contains(input))
 
432
        return 'O';
 
433
 
 
434
    if (QString("��").contains(input))
 
435
        return 'U';
 
436
 
 
437
    if (input == '�')
 
438
        return 'Y';
 
439
 
 
440
    if (QString("��").contains(input))
 
441
        return 'a';
 
442
 
 
443
    if (QString("��").contains(input))
 
444
        return 'e';
 
445
 
 
446
    if (QString("��").contains(input))
 
447
        return 'i';
 
448
 
 
449
    if (QString("��").contains(input))
 
450
        return 'o';
 
451
 
 
452
    if (QString("��").contains(input))
 
453
        return 'u';
 
454
 
 
455
   return input;
 
456
}
 
457
 
 
458
#include "waSkinModel.moc"