dynamic pixmap cache update

This commit is contained in:
Max-Wilhelm Bruker 2009-08-29 20:17:02 +02:00
parent 0f737e6155
commit 4beb990f38
6 changed files with 37 additions and 8 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -6,7 +6,7 @@
#include <QMessageBox>
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:"));

View file

@ -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

View file

@ -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();
}

View file

@ -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; }