mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 00:54:53 -07:00
Fix deckeditor jitter problem; fix #1143
This commit is contained in:
parent
853342463a
commit
d6ce1852a1
4 changed files with 50 additions and 47 deletions
|
|
@ -1,25 +1,21 @@
|
|||
#include "cardinfopicture.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QStyle>
|
||||
|
||||
#include "carditem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
|
||||
CardInfoPicture::CardInfoPicture(int maximumWidth, QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, info(0)
|
||||
, noPicture(true)
|
||||
CardInfoPicture::CardInfoPicture(int width, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
info(0),
|
||||
pixmapDirty(true)
|
||||
{
|
||||
setAlignment(Qt::AlignCenter);
|
||||
setMaximumWidth(maximumWidth);
|
||||
}
|
||||
|
||||
void CardInfoPicture::setNoPicture(bool status)
|
||||
{
|
||||
if (noPicture != status) {
|
||||
noPicture = status;
|
||||
emit hasPictureChanged();
|
||||
}
|
||||
setFixedWidth(width);
|
||||
setMinimumHeight(100);
|
||||
setMaximumHeight(width / (qreal) CARD_WIDTH * (qreal) CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void CardInfoPicture::setCard(CardInfo *card)
|
||||
|
|
@ -32,26 +28,37 @@ void CardInfoPicture::setCard(CardInfo *card)
|
|||
updatePixmap();
|
||||
}
|
||||
|
||||
void CardInfoPicture::resizeEvent(QResizeEvent * /* e */)
|
||||
void CardInfoPicture::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
updatePixmap();
|
||||
}
|
||||
|
||||
void CardInfoPicture::updatePixmap()
|
||||
{
|
||||
if (info == 0 || width() == 0 || height() == 0) {
|
||||
setNoPicture(true);
|
||||
return;
|
||||
}
|
||||
|
||||
QPixmap resizedPixmap;
|
||||
info->getPixmap(size(), resizedPixmap);
|
||||
|
||||
if (resizedPixmap.isNull()) {
|
||||
setNoPicture(true);
|
||||
db->getCard()->getPixmap(size(), resizedPixmap);
|
||||
} else {
|
||||
setNoPicture(false);
|
||||
}
|
||||
this->setPixmap(resizedPixmap);
|
||||
pixmapDirty = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void CardInfoPicture::loadPixmap()
|
||||
{
|
||||
if(info)
|
||||
info->getPixmap(size(), resizedPixmap);
|
||||
else
|
||||
resizedPixmap = QPixmap();
|
||||
|
||||
|
||||
if (resizedPixmap.isNull())
|
||||
db->getCard()->getPixmap(size(), resizedPixmap);
|
||||
}
|
||||
|
||||
void CardInfoPicture::paintEvent(QPaintEvent *)
|
||||
{
|
||||
if (width() == 0 || height() == 0)
|
||||
return;
|
||||
|
||||
if(pixmapDirty)
|
||||
loadPixmap();
|
||||
|
||||
QPainter painter(this);
|
||||
style()->drawItemPixmap(&painter, rect(), Qt::AlignHCenter, resizedPixmap);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue