diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index c9fcfbd7..43f23356 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -224,6 +224,8 @@ void CardInfo::updatePixmapCache() qDebug(QString("Updating pixmap cache for %1").arg(name).toLatin1()); clearPixmapCache(); loadPixmap(); + + emit pixmapUpdated(); } QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 87278f84..c63bf0e0 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -33,7 +33,7 @@ public: void sortByKey(); }; -class CardInfo : QObject { +class CardInfo : public QObject { Q_OBJECT private: CardDatabase *db; @@ -86,6 +86,8 @@ public: void updatePixmapCache(); private slots: void picDownloadFinished(int id, bool error); +signals: + void pixmapUpdated(); }; class CardDatabase : public QObject { diff --git a/cockatrice/src/cardinfowidget.cpp b/cockatrice/src/cardinfowidget.cpp index 4d82c656..77e7aa9b 100644 --- a/cockatrice/src/cardinfowidget.cpp +++ b/cockatrice/src/cardinfowidget.cpp @@ -6,7 +6,7 @@ #include CardInfoWidget::CardInfoWidget(CardDatabase *_db, QWidget *parent) - : QFrame(parent), db(_db), pixmapHeight(pixmapWidth) + : QFrame(parent), db(_db), pixmapHeight(pixmapWidth), info(0) { cardPicture = new QLabel; cardPicture->setAlignment(Qt::AlignCenter); @@ -71,12 +71,12 @@ void CardInfoWidget::setCard(CardInfo *card) if (!card) return; - QPixmap *resizedPixmap = card->getPixmap(QSize(pixmapWidth, pixmapHeight)); - if (resizedPixmap) - cardPicture->setPixmap(*resizedPixmap); - else - cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapHeight)))); + if (info) + disconnect(info, 0, this, 0); + info = card; + connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap())); + updatePixmap(); nameLabel2->setText(card->getName()); manacostLabel2->setText(card->getManaCost()); cardtypeLabel2->setText(card->getCardType()); @@ -89,6 +89,15 @@ void CardInfoWidget::setCard(const QString &cardName) setCard(db->getCard(cardName)); } +void CardInfoWidget::updatePixmap() +{ + QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapHeight)); + if (resizedPixmap) + cardPicture->setPixmap(*resizedPixmap); + else + cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapHeight)))); +} + void CardInfoWidget::retranslateUi() { nameLabel1->setText(tr("Name:")); diff --git a/cockatrice/src/cardinfowidget.h b/cockatrice/src/cardinfowidget.h index 3015a921..095d11b4 100644 --- a/cockatrice/src/cardinfowidget.h +++ b/cockatrice/src/cardinfowidget.h @@ -20,12 +20,16 @@ private: QLabel *cardtypeLabel1, *cardtypeLabel2; QLabel *powtoughLabel1, *powtoughLabel2; QTextEdit *textLabel; + + CardInfo *info; public: CardInfoWidget(CardDatabase *_db, QWidget *parent = 0); void retranslateUi(); public slots: void setCard(CardInfo *card); void setCard(const QString &cardName); +private slots: + void updatePixmap(); }; #endif diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index bfe44d75..f0156008 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -15,6 +15,8 @@ CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphi setFlag(ItemIsSelectable); setAcceptsHoverEvents(true); setCacheMode(DeviceCoordinateCache); + + connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); } CardItem::~CardItem() @@ -28,6 +30,11 @@ QRectF CardItem::boundingRect() const return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); } +void CardItem::pixmapUpdated() +{ + update(); +} + void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/) { painter->save(); @@ -105,8 +112,10 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void CardItem::setName(const QString &_name) { + disconnect(info, 0, this, 0); name = _name; info = db->getCard(name); + connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); update(); } diff --git a/cockatrice/src/carditem.h b/cockatrice/src/carditem.h index 9dd0a785..244de80d 100644 --- a/cockatrice/src/carditem.h +++ b/cockatrice/src/carditem.h @@ -20,7 +20,8 @@ enum CardItemType { typeOther = QGraphicsItem::UserType + 4 }; -class CardItem : public AbstractGraphicsItem { +class CardItem : public QObject, public AbstractGraphicsItem { + Q_OBJECT private: CardDatabase *db; CardInfo *info; @@ -34,6 +35,8 @@ private: bool doesntUntap; QPoint gridPoint; CardDragItem *dragItem; +private slots: + void pixmapUpdated(); public: enum { Type = typeCard }; int type() const { return Type; }