Commit d6ce1852 authored by Fabio Bas's avatar Fabio Bas
Browse files

Fix deckeditor jitter problem; fix #1143

parent 85334246
...@@ -15,11 +15,11 @@ CardFrame::CardFrame(int width, int height, ...@@ -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);
......
#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);
setMaximumWidth(maximumWidth);
}
void CardInfoPicture::setNoPicture(bool status)
{ {
if (noPicture != status) { setFixedWidth(width);
noPicture = status; setMinimumHeight(100);
emit hasPictureChanged(); setMaximumHeight(width / (qreal) CARD_WIDTH * (qreal) CARD_HEIGHT);
}
} }
void CardInfoPicture::setCard(CardInfo *card) void CardInfoPicture::setCard(CardInfo *card)
...@@ -32,26 +28,37 @@ 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()
{
if(info)
info->getPixmap(size(), resizedPixmap);
else
resizedPixmap = QPixmap();
QPixmap resizedPixmap;
info->getPixmap(size(), resizedPixmap);
if (resizedPixmap.isNull()) { if (resizedPixmap.isNull())
setNoPicture(true);
db->getCard()->getPixmap(size(), resizedPixmap); db->getCard()->getPixmap(size(), resizedPixmap);
} else { }
setNoPicture(false);
} void CardInfoPicture::paintEvent(QPaintEvent *)
this->setPixmap(resizedPixmap); {
if (width() == 0 || height() == 0)
return;
if(pixmapDirty)
loadPixmap();
QPainter painter(this);
style()->drawItemPixmap(&painter, rect(), Qt::AlignHCenter, resizedPixmap);
} }
#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) ...@@ -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) ...@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment