refactor cardframe as a parent of a text card frame and a picture card frame
cardframe is now a stacked widget that prefers to show the card picture only so that the screen can be more space efficient and the card pixel map can be displayed as a larger size. however if the card pixel map can not be loaded for some reason, the cardframe class will automatically switch to the text version of the card. a menu item was added under the database menu to allow for users to prefer card text only.
This commit is contained in:
parent
5d223b5917
commit
f77054f20d
9 changed files with 231 additions and 34 deletions
|
@ -34,6 +34,8 @@ SET(cockatrice_SOURCES
|
||||||
src/dlg_load_remote_deck.cpp
|
src/dlg_load_remote_deck.cpp
|
||||||
src/cardinfowidget.cpp
|
src/cardinfowidget.cpp
|
||||||
src/cardframe.cpp
|
src/cardframe.cpp
|
||||||
|
src/cardinfopicture.cpp
|
||||||
|
src/cardinfotext.cpp
|
||||||
src/filterbuilder.cpp
|
src/filterbuilder.cpp
|
||||||
src/cardfilter.cpp
|
src/cardfilter.cpp
|
||||||
src/filtertreemodel.cpp
|
src/filtertreemodel.cpp
|
||||||
|
@ -116,6 +118,8 @@ SET(cockatrice_HEADERS
|
||||||
src/dlg_load_remote_deck.h
|
src/dlg_load_remote_deck.h
|
||||||
src/cardinfowidget.h
|
src/cardinfowidget.h
|
||||||
src/cardframe.h
|
src/cardframe.h
|
||||||
|
src/cardinfopicture.h
|
||||||
|
src/cardinfotext.h
|
||||||
src/filterbuilder.h
|
src/filterbuilder.h
|
||||||
src/cardfilter.h
|
src/cardfilter.h
|
||||||
src/filtertreemodel.h
|
src/filtertreemodel.h
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
#include "cardframe.h"
|
#include "cardframe.h"
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "cardinfopicture.h"
|
||||||
|
#include "cardinfotext.h"
|
||||||
|
|
||||||
CardFrame::CardFrame(const QString &cardName, QWidget *parent)
|
CardFrame::CardFrame(int width, int height,
|
||||||
: QLabel(parent)
|
const QString &cardName, QWidget *parent)
|
||||||
|
: QStackedWidget(parent)
|
||||||
, info(0)
|
, info(0)
|
||||||
|
, cardTextOnly(false)
|
||||||
{
|
{
|
||||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||||
setMaximumWidth(250);
|
setMaximumWidth(width);
|
||||||
|
setMinimumWidth(width);
|
||||||
|
setMaximumHeight(height);
|
||||||
|
setMinimumHeight(height);
|
||||||
|
pic = new CardInfoPicture(width);
|
||||||
|
addWidget(pic);
|
||||||
|
text = new CardInfoText();
|
||||||
|
addWidget(text);
|
||||||
|
connect(pic, SIGNAL(hasPictureChanged()), this, SLOT(hasPictureChanged()));
|
||||||
setCard(db->getCard(cardName));
|
setCard(db->getCard(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,10 +30,9 @@ void CardFrame::setCard(CardInfo *card)
|
||||||
if (info)
|
if (info)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, 0, this, 0);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
|
||||||
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||||
|
text->setCard(info);
|
||||||
updatePixmap();
|
pic->setCard(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardFrame::setCard(const QString &cardName)
|
void CardFrame::setCard(const QString &cardName)
|
||||||
|
@ -40,22 +50,10 @@ void CardFrame::clear()
|
||||||
setCard(db->getCard());
|
setCard(db->getCard());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardFrame::updatePixmap()
|
void CardFrame::hasPictureChanged()
|
||||||
{
|
{
|
||||||
qreal aspectRatio = (qreal) CARD_HEIGHT / (qreal) CARD_WIDTH;
|
if (pic->hasPicture() && !cardTextOnly)
|
||||||
qreal pixmapWidth = this->width();
|
setCurrentWidget(pic);
|
||||||
|
|
||||||
if (pixmapWidth == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
|
||||||
if (resizedPixmap)
|
|
||||||
this->setPixmap(*resizedPixmap);
|
|
||||||
else
|
else
|
||||||
this->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
setCurrentWidget(text);
|
||||||
}
|
|
||||||
|
|
||||||
QString CardFrame::getCardName() const
|
|
||||||
{
|
|
||||||
return info->getName();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,36 @@
|
||||||
#ifndef CARDFRAME_H
|
#ifndef CARDFRAME_H
|
||||||
#define CARDFRAME_H
|
#define CARDFRAME_H
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QStackedWidget>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
class AbstractCardItem;
|
class AbstractCardItem;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
class QResizeEvent;
|
class CardInfoPicture;
|
||||||
|
class CardInfoText;
|
||||||
|
|
||||||
class CardFrame : public QLabel {
|
class CardFrame : public QStackedWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
|
CardInfoPicture *pic;
|
||||||
|
CardInfoText *text;
|
||||||
|
bool cardTextOnly;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardFrame(const QString &cardName = QString(), QWidget *parent = 0);
|
CardFrame(int width, int height, const QString &cardName = QString(),
|
||||||
QString getCardName() const;
|
QWidget *parent = 0);
|
||||||
|
void setCardTextOnly(bool status) { cardTextOnly = status; hasPictureChanged(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCard(CardInfo *card);
|
void setCard(CardInfo *card);
|
||||||
void setCard(const QString &cardName);
|
void setCard(const QString &cardName);
|
||||||
void setCard(AbstractCardItem *card);
|
void setCard(AbstractCardItem *card);
|
||||||
|
void clear();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void clear();
|
void hasPictureChanged();
|
||||||
void updatePixmap();
|
void toggleCardTextOnly() { setCardTextOnly(!cardTextOnly); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
53
cockatrice/src/cardinfopicture.cpp
Normal file
53
cockatrice/src/cardinfopicture.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#include "cardinfopicture.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include "carditem.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
CardInfoPicture::CardInfoPicture(int maximumWidth, QWidget *parent)
|
||||||
|
: QLabel(parent)
|
||||||
|
, info(0)
|
||||||
|
, noPicture(true)
|
||||||
|
{
|
||||||
|
setMaximumWidth(maximumWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfoPicture::setNoPicture(bool status)
|
||||||
|
{
|
||||||
|
if (noPicture != status) {
|
||||||
|
noPicture = status;
|
||||||
|
emit hasPictureChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfoPicture::setCard(CardInfo *card)
|
||||||
|
{
|
||||||
|
if (info)
|
||||||
|
disconnect(info, 0, this, 0);
|
||||||
|
info = card;
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
||||||
|
|
||||||
|
updatePixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfoPicture::updatePixmap()
|
||||||
|
{
|
||||||
|
qreal aspectRatio = (qreal) CARD_HEIGHT / (qreal) CARD_WIDTH;
|
||||||
|
qreal pixmapWidth = this->width();
|
||||||
|
|
||||||
|
if (pixmapWidth == 0) {
|
||||||
|
setNoPicture(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
||||||
|
if (resizedPixmap) {
|
||||||
|
setNoPicture(false);
|
||||||
|
this->setPixmap(*resizedPixmap);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setNoPicture(true);
|
||||||
|
this->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
||||||
|
}
|
||||||
|
}
|
34
cockatrice/src/cardinfopicture.h
Normal file
34
cockatrice/src/cardinfopicture.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef CARDINFOPICTURE_H
|
||||||
|
#define CARDINFOPICTURE_H
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
class AbstractCardItem;
|
||||||
|
class CardInfo;
|
||||||
|
|
||||||
|
class CardInfoPicture : public QLabel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hasPictureChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CardInfo *info;
|
||||||
|
bool noPicture;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CardInfoPicture(int maximumWidth, QWidget *parent = 0);
|
||||||
|
bool hasPicture() const { return !noPicture; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setNoPicture(bool status);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setCard(CardInfo *card);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updatePixmap();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
67
cockatrice/src/cardinfotext.cpp
Normal file
67
cockatrice/src/cardinfotext.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include "cardinfotext.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include "carditem.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
CardInfoText::CardInfoText(QWidget *parent)
|
||||||
|
: QFrame(parent)
|
||||||
|
, info(0)
|
||||||
|
{
|
||||||
|
nameLabel1 = new QLabel;
|
||||||
|
nameLabel2 = new QLabel;
|
||||||
|
nameLabel2->setWordWrap(true);
|
||||||
|
manacostLabel1 = new QLabel;
|
||||||
|
manacostLabel2 = new QLabel;
|
||||||
|
manacostLabel2->setWordWrap(true);
|
||||||
|
cardtypeLabel1 = new QLabel;
|
||||||
|
cardtypeLabel2 = new QLabel;
|
||||||
|
cardtypeLabel2->setWordWrap(true);
|
||||||
|
powtoughLabel1 = new QLabel;
|
||||||
|
powtoughLabel2 = new QLabel;
|
||||||
|
loyaltyLabel1 = new QLabel;
|
||||||
|
loyaltyLabel2 = new QLabel;
|
||||||
|
|
||||||
|
textLabel = new QTextEdit();
|
||||||
|
textLabel->setReadOnly(true);
|
||||||
|
|
||||||
|
QGridLayout *grid = new QGridLayout(this);
|
||||||
|
int row = 0;
|
||||||
|
grid->addWidget(nameLabel1, row, 0);
|
||||||
|
grid->addWidget(nameLabel2, row++, 1);
|
||||||
|
grid->addWidget(manacostLabel1, row, 0);
|
||||||
|
grid->addWidget(manacostLabel2, row++, 1);
|
||||||
|
grid->addWidget(cardtypeLabel1, row, 0);
|
||||||
|
grid->addWidget(cardtypeLabel2, row++, 1);
|
||||||
|
grid->addWidget(powtoughLabel1, row, 0);
|
||||||
|
grid->addWidget(powtoughLabel2, row++, 1);
|
||||||
|
grid->addWidget(loyaltyLabel1, row, 0);
|
||||||
|
grid->addWidget(loyaltyLabel2, row++, 1);
|
||||||
|
grid->addWidget(textLabel, row, 0, -1, 2);
|
||||||
|
grid->setRowStretch(row, 1);
|
||||||
|
grid->setColumnStretch(1, 1);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfoText::setCard(CardInfo *card)
|
||||||
|
{
|
||||||
|
nameLabel2->setText(card->getName());
|
||||||
|
manacostLabel2->setText(card->getManaCost());
|
||||||
|
cardtypeLabel2->setText(card->getCardType());
|
||||||
|
powtoughLabel2->setText(card->getPowTough());
|
||||||
|
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
||||||
|
textLabel->setText(card->getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfoText::retranslateUi()
|
||||||
|
{
|
||||||
|
nameLabel1->setText(tr("Name:"));
|
||||||
|
manacostLabel1->setText(tr("Mana cost:"));
|
||||||
|
cardtypeLabel1->setText(tr("Card type:"));
|
||||||
|
powtoughLabel1->setText(tr("P / T:"));
|
||||||
|
loyaltyLabel1->setText(tr("Loyalty:"));
|
||||||
|
}
|
31
cockatrice/src/cardinfotext.h
Normal file
31
cockatrice/src/cardinfotext.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef CARDINFOTEXT_H
|
||||||
|
#define CARDINFOTEXT_H
|
||||||
|
|
||||||
|
#include <QFrame>
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QTextEdit;
|
||||||
|
class CardInfo;
|
||||||
|
|
||||||
|
class CardInfoText : public QFrame {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLabel *nameLabel1, *nameLabel2;
|
||||||
|
QLabel *manacostLabel1, *manacostLabel2;
|
||||||
|
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
||||||
|
QLabel *powtoughLabel1, *powtoughLabel2;
|
||||||
|
QLabel *loyaltyLabel1, *loyaltyLabel2;
|
||||||
|
QTextEdit *textLabel;
|
||||||
|
|
||||||
|
CardInfo *info;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CardInfoText(QWidget *parent = 0);
|
||||||
|
void retranslateUi();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setCard(CardInfo *card);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -87,7 +87,11 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
leftFrame->addLayout(searchLayout);
|
leftFrame->addLayout(searchLayout);
|
||||||
leftFrame->addWidget(databaseView);
|
leftFrame->addWidget(databaseView);
|
||||||
|
|
||||||
cardInfo = new CardFrame();
|
cardInfo = new CardFrame(250, 356);
|
||||||
|
aCardTextOnly = new QAction(QString(), this);
|
||||||
|
aCardTextOnly->setCheckable(true);
|
||||||
|
connect(aCardTextOnly, SIGNAL(triggered()), cardInfo, SLOT(toggleCardTextOnly()));
|
||||||
|
|
||||||
filterModel = new FilterTreeModel();
|
filterModel = new FilterTreeModel();
|
||||||
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
||||||
filterView = new QTreeView;
|
filterView = new QTreeView;
|
||||||
|
@ -221,6 +225,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
dbMenu->addAction(aEditTokens);
|
dbMenu->addAction(aEditTokens);
|
||||||
dbMenu->addSeparator();
|
dbMenu->addSeparator();
|
||||||
dbMenu->addAction(aClearSearch);
|
dbMenu->addAction(aClearSearch);
|
||||||
|
dbMenu->addAction(aCardTextOnly);
|
||||||
addTabMenu(dbMenu);
|
addTabMenu(dbMenu);
|
||||||
|
|
||||||
aAddCard = new QAction(QString(), this);
|
aAddCard = new QAction(QString(), this);
|
||||||
|
@ -258,6 +263,7 @@ TabDeckEditor::~TabDeckEditor()
|
||||||
|
|
||||||
void TabDeckEditor::retranslateUi()
|
void TabDeckEditor::retranslateUi()
|
||||||
{
|
{
|
||||||
|
aCardTextOnly->setText(tr("&Show card text only"));
|
||||||
aClearSearch->setText(tr("&Clear search"));
|
aClearSearch->setText(tr("&Clear search"));
|
||||||
searchLabel->setText(tr("&Search for:"));
|
searchLabel->setText(tr("&Search for:"));
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ private:
|
||||||
|
|
||||||
QMenu *deckMenu, *dbMenu;
|
QMenu *deckMenu, *dbMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose;
|
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose;
|
||||||
QAction *aEditSets, *aEditTokens, *aClearSearch;
|
QAction *aEditSets, *aEditTokens, *aClearSearch, *aCardTextOnly;
|
||||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
|
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
|
||||||
|
|
||||||
bool modified;
|
bool modified;
|
||||||
|
|
Loading…
Reference in a new issue