From 8ad448a23ce012d512427e145d975d51e4ab6b52 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Tue, 25 Apr 2017 06:29:32 +0200 Subject: [PATCH] fix #2600 (#2638) --- cockatrice/src/abstractcarditem.cpp | 2 +- cockatrice/src/cardinfopicture.cpp | 5 +++- cockatrice/src/pictureloader.cpp | 39 +++++++++++++---------------- cockatrice/src/pictureloader.h | 3 +-- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index 8f6b4023..1de82e54 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -95,7 +95,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS if(facedown) { // never reveal card color, always paint the card back - PictureLoader::getPixmap(translatedPixmap, nullptr, translatedSize.toSize()); + PictureLoader::getCardBackPixmap(translatedPixmap, translatedSize.toSize()); } else { // don't even spend time trying to load the picture if our size is too small if(translatedSize.width() > 10) diff --git a/cockatrice/src/cardinfopicture.cpp b/cockatrice/src/cardinfopicture.cpp index 58f66763..e9f2293e 100644 --- a/cockatrice/src/cardinfopicture.cpp +++ b/cockatrice/src/cardinfopicture.cpp @@ -41,7 +41,10 @@ void CardInfoPicture::updatePixmap() void CardInfoPicture::loadPixmap() { - PictureLoader::getPixmap(resizedPixmap, info, size()); + if(info) + PictureLoader::getPixmap(resizedPixmap, info, size()); + else + PictureLoader::getCardBackPixmap(resizedPixmap, size()); } void CardInfoPicture::paintEvent(QPaintEvent *) diff --git a/cockatrice/src/pictureloader.cpp b/cockatrice/src/pictureloader.cpp index 39944b1b..6d0a8957 100644 --- a/cockatrice/src/pictureloader.cpp +++ b/cockatrice/src/pictureloader.cpp @@ -422,7 +422,7 @@ PictureLoader::~PictureLoader() worker->deleteLater(); } -void PictureLoader::internalGetCardBackPixmap(QPixmap &pixmap, QSize size) +void PictureLoader::getCardBackPixmap(QPixmap &pixmap, QSize size) { QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height()); if(!QPixmapCache::find(backCacheKey, &pixmap)) @@ -435,29 +435,26 @@ void PictureLoader::internalGetCardBackPixmap(QPixmap &pixmap, QSize size) void PictureLoader::getPixmap(QPixmap &pixmap, CardInfo *card, QSize size) { - if(card) - { - // search for an exact size copy of the picure in cache - QString key = card->getPixmapCacheKey(); - QString sizekey = key + QLatin1Char('_') + QString::number(size.width()) + QString::number(size.height()); - if(QPixmapCache::find(sizekey, &pixmap)) - return; + if(card == nullptr) + return; - // load the image and create a copy of the correct size - QPixmap bigPixmap; - if(QPixmapCache::find(key, &bigPixmap)) - { - pixmap = bigPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); - QPixmapCache::insert(sizekey, pixmap); - return; - } + // search for an exact size copy of the picure in cache + QString key = card->getPixmapCacheKey(); + QString sizekey = key + QLatin1Char('_') + QString::number(size.width()) + QString::number(size.height()); + if(QPixmapCache::find(sizekey, &pixmap)) + return; - // add the card to the load queue - getInstance().worker->enqueueImageLoad(card); - } else { - // requesting the image for a null card is a shortcut to get the card background image - internalGetCardBackPixmap(pixmap, size); + // load the image and create a copy of the correct size + QPixmap bigPixmap; + if(QPixmapCache::find(key, &bigPixmap)) + { + pixmap = bigPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); + QPixmapCache::insert(sizekey, pixmap); + return; } + + // add the card to the load queue + getInstance().worker->enqueueImageLoad(card); } void PictureLoader::imageLoaded(CardInfo *card, const QImage &image) diff --git a/cockatrice/src/pictureloader.h b/cockatrice/src/pictureloader.h index 899d6a72..9a3faf5f 100644 --- a/cockatrice/src/pictureloader.h +++ b/cockatrice/src/pictureloader.h @@ -82,11 +82,10 @@ private: PictureLoaderWorker * worker; public: static void getPixmap(QPixmap &pixmap, CardInfo *card, QSize size); + static void getCardBackPixmap(QPixmap &pixmap, QSize size); static void clearPixmapCache(CardInfo *card); static void clearPixmapCache(); static void cacheCardPixmaps(QList cards); -protected: - static void internalGetCardBackPixmap(QPixmap &pixmap, QSize size); private slots: void picDownloadChanged(); void picsPathChanged();