mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
initial experiment with editor layout
This commit is contained in:
parent
95c6058dc3
commit
0b2231639f
6 changed files with 158 additions and 42 deletions
64
cockatrice/src/cardframe.cpp
Normal file
64
cockatrice/src/cardframe.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include "cardframe.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include "carditem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
|
||||
CardFrame::CardFrame(const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QLabel(parent, flags)
|
||||
, info(0)
|
||||
{
|
||||
this->setAlignment(Qt::AlignCenter);
|
||||
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
setFixedWidth(250);
|
||||
|
||||
setCard(db->getCard(cardName));
|
||||
}
|
||||
|
||||
void CardFrame::setCard(CardInfo *card)
|
||||
{
|
||||
if (info)
|
||||
disconnect(info, 0, this, 0);
|
||||
info = card;
|
||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
||||
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||
|
||||
updatePixmap();
|
||||
}
|
||||
|
||||
void CardFrame::setCard(const QString &cardName)
|
||||
{
|
||||
setCard(db->getCard(cardName));
|
||||
}
|
||||
|
||||
void CardFrame::setCard(AbstractCardItem *card)
|
||||
{
|
||||
setCard(card->getInfo());
|
||||
}
|
||||
|
||||
void CardFrame::clear()
|
||||
{
|
||||
setCard(db->getCard());
|
||||
}
|
||||
|
||||
void CardFrame::updatePixmap()
|
||||
{
|
||||
qreal aspectRatio = (qreal) CARD_HEIGHT / (qreal) CARD_WIDTH;
|
||||
qreal pixmapWidth = this->width();
|
||||
|
||||
if (pixmapWidth == 0)
|
||||
return;
|
||||
|
||||
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
||||
if (resizedPixmap)
|
||||
this->setPixmap(*resizedPixmap);
|
||||
else
|
||||
this->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
||||
}
|
||||
|
||||
QString CardFrame::getCardName() const
|
||||
{
|
||||
return info->getName();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue