diff --git a/cockatrice/src/handcounter.h b/cockatrice/src/handcounter.h index 46de6889..111d1c53 100644 --- a/cockatrice/src/handcounter.h +++ b/cockatrice/src/handcounter.h @@ -23,4 +23,3 @@ public: }; #endif - diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index ea422891..96bad503 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -22,36 +22,65 @@ #include #include +PlayerArea::PlayerArea(QGraphicsItem *parentItem) + : QObject(), QGraphicsItem(parentItem) +{ + setCacheMode(DeviceCoordinateCache); + connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap())); + updateBgPixmap(); +} + +void PlayerArea::updateBgPixmap() +{ + QString bgPath = settingsCache->getPlayerBgPath(); + if (bgPath.isEmpty()) + bgPixmapBrush = QBrush(QColor(200, 200, 200)); + else { + qDebug() << "loading" << bgPath; + bgPixmapBrush = QBrush(QPixmap(bgPath)); + } + update(); +} + +void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) +{ + painter->fillRect(bRect, bgPixmapBrush); +} + +void PlayerArea::setSize(qreal width, qreal height) +{ + prepareGeometryChange(); + bRect = QRectF(0, 0, width, height); +} + Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent) : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), handVisible(false), conceded(false), dialogSemaphore(false) { - setCacheMode(DeviceCoordinateCache); - connect(settingsCache, SIGNAL(horizontalHandChanged()), this, SLOT(rearrangeZones())); - connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap())); - updateBgPixmap(); - playerTarget = new PlayerTarget(this); + playerArea = new PlayerArea(this); + + playerTarget = new PlayerTarget(this, playerArea); qreal avatarMargin = (counterAreaWidth + CARD_HEIGHT + 15 - playerTarget->boundingRect().width()) / 2.0; playerTarget->setPos(QPointF(avatarMargin, avatarMargin)); - PileZone *deck = new PileZone(this, "deck", true, false, this); + PileZone *deck = new PileZone(this, "deck", true, false, playerArea); QPointF base = QPointF(counterAreaWidth + (CARD_HEIGHT - CARD_WIDTH + 15) / 2.0, 10 + playerTarget->boundingRect().height() + 5 - (CARD_HEIGHT - CARD_WIDTH) / 2.0); deck->setPos(base); qreal h = deck->boundingRect().width() + 5; - HandCounter *handCounter = new HandCounter(this); + HandCounter *handCounter = new HandCounter(playerArea); handCounter->setPos(base + QPointF(0, h + 10)); qreal h2 = handCounter->boundingRect().height(); - PileZone *grave = new PileZone(this, "grave", false, true, this); + PileZone *grave = new PileZone(this, "grave", false, true, playerArea); grave->setPos(base + QPointF(0, h + h2 + 10)); - PileZone *rfg = new PileZone(this, "rfg", false, true, this); + PileZone *rfg = new PileZone(this, "rfg", false, true, playerArea); rfg->setPos(base + QPointF(0, 2 * h + h2 + 10)); - PileZone *sb = new PileZone(this, "sb", false, false, this); + PileZone *sb = new PileZone(this, "sb", false, false, playerArea); sb->setVisible(false); table = new TableZone(this, this); @@ -377,16 +406,6 @@ void Player::updateZones() table->reorganizeCards(); } -void Player::updateBgPixmap() -{ - QString bgPath = settingsCache->getPlayerBgPath(); - if (!bgPath.isEmpty()) { - qDebug() << "loading" << bgPath; - bgPixmap.load(bgPath); - } - update(); -} - void Player::updateBoundingRect() { prepareGeometryChange(); @@ -396,6 +415,8 @@ void Player::updateBoundingRect() bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + handHeight); } else bRect = QRectF(0, 0, width + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height()); + playerArea->setSize(CARD_HEIGHT + counterAreaWidth + 15, bRect.height()); + emit sizeChanged(); } @@ -1054,13 +1075,8 @@ QRectF Player::boundingRect() const return bRect; } -void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) +void Player::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - int totalWidth = CARD_HEIGHT + counterAreaWidth + 15; - if (bgPixmap.isNull()) - painter->fillRect(QRectF(0, 0, totalWidth, boundingRect().height()), QColor(200, 200, 200)); - else - painter->fillRect(QRectF(0, 0, totalWidth, boundingRect().height()), QBrush(bgPixmap)); } void Player::processPlayerInfo(ServerInfo_Player *info) diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index aeaba8cd..c30fc376 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -46,6 +46,24 @@ class Event_AttachCard; class Event_DrawCards; class Event_RevealCards; +class PlayerArea : public QObject, public QGraphicsItem { + Q_OBJECT +private: + QBrush bgPixmapBrush; + QRectF bRect; +private slots: + void updateBgPixmap(); +public: + enum { Type = typeOther }; + int type() const { return Type; } + + PlayerArea(QGraphicsItem *parent = 0); + QRectF boundingRect() const { return bRect; } + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + void setSize(qreal width, qreal height); +}; + class Player : public QObject, public QGraphicsItem { Q_OBJECT signals: @@ -109,7 +127,6 @@ private slots: void removePlayer(Player *player); void playerListActionTriggered(); - void updateBgPixmap(); void updateBoundingRect(); void rearrangeZones(); private: @@ -142,6 +159,7 @@ private: bool clearCardsToDelete(); QList cardsToDelete; + PlayerArea *playerArea; QMap zones; StackZone *stack; TableZone *table; @@ -150,7 +168,6 @@ private: void setCardAttrHelper(GameEventContext *context, CardItem *card, const QString &aname, const QString &avalue, bool allCards); - QPixmap bgPixmap; QRectF bRect; QMap counters; diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index e4f5aa58..976563d6 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -46,8 +46,8 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /* painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value)); } -PlayerTarget::PlayerTarget(Player *_owner) - : ArrowTarget(_owner, _owner), playerCounter(0) +PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem) + : ArrowTarget(_owner, parentItem), playerCounter(0) { setCacheMode(DeviceCoordinateCache); diff --git a/cockatrice/src/playertarget.h b/cockatrice/src/playertarget.h index 5957b517..f8b6f2c4 100644 --- a/cockatrice/src/playertarget.h +++ b/cockatrice/src/playertarget.h @@ -27,7 +27,7 @@ public: enum { Type = typePlayerTarget }; int type() const { return Type; } - PlayerTarget(Player *parent = 0); + PlayerTarget(Player *_player = 0, QGraphicsItem *parentItem = 0); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);