Drop CardInfo’s own pixmap caches; use QPixmapCache instead. Use QPixmap references instead of pointers. Being stored in QPixmapCache, all card images are now subjected to QPixmapCache’s size limit
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "cardinfopicture.h"
|
|
|
|
#include <QLabel>
|
|
#include "carditem.h"
|
|
#include "carddatabase.h"
|
|
#include "main.h"
|
|
|
|
CardInfoPicture::CardInfoPicture(int maximumWidth, QWidget *parent)
|
|
: QLabel(parent)
|
|
, info(0)
|
|
, noPicture(true)
|
|
{
|
|
setMaximumWidth(maximumWidth);
|
|
}
|
|
|
|
void CardInfoPicture::setNoPicture(bool status)
|
|
{
|
|
if (noPicture != status) {
|
|
noPicture = status;
|
|
emit hasPictureChanged();
|
|
}
|
|
}
|
|
|
|
void CardInfoPicture::setCard(CardInfo *card)
|
|
{
|
|
if (info)
|
|
disconnect(info, 0, this, 0);
|
|
info = card;
|
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
|
|
|
updatePixmap();
|
|
}
|
|
|
|
void CardInfoPicture::updatePixmap()
|
|
{
|
|
qreal aspectRatio = (qreal) CARD_HEIGHT / (qreal) CARD_WIDTH;
|
|
qreal pixmapWidth = this->width();
|
|
|
|
if (pixmapWidth == 0) {
|
|
setNoPicture(true);
|
|
return;
|
|
}
|
|
|
|
QPixmap resizedPixmap;
|
|
info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio), resizedPixmap);
|
|
|
|
if (resizedPixmap.isNull()) {
|
|
setNoPicture(true);
|
|
db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio), resizedPixmap);
|
|
} else {
|
|
setNoPicture(false);
|
|
}
|
|
this->setPixmap(resizedPixmap);
|
|
}
|