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)
|
, info(0)
|
||||||
, cardTextOnly(false)
|
, cardTextOnly(false)
|
||||||
{
|
{
|
||||||
setMaximumWidth(width);
|
setFixedWidth(width);
|
||||||
setMinimumWidth(width);
|
|
||||||
setMinimumHeight(height);
|
setMinimumHeight(height);
|
||||||
|
|
||||||
pic = new CardInfoPicture(width);
|
setContentsMargins(3, 3, 3, 3);
|
||||||
|
pic = new CardInfoPicture(width - 6);
|
||||||
text = new CardInfoText();
|
text = new CardInfoText();
|
||||||
|
|
||||||
tab1 = new QWidget(this);
|
tab1 = new QWidget(this);
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
#include "cardinfopicture.h"
|
#include "cardinfopicture.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QWidget>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
CardInfoPicture::CardInfoPicture(int maximumWidth, QWidget *parent)
|
CardInfoPicture::CardInfoPicture(int width, QWidget *parent)
|
||||||
: QLabel(parent)
|
: QWidget(parent),
|
||||||
, info(0)
|
info(0),
|
||||||
, noPicture(true)
|
pixmapDirty(true)
|
||||||
{
|
{
|
||||||
setAlignment(Qt::AlignCenter);
|
setFixedWidth(width);
|
||||||
setMaximumWidth(maximumWidth);
|
setMinimumHeight(100);
|
||||||
}
|
setMaximumHeight(width / (qreal) CARD_WIDTH * (qreal) CARD_HEIGHT);
|
||||||
|
|
||||||
void CardInfoPicture::setNoPicture(bool status)
|
|
||||||
{
|
|
||||||
if (noPicture != status) {
|
|
||||||
noPicture = status;
|
|
||||||
emit hasPictureChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoPicture::setCard(CardInfo *card)
|
void CardInfoPicture::setCard(CardInfo *card)
|
||||||
|
@ -32,26 +28,37 @@ void CardInfoPicture::setCard(CardInfo *card)
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoPicture::resizeEvent(QResizeEvent * /* e */)
|
void CardInfoPicture::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoPicture::updatePixmap()
|
void CardInfoPicture::updatePixmap()
|
||||||
{
|
{
|
||||||
if (info == 0 || width() == 0 || height() == 0) {
|
pixmapDirty = true;
|
||||||
setNoPicture(true);
|
update();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
void CardInfoPicture::loadPixmap()
|
||||||
QPixmap resizedPixmap;
|
{
|
||||||
info->getPixmap(size(), resizedPixmap);
|
if(info)
|
||||||
|
info->getPixmap(size(), resizedPixmap);
|
||||||
if (resizedPixmap.isNull()) {
|
else
|
||||||
setNoPicture(true);
|
resizedPixmap = QPixmap();
|
||||||
db->getCard()->getPixmap(size(), resizedPixmap);
|
|
||||||
} else {
|
|
||||||
setNoPicture(false);
|
if (resizedPixmap.isNull())
|
||||||
}
|
db->getCard()->getPixmap(size(), resizedPixmap);
|
||||||
this->setPixmap(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
|
#ifndef CARDINFOPICTURE_H
|
||||||
#define CARDINFOPICTURE_H
|
#define CARDINFOPICTURE_H
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QWidget>
|
||||||
|
|
||||||
class AbstractCardItem;
|
class AbstractCardItem;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
||||||
class CardInfoPicture : public QLabel {
|
class CardInfoPicture : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
signals:
|
|
||||||
void hasPictureChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
bool noPicture;
|
QPixmap resizedPixmap;
|
||||||
|
bool pixmapDirty;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardInfoPicture(int maximumWidth, QWidget *parent = 0);
|
CardInfoPicture(int width, QWidget *parent = 0);
|
||||||
bool hasPicture() const { return !noPicture; }
|
|
||||||
private:
|
|
||||||
void setNoPicture(bool status);
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
void paintEvent(QPaintEvent *);
|
||||||
|
void loadPixmap();
|
||||||
public slots:
|
public slots:
|
||||||
void setCard(CardInfo *card);
|
void setCard(CardInfo *card);
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
|
|
|
@ -108,7 +108,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
leftFrame->addLayout(searchLayout);
|
leftFrame->addLayout(searchLayout);
|
||||||
leftFrame->addWidget(databaseView);
|
leftFrame->addWidget(databaseView);
|
||||||
|
|
||||||
cardInfo = new CardFrame(250, 356);
|
cardInfo = new CardFrame(250, 372);
|
||||||
|
|
||||||
filterModel = new FilterTreeModel();
|
filterModel = new FilterTreeModel();
|
||||||
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
||||||
|
@ -143,7 +143,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
filterBox->setLayout(filterLayout);
|
filterBox->setLayout(filterLayout);
|
||||||
|
|
||||||
QVBoxLayout *middleFrame = new QVBoxLayout;
|
QVBoxLayout *middleFrame = new QVBoxLayout;
|
||||||
middleFrame->addWidget(cardInfo, 0, Qt::AlignTop);
|
middleFrame->addWidget(cardInfo, 1, Qt::AlignTop);
|
||||||
middleFrame->addWidget(filterBox, 0);
|
middleFrame->addWidget(filterBox, 0);
|
||||||
|
|
||||||
deckModel = new DeckListModel(this);
|
deckModel = new DeckListModel(this);
|
||||||
|
|
Loading…
Reference in a new issue