Merge pull request #1150 from ctrlaltca/deckeditor_fix2

Fix deckeditor jitter problem; fix #1143
This commit is contained in:
ctrlaltca 2015-06-19 14:57:44 +02:00
commit e581ef77e5
4 changed files with 50 additions and 47 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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();

View file

@ -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);