mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
Themes: remove all hardcoded extensions
This commit is contained in:
parent
226a8cc017
commit
00e3e63f41
27 changed files with 348 additions and 419 deletions
|
|
@ -16,7 +16,6 @@
|
|||
#define PLAYERZONE_BG_NAME "playerzone"
|
||||
#define STACKZONE_BG_NAME "stackzone"
|
||||
#define TABLEZONE_BG_NAME "tablezone"
|
||||
#define CARD_BACK_NAME "cardback"
|
||||
|
||||
ThemeManager::ThemeManager(QObject *parent)
|
||||
:QObject(parent)
|
||||
|
|
@ -78,41 +77,18 @@ QStringMap & ThemeManager::getAvailableThemes()
|
|||
QBrush ThemeManager::loadBrush(QDir dir, QString fileName, QColor fallbackColor)
|
||||
{
|
||||
QBrush brush;
|
||||
QPixmap tmp;
|
||||
QStringList exts;
|
||||
exts << ".png" << ".jpg" << ".jpeg" << ".gif" << ".bmp";
|
||||
|
||||
brush.setColor(fallbackColor);
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
|
||||
foreach (const QString &ext, exts) {
|
||||
if (dir.exists(fileName + ext)) {
|
||||
tmp.load(dir.absoluteFilePath(fileName + ext));
|
||||
if(!tmp.isNull())
|
||||
brush.setTexture(tmp);
|
||||
break;
|
||||
}
|
||||
QPixmap tmp = QPixmap("theme:zones/" + fileName);
|
||||
if(tmp.isNull())
|
||||
{
|
||||
brush.setColor(fallbackColor);
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
} else {
|
||||
brush.setTexture(tmp);
|
||||
}
|
||||
|
||||
return brush;
|
||||
}
|
||||
|
||||
QPixmap ThemeManager::loadPixmap(QDir dir, QString fileName)
|
||||
{
|
||||
QPixmap pix;
|
||||
QStringList exts;
|
||||
exts << ".png" << ".jpg" << ".jpeg" << ".gif" << ".bmp";
|
||||
|
||||
foreach (const QString &ext, exts) {
|
||||
if (dir.exists(fileName + ext)) {
|
||||
pix.load(dir.absoluteFilePath(fileName + ext));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
void ThemeManager::themeChangedSlot()
|
||||
{
|
||||
QString themeName = settingsCache->getThemeName();
|
||||
|
|
@ -127,8 +103,10 @@ void ThemeManager::themeChangedSlot()
|
|||
else
|
||||
qApp->setStyleSheet("");
|
||||
|
||||
// card background
|
||||
cardBackPixmap = loadPixmap(dir, CARD_BACK_NAME);
|
||||
// resources
|
||||
QStringList resources;
|
||||
resources << dir.absolutePath() << ":/resources";
|
||||
QDir::setSearchPaths("theme", resources);
|
||||
|
||||
// zones bg
|
||||
dir.cd("zones");
|
||||
|
|
@ -137,10 +115,6 @@ void ThemeManager::themeChangedSlot()
|
|||
playerBgBrush = loadBrush(dir, PLAYERZONE_BG_NAME, QColor(200, 200, 200));
|
||||
stackBgBrush = loadBrush(dir, STACKZONE_BG_NAME, QColor(113, 43, 43));
|
||||
|
||||
// resources
|
||||
QStringList resources;
|
||||
resources << dir.absolutePath() << ":/resources";
|
||||
QDir::setSearchPaths("theme", resources);
|
||||
|
||||
emit themeChanged();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue