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
...@@ -13,11 +13,7 @@ SettingsCache::SettingsCache() ...@@ -13,11 +13,7 @@ SettingsCache::SettingsCache()
cardDatabasePath = settings->value("paths/carddatabase").toString(); cardDatabasePath = settings->value("paths/carddatabase").toString();
tokenDatabasePath = settings->value("paths/tokendatabase").toString(); tokenDatabasePath = settings->value("paths/tokendatabase").toString();
handBgPath = settings->value("zonebg/hand").toString(); themeName = settings->value("theme/name").toString();
stackBgPath = settings->value("zonebg/stack").toString();
tableBgPath = settings->value("zonebg/table").toString();
playerBgPath = settings->value("zonebg/playerarea").toString();
cardBackPicturePath = settings->value("paths/cardbackpicture").toString();
// we only want to reset the cache once, then its up to the user // we only want to reset the cache once, then its up to the user
bool updateCache = settings->value("revert/pixmapCacheSize", false).toBool(); bool updateCache = settings->value("revert/pixmapCacheSize", false).toBool();
...@@ -148,39 +144,11 @@ void SettingsCache::setTokenDatabasePath(const QString &_tokenDatabasePath) ...@@ -148,39 +144,11 @@ void SettingsCache::setTokenDatabasePath(const QString &_tokenDatabasePath)
emit tokenDatabasePathChanged(); emit tokenDatabasePathChanged();
} }
void SettingsCache::setHandBgPath(const QString &_handBgPath) void SettingsCache::setThemeName(const QString &_themeName)
{ {
handBgPath = _handBgPath; themeName = _themeName;
settings->setValue("zonebg/hand", handBgPath); settings->setValue("theme/name", themeName);
emit handBgPathChanged(); emit themeChanged();
}
void SettingsCache::setStackBgPath(const QString &_stackBgPath)
{
stackBgPath = _stackBgPath;
settings->setValue("zonebg/stack", stackBgPath);
emit stackBgPathChanged();
}
void SettingsCache::setTableBgPath(const QString &_tableBgPath)
{
tableBgPath = _tableBgPath;
settings->setValue("zonebg/table", tableBgPath);
emit tableBgPathChanged();
}
void SettingsCache::setPlayerBgPath(const QString &_playerBgPath)
{
playerBgPath = _playerBgPath;
settings->setValue("zonebg/playerarea", playerBgPath);
emit playerBgPathChanged();
}
void SettingsCache::setCardBackPicturePath(const QString &_cardBackPicturePath)
{
cardBackPicturePath = _cardBackPicturePath;
settings->setValue("paths/cardbackpicture", cardBackPicturePath);
emit cardBackPicturePathChanged();
} }
void SettingsCache::setPicDownload(int _picDownload) void SettingsCache::setPicDownload(int _picDownload)
......
...@@ -21,11 +21,7 @@ signals: ...@@ -21,11 +21,7 @@ signals:
void picsPathChanged(); void picsPathChanged();
void cardDatabasePathChanged(); void cardDatabasePathChanged();
void tokenDatabasePathChanged(); void tokenDatabasePathChanged();
void handBgPathChanged(); void themeChanged();
void stackBgPathChanged();
void tableBgPathChanged();
void playerBgPathChanged();
void cardBackPicturePathChanged();
void picDownloadChanged(); void picDownloadChanged();
void picDownloadHqChanged(); void picDownloadHqChanged();
void displayCardNamesChanged(); void displayCardNamesChanged();
...@@ -45,8 +41,7 @@ private: ...@@ -45,8 +41,7 @@ private:
QByteArray mainWindowGeometry; QByteArray mainWindowGeometry;
QString lang; QString lang;
QString deckPath, replaysPath, picsPath, cardDatabasePath, tokenDatabasePath; QString deckPath, replaysPath, picsPath, cardDatabasePath, tokenDatabasePath, themeName;
QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath;
bool picDownload; bool picDownload;
bool picDownloadHq; bool picDownloadHq;
bool notificationsEnabled; bool notificationsEnabled;
...@@ -90,11 +85,7 @@ public: ...@@ -90,11 +85,7 @@ public:
QString getPicsPath() const { return picsPath; } QString getPicsPath() const { return picsPath; }
QString getCardDatabasePath() const { return cardDatabasePath; } QString getCardDatabasePath() const { return cardDatabasePath; }
QString getTokenDatabasePath() const { return tokenDatabasePath; } QString getTokenDatabasePath() const { return tokenDatabasePath; }
QString getHandBgPath() const { return handBgPath; } QString getThemeName() const { return themeName; }
QString getStackBgPath() const { return stackBgPath; }
QString getTableBgPath() const { return tableBgPath; }
QString getPlayerBgPath() const { return playerBgPath; }
QString getCardBackPicturePath() const { return cardBackPicturePath; }
QString getChatMentionColor() const { return chatMentionColor; } QString getChatMentionColor() const { return chatMentionColor; }
bool getPicDownload() const { return picDownload; } bool getPicDownload() const { return picDownload; }
bool getPicDownloadHq() const { return picDownloadHq; } bool getPicDownloadHq() const { return picDownloadHq; }
...@@ -144,11 +135,7 @@ public slots: ...@@ -144,11 +135,7 @@ public slots:
void setPicsPath(const QString &_picsPath); void setPicsPath(const QString &_picsPath);
void setCardDatabasePath(const QString &_cardDatabasePath); void setCardDatabasePath(const QString &_cardDatabasePath);
void setTokenDatabasePath(const QString &_tokenDatabasePath); void setTokenDatabasePath(const QString &_tokenDatabasePath);
void setHandBgPath(const QString &_handBgPath); void setThemeName(const QString &_themeName);
void setStackBgPath(const QString &_stackBgPath);
void setTableBgPath(const QString &_tableBgPath);
void setPlayerBgPath(const QString &_playerBgPath);
void setCardBackPicturePath(const QString &_cardBackPicturePath);
void setChatMentionColor(const QString &_chatMentionColor); void setChatMentionColor(const QString &_chatMentionColor);
void setPicDownload(int _picDownload); void setPicDownload(int _picDownload);
void setPicDownloadHq(int _picDownloadHq); void setPicDownloadHq(int _picDownloadHq);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "arrowitem.h" #include "arrowitem.h"
#include "stackzone.h" #include "stackzone.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"
...@@ -12,16 +13,13 @@ ...@@ -12,16 +13,13 @@
StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent) StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
: SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight) : SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight)
{ {
connect(settingsCache, SIGNAL(stackBgPathChanged()), this, SLOT(updateBgPixmap())); connect(themeManager, SIGNAL(themeChanged()), this, SLOT(updateBg()));
updateBgPixmap(); updateBg();
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
} }
void StackZone::updateBgPixmap() void StackZone::updateBg()
{ {
QString bgPath = settingsCache->getStackBgPath();
if (!bgPath.isEmpty())
bgPixmap.load(bgPath);
update(); update();
} }
...@@ -48,10 +46,7 @@ QRectF StackZone::boundingRect() const ...@@ -48,10 +46,7 @@ QRectF StackZone::boundingRect() const
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
if (bgPixmap.isNull()) painter->fillRect(boundingRect(), themeManager->getStackBgBrush());
painter->fillRect(boundingRect(), QColor(113, 43, 43));
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
} }
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/) void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
......
...@@ -7,9 +7,8 @@ class StackZone : public SelectZone { ...@@ -7,9 +7,8 @@ class StackZone : public SelectZone {
Q_OBJECT Q_OBJECT
private: private:
qreal zoneHeight; qreal zoneHeight;
QPixmap bgPixmap;
private slots: private slots:
void updateBgPixmap(); void updateBg();
public: public:
StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent = 0); StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent = 0);
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint); void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
......
...@@ -50,11 +50,11 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) ...@@ -50,11 +50,11 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
: Tab(_tabSupervisor, parent), modified(false) : Tab(_tabSupervisor, parent), modified(false)
{ {
aClearSearch = new QAction(QString(), this); aClearSearch = new QAction(QString(), this);
aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg")); aClearSearch->setIcon(QIcon("theme:icon_clearsearch.svg"));
connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch())); connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch()));
searchEdit = new SearchLineEdit; searchEdit = new SearchLineEdit;
#if QT_VERSION >= 0x050300 #if QT_VERSION >= 0x050300
searchEdit->addAction(QIcon(":/resources/icon_search_black.svg"), QLineEdit::LeadingPosition); searchEdit->addAction(QIcon("theme:icon_search_black.svg"), QLineEdit::LeadingPosition);
#endif #endif
searchEdit->setObjectName("searchEdit"); searchEdit->setObjectName("searchEdit");
...@@ -177,7 +177,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) ...@@ -177,7 +177,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
/* Update price /* Update price
aUpdatePrices = new QAction(QString(), this); aUpdatePrices = new QAction(QString(), this);
aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png")); aUpdatePrices->setIcon(QIcon("theme:icon_update.png"));
connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices())); connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
if (!settingsCache->getPriceTagFeature()) if (!settingsCache->getPriceTagFeature())
aUpdatePrices->setVisible(false); aUpdatePrices->setVisible(false);
...@@ -267,19 +267,19 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) ...@@ -267,19 +267,19 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
addTabMenu(dbMenu); addTabMenu(dbMenu);
aAddCard = new QAction(QString(), this); aAddCard = new QAction(QString(), this);
aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg")); aAddCard->setIcon(QIcon("theme:arrow_right_green.svg"));
connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard())); connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard()));
aAddCardToSideboard = new QAction(QString(), this); aAddCardToSideboard = new QAction(QString(), this);
aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg")); aAddCardToSideboard->setIcon(QIcon("theme:add_to_sideboard.svg"));
connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard())); connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard()));
aRemoveCard = new QAction(QString(), this); aRemoveCard = new QAction(QString(), this);
aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg")); aRemoveCard->setIcon(QIcon("theme:remove_row.svg"));
connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard())); connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard()));
aIncrement = new QAction(QString(), this); aIncrement = new QAction(QString(), this);
aIncrement->setIcon(QIcon(":/resources/increment.svg")); aIncrement->setIcon(QIcon("theme:increment.svg"));
connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement())); connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement()));
aDecrement = new QAction(QString(), this); aDecrement = new QAction(QString(), this);
aDecrement->setIcon(QIcon(":/resources/decrement.svg")); aDecrement->setIcon(QIcon("theme:decrement.svg"));
connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement())); connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement()));
deckEditToolBar->addAction(aAddCard); deckEditToolBar->addAction(aAddCard);
......
...@@ -80,25 +80,25 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c ...@@ -80,25 +80,25 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
hbox->addWidget(rightGroupBox); hbox->addWidget(rightGroupBox);
aOpenLocalDeck = new QAction(this); aOpenLocalDeck = new QAction(this);
aOpenLocalDeck->setIcon(QIcon(":/resources/pencil.svg")); aOpenLocalDeck->setIcon(QIcon("theme:pencil.svg"));
connect(aOpenLocalDeck, SIGNAL(triggered()), this, SLOT(actOpenLocalDeck())); connect(aOpenLocalDeck, SIGNAL(triggered()), this, SLOT(actOpenLocalDeck()));
aUpload = new QAction(this); aUpload = new QAction(this);
aUpload->setIcon(QIcon(":/resources/arrow_right_green.svg")); aUpload->setIcon(QIcon("theme:arrow_right_green.svg"));
connect(aUpload, SIGNAL(triggered()), this, SLOT(actUpload())); connect(aUpload, SIGNAL(triggered()), this, SLOT(actUpload()));
aDeleteLocalDeck = new QAction(this); aDeleteLocalDeck = new QAction(this);
aDeleteLocalDeck->setIcon(QIcon(":/resources/remove_row.svg")); aDeleteLocalDeck->setIcon(QIcon("theme:remove_row.svg"));
connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck())); connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck()));
aOpenRemoteDeck = new QAction(this); aOpenRemoteDeck = new QAction(this);
aOpenRemoteDeck->setIcon(QIcon(":/resources/pencil.svg")); aOpenRemoteDeck->setIcon(QIcon("theme:pencil.svg"));
connect(aOpenRemoteDeck, SIGNAL(triggered()), this, SLOT(actOpenRemoteDeck())); connect(aOpenRemoteDeck, SIGNAL(triggered()), this, SLOT(actOpenRemoteDeck()));
aDownload = new QAction(this); aDownload = new QAction(this);
aDownload->setIcon(QIcon(":/resources/arrow_left_green.svg")); aDownload->setIcon(QIcon("theme:arrow_left_green.svg"));
connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload())); connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload()));
aNewFolder = new QAction(this); aNewFolder = new QAction(this);
aNewFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogNewFolder)); aNewFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogNewFolder));
connect(aNewFolder, SIGNAL(triggered()), this, SLOT(actNewFolder())); connect(aNewFolder, SIGNAL(triggered()), this, SLOT(actNewFolder()));
aDeleteRemoteDeck = new QAction(this); aDeleteRemoteDeck = new QAction(this);
aDeleteRemoteDeck->setIcon(QIcon(":/resources/remove_row.svg")); aDeleteRemoteDeck->setIcon(QIcon("theme:remove_row.svg"));
connect(aDeleteRemoteDeck, SIGNAL(triggered()), this, SLOT(actDeleteRemoteDeck())); connect(aDeleteRemoteDeck, SIGNAL(triggered()), this, SLOT(actDeleteRemoteDeck()));
leftToolBar->addAction(aOpenLocalDeck); leftToolBar->addAction(aOpenLocalDeck);
......
...@@ -304,17 +304,17 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay) ...@@ -304,17 +304,17 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
replayStartButton = new QToolButton; replayStartButton = new QToolButton;
replayStartButton->setIconSize(QSize(32, 32)); replayStartButton->setIconSize(QSize(32, 32));
replayStartButton->setIcon(QIcon(":/resources/replay_start.svg")); replayStartButton->setIcon(QIcon("theme:replay_start.svg"));
connect(replayStartButton, SIGNAL(clicked()), this, SLOT(replayStartButtonClicked())); connect(replayStartButton, SIGNAL(clicked()), this, SLOT(replayStartButtonClicked()));
replayPauseButton = new QToolButton; replayPauseButton = new QToolButton;
replayPauseButton->setIconSize(QSize(32, 32)); replayPauseButton->setIconSize(QSize(32, 32));
replayPauseButton->setEnabled(false); replayPauseButton->setEnabled(false);
replayPauseButton->setIcon(QIcon(":/resources/replay_pause.svg")); replayPauseButton->setIcon(QIcon("theme:replay_pause.svg"));
connect(replayPauseButton, SIGNAL(clicked()), this, SLOT(replayPauseButtonClicked())); connect(replayPauseButton, SIGNAL(clicked()), this, SLOT(replayPauseButtonClicked()));
replayFastForwardButton = new QToolButton; replayFastForwardButton = new QToolButton;
replayFastForwardButton->setIconSize(QSize(32, 32)); replayFastForwardButton->setIconSize(QSize(32, 32));
replayFastForwardButton->setEnabled(false); replayFastForwardButton->setEnabled(false);
replayFastForwardButton->setIcon(QIcon(":/resources/replay_fastforward.svg")); replayFastForwardButton->setIcon(QIcon("theme:replay_fastforward.svg"));
replayFastForwardButton->setCheckable(true); replayFastForwardButton->setCheckable(true);
connect(replayFastForwardButton, SIGNAL(toggled(bool)), this, SLOT(replayFastForwardButtonToggled(bool))); connect(replayFastForwardButton, SIGNAL(toggled(bool)), this, SLOT(replayFastForwardButtonToggled(bool)));
......
...@@ -78,22 +78,22 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) ...@@ -78,22 +78,22 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
hbox->addWidget(rightGroupBox); hbox->addWidget(rightGroupBox);
aOpenLocalReplay = new QAction(this); aOpenLocalReplay = new QAction(this);
aOpenLocalReplay->setIcon(QIcon(":/resources/icon_view.svg")); aOpenLocalReplay->setIcon(QIcon("theme:icon_view.svg"));
connect(aOpenLocalReplay, SIGNAL(triggered()), this, SLOT(actOpenLocalReplay())); connect(aOpenLocalReplay, SIGNAL(triggered()), this, SLOT(actOpenLocalReplay()));
aDeleteLocalReplay = new QAction(this); aDeleteLocalReplay = new QAction(this);
aDeleteLocalReplay->setIcon(QIcon(":/resources/remove_row.svg")); aDeleteLocalReplay->setIcon(QIcon("theme:remove_row.svg"));
connect(aDeleteLocalReplay, SIGNAL(triggered()), this, SLOT(actDeleteLocalReplay())); connect(aDeleteLocalReplay, SIGNAL(triggered()), this, SLOT(actDeleteLocalReplay()));
aOpenRemoteReplay = new QAction(this); aOpenRemoteReplay = new QAction(this);
aOpenRemoteReplay->setIcon(QIcon(":/resources/icon_view.svg")); aOpenRemoteReplay->setIcon(QIcon("theme:icon_view.svg"));
connect(aOpenRemoteReplay, SIGNAL(triggered()), this, SLOT(actOpenRemoteReplay())); connect(aOpenRemoteReplay, SIGNAL(triggered()), this, SLOT(actOpenRemoteReplay()));
aDownload = new QAction(this); aDownload = new QAction(this);
aDownload->setIcon(QIcon(":/resources/arrow_left_green.svg")); aDownload->setIcon(QIcon("theme:arrow_left_green.svg"));
connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload())); connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload()));
aKeep = new QAction(this); aKeep = new QAction(this);
aKeep->setIcon(QIcon(":/resources/lock.svg")); aKeep->setIcon(QIcon("theme:lock.svg"));
connect(aKeep, SIGNAL(triggered()), this, SLOT(actKeepRemoteReplay())); connect(aKeep, SIGNAL(triggered()), this, SLOT(actKeepRemoteReplay()));
aDeleteRemoteReplay = new QAction(this); aDeleteRemoteReplay = new QAction(this);
aDeleteRemoteReplay->setIcon(QIcon(":/resources/remove_row.svg")); aDeleteRemoteReplay->setIcon(QIcon("theme:remove_row.svg"));
connect(aDeleteRemoteReplay, SIGNAL(triggered()), this, SLOT(actDeleteRemoteReplay())); connect(aDeleteRemoteReplay, SIGNAL(triggered()), this, SLOT(actDeleteRemoteReplay()));
leftToolBar->addAction(aOpenLocalReplay); leftToolBar->addAction(aOpenLocalReplay);
......
...@@ -68,7 +68,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI ...@@ -68,7 +68,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
connect(aOpenChatSettings, SIGNAL(triggered()), this, SLOT(actOpenChatSettings())); connect(aOpenChatSettings, SIGNAL(triggered()), this, SLOT(actOpenChatSettings()));
QToolButton *chatSettingsButton = new QToolButton; QToolButton *chatSettingsButton = new QToolButton;
chatSettingsButton->setIcon(QIcon(":/resources/icon_settings.svg")); chatSettingsButton->setIcon(QIcon("theme:icon_settings.svg"));
chatSettingsButton->setMenu(chatSettingsMenu); chatSettingsButton->setMenu(chatSettingsMenu);
chatSettingsButton->setPopupMode(QToolButton::InstantPopup); chatSettingsButton->setPopupMode(QToolButton::InstantPopup);
......
...@@ -79,7 +79,7 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/) ...@@ -79,7 +79,7 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/)
TabSupervisor::TabSupervisor(AbstractClient *_client, QWidget *parent) TabSupervisor::TabSupervisor(AbstractClient *_client, QWidget *parent)
: QTabWidget(parent), userInfo(0), client(_client), tabServer(0), tabUserLists(0), tabDeckStorage(0), tabReplays(0), tabAdmin(0) : QTabWidget(parent), userInfo(0), client(_client), tabServer(0), tabUserLists(0), tabDeckStorage(0), tabReplays(0), tabAdmin(0)
{ {
tabChangedIcon = new QIcon(":/resources/icon_tab_changed.svg"); tabChangedIcon = new QIcon("theme:icon_tab_changed.svg");
setElideMode(Qt::ElideRight); setElideMode(Qt::ElideRight);
setMovable(true); setMovable(true);
setIconSize(QSize(15, 15)); setIconSize(QSize(15, 15));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "tablezone.h" #include "tablezone.h"
#include "player.h" #include "player.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
#include "arrowitem.h" #include "arrowitem.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "carddatabase.h" #include "carddatabase.h"
...@@ -16,20 +17,18 @@ ...@@ -16,20 +17,18 @@
#include "pb/command_move_card.pb.h" #include "pb/command_move_card.pb.h"
#include "pb/command_set_card_attr.pb.h" #include "pb/command_set_card_attr.pb.h"
const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100); const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100);
const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80); const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80);
const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150); const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150);
const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0); const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0);
TableZone::TableZone(Player *_p, QGraphicsItem *parent) TableZone::TableZone(Player *_p, QGraphicsItem *parent)
: SelectZone(_p, "table", true, false, true, parent), active(false) : SelectZone(_p, "table", true, false, true, parent), active(false)
{ {
connect(settingsCache, SIGNAL(tableBgPathChanged()), this, SLOT(updateBgPixmap())); connect(themeManager, SIGNAL(themeChanged()), this, SLOT(updateBg()));
connect(settingsCache, SIGNAL(invertVerticalCoordinateChanged()), this, SLOT(reorganizeCards())); connect(settingsCache, SIGNAL(invertVerticalCoordinateChanged()), this, SLOT(reorganizeCards()));
updateBgPixmap(); updateBg();
height = 2 * BOX_LINE_WIDTH + 3 * (CARD_HEIGHT + 20) + 2 * PADDING_Y; height = 2 * BOX_LINE_WIDTH + 3 * (CARD_HEIGHT + 20) + 2 * PADDING_Y;
width = MIN_WIDTH + 2 * MARGIN_X + 2 * BOX_LINE_WIDTH; width = MIN_WIDTH + 2 * MARGIN_X + 2 * BOX_LINE_WIDTH;
...@@ -44,11 +43,8 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent) ...@@ -44,11 +43,8 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
} }
void TableZone::updateBgPixmap() void TableZone::updateBg()
{ {
QString bgPath = settingsCache->getTableBgPath();
if (!bgPath.isEmpty())
backgroundPixelMap.load(bgPath);
update(); update();
} }
...@@ -67,11 +63,7 @@ bool TableZone::isInverted() const ...@@ -67,11 +63,7 @@ bool TableZone::isInverted() const
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
// if no custom background is provided then use the default color painter->fillRect(boundingRect(), themeManager->getTableBgBrush());
if (backgroundPixelMap.isNull())
painter->fillRect(boundingRect(), BACKGROUND_COLOR);
else
painter->fillRect(boundingRect(), QBrush(backgroundPixelMap));
if (active) { if (active) {
paintZoneOutline(painter); paintZoneOutline(painter);
......
...@@ -27,7 +27,7 @@ private: ...@@ -27,7 +27,7 @@ private:
static const int MIN_WIDTH = 15 * CARD_WIDTH / 2; static const int MIN_WIDTH = 15 * CARD_WIDTH / 2;
/* /*
Default background color, inactive mask and boarder gradient Default inactive mask and border gradient
*/ */
static const QColor BACKGROUND_COLOR; static const QColor BACKGROUND_COLOR;
static const QColor FADE_MASK; static const QColor FADE_MASK;
...@@ -42,11 +42,6 @@ private: ...@@ -42,11 +42,6 @@ private:
int height; int height;
int currentMinimumWidth; int currentMinimumWidth;
/*
Holds any custom background image for the TableZone
*/
QPixmap backgroundPixelMap;
/* /*
If this TableZone is currently active If this TableZone is currently active
*/ */
...@@ -58,7 +53,7 @@ private slots: ...@@ -58,7 +53,7 @@ private slots:
/** /**
Loads in any found custom background and updates Loads in any found custom background and updates
*/ */
void updateBgPixmap(); void updateBg();
public slots: public slots:
/** /**
......
#include "thememanager.h"
#include "settingscache.h"
#include <QApplication>
#include <QDebug>
#include <QColor>
#include <QLibraryInfo>
#if QT_VERSION < 0x050000
#include <QDesktopServices>
#else
#include <QStandardPaths>
#endif
#define DEFAULT_THEME_NAME "Default"
#define STYLE_CSS_NAME "style.css"
#define HANDZONE_BG_NAME "handzone"
#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)
{
ensureThemeDirectoryExists();
connect(settingsCache, SIGNAL(themeChanged()), this, SLOT(themeChangedSlot()));
themeChangedSlot();
}
void ThemeManager::ensureThemeDirectoryExists()
{
if(settingsCache->getThemeName().isEmpty() ||
!getAvailableThemes().contains(settingsCache->getThemeName()))
{
qDebug() << "Theme name not set, setting default value";
settingsCache->setThemeName(DEFAULT_THEME_NAME);
}
}
QStringMap & ThemeManager::getAvailableThemes()
{
QDir dir;
availableThemes.clear();
// load themes from user profile dir
dir =
#if QT_VERSION < 0x050000
QDesktopServices::storageLocation(QDesktopServices::DataLocation) +
#else
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() +
#endif
"/themes";
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
{
if(!availableThemes.contains(themeName))
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
}
// load themes from cockatrice system dir
#ifdef Q_OS_MAC
dir = qApp->applicationDirPath() + "/../Resources/themes";
#elif defined(Q_OS_WIN)
dir = qApp->applicationDirPath() + "/themes";
#else // linux
dir = qApp->applicationDirPath() + "/../share/cockatrice/themes";
#endif
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
{
if(!availableThemes.contains(themeName))
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
}
return availableThemes;
}
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;
}
}
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();
qDebug() << "Theme changed:" << themeName;
QDir dir = getAvailableThemes().value(themeName);
// css
if(dir.exists(STYLE_CSS_NAME))
qApp->setStyleSheet("file:///" + dir.absoluteFilePath(STYLE_CSS_NAME));
else
qApp->setStyleSheet("");
// card background
cardBackPixmap = loadPixmap(dir, CARD_BACK_NAME);
// zones bg
dir.cd("zones");
handBgBrush = loadBrush(dir, HANDZONE_BG_NAME, QColor(80, 100, 50));
tableBgBrush = loadBrush(dir, TABLEZONE_BG_NAME, QColor(70, 50, 100));
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();
}
\ No newline at end of file
#ifndef THEMEMANAGER_H
#define THEMEMANAGER_H
#include <QObject>
#include <QBrush>
#include <QPixmap>
#include <QMap>
#include <QDir>
#include <QString>
typedef QMap<QString, QString> QStringMap;
class QApplication;
class ThemeManager : public QObject {
Q_OBJECT
public:
ThemeManager(QObject *parent = 0);
private:
QBrush handBgBrush, stackBgBrush, tableBgBrush, playerBgBrush;
QPixmap cardBackPixmap;
QStringMap availableThemes;
protected:
void ensureThemeDirectoryExists();
QBrush loadBrush(QDir dir, QString fileName, QColor fallbackColor);
QPixmap loadPixmap(QDir dir, QString fileName);
public:
QBrush &getHandBgBrush() { return handBgBrush; }
QBrush &getStackBgBrush() { return stackBgBrush; }
QBrush &getTableBgBrush() { return tableBgBrush; }
QBrush &getPlayerBgBrush() { return playerBgBrush; }
QPixmap &getCardBackPixmap() { return cardBackPixmap; }
QStringMap &getAvailableThemes();
protected slots:
void themeChangedSlot();
signals:
void themeChanged();
};
extern ThemeManager * themeManager;
#endif
...@@ -454,7 +454,7 @@ void MainWindow::createTrayIcon() { ...@@ -454,7 +454,7 @@ void MainWindow::createTrayIcon() {
trayIcon = new QSystemTrayIcon(this); trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu); trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/resources/appicon.svg")); trayIcon->setIcon(QIcon("theme:appicon.svg"));
trayIcon->show(); trayIcon->show();
connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this, connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,
......
...@@ -24,28 +24,28 @@ WndSets::WndSets(QWidget *parent) ...@@ -24,28 +24,28 @@ WndSets::WndSets(QWidget *parent)
setsEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setsEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
aTop = new QAction(QString(), this); aTop = new QAction(QString(), this);
aTop->setIcon(QIcon(":/resources/arrow_top_green.svg")); aTop->setIcon(QIcon("theme:arrow_top_green.svg"));
aTop->setToolTip(tr("Move selected set to top")); aTop->setToolTip(tr("Move selected set to top"));
aTop->setEnabled(false); aTop->setEnabled(false);
connect(aTop, SIGNAL(triggered()), this, SLOT(actTop())); connect(aTop, SIGNAL(triggered()), this, SLOT(actTop()));
setsEditToolBar->addAction(aTop); setsEditToolBar->addAction(aTop);
aUp = new QAction(QString(), this); aUp = new QAction(QString(), this);
aUp->setIcon(QIcon(":/resources/arrow_up_green.svg")); aUp->setIcon(QIcon("theme:arrow_up_green.svg"));
aUp->setToolTip(tr("Move selected set up")); aUp->setToolTip(tr("Move selected set up"));
aUp->setEnabled(false); aUp->setEnabled(false);
connect(aUp, SIGNAL(triggered()), this, SLOT(actUp())); connect(aUp, SIGNAL(triggered()), this, SLOT(actUp()));
setsEditToolBar->addAction(aUp); setsEditToolBar->addAction(aUp);
aDown = new QAction(QString(), this); aDown = new QAction(QString(), this);
aDown->setIcon(QIcon(":/resources/arrow_down_green.svg")); aDown->setIcon(QIcon("theme:arrow_down_green.svg"));
aDown->setToolTip(tr("Move selected set down")); aDown->setToolTip(tr("Move selected set down"));
aDown->setEnabled(false); aDown->setEnabled(false);
connect(aDown, SIGNAL(triggered()), this, SLOT(actDown())); connect(aDown, SIGNAL(triggered()), this, SLOT(actDown()));
setsEditToolBar->addAction(aDown); setsEditToolBar->addAction(aDown);
aBottom = new QAction(QString(), this); aBottom = new QAction(QString(), this);
aBottom->setIcon(QIcon(":/resources/arrow_bottom_green.svg")); aBottom->setIcon(QIcon("theme:arrow_bottom_green.svg"));
aBottom->setToolTip(tr("Move selected set to bottom")); aBottom->setToolTip(tr("Move selected set to bottom"));
aBottom->setEnabled(false); aBottom->setEnabled(false);
connect(aBottom, SIGNAL(triggered()), this, SLOT(actBottom())); connect(aBottom, SIGNAL(triggered()), this, SLOT(actBottom()));
......
...@@ -250,5 +250,5 @@ void ZoneViewWidget::zoneDeleted() ...@@ -250,5 +250,5 @@ void ZoneViewWidget::zoneDeleted()
void ZoneViewWidget::initStyleOption(QStyleOption *option) const { void ZoneViewWidget::initStyleOption(QStyleOption *option) const {
QStyleOptionTitleBar *titleBar = qstyleoption_cast<QStyleOptionTitleBar *>(option); QStyleOptionTitleBar *titleBar = qstyleoption_cast<QStyleOptionTitleBar *>(option);
if (titleBar) if (titleBar)
titleBar->icon = QIcon(":/resources/appicon.svg"); titleBar->icon = QIcon("theme:appicon.svg");
} }
...@@ -13,6 +13,7 @@ SET(oracle_SOURCES ...@@ -13,6 +13,7 @@ SET(oracle_SOURCES
src/oracleimporter.cpp src/oracleimporter.cpp
../cockatrice/src/carddatabase.cpp ../cockatrice/src/carddatabase.cpp
../cockatrice/src/settingscache.cpp ../cockatrice/src/settingscache.cpp
../cockatrice/src/thememanager.cpp
../cockatrice/src/qt-json/json.cpp ../cockatrice/src/qt-json/json.cpp
) )
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#include "main.h" #include "main.h"
#include "oraclewizard.h" #include "oraclewizard.h"
#include "settingscache.h" #include "settingscache.h"
#include "thememanager.h"
QTranslator *translator, *qtTranslator; QTranslator *translator, *qtTranslator;
SettingsCache *settingsCache; SettingsCache *settingsCache;
ThemeManager *themeManager;
const QString translationPrefix = "oracle"; const QString translationPrefix = "oracle";
#ifdef TRANSLATION_PATH #ifdef TRANSLATION_PATH
...@@ -51,6 +53,7 @@ int main(int argc, char *argv[]) ...@@ -51,6 +53,7 @@ int main(int argc, char *argv[])
} }
settingsCache = new SettingsCache; settingsCache = new SettingsCache;
themeManager = new ThemeManager;
qtTranslator = new QTranslator; qtTranslator = new QTranslator;
translator = new QTranslator; translator = new QTranslator;
......
# CMakeLists for themes directory
#
# add themes subfolders
SET(defthemes
Default
Fabric
Leather
Plasma
VelvetMarble
)
if(UNIX)
if(APPLE)
INSTALL(DIRECTORY ${defthemes} DESTINATION cockatrice.app/Contents/Resources/themes/)
else()
# Assume linux
INSTALL(DIRECTORY ${defthemes} DESTINATION share/cockatrice/themes/)
endif()
elseif(WIN32)
INSTALL(DIRECTORY ${defthemes} DESTINATION themes/)
endif()
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