Fix deckeditor jitter problem; fix #1143
This commit is contained in:
parent
853342463a
commit
d6ce1852a1
4 changed files with 50 additions and 47 deletions
|
@ -15,11 +15,11 @@ CardFrame::CardFrame(int width, int height,
|
|||
, info(0)
|
||||
, cardTextOnly(false)
|
||||
{
|
||||
setMaximumWidth(width);
|
||||
setMinimumWidth(width);
|
||||
setFixedWidth(width);
|
||||
setMinimumHeight(height);
|
||||
|
||||
pic = new CardInfoPicture(width);
|
||||
setContentsMargins(3, 3, 3, 3);
|
||||
pic = new CardInfoPicture(width - 6);
|
||||
text = new CardInfoText();
|
||||
|
||||
tab1 = new QWidget(this);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
#ifndef CARDINFOPICTURE_H
|
||||
#define CARDINFOPICTURE_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
class AbstractCardItem;
|
||||
class CardInfo;
|
||||
|
||||
class CardInfoPicture : public QLabel {
|
||||
class CardInfoPicture : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void hasPictureChanged();
|
||||
|
||||
private:
|
||||
CardInfo *info;
|
||||
bool noPicture;
|
||||
QPixmap resizedPixmap;
|
||||
bool pixmapDirty;
|
||||
|
||||
public:
|
||||
CardInfoPicture(int maximumWidth, QWidget *parent = 0);
|
||||
bool hasPicture() const { return !noPicture; }
|
||||
private:
|
||||
void setNoPicture(bool status);
|
||||
CardInfoPicture(int width, QWidget *parent = 0);
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
void paintEvent(QPaintEvent *);
|
||||
void loadPixmap();
|
||||
public slots:
|
||||
void setCard(CardInfo *card);
|
||||
void updatePixmap();
|
||||
|
|
|
@ -108,7 +108,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
|||
leftFrame->addLayout(searchLayout);
|
||||
leftFrame->addWidget(databaseView);
|
||||
|
||||
cardInfo = new CardFrame(250, 356);
|
||||
cardInfo = new CardFrame(250, 372);
|
||||
|
||||
filterModel = new FilterTreeModel();
|
||||
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
||||
|
@ -143,7 +143,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
|||
filterBox->setLayout(filterLayout);
|
||||
|
||||
QVBoxLayout *middleFrame = new QVBoxLayout;
|
||||
middleFrame->addWidget(cardInfo, 0, Qt::AlignTop);
|
||||
middleFrame->addWidget(cardInfo, 1, Qt::AlignTop);
|
||||
middleFrame->addWidget(filterBox, 0);
|
||||
|
||||
deckModel = new DeckListModel(this);
|
||||
|
|
Loading…
Reference in a new issue