2
operations with skinset.
3
Copyright (C) 1999 Martin Vogt
4
Copyright (C) 2001 Ryan Cumming
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.
10
For more information look at the file COPYRIGHT in this package
17
#include <qstringlist.h>
20
#include <kstandarddirs.h>
22
#include "waSkinMapping.h"
23
#include "waShadeMapping.h"
25
#include "waSkinModel.h"
30
WaSkinModel *_waskinmodel_instance = NULL;
32
// Our current skin map
33
// Can switch between normal and windowshade maps
34
const SkinMap *mapToGui;
35
const SkinDesc *mapFromFile;
40
struct WaPixmapEntry {
45
WaPixmapEntry waPixmapEntries[11] = {
47
{"cbuttons.bmp", NULL},
48
{"monoster.bmp", NULL},
49
{"numbers.bmp", NULL},
50
{"shufrep.bmp", NULL},
53
{"balance.bmp", NULL},
55
{"playpaus.bmp", NULL},
56
{"titlebar.bmp", NULL}
59
WaSkinModel::WaSkinModel()
61
for (int x = 0;x < 11;x++)
62
waPixmapEntries[x].pixmap = new QPixmap;
65
_waskinmodel_instance = this;
68
WaSkinModel::~WaSkinModel()
70
for (int x = 0;x < 11;x++)
71
delete waPixmapEntries[x].pixmap;
77
bool WaSkinModel::load(QString skinDir)
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]);
89
for (int x = 0;x < 11;x++) {
90
getPixmap(dir, waPixmapEntries[x].filename,
91
waPixmapEntries[x].pixmap);
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
108
QString WaSkinModel::findFile(const QDir &dir, const QString &filename) {
112
QStringList strList = dir.entryList();
114
for (QStringList::iterator file = strList.begin(); file != strList.end(); file++) {
115
QFileInfo fileInfo(*file);
117
if (fileInfo.isDir())
120
if (fileInfo.filePath().lower() == filename)
121
return dir.absPath() + "/" + QString(fileInfo.filePath());
127
void WaSkinModel::loadColors(const QDir &dir) {
128
QString colorFile = findFile(dir, "viscolor.txt");
134
colorScheme = new WaColor(colorFile);
137
void WaSkinModel::loadRegion(const QDir &dir) {
138
QString regionFile = findFile(dir, "region.txt");
145
windowRegion = new WaRegion(regionFile);
148
int WaSkinModel::getPixmap(const QDir &dir, QString fname,
152
QStringList strList = dir.entryList();
155
abspath = findFile(dir, fname);
157
if (!abspath.isEmpty()) {
158
target->load(abspath);
162
// now the filename mapping 1.8x -> 2.0
163
if (fname == "volume.bmp")
164
return WaSkinModel::getPixmap(dir, QString("volbar.bmp"), target);
166
if (fname == "numbers.bmp")
167
return WaSkinModel::getPixmap(dir, QString("nums_ex.bmp"), target);
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);
177
QRect WaSkinModel::getGeometry(int id) {
178
if ( (id < 0) || (id >= _WA_SKIN_ENTRIES) ) {
179
kdDebug() << "Array index out of range. WaSkinModel::getGeometry"<<endl;
182
return QRect(mapFromFile[id].x, mapFromFile[id].y,
183
mapFromFile[id].width, mapFromFile[id].height);
186
QRect WaSkinModel::getMapGeometry(int id) {
187
if ( (id < 0) || (id >= _WA_MAPPING_ENTRIES) ) {
188
kdDebug() << "Array index out of range. WaSkinModel::getMapGeometry"<<endl;
191
return QRect(mapToGui[id].x, mapToGui[id].y,
192
mapToGui[id].width, mapToGui[id].height);
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);
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;
205
int nBar = int((float)argument * 27.0 / 100.0);
206
bitBlt(dest, x, y, pix, 0, 15 * nBar, 68, 13);
211
if (id == _WA_SKIN_BALANCE_BAR) {
212
QPixmap *pix = waPixmapEntries[_WA_FILE_BALANCE].pixmap;
214
argument = abs(argument);
216
int nBar = int((float)argument * 27.0 / 100.0);
217
bitBlt(dest, x, y, pix, 9, 15 * nBar, 38, 13);
222
bltTo(id, dest, x, y);
225
void WaSkinModel::getDigit(char number, QPaintDevice *dest, int x, int y) {
227
bltTo(_WA_SKIN_NUMBERS_MINUS, dest, x, y);
233
bltTo(_WA_SKIN_NUMBERS_BLANK, dest, x, y);
238
QPixmap *pix = waPixmapEntries[mapFromFile[_WA_SKIN_NUMBERS].fileId].pixmap;
241
int index = number - '0';
242
if ((index < 0) || (index > 9))
245
bitBlt(dest, x, y, pix , (index * digit_width) + mapFromFile[_WA_SKIN_NUMBERS].x, mapFromFile[_WA_SKIN_NUMBERS].y, digit_width, digit_height);
250
void WaSkinModel::getText(char text, QPaintDevice * dest, int x, int y) {
251
QPixmap *pix = waPixmapEntries[_WA_FILE_TEXT].pixmap;
253
text = deaccent(text);
255
if (('A' <= text) && (text <= 'Z')) {
256
bitBlt(dest, x, y,pix,(text-'A')*5,0,5,6);
259
if (('a' <= text) && (text <= 'z')) {
260
bitBlt(dest, x, y,pix,(text-'a')*5,0,5,6);
263
if (('0' <= text) && (text <= '9')) {
264
bitBlt(dest, x, y,pix,(text-'0')*5,6,5,6);
268
bitBlt(dest, x, y,pix,27*5,0,5,6);
272
bitBlt(dest, x, y,pix,28*5,0,5,6);
278
bitBlt(dest, x, y,pix,11*5,6,5,6);
282
bitBlt(dest, x, y,pix,12*5,6,5,6);
285
if (('(' == text) || ('<' == text) || ('{' == text)) {
286
bitBlt(dest, x, y,pix,13*5,6,5,6);
289
if ((')' == text) || ('>' == text) || ('}' == text)) {
290
bitBlt(dest, x, y,pix,14*5,6,5,6);
294
bitBlt(dest, x, y,pix,15*5,6,5,6);
297
if (('`' == text) || ('\'' == text)) {
298
bitBlt(dest, x, y,pix,16*5,6,5,6);
302
bitBlt(dest, x, y,pix,17*5,6,5,6);
306
bitBlt(dest, x, y,pix,18*5,6,5,6);
310
bitBlt(dest, x, y,pix,19*5,6,5,6);
314
bitBlt(dest, x, y,pix,20*5,6,5,6);
318
bitBlt(dest, x, y,pix,21*5,6,5,6);
322
bitBlt(dest, x, y,pix,22*5,6,5,6);
326
bitBlt(dest, x, y,pix,23*5,6,5,6);
330
bitBlt(dest, x, y,pix,24*5,6,5,6);
334
bitBlt(dest, x, y,pix,25*5,6,5,6);
338
bitBlt(dest, x, y,pix,26*5,6,5,6);
342
bitBlt(dest, x, y,pix,27*5,6,5,6);
346
bitBlt(dest, x, y,pix,28*5,6,5,6);
350
bitBlt(dest, x, y,pix,29*5,6,5,6);
354
bitBlt(dest, x, y,pix,30*5,6,5,6);
357
if (('�' == text) || ('�' == text)) {
358
bitBlt(dest, x, y,pix,0*5,12,5,6);
361
if (('�' == text) || ('�' == text)) {
362
bitBlt(dest, x, y,pix,1*5,12,5,6);
365
if (('�' == text) || ('�' == text)) {
366
bitBlt(dest, x, y,pix,2*5,12,5,6);
370
bitBlt(dest, x, y,pix,3*5,12,5,6);
374
bitBlt(dest, x, y,pix,4*5,12,5,6);
377
// default back is space char
378
bitBlt(dest, x, y,pix,(10*5),12,5,6);
381
void WaSkinModel::paintBackgroundTo(int mapping, QPaintDevice *dest, int x, int y)
383
QPixmap *pix = waPixmapEntries[mapFromFile[_WA_SKIN_MAIN].fileId].pixmap;
384
QRect main_rect = getGeometry(_WA_SKIN_MAIN);
385
QRect dest_rect = getMapGeometry(mapping);
387
int source_x = main_rect.x() + dest_rect.x() + x;
388
int source_y = main_rect.y() + dest_rect.y() + y;
390
int width = dest_rect.width() - x;
391
int height = dest_rect.height() - y;
393
bitBlt(dest, x, y, pix, source_x, source_y, width, height);
396
void WaSkinModel::setSkinModel(skin_models new_model) {
397
if (new_model == WA_MODEL_NORMAL) {
398
mapToGui = normalMapToGui;
399
mapFromFile = normalMapFromFile;
403
else if (new_model == WA_MODEL_WINDOWSHADE) {
404
mapToGui = shadeMapToGui;
405
mapFromFile = shadeMapFromFile;
413
void WaSkinModel::resetSkinModel() {
414
mapToGui = normalMapToGui;
415
mapFromFile = normalMapFromFile;
421
QChar WaSkinModel::deaccent(QChar input) {
422
if (QString("�").contains(input))
425
if (QString("��").contains(input))
428
if (QString("��").contains(input))
431
if (QString("��").contains(input))
434
if (QString("��").contains(input))
440
if (QString("��").contains(input))
443
if (QString("��").contains(input))
446
if (QString("��").contains(input))
449
if (QString("��").contains(input))
452
if (QString("��").contains(input))
458
#include "waSkinModel.moc"