Commit bdd55db5 authored by Fabio Bas's avatar Fabio Bas
Browse files

Theme manager

This is the first implementation of a theme manager. It’s a rebased and
revisited version of #792.
parent 5d08236c
...@@ -221,7 +221,7 @@ option(WITH_CLIENT "build cockatrice" ON) ...@@ -221,7 +221,7 @@ option(WITH_CLIENT "build cockatrice" ON)
if(WITH_CLIENT) if(WITH_CLIENT)
add_subdirectory(cockatrice) add_subdirectory(cockatrice)
add_subdirectory(sounds) add_subdirectory(sounds)
add_subdirectory(zonebg) add_subdirectory(themes)
SET(CPACK_INSTALL_CMAKE_PROJECTS "cockatrice;cockatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) SET(CPACK_INSTALL_CMAKE_PROJECTS "cockatrice;cockatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS})
endif() endif()
......
...@@ -83,6 +83,7 @@ SET(cockatrice_SOURCES ...@@ -83,6 +83,7 @@ SET(cockatrice_SOURCES
src/playerlistwidget.cpp src/playerlistwidget.cpp
src/pixmapgenerator.cpp src/pixmapgenerator.cpp
src/settingscache.cpp src/settingscache.cpp
src/thememanager.cpp
src/localserver.cpp src/localserver.cpp
src/localserverinterface.cpp src/localserverinterface.cpp
src/localclient.cpp src/localclient.cpp
......
<RCC> <RCC>
<qresource prefix="/" > <qresource prefix="/" >
<file alias="back.svg" >resources/back.svg</file> <file>resources/back.svg</file>
<file>resources/lock.svg</file> <file>resources/lock.svg</file>
<file>resources/icon_delete.svg</file> <file>resources/icon_delete.svg</file>
<file>resources/icon_tab_changed.svg</file> <file>resources/icon_tab_changed.svg</file>
......
#include "carddatabase.h" #include "carddatabase.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
#include <QFile> #include <QFile>
...@@ -570,7 +571,7 @@ void CardInfo::loadPixmap(QPixmap &pixmap) ...@@ -570,7 +571,7 @@ void CardInfo::loadPixmap(QPixmap &pixmap)
pixmap = QPixmap(); pixmap = QPixmap();
if (getName().isEmpty()) { if (getName().isEmpty()) {
pixmap.load(settingsCache->getCardBackPicturePath()); pixmap = themeManager->getCardBackPixmap();
return; return;
} }
...@@ -594,15 +595,15 @@ void CardInfo::getPixmap(QSize size, QPixmap &pixmap) ...@@ -594,15 +595,15 @@ void CardInfo::getPixmap(QSize size, QPixmap &pixmap)
QPixmap bigPixmap; QPixmap bigPixmap;
loadPixmap(bigPixmap); loadPixmap(bigPixmap);
if (bigPixmap.isNull()) { if (bigPixmap.isNull()) {
if (!getName().isEmpty()) { if (getName().isEmpty()) {
pixmap = QPixmap(); // null
return;
} else {
pixmap = QPixmap(size); pixmap = QPixmap(size);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
QSvgRenderer svg(QString(":/back.svg")); QSvgRenderer svg(QString("theme:back.svg"));
QPainter painter(&pixmap); QPainter painter(&pixmap);
svg.render(&painter, QRectF(0, 0, size.width(), size.height())); svg.render(&painter, QRectF(0, 0, size.width(), size.height()));
} else {
pixmap = QPixmap(); // null
return;
} }
} else { } else {
pixmap = bigPixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); pixmap = bigPixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
...@@ -724,7 +725,7 @@ CardDatabase::CardDatabase(QObject *parent) ...@@ -724,7 +725,7 @@ CardDatabase::CardDatabase(QObject *parent)
noCard = new CardInfo(this); noCard = new CardInfo(this);
QPixmap tmp; QPixmap tmp;
noCard->loadPixmap(tmp); // cache pixmap for card back noCard->loadPixmap(tmp); // cache pixmap for card back
connect(settingsCache, SIGNAL(cardBackPicturePathChanged()), noCard, SLOT(updatePixmapCache())); connect(themeManager, SIGNAL(themeChanged()), noCard, SLOT(updatePixmapCache()));
} }
CardDatabase::~CardDatabase() CardDatabase::~CardDatabase()
......
...@@ -463,7 +463,7 @@ void DeckListModel::printDeckList(QPrinter *printer) ...@@ -463,7 +463,7 @@ void DeckListModel::printDeckList(QPrinter *printer)
cursor.insertBlock(headerBlockFormat, headerCharFormat); cursor.insertBlock(headerBlockFormat, headerCharFormat);
for (int i = 0; i < root->size(); i++) { for (int i = 0; i < root->size(); i++) {
cursor.insertHtml("<br><img src=:/resources/hr.jpg>"); cursor.insertHtml("<br><img src=theme:hr.jpg>");
//cursor.insertHtml("<hr>"); //cursor.insertHtml("<hr>");
cursor.insertBlock(headerBlockFormat, headerCharFormat); cursor.insertBlock(headerBlockFormat, headerCharFormat);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "decklist.h" #include "decklist.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "main.h" #include "main.h"
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag) DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
...@@ -128,10 +129,6 @@ void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event) ...@@ -128,10 +129,6 @@ void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
DeckViewCardContainer::DeckViewCardContainer(const QString &_name) DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
: QGraphicsItem(), name(_name), width(0), height(0) : QGraphicsItem(), name(_name), width(0), height(0)
{ {
QString bgPath = settingsCache->getTableBgPath();
if (!bgPath.isEmpty())
bgPixmap.load(bgPath);
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
} }
...@@ -144,17 +141,7 @@ void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsI ...@@ -144,17 +141,7 @@ void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsI
{ {
qreal totalTextWidth = getCardTypeTextWidth(); qreal totalTextWidth = getCardTypeTextWidth();
if (bgPixmap.isNull()) { painter->fillRect(boundingRect(), themeManager->getTableBgBrush());
QLinearGradient grad1(0, 0, 1, 0);
grad1.setCoordinateMode(QGradient::ObjectBoundingMode);
grad1.setColorAt(0, QColor(30, 30, 30));
grad1.setColorAt(1, QColor(80, 80, 80));
painter->fillRect(QRectF(0, 0, width, height), QBrush(grad1));
painter->fillRect(boundingRect(), QColor(0, 0, 0, 80));
}
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
painter->setPen(QColor(255, 255, 255, 100)); painter->setPen(QColor(255, 255, 255, 100));
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY)); painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
......
...@@ -52,7 +52,6 @@ private: ...@@ -52,7 +52,6 @@ private:
QMultiMap<QString, DeckViewCard *> cardsByType; QMultiMap<QString, DeckViewCard *> cardsByType;
QList<QPair<int, int> > currentRowsAndCols; QList<QPair<int, int> > currentRowsAndCols;
qreal width, height; qreal width, height;
QPixmap bgPixmap;
int getCardTypeTextWidth() const; int getCardTypeTextWidth() const;
public: public:
enum { Type = typeDeckViewCardContainer }; enum { Type = typeDeckViewCardContainer };
......
...@@ -83,10 +83,10 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par ...@@ -83,10 +83,10 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex))); connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
QAction *aAddToken = new QAction(tr("Add token"), this); QAction *aAddToken = new QAction(tr("Add token"), this);
aAddToken->setIcon(QIcon(":/resources/increment.svg")); aAddToken->setIcon(QIcon("theme:increment.svg"));
connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken())); connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken()));
QAction *aRemoveToken = new QAction(tr("Remove token"), this); QAction *aRemoveToken = new QAction(tr("Remove token"), this);
aRemoveToken->setIcon(QIcon(":/resources/decrement.svg")); aRemoveToken->setIcon(QIcon("theme:decrement.svg"));
connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken())); connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken()));
QToolBar *databaseToolBar = new QToolBar; QToolBar *databaseToolBar = new QToolBar;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "dlg_settings.h" #include "dlg_settings.h"
#include "main.h" #include "main.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "priceupdater.h" #include "priceupdater.h"
#include "soundengine.h" #include "soundengine.h"
...@@ -234,67 +235,23 @@ void GeneralSettingsPage::retranslateUi() ...@@ -234,67 +235,23 @@ void GeneralSettingsPage::retranslateUi()
AppearanceSettingsPage::AppearanceSettingsPage() AppearanceSettingsPage::AppearanceSettingsPage()
{ {
QIcon deleteIcon(":/resources/icon_delete.svg"); QString themeName = settingsCache->getThemeName();
handBgEdit = new QLineEdit(settingsCache->getHandBgPath()); QStringList themeDirs = themeManager->getAvailableThemes().keys();
handBgEdit->setReadOnly(true); for (int i = 0; i < themeDirs.size(); i++) {
QPushButton *handBgClearButton = new QPushButton(deleteIcon, QString()); themeBox.addItem(themeDirs[i]);
connect(handBgClearButton, SIGNAL(clicked()), this, SLOT(handBgClearButtonClicked())); if (themeDirs[i] == themeName)
QPushButton *handBgButton = new QPushButton("..."); themeBox.setCurrentIndex(i);
connect(handBgButton, SIGNAL(clicked()), this, SLOT(handBgButtonClicked())); }
stackBgEdit = new QLineEdit(settingsCache->getStackBgPath()); connect(&themeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeBoxChanged(int)));
stackBgEdit->setReadOnly(true);
QPushButton *stackBgClearButton = new QPushButton(deleteIcon, QString()); QGridLayout *themeGrid = new QGridLayout;
connect(stackBgClearButton, SIGNAL(clicked()), this, SLOT(stackBgClearButtonClicked())); themeGrid->addWidget(&themeLabel, 0, 0);
QPushButton *stackBgButton = new QPushButton("..."); themeGrid->addWidget(&themeBox, 0, 1);
connect(stackBgButton, SIGNAL(clicked()), this, SLOT(stackBgButtonClicked()));
themeGroupBox = new QGroupBox;
tableBgEdit = new QLineEdit(settingsCache->getTableBgPath()); themeGroupBox->setLayout(themeGrid);
tableBgEdit->setReadOnly(true);
QPushButton *tableBgClearButton = new QPushButton(deleteIcon, QString());
connect(tableBgClearButton, SIGNAL(clicked()), this, SLOT(tableBgClearButtonClicked()));
QPushButton *tableBgButton = new QPushButton("...");
connect(tableBgButton, SIGNAL(clicked()), this, SLOT(tableBgButtonClicked()));
playerAreaBgEdit = new QLineEdit(settingsCache->getPlayerBgPath());
playerAreaBgEdit->setReadOnly(true);
QPushButton *playerAreaBgClearButton = new QPushButton(deleteIcon, QString());
connect(playerAreaBgClearButton, SIGNAL(clicked()), this, SLOT(playerAreaBgClearButtonClicked()));
QPushButton *playerAreaBgButton = new QPushButton("...");
connect(playerAreaBgButton, SIGNAL(clicked()), this, SLOT(playerAreaBgButtonClicked()));
cardBackPicturePathEdit = new QLineEdit(settingsCache->getCardBackPicturePath());
cardBackPicturePathEdit->setReadOnly(true);
QPushButton *cardBackPicturePathClearButton = new QPushButton(deleteIcon, QString());
connect(cardBackPicturePathClearButton, SIGNAL(clicked()), this, SLOT(cardBackPicturePathClearButtonClicked()));
QPushButton *cardBackPicturePathButton = new QPushButton("...");
connect(cardBackPicturePathButton, SIGNAL(clicked()), this, SLOT(cardBackPicturePathButtonClicked()));
QGridLayout *zoneBgGrid = new QGridLayout;
zoneBgGrid->addWidget(&handBgLabel, 0, 0);
zoneBgGrid->addWidget(handBgEdit, 0, 1);
zoneBgGrid->addWidget(handBgClearButton, 0, 2);
zoneBgGrid->addWidget(handBgButton, 0, 3);
zoneBgGrid->addWidget(&stackBgLabel, 1, 0);
zoneBgGrid->addWidget(stackBgEdit, 1, 1);
zoneBgGrid->addWidget(stackBgClearButton, 1, 2);
zoneBgGrid->addWidget(stackBgButton, 1, 3);
zoneBgGrid->addWidget(&tableBgLabel, 2, 0);
zoneBgGrid->addWidget(tableBgEdit, 2, 1);
zoneBgGrid->addWidget(tableBgClearButton, 2, 2);
zoneBgGrid->addWidget(tableBgButton, 2, 3);
zoneBgGrid->addWidget(&playerAreaBgLabel, 3, 0);
zoneBgGrid->addWidget(playerAreaBgEdit, 3, 1);
zoneBgGrid->addWidget(playerAreaBgClearButton, 3, 2);
zoneBgGrid->addWidget(playerAreaBgButton, 3, 3);
zoneBgGrid->addWidget(&cardBackPicturePathLabel, 4, 0);
zoneBgGrid->addWidget(cardBackPicturePathEdit, 4, 1);
zoneBgGrid->addWidget(cardBackPicturePathClearButton, 4, 2);
zoneBgGrid->addWidget(cardBackPicturePathButton, 4, 3);
zoneBgGroupBox = new QGroupBox;
zoneBgGroupBox->setLayout(zoneBgGrid);
displayCardNamesCheckBox.setChecked(settingsCache->getDisplayCardNames()); displayCardNamesCheckBox.setChecked(settingsCache->getDisplayCardNames());
connect(&displayCardNamesCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setDisplayCardNames(int))); connect(&displayCardNamesCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setDisplayCardNames(int)));
...@@ -339,7 +296,7 @@ AppearanceSettingsPage::AppearanceSettingsPage() ...@@ -339,7 +296,7 @@ AppearanceSettingsPage::AppearanceSettingsPage()
tableGroupBox->setLayout(tableGrid); tableGroupBox->setLayout(tableGrid);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(zoneBgGroupBox); mainLayout->addWidget(themeGroupBox);
mainLayout->addWidget(cardsGroupBox); mainLayout->addWidget(cardsGroupBox);
mainLayout->addWidget(handGroupBox); mainLayout->addWidget(handGroupBox);
mainLayout->addWidget(tableGroupBox); mainLayout->addWidget(tableGroupBox);
...@@ -347,14 +304,17 @@ AppearanceSettingsPage::AppearanceSettingsPage() ...@@ -347,14 +304,17 @@ AppearanceSettingsPage::AppearanceSettingsPage()
setLayout(mainLayout); setLayout(mainLayout);
} }
void AppearanceSettingsPage::themeBoxChanged(int index)
{
QStringList themeDirs = themeManager->getAvailableThemes().keys();
if(index >= 0 && index < themeDirs.count())
settingsCache->setThemeName(themeDirs.at(index));
}
void AppearanceSettingsPage::retranslateUi() void AppearanceSettingsPage::retranslateUi()
{ {
zoneBgGroupBox->setTitle(tr("Zone background pictures")); themeGroupBox->setTitle(tr("Theme settings"));
handBgLabel.setText(tr("Hand background:")); themeLabel.setText(tr("Current theme:"));
stackBgLabel.setText(tr("Stack background:"));
tableBgLabel.setText(tr("Table background:"));
playerAreaBgLabel.setText(tr("Player info background:"));
cardBackPicturePathLabel.setText(tr("Card back:"));
cardsGroupBox->setTitle(tr("Card rendering")); cardsGroupBox->setTitle(tr("Card rendering"));
displayCardNamesCheckBox.setText(tr("Display card names on cards having a picture")); displayCardNamesCheckBox.setText(tr("Display card names on cards having a picture"));
...@@ -369,86 +329,6 @@ void AppearanceSettingsPage::retranslateUi() ...@@ -369,86 +329,6 @@ void AppearanceSettingsPage::retranslateUi()
minPlayersForMultiColumnLayoutLabel.setText(tr("Minimum player count for multi-column layout:")); minPlayersForMultiColumnLayoutLabel.setText(tr("Minimum player count for multi-column layout:"));
} }
void AppearanceSettingsPage::handBgClearButtonClicked()
{
handBgEdit->setText(QString());
settingsCache->setHandBgPath(QString());
}
void AppearanceSettingsPage::handBgButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
handBgEdit->setText(path);
settingsCache->setHandBgPath(path);
}
void AppearanceSettingsPage::stackBgClearButtonClicked()
{
stackBgEdit->setText(QString());
settingsCache->setStackBgPath(QString());
}
void AppearanceSettingsPage::stackBgButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
stackBgEdit->setText(path);
settingsCache->setStackBgPath(path);
}
void AppearanceSettingsPage::tableBgClearButtonClicked()
{
tableBgEdit->setText(QString());
settingsCache->setTableBgPath(QString());
}
void AppearanceSettingsPage::tableBgButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
tableBgEdit->setText(path);
settingsCache->setTableBgPath(path);
}
void AppearanceSettingsPage::playerAreaBgClearButtonClicked()
{
playerAreaBgEdit->setText(QString());
settingsCache->setPlayerBgPath(QString());
}
void AppearanceSettingsPage::playerAreaBgButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
playerAreaBgEdit->setText(path);
settingsCache->setPlayerBgPath(path);
}
void AppearanceSettingsPage::cardBackPicturePathClearButtonClicked()
{
cardBackPicturePathEdit->setText(QString());
settingsCache->setCardBackPicturePath(QString());
}
void AppearanceSettingsPage::cardBackPicturePathButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
cardBackPicturePathEdit->setText(path);
settingsCache->setCardBackPicturePath(path);
}
UserInterfaceSettingsPage::UserInterfaceSettingsPage() UserInterfaceSettingsPage::UserInterfaceSettingsPage()
{ {
notificationsEnabledCheckBox.setChecked(settingsCache->getNotificationsEnabled()); notificationsEnabledCheckBox.setChecked(settingsCache->getNotificationsEnabled());
...@@ -588,10 +468,10 @@ MessagesSettingsPage::MessagesSettingsPage() ...@@ -588,10 +468,10 @@ MessagesSettingsPage::MessagesSettingsPage()
messageList->addItem(settings.value(QString("msg%1").arg(i)).toString()); messageList->addItem(settings.value(QString("msg%1").arg(i)).toString());
aAdd = new QAction(this); aAdd = new QAction(this);
aAdd->setIcon(QIcon(":/resources/increment.svg")); aAdd->setIcon(QIcon("theme:increment.svg"));
connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd())); connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd()));
aRemove = new QAction(this); aRemove = new QAction(this);
aRemove->setIcon(QIcon(":/resources/decrement.svg")); aRemove->setIcon(QIcon("theme:decrement.svg"));
connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove())); connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove()));
QToolBar *messageToolBar = new QToolBar; QToolBar *messageToolBar = new QToolBar;
...@@ -679,7 +559,7 @@ void MessagesSettingsPage::retranslateUi() ...@@ -679,7 +559,7 @@ void MessagesSettingsPage::retranslateUi()
SoundSettingsPage::SoundSettingsPage() SoundSettingsPage::SoundSettingsPage()
{ {
QIcon deleteIcon(":/resources/icon_delete.svg"); QIcon deleteIcon("theme:icon_delete.svg");
soundEnabledCheckBox.setChecked(settingsCache->getSoundEnabled()); soundEnabledCheckBox.setChecked(settingsCache->getSoundEnabled());
connect(&soundEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setSoundEnabled(int))); connect(&soundEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setSoundEnabled(int)));
...@@ -815,32 +695,32 @@ void DlgSettings::createIcons() ...@@ -815,32 +695,32 @@ void DlgSettings::createIcons()
generalButton = new QListWidgetItem(contentsWidget); generalButton = new QListWidgetItem(contentsWidget);
generalButton->setTextAlignment(Qt::AlignHCenter); generalButton->setTextAlignment(Qt::AlignHCenter);
generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
generalButton->setIcon(QIcon(":/resources/icon_config_general.svg")); generalButton->setIcon(QIcon("theme:icon_config_general.svg"));
appearanceButton = new QListWidgetItem(contentsWidget); appearanceButton = new QListWidgetItem(contentsWidget);
appearanceButton->setTextAlignment(Qt::AlignHCenter); appearanceButton->setTextAlignment(Qt::AlignHCenter);
appearanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); appearanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
appearanceButton->setIcon(QIcon(":/resources/icon_config_appearance.svg")); appearanceButton->setIcon(QIcon("theme:icon_config_appearance.svg"));
userInterfaceButton = new QListWidgetItem(contentsWidget); userInterfaceButton = new QListWidgetItem(contentsWidget);
userInterfaceButton->setTextAlignment(Qt::AlignHCenter); userInterfaceButton->setTextAlignment(Qt::AlignHCenter);
userInterfaceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); userInterfaceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
userInterfaceButton->setIcon(QIcon(":/resources/icon_config_interface.svg")); userInterfaceButton->setIcon(QIcon("theme:icon_config_interface.svg"));
deckEditorButton = new QListWidgetItem(contentsWidget); deckEditorButton = new QListWidgetItem(contentsWidget);
deckEditorButton->setTextAlignment(Qt::AlignHCenter); deckEditorButton->setTextAlignment(Qt::AlignHCenter);
deckEditorButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); deckEditorButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
deckEditorButton->setIcon(QIcon(":/resources/icon_config_deckeditor.svg")); deckEditorButton->setIcon(QIcon("theme:icon_config_deckeditor.svg"));
messagesButton = new QListWidgetItem(contentsWidget); messagesButton = new QListWidgetItem(contentsWidget);
messagesButton->setTextAlignment(Qt::AlignHCenter); messagesButton->setTextAlignment(Qt::AlignHCenter);
messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
messagesButton->setIcon(QIcon(":/resources/icon_config_messages.svg")); messagesButton->setIcon(QIcon("theme:icon_config_messages.svg"));
soundButton = new QListWidgetItem(contentsWidget); soundButton = new QListWidgetItem(contentsWidget);
soundButton->setTextAlignment(Qt::AlignHCenter); soundButton->setTextAlignment(Qt::AlignHCenter);
soundButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); soundButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
soundButton->setIcon(QIcon(":/resources/icon_config_sound.svg")); soundButton->setIcon(QIcon("theme:icon_config_sound.svg"));
connect(contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem *))); connect(contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem *)));
} }
......
...@@ -71,40 +71,17 @@ private: ...@@ -71,40 +71,17 @@ private:
class AppearanceSettingsPage : public AbstractSettingsPage { class AppearanceSettingsPage : public AbstractSettingsPage {
Q_OBJECT Q_OBJECT
private slots: private slots:
void handBgClearButtonClicked(); void themeBoxChanged(int index);
void handBgButtonClicked();
void stackBgClearButtonClicked();
void stackBgButtonClicked();
void tableBgClearButtonClicked();
void tableBgButtonClicked();
void playerAreaBgClearButtonClicked();
void playerAreaBgButtonClicked();
void cardBackPicturePathClearButtonClicked();
void cardBackPicturePathButtonClicked();
signals:
void handBgChanged(const QString &path);
void stackBgChanged(const QString &path);
void tableBgChanged(const QString &path);
void playerAreaBgChanged(const QString &path);
void cardBackPicturePathChanged(const QString &path);
private: private:
QLabel handBgLabel; QLabel themeLabel;
QLabel stackBgLabel; QComboBox themeBox;
QLabel tableBgLabel;
QLabel playerAreaBgLabel;
QLabel cardBackPicturePathLabel;
QLabel minPlayersForMultiColumnLayoutLabel; QLabel minPlayersForMultiColumnLayoutLabel;
QLineEdit *handBgEdit;
QLineEdit *stackBgEdit;
QLineEdit *tableBgEdit;
QLineEdit *playerAreaBgEdit;
QLineEdit *cardBackPicturePathEdit;
QCheckBox displayCardNamesCheckBox; QCheckBox displayCardNamesCheckBox;
QCheckBox cardScalingCheckBox; QCheckBox cardScalingCheckBox;
QCheckBox horizontalHandCheckBox; QCheckBox horizontalHandCheckBox;
QCheckBox leftJustifiedHandCheckBox; QCheckBox leftJustifiedHandCheckBox;
QCheckBox invertVerticalCoordinateCheckBox; QCheckBox invertVerticalCoordinateCheckBox;
QGroupBox *zoneBgGroupBox; QGroupBox *themeGroupBox;
QGroupBox *cardsGroupBox; QGroupBox *cardsGroupBox;
QGroupBox *handGroupBox; QGroupBox *handGroupBox;
QGroupBox *tableGroupBox; QGroupBox *tableGroupBox;
......
...@@ -60,10 +60,10 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup ...@@ -60,10 +60,10 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
#endif #endif
filterButton = new QPushButton; filterButton = new QPushButton;
filterButton->setIcon(QIcon(":/resources/icon_search_black.svg")); filterButton->setIcon(QIcon("theme:icon_search_black.svg"));
connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter())); connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter()));
clearFilterButton = new QPushButton; clearFilterButton = new QPushButton;
clearFilterButton->setIcon(QIcon(":/resources/icon_clearsearch.svg")); clearFilterButton->setIcon(QIcon("theme:icon_clearsearch.svg"));
clearFilterButton->setEnabled(true); clearFilterButton->setEnabled(true);
connect(clearFilterButton, SIGNAL(clicked()), this, SLOT(actClearFilter())); connect(clearFilterButton, SIGNAL(clicked()), this, SLOT(actClearFilter()));
......
...@@ -36,7 +36,7 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op ...@@ -36,7 +36,7 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
#else #else
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), cachedPixmap)) { if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), cachedPixmap)) {
#endif #endif
QSvgRenderer svg(QString(":/resources/hand.svg")); QSvgRenderer svg(QString("theme:hand.svg"));
cachedPixmap = QPixmap(translatedSize); cachedPixmap = QPixmap(translatedSize);
cachedPixmap.fill(Qt::transparent); cachedPixmap.fill(Qt::transparent);
QPainter painter(&cachedPixmap); QPainter painter(&cachedPixmap);
......
#include <QPainter> #include <QPainter>
#include "handzone.h" #include "handzone.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "player.h" #include "player.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "carditem.h" #include "carditem.h"
...@@ -10,16 +11,13 @@ ...@@ -10,16 +11,13 @@
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent) HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight) : SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
{ {
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap())); connect(themeManager, SIGNAL(themeChanged()), this, SLOT(updateBg()));
updateBgPixmap(); updateBg();
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
} }
void HandZone::updateBgPixmap() void HandZone::updateBg()
{ {
QString bgPath = settingsCache->getHandBgPath();
if (!bgPath.isEmpty())
bgPixmap.load(bgPath);
update(); update();
} }
...@@ -77,10 +75,7 @@ QRectF HandZone::boundingRect() const ...@@ -77,10 +75,7 @@ QRectF HandZone::boundingRect() const
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
if (bgPixmap.isNull()) painter->fillRect(boundingRect(), themeManager->getHandBgBrush());
painter->fillRect(boundingRect(), QColor(30, 30, 30));
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
} }
void HandZone::reorganizeCards() void HandZone::reorganizeCards()
......
...@@ -7,9 +7,8 @@ class HandZone : public SelectZone { ...@@ -7,9 +7,8 @@ class HandZone : public SelectZone {
Q_OBJECT Q_OBJECT
private: private:
qreal width, zoneHeight; qreal width, zoneHeight;
QPixmap bgPixmap;
private slots: private slots:
void updateBgPixmap(); void updateBg();
public slots: public slots:
void updateOrientation(); void updateOrientation();
public: public:
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "dlg_settings.h" #include "dlg_settings.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "pixmapgenerator.h" #include "pixmapgenerator.h"
#include "rng_sfmt.h" #include "rng_sfmt.h"
#include "soundengine.h" #include "soundengine.h"
...@@ -50,7 +51,7 @@ SettingsCache *settingsCache; ...@@ -50,7 +51,7 @@ SettingsCache *settingsCache;
RNG_Abstract *rng; RNG_Abstract *rng;
SoundEngine *soundEngine; SoundEngine *soundEngine;
QSystemTrayIcon *trayIcon; QSystemTrayIcon *trayIcon;
ThemeManager *themeManager;
const QString translationPrefix = "cockatrice"; const QString translationPrefix = "cockatrice";
#ifdef TRANSLATION_PATH #ifdef TRANSLATION_PATH
...@@ -132,6 +133,7 @@ int main(int argc, char *argv[]) ...@@ -132,6 +133,7 @@ int main(int argc, char *argv[])
rng = new RNG_SFMT; rng = new RNG_SFMT;
settingsCache = new SettingsCache; settingsCache = new SettingsCache;
themeManager = new ThemeManager;
db = new CardDatabase; db = new CardDatabase;
qtTranslator = new QTranslator; qtTranslator = new QTranslator;
...@@ -188,13 +190,14 @@ int main(int argc, char *argv[]) ...@@ -188,13 +190,14 @@ int main(int argc, char *argv[])
if (settingsValid()) { if (settingsValid()) {
qDebug("main(): starting main program"); qDebug("main(): starting main program");
soundEngine = new SoundEngine; soundEngine = new SoundEngine;
qDebug("main(): SoundEngine constructor finished"); qDebug("main(): SoundEngine constructor finished");
MainWindow ui; MainWindow ui;
qDebug("main(): MainWindow constructor finished"); qDebug("main(): MainWindow constructor finished");
QIcon icon(":/resources/appicon.svg"); QIcon icon("theme:appicon.svg");
ui.setWindowIcon(icon); ui.setWindowIcon(icon);
ui.show(); ui.show();
......
...@@ -16,7 +16,7 @@ QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name) ...@@ -16,7 +16,7 @@ QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name)
if (pmCache.contains(key)) if (pmCache.contains(key))
return pmCache.value(key); return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/phases/icon_phase_" + name + ".svg")); QSvgRenderer svg(QString("theme:phases/icon_phase_" + name + ".svg"));
QPixmap pixmap(height, height); QPixmap pixmap(height, height);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
...@@ -36,13 +36,13 @@ QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool hi ...@@ -36,13 +36,13 @@ QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool hi
if (pmCache.contains(key)) if (pmCache.contains(key))
return pmCache.value(key); return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/counters/" + name + ".svg")); QSvgRenderer svg(QString("theme:counters/" + name + ".svg"));
if (!svg.isValid()) { if (!svg.isValid()) {
name = "general"; name = "general";
if (highlight) if (highlight)
name.append("_highlight"); name.append("_highlight");
svg.load(QString(":/resources/counters/" + name + ".svg")); svg.load(QString("theme:counters/" + name + ".svg"));
} }
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
...@@ -98,7 +98,7 @@ QPixmap GenderPixmapGenerator::generatePixmap(int height, int _gender) ...@@ -98,7 +98,7 @@ QPixmap GenderPixmapGenerator::generatePixmap(int height, int _gender)
default: genderStr = "unknown"; default: genderStr = "unknown";
}; };
QSvgRenderer svg(QString(":/resources/genders/" + genderStr + ".svg")); QSvgRenderer svg(QString("theme:genders/" + genderStr + ".svg"));
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height); QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
...@@ -119,7 +119,7 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr ...@@ -119,7 +119,7 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
if (pmCache.contains(key)) if (pmCache.contains(key))
return pmCache.value(key); return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/countries/" + countryCode + ".svg")); QSvgRenderer svg(QString("theme:countries/" + countryCode + ".svg"));
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height); QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
...@@ -154,7 +154,7 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user ...@@ -154,7 +154,7 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user
if (isBuddy) if (isBuddy)
levelString.append("_buddy"); levelString.append("_buddy");
QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg")); QSvgRenderer svg(QString("theme:userlevels/" + levelString + ".svg"));
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height); QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
...@@ -175,7 +175,7 @@ QPixmap LockPixmapGenerator::generatePixmap(int height) ...@@ -175,7 +175,7 @@ QPixmap LockPixmapGenerator::generatePixmap(int height)
if (pmCache.contains(key)) if (pmCache.contains(key))
return pmCache.value(key); return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/lock.svg")); QSvgRenderer svg(QString("theme:lock.svg"));
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height); QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "tab_game.h" #include "tab_game.h"
#include "gamescene.h" #include "gamescene.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "dlg_create_token.h" #include "dlg_create_token.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "color.h" #include "color.h"
...@@ -69,25 +70,18 @@ PlayerArea::PlayerArea(QGraphicsItem *parentItem) ...@@ -69,25 +70,18 @@ PlayerArea::PlayerArea(QGraphicsItem *parentItem)
: QObject(), QGraphicsItem(parentItem) : QObject(), QGraphicsItem(parentItem)
{ {
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap())); connect(themeManager, SIGNAL(themeChanged()), this, SLOT(updateBg()));
updateBgPixmap(); updateBg();
} }
void PlayerArea::updateBgPixmap() void PlayerArea::updateBg()
{ {
QString bgPath = settingsCache->getPlayerBgPath();
if (bgPath.isEmpty())
bgPixmapBrush = QBrush(QColor(200, 200, 200));
else {
qDebug() << "loading" << bgPath;
bgPixmapBrush = QBrush(QPixmap(bgPath));
}
update(); update();
} }
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
painter->fillRect(bRect, bgPixmapBrush); painter->fillRect(bRect, themeManager->getPlayerBgBrush());
} }
void PlayerArea::setSize(qreal width, qreal height) void PlayerArea::setSize(qreal width, qreal height)
......
...@@ -60,10 +60,9 @@ class PlayerArea : public QObject, public QGraphicsItem { ...@@ -60,10 +60,9 @@ class PlayerArea : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
Q_INTERFACES(QGraphicsItem) Q_INTERFACES(QGraphicsItem)
private: private:
QBrush bgPixmapBrush;
QRectF bRect; QRectF bRect;
private slots: private slots:
void updateBgPixmap(); void updateBg();
public: public:
enum { Type = typeOther }; enum { Type = typeOther };
int type() const { return Type; } int type() const { return Type; }
......
...@@ -51,12 +51,12 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const ...@@ -51,12 +51,12 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent) PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent)
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false) : QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
{ {
readyIcon = QIcon(":/resources/icon_ready_start.svg"); readyIcon = QIcon("theme:icon_ready_start.svg");
notReadyIcon = QIcon(":/resources/icon_not_ready_start.svg"); notReadyIcon = QIcon("theme:icon_not_ready_start.svg");
concededIcon = QIcon(":/resources/icon_conceded.svg"); concededIcon = QIcon("theme:icon_conceded.svg");
playerIcon = QIcon(":/resources/icon_player.svg"); playerIcon = QIcon("theme:icon_player.svg");
spectatorIcon = QIcon(":/resources/icon_spectator.svg"); spectatorIcon = QIcon("theme:icon_spectator.svg");
lockIcon = QIcon(":/resources/lock.svg"); lockIcon = QIcon("theme:lock.svg");
if (tabSupervisor) { if (tabSupervisor) {
itemDelegate = new PlayerListItemDelegate(this); itemDelegate = new PlayerListItemDelegate(this);
......
...@@ -35,7 +35,7 @@ RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client, ...@@ -35,7 +35,7 @@ RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client,
QFileIconProvider fip; QFileIconProvider fip;
dirIcon = fip.icon(QFileIconProvider::Folder); dirIcon = fip.icon(QFileIconProvider::Folder);
fileIcon = fip.icon(QFileIconProvider::File); fileIcon = fip.icon(QFileIconProvider::File);
lockIcon = QIcon(":/resources/lock.svg"); lockIcon = QIcon("theme:lock.svg");
refreshTree(); refreshTree();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment