Multiple background images on all zones (#4144)
This commit is contained in:
parent
e10446f5b8
commit
1a94261490
6 changed files with 84 additions and 5 deletions
|
@ -76,7 +76,13 @@ QRectF HandZone::boundingRect() const
|
|||
|
||||
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
painter->fillRect(boundingRect(), themeManager->getHandBgBrush());
|
||||
QBrush brush = themeManager->getHandBgBrush();
|
||||
|
||||
if (player->getZoneId() > 0) {
|
||||
// If the extra image is not found, load the default one
|
||||
brush = themeManager->getExtraHandBgBrush(QString::number(player->getZoneId()), brush);
|
||||
}
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void HandZone::reorganizeCards()
|
||||
|
|
|
@ -83,7 +83,13 @@ void PlayerArea::updateBg()
|
|||
|
||||
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
painter->fillRect(bRect, themeManager->getPlayerBgBrush());
|
||||
QBrush brush = themeManager->getPlayerBgBrush();
|
||||
|
||||
if (playerZoneId > 0) {
|
||||
// If the extra image is not found, load the default one
|
||||
brush = themeManager->getExtraPlayerBgBrush(QString::number(playerZoneId), brush);
|
||||
}
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void PlayerArea::setSize(qreal width, qreal height)
|
||||
|
@ -92,6 +98,11 @@ void PlayerArea::setSize(qreal width, qreal height)
|
|||
bRect = QRectF(0, 0, width, height);
|
||||
}
|
||||
|
||||
void PlayerArea::setPlayerZoneId(int _playerZoneId)
|
||||
{
|
||||
playerZoneId = _playerZoneId;
|
||||
}
|
||||
|
||||
Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent)
|
||||
: QObject(_parent), game(_parent), shortcutsActive(false), defaultNumberTopCards(1),
|
||||
defaultNumberTopCardsToPlaceBelow(1), lastTokenDestroy(true), lastTokenTableRow(0), id(_id), active(false),
|
||||
|
@ -3266,6 +3277,7 @@ void Player::setConceded(bool _conceded)
|
|||
void Player::setZoneId(int _zoneId)
|
||||
{
|
||||
zoneId = _zoneId;
|
||||
playerArea->setPlayerZoneId(_zoneId);
|
||||
}
|
||||
|
||||
void Player::setMirrored(bool _mirrored)
|
||||
|
|
|
@ -73,6 +73,7 @@ class PlayerArea : public QObject, public QGraphicsItem
|
|||
Q_INTERFACES(QGraphicsItem)
|
||||
private:
|
||||
QRectF bRect;
|
||||
int playerZoneId;
|
||||
private slots:
|
||||
void updateBg();
|
||||
|
||||
|
@ -94,6 +95,12 @@ public:
|
|||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
void setSize(qreal width, qreal height);
|
||||
|
||||
void setPlayerZoneId(int _playerZoneId);
|
||||
int getPlayerZoneId() const
|
||||
{
|
||||
return playerZoneId;
|
||||
}
|
||||
};
|
||||
|
||||
class Player : public QObject, public QGraphicsItem
|
||||
|
|
|
@ -47,7 +47,13 @@ QRectF StackZone::boundingRect() const
|
|||
|
||||
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
painter->fillRect(boundingRect(), themeManager->getStackBgBrush());
|
||||
QBrush brush = themeManager->getStackBgBrush();
|
||||
|
||||
if (player->getZoneId() > 0) {
|
||||
// If the extra image is not found, load the default one
|
||||
brush = themeManager->getExtraStackBgBrush(QString::number(player->getZoneId()), brush);
|
||||
}
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||
|
|
|
@ -118,6 +118,9 @@ void ThemeManager::themeChangedSlot()
|
|||
playerBgBrush = loadBrush(PLAYERZONE_BG_NAME, QColor(200, 200, 200));
|
||||
stackBgBrush = loadBrush(STACKZONE_BG_NAME, QColor(113, 43, 43));
|
||||
tableBgBrushesCache.clear();
|
||||
stackBgBrushesCache.clear();
|
||||
playerBgBrushesCache.clear();
|
||||
handBgBrushesCache.clear();
|
||||
|
||||
QPixmapCache::clear();
|
||||
|
||||
|
@ -137,3 +140,45 @@ QBrush ThemeManager::getExtraTableBgBrush(QString extraNumber, QBrush &fallbackB
|
|||
|
||||
return returnBrush;
|
||||
}
|
||||
|
||||
QBrush ThemeManager::getExtraStackBgBrush(QString extraNumber, QBrush &fallbackBrush)
|
||||
{
|
||||
QBrush returnBrush;
|
||||
|
||||
if (!stackBgBrushesCache.contains(extraNumber.toInt())) {
|
||||
returnBrush = loadExtraBrush(STACKZONE_BG_NAME + extraNumber, fallbackBrush);
|
||||
stackBgBrushesCache.insert(extraNumber.toInt(), returnBrush);
|
||||
} else {
|
||||
returnBrush = stackBgBrushesCache.value(extraNumber.toInt());
|
||||
}
|
||||
|
||||
return returnBrush;
|
||||
}
|
||||
|
||||
QBrush ThemeManager::getExtraPlayerBgBrush(QString extraNumber, QBrush &fallbackBrush)
|
||||
{
|
||||
QBrush returnBrush;
|
||||
|
||||
if (!playerBgBrushesCache.contains(extraNumber.toInt())) {
|
||||
returnBrush = loadExtraBrush(PLAYERZONE_BG_NAME + extraNumber, fallbackBrush);
|
||||
playerBgBrushesCache.insert(extraNumber.toInt(), returnBrush);
|
||||
} else {
|
||||
returnBrush = playerBgBrushesCache.value(extraNumber.toInt());
|
||||
}
|
||||
|
||||
return returnBrush;
|
||||
}
|
||||
|
||||
QBrush ThemeManager::getExtraHandBgBrush(QString extraNumber, QBrush &fallbackBrush)
|
||||
{
|
||||
QBrush returnBrush;
|
||||
|
||||
if (!handBgBrushesCache.contains(extraNumber.toInt())) {
|
||||
returnBrush = loadExtraBrush(HANDZONE_BG_NAME + extraNumber, fallbackBrush);
|
||||
handBgBrushesCache.insert(extraNumber.toInt(), returnBrush);
|
||||
} else {
|
||||
returnBrush = handBgBrushesCache.value(extraNumber.toInt());
|
||||
}
|
||||
|
||||
return returnBrush;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ private:
|
|||
QBrush handBgBrush, stackBgBrush, tableBgBrush, playerBgBrush;
|
||||
QStringMap availableThemes;
|
||||
/*
|
||||
Internal cache for table backgrounds
|
||||
Internal cache for multiple backgrounds
|
||||
*/
|
||||
QBrushMap tableBgBrushesCache;
|
||||
QBrushMap tableBgBrushesCache, stackBgBrushesCache, playerBgBrushesCache, handBgBrushesCache;
|
||||
|
||||
protected:
|
||||
void ensureThemeDirectoryExists();
|
||||
|
@ -51,6 +51,9 @@ public:
|
|||
}
|
||||
QStringMap &getAvailableThemes();
|
||||
QBrush getExtraTableBgBrush(QString extraNumber, QBrush &fallbackBrush);
|
||||
QBrush getExtraStackBgBrush(QString extraNumber, QBrush &fallbackBrush);
|
||||
QBrush getExtraPlayerBgBrush(QString extraNumber, QBrush &fallbackBrush);
|
||||
QBrush getExtraHandBgBrush(QString extraNumber, QBrush &fallbackBrush);
|
||||
protected slots:
|
||||
void themeChangedSlot();
|
||||
signals:
|
||||
|
|
Loading…
Reference in a new issue