parent
acb40bc738
commit
8ad448a23c
4 changed files with 24 additions and 25 deletions
|
@ -95,7 +95,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
|
||||||
if(facedown)
|
if(facedown)
|
||||||
{
|
{
|
||||||
// never reveal card color, always paint the card back
|
// never reveal card color, always paint the card back
|
||||||
PictureLoader::getPixmap(translatedPixmap, nullptr, translatedSize.toSize());
|
PictureLoader::getCardBackPixmap(translatedPixmap, translatedSize.toSize());
|
||||||
} else {
|
} else {
|
||||||
// don't even spend time trying to load the picture if our size is too small
|
// don't even spend time trying to load the picture if our size is too small
|
||||||
if(translatedSize.width() > 10)
|
if(translatedSize.width() > 10)
|
||||||
|
|
|
@ -41,7 +41,10 @@ void CardInfoPicture::updatePixmap()
|
||||||
|
|
||||||
void CardInfoPicture::loadPixmap()
|
void CardInfoPicture::loadPixmap()
|
||||||
{
|
{
|
||||||
PictureLoader::getPixmap(resizedPixmap, info, size());
|
if(info)
|
||||||
|
PictureLoader::getPixmap(resizedPixmap, info, size());
|
||||||
|
else
|
||||||
|
PictureLoader::getCardBackPixmap(resizedPixmap, size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoPicture::paintEvent(QPaintEvent *)
|
void CardInfoPicture::paintEvent(QPaintEvent *)
|
||||||
|
|
|
@ -422,7 +422,7 @@ PictureLoader::~PictureLoader()
|
||||||
worker->deleteLater();
|
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());
|
QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height());
|
||||||
if(!QPixmapCache::find(backCacheKey, &pixmap))
|
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)
|
void PictureLoader::getPixmap(QPixmap &pixmap, CardInfo *card, QSize size)
|
||||||
{
|
{
|
||||||
if(card)
|
if(card == nullptr)
|
||||||
{
|
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;
|
|
||||||
|
|
||||||
// load the image and create a copy of the correct size
|
// search for an exact size copy of the picure in cache
|
||||||
QPixmap bigPixmap;
|
QString key = card->getPixmapCacheKey();
|
||||||
if(QPixmapCache::find(key, &bigPixmap))
|
QString sizekey = key + QLatin1Char('_') + QString::number(size.width()) + QString::number(size.height());
|
||||||
{
|
if(QPixmapCache::find(sizekey, &pixmap))
|
||||||
pixmap = bigPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
return;
|
||||||
QPixmapCache::insert(sizekey, pixmap);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the card to the load queue
|
// load the image and create a copy of the correct size
|
||||||
getInstance().worker->enqueueImageLoad(card);
|
QPixmap bigPixmap;
|
||||||
} else {
|
if(QPixmapCache::find(key, &bigPixmap))
|
||||||
// requesting the image for a null card is a shortcut to get the card background image
|
{
|
||||||
internalGetCardBackPixmap(pixmap, size);
|
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)
|
void PictureLoader::imageLoaded(CardInfo *card, const QImage &image)
|
||||||
|
|
|
@ -82,11 +82,10 @@ private:
|
||||||
PictureLoaderWorker * worker;
|
PictureLoaderWorker * worker;
|
||||||
public:
|
public:
|
||||||
static void getPixmap(QPixmap &pixmap, CardInfo *card, QSize size);
|
static void getPixmap(QPixmap &pixmap, CardInfo *card, QSize size);
|
||||||
|
static void getCardBackPixmap(QPixmap &pixmap, QSize size);
|
||||||
static void clearPixmapCache(CardInfo *card);
|
static void clearPixmapCache(CardInfo *card);
|
||||||
static void clearPixmapCache();
|
static void clearPixmapCache();
|
||||||
static void cacheCardPixmaps(QList<CardInfo *> cards);
|
static void cacheCardPixmaps(QList<CardInfo *> cards);
|
||||||
protected:
|
|
||||||
static void internalGetCardBackPixmap(QPixmap &pixmap, QSize size);
|
|
||||||
private slots:
|
private slots:
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
|
|
Loading…
Reference in a new issue