Commit 07706262 authored by sylvanbasilisk's avatar sylvanbasilisk
Browse files

Merge branch 'master' into editor-redesign

Conflicts:
	cockatrice/src/carddatabasemodel.cpp
	cockatrice/src/carddatabasemodel.h
	cockatrice/src/decklistmodel.cpp
	cockatrice/src/decklistmodel.h
	cockatrice/src/tab_deck_editor.cpp
	cockatrice/src/tab_deck_editor.h
parents 748aac7e ed5f02bf
...@@ -12,209 +12,209 @@ ...@@ -12,209 +12,209 @@
#include "settingscache.h" #include "settingscache.h"
CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags) CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags) : QFrame(parent, flags)
, pixmapWidth(0) , pixmapWidth(0)
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH) , aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache. , minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
, mode(_mode) , mode(_mode)
, info(0) , info(0)
{ {
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
// Create indexed list of status views for card. // Create indexed list of status views for card.
const QStringList cardInfoStatus = QStringList() << tr("Show card only") << tr("Show text only") << tr("Show full info"); const QStringList cardInfoStatus = QStringList() << tr("Show card only") << tr("Show text only") << tr("Show full info");
// Create droplist for cardinfo view selection, and set right current index. // Create droplist for cardinfo view selection, and set right current index.
dropList = new QComboBox(); dropList = new QComboBox();
dropList->addItems(cardInfoStatus); dropList->addItems(cardInfoStatus);
dropList->setCurrentIndex(minimized); dropList->setCurrentIndex(minimized);
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int))); connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
} }
cardPicture = new QLabel; cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter); cardPicture->setAlignment(Qt::AlignCenter);
nameLabel1 = new QLabel; nameLabel1 = new QLabel;
nameLabel2 = new QLabel; nameLabel2 = new QLabel;
nameLabel2->setWordWrap(true); nameLabel2->setWordWrap(true);
manacostLabel1 = new QLabel; manacostLabel1 = new QLabel;
manacostLabel2 = new QLabel; manacostLabel2 = new QLabel;
manacostLabel2->setWordWrap(true); manacostLabel2->setWordWrap(true);
cardtypeLabel1 = new QLabel; cardtypeLabel1 = new QLabel;
cardtypeLabel2 = new QLabel; cardtypeLabel2 = new QLabel;
cardtypeLabel2->setWordWrap(true); cardtypeLabel2->setWordWrap(true);
powtoughLabel1 = new QLabel; powtoughLabel1 = new QLabel;
powtoughLabel2 = new QLabel; powtoughLabel2 = new QLabel;
loyaltyLabel1 = new QLabel; loyaltyLabel1 = new QLabel;
loyaltyLabel2 = new QLabel; loyaltyLabel2 = new QLabel;
textLabel = new QTextEdit(); textLabel = new QTextEdit();
textLabel->setReadOnly(true); textLabel->setReadOnly(true);
QGridLayout *grid = new QGridLayout(this); QGridLayout *grid = new QGridLayout(this);
int row = 0; int row = 0;
if (mode == ModeGameTab) if (mode == ModeGameTab)
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight); grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
grid->addWidget(cardPicture, row++, 0, 1, 2); grid->addWidget(cardPicture, row++, 0, 1, 2);
grid->addWidget(nameLabel1, row, 0); grid->addWidget(nameLabel1, row, 0);
grid->addWidget(nameLabel2, row++, 1); grid->addWidget(nameLabel2, row++, 1);
grid->addWidget(manacostLabel1, row, 0); grid->addWidget(manacostLabel1, row, 0);
grid->addWidget(manacostLabel2, row++, 1); grid->addWidget(manacostLabel2, row++, 1);
grid->addWidget(cardtypeLabel1, row, 0); grid->addWidget(cardtypeLabel1, row, 0);
grid->addWidget(cardtypeLabel2, row++, 1); grid->addWidget(cardtypeLabel2, row++, 1);
grid->addWidget(powtoughLabel1, row, 0); grid->addWidget(powtoughLabel1, row, 0);
grid->addWidget(powtoughLabel2, row++, 1); grid->addWidget(powtoughLabel2, row++, 1);
grid->addWidget(loyaltyLabel1, row, 0); grid->addWidget(loyaltyLabel1, row, 0);
grid->addWidget(loyaltyLabel2, row++, 1); grid->addWidget(loyaltyLabel2, row++, 1);
grid->addWidget(textLabel, row, 0, -1, 2); grid->addWidget(textLabel, row, 0, -1, 2);
grid->setRowStretch(row, 1); grid->setRowStretch(row, 1);
grid->setColumnStretch(1, 1); grid->setColumnStretch(1, 1);
retranslateUi(); retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised); setFrameStyle(QFrame::Panel | QFrame::Raised);
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
textLabel->setMinimumHeight(100); textLabel->setMinimumHeight(100);
setFixedWidth(sizeHint().width()); setFixedWidth(sizeHint().width());
} else if (mode == ModePopUp) { } else if (mode == ModePopUp) {
QDesktopWidget desktopWidget; QDesktopWidget desktopWidget;
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio; pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
setFixedWidth(pixmapWidth + 150); setFixedWidth(pixmapWidth + 150);
} else } else
setFixedWidth(250); setFixedWidth(250);
setCard(db->getCard(cardName)); setCard(db->getCard(cardName));
setMinimized(settingsCache->getCardInfoMinimized()); setMinimized(settingsCache->getCardInfoMinimized());
} }
void CardInfoWidget::minimizeClicked(int newMinimized) void CardInfoWidget::minimizeClicked(int newMinimized)
{ {
// Set new status, and store it in the settings cache. // Set new status, and store it in the settings cache.
setMinimized(newMinimized); setMinimized(newMinimized);
settingsCache->setCardInfoMinimized(newMinimized); settingsCache->setCardInfoMinimized(newMinimized);
} }
bool CardInfoWidget::shouldShowPowTough() bool CardInfoWidget::shouldShowPowTough()
{ {
// return (!info->getPowTough().isEmpty() && (minimized != 0)); // return (!info->getPowTough().isEmpty() && (minimized != 0));
return (minimized != 0); return (minimized != 0);
} }
bool CardInfoWidget::shouldShowLoyalty() bool CardInfoWidget::shouldShowLoyalty()
{ {
// return ((info->getLoyalty() > 0) && (minimized != 0)); // return ((info->getLoyalty() > 0) && (minimized != 0));
return (minimized != 0); return (minimized != 0);
} }
void CardInfoWidget::setMinimized(int _minimized) void CardInfoWidget::setMinimized(int _minimized)
{ {
minimized = _minimized; minimized = _minimized;
// Toggle oracle fields according to selected view. // Toggle oracle fields according to selected view.
bool showAll = ((minimized == 1) || (minimized == 2)); bool showAll = ((minimized == 1) || (minimized == 2));
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true; bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true; bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
nameLabel1->setVisible(showAll); nameLabel1->setVisible(showAll);
nameLabel2->setVisible(showAll); nameLabel2->setVisible(showAll);
manacostLabel1->setVisible(showAll); manacostLabel1->setVisible(showAll);
manacostLabel2->setVisible(showAll); manacostLabel2->setVisible(showAll);
cardtypeLabel1->setVisible(showAll); cardtypeLabel1->setVisible(showAll);
cardtypeLabel2->setVisible(showAll); cardtypeLabel2->setVisible(showAll);
powtoughLabel1->setVisible(showPowTough); powtoughLabel1->setVisible(showPowTough);
powtoughLabel2->setVisible(showPowTough); powtoughLabel2->setVisible(showPowTough);
loyaltyLabel1->setVisible(showLoyalty); loyaltyLabel1->setVisible(showLoyalty);
loyaltyLabel2->setVisible(showLoyalty); loyaltyLabel2->setVisible(showLoyalty);
textLabel->setVisible(showAll); textLabel->setVisible(showAll);
} }
cardPicture->hide(); cardPicture->hide();
cardHeightOffset = minimumSizeHint().height() + 10; cardHeightOffset = minimumSizeHint().height() + 10;
// Set the picture to be shown only at "card only" (0) and "full info" (2) // Set the picture to be shown only at "card only" (0) and "full info" (2)
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
cardPicture->setVisible((minimized == 0) || (minimized == 2)); cardPicture->setVisible((minimized == 0) || (minimized == 2));
if (minimized == 0) if (minimized == 0)
setMaximumHeight(cardHeightOffset + width() * aspectRatio); setMaximumHeight(cardHeightOffset + width() * aspectRatio);
else else
setMaximumHeight(1000000); setMaximumHeight(1000000);
} else } else
cardPicture->show(); cardPicture->show();
resize(width(), sizeHint().height()); resize(width(), sizeHint().height());
} }
void CardInfoWidget::setCard(CardInfo *card) void CardInfoWidget::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(pixmapUpdated()), this, SLOT(updatePixmap()));
connect(info, SIGNAL(destroyed()), this, SLOT(clear())); connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
updatePixmap(); updatePixmap();
nameLabel2->setText(card->getName()); nameLabel2->setText(card->getName());
manacostLabel2->setText(card->getManaCost()); manacostLabel2->setText(card->getManaCost());
cardtypeLabel2->setText(card->getCardType()); cardtypeLabel2->setText(card->getCardType());
powtoughLabel2->setText(card->getPowTough()); powtoughLabel2->setText(card->getPowTough());
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString()); loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
textLabel->setText(card->getText()); textLabel->setText(card->getText());
powtoughLabel1->setVisible(shouldShowPowTough()); powtoughLabel1->setVisible(shouldShowPowTough());
powtoughLabel2->setVisible(shouldShowPowTough()); powtoughLabel2->setVisible(shouldShowPowTough());
loyaltyLabel1->setVisible(shouldShowLoyalty()); loyaltyLabel1->setVisible(shouldShowLoyalty());
loyaltyLabel2->setVisible(shouldShowLoyalty()); loyaltyLabel2->setVisible(shouldShowLoyalty());
} }
void CardInfoWidget::setCard(const QString &cardName) void CardInfoWidget::setCard(const QString &cardName)
{ {
setCard(db->getCard(cardName)); setCard(db->getCard(cardName));
} }
void CardInfoWidget::setCard(AbstractCardItem *card) void CardInfoWidget::setCard(AbstractCardItem *card)
{ {
setCard(card->getInfo()); setCard(card->getInfo());
} }
void CardInfoWidget::clear() void CardInfoWidget::clear()
{ {
setCard(db->getCard()); setCard(db->getCard());
} }
void CardInfoWidget::updatePixmap() void CardInfoWidget::updatePixmap()
{ {
if (pixmapWidth == 0) if (pixmapWidth == 0)
return; return;
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio)); QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
if (resizedPixmap) if (resizedPixmap)
cardPicture->setPixmap(*resizedPixmap); cardPicture->setPixmap(*resizedPixmap);
else else
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio)))); cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
} }
void CardInfoWidget::retranslateUi() void CardInfoWidget::retranslateUi()
{ {
nameLabel1->setText(tr("Name:")); nameLabel1->setText(tr("Name:"));
manacostLabel1->setText(tr("Mana cost:")); manacostLabel1->setText(tr("Mana cost:"));
cardtypeLabel1->setText(tr("Card type:")); cardtypeLabel1->setText(tr("Card type:"));
powtoughLabel1->setText(tr("P / T:")); powtoughLabel1->setText(tr("P / T:"));
loyaltyLabel1->setText(tr("Loyalty:")); loyaltyLabel1->setText(tr("Loyalty:"));
} }
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/) void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{ {
if (mode == ModePopUp) if (mode == ModePopUp)
return; return;
if ((minimized == 1) && (mode == ModeGameTab)) { if ((minimized == 1) && (mode == ModeGameTab)) {
pixmapWidth = 0; pixmapWidth = 0;
return; return;
} }
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio))); qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
if (newPixmapWidth != pixmapWidth) { if (newPixmapWidth != pixmapWidth) {
pixmapWidth = newPixmapWidth; pixmapWidth = newPixmapWidth;
updatePixmap(); updatePixmap();
} }
} }
QString CardInfoWidget::getCardName() const QString CardInfoWidget::getCardName() const
{ {
return nameLabel2->text(); return nameLabel2->text();
} }
...@@ -14,51 +14,51 @@ class QResizeEvent; ...@@ -14,51 +14,51 @@ class QResizeEvent;
class QMouseEvent; class QMouseEvent;
class CardInfoWidget : public QFrame { class CardInfoWidget : public QFrame {
Q_OBJECT Q_OBJECT
public: public:
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp }; enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
private: private:
int pixmapWidth; int pixmapWidth;
qreal cardHeightOffset; qreal cardHeightOffset;
qreal aspectRatio; qreal aspectRatio;
// XXX: Why isn't this an eunm? // XXX: Why isn't this an eunm?
int minimized; // 0 - card, 1 - oracle only, 2 - full int minimized; // 0 - card, 1 - oracle only, 2 - full
ResizeMode mode; ResizeMode mode;
QComboBox *dropList; QComboBox *dropList;
QLabel *cardPicture; QLabel *cardPicture;
QLabel *nameLabel1, *nameLabel2; QLabel *nameLabel1, *nameLabel2;
QLabel *manacostLabel1, *manacostLabel2; QLabel *manacostLabel1, *manacostLabel2;
QLabel *cardtypeLabel1, *cardtypeLabel2; QLabel *cardtypeLabel1, *cardtypeLabel2;
QLabel *powtoughLabel1, *powtoughLabel2; QLabel *powtoughLabel1, *powtoughLabel2;
QLabel *loyaltyLabel1, *loyaltyLabel2; QLabel *loyaltyLabel1, *loyaltyLabel2;
QTextEdit *textLabel; QTextEdit *textLabel;
bool shouldShowPowTough(); bool shouldShowPowTough();
bool shouldShowLoyalty(); bool shouldShowLoyalty();
CardInfo *info; CardInfo *info;
void setMinimized(int _minimized); void setMinimized(int _minimized);
public: public:
CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0); CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
void retranslateUi(); void retranslateUi();
QString getCardName() const; QString getCardName() const;
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);
private slots: private slots:
void clear(); void clear();
void updatePixmap(); void updatePixmap();
void minimizeClicked(int newMinimized); void minimizeClicked(int newMinimized);
protected: protected:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
}; };
#endif #endif
This diff is collapsed.
...@@ -14,75 +14,75 @@ class QColor; ...@@ -14,75 +14,75 @@ class QColor;
const int MAX_COUNTERS_ON_CARD = 999; const int MAX_COUNTERS_ON_CARD = 999;
class CardItem : public AbstractCardItem { class CardItem : public AbstractCardItem {
Q_OBJECT Q_OBJECT
private: private:
CardZone *zone; CardZone *zone;
bool revealedCard; bool revealedCard;
bool attacking; bool attacking;
QMap<int, int> counters; QMap<int, int> counters;
QString annotation; QString annotation;
QString pt; QString pt;
bool destroyOnZoneChange; bool destroyOnZoneChange;
bool doesntUntap; bool doesntUntap;
QPoint gridPoint; QPoint gridPoint;
CardDragItem *dragItem; CardDragItem *dragItem;
CardItem *attachedTo; CardItem *attachedTo;
QList<CardItem *> attachedCards; QList<CardItem *> attachedCards;
QMenu *cardMenu, *ptMenu, *moveMenu; QMenu *cardMenu, *ptMenu, *moveMenu;
void prepareDelete(); void prepareDelete();
public slots: public slots:
void deleteLater(); void deleteLater();
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } int type() const { return Type; }
CardItem(Player *_owner, const QString &_name = QString(), int _cardid = -1, bool revealedCard = false, QGraphicsItem *parent = 0); CardItem(Player *_owner, const QString &_name = QString(), int _cardid = -1, bool revealedCard = false, QGraphicsItem *parent = 0);
~CardItem(); ~CardItem();
void retranslateUi(); void retranslateUi();
CardZone *getZone() const { return zone; } CardZone *getZone() const { return zone; }
void setZone(CardZone *_zone); void setZone(CardZone *_zone);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPoint getGridPoint() const { return gridPoint; } QPoint getGridPoint() const { return gridPoint; }
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; } void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
QPoint getGridPos() const { return gridPoint; } QPoint getGridPos() const { return gridPoint; }
Player *getOwner() const { return owner; } Player *getOwner() const { return owner; }
void setOwner(Player *_owner) { owner = _owner; } void setOwner(Player *_owner) { owner = _owner; }
bool getRevealedCard() const { return revealedCard; } bool getRevealedCard() const { return revealedCard; }
bool getAttacking() const { return attacking; } bool getAttacking() const { return attacking; }
void setAttacking(bool _attacking); void setAttacking(bool _attacking);
const QMap<int, int> &getCounters() const { return counters; } const QMap<int, int> &getCounters() const { return counters; }
void setCounter(int _id, int _value); void setCounter(int _id, int _value);
QString getAnnotation() const { return annotation; } QString getAnnotation() const { return annotation; }
void setAnnotation(const QString &_annotation); void setAnnotation(const QString &_annotation);
bool getDoesntUntap() const { return doesntUntap; } bool getDoesntUntap() const { return doesntUntap; }
void setDoesntUntap(bool _doesntUntap); void setDoesntUntap(bool _doesntUntap);
QString getPT() const { return pt; } QString getPT() const { return pt; }
void setPT(const QString &_pt); void setPT(const QString &_pt);
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; } bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; } void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
CardItem *getAttachedTo() const { return attachedTo; } CardItem *getAttachedTo() const { return attachedTo; }
void setAttachedTo(CardItem *_attachedTo); void setAttachedTo(CardItem *_attachedTo);
void addAttachedCard(CardItem *card) { attachedCards.append(card); } void addAttachedCard(CardItem *card) { attachedCards.append(card); }
void removeAttachedCard(CardItem *card) { attachedCards.removeAt(attachedCards.indexOf(card)); } void removeAttachedCard(CardItem *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
const QList<CardItem *> &getAttachedCards() const { return attachedCards; } const QList<CardItem *> &getAttachedCards() const { return attachedCards; }
void resetState(); void resetState();
void processCardInfo(const ServerInfo_Card &info); void processCardInfo(const ServerInfo_Card &info);
QMenu *getCardMenu() const { return cardMenu; } QMenu *getCardMenu() const { return cardMenu; }
QMenu *getPTMenu() const { return ptMenu; } QMenu *getPTMenu() const { return ptMenu; }
QMenu *getMoveMenu() const { return moveMenu; } QMenu *getMoveMenu() const { return moveMenu; }
bool animationEvent(); bool animationEvent();
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown); CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
void deleteDragItem(); void deleteDragItem();
void drawArrow(const QColor &arrowColor); void drawArrow(const QColor &arrowColor);
void playCard(bool faceDown); void playCard(bool faceDown);
protected: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; };
#endif #endif
...@@ -3,57 +3,57 @@ ...@@ -3,57 +3,57 @@
#include "carddatabase.h" #include "carddatabase.h"
CardList::CardList(bool _contentsKnown) CardList::CardList(bool _contentsKnown)
: QList<CardItem *>(), contentsKnown(_contentsKnown) : QList<CardItem *>(), contentsKnown(_contentsKnown)
{ {
} }
CardItem *CardList::findCard(const int id, const bool remove, int *position) CardItem *CardList::findCard(const int id, const bool remove, int *position)
{ {
if (!contentsKnown) { if (!contentsKnown) {
if (empty()) if (empty())
return 0; return 0;
CardItem *temp = at(0); CardItem *temp = at(0);
if (remove) if (remove)
removeAt(0); removeAt(0);
if (position) if (position)
*position = id; *position = id;
return temp; return temp;
} else } else
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
CardItem *temp = at(i); CardItem *temp = at(i);
if (temp->getId() == id) { if (temp->getId() == id) {
if (remove) if (remove)
removeAt(i); removeAt(i);
if (position) if (position)
*position = i; *position = i;
return temp; return temp;
} }
} }
return 0; return 0;
} }
class CardList::compareFunctor { class CardList::compareFunctor {
private: private:
int flags; int flags;
public: public:
compareFunctor(int _flags) : flags(_flags) compareFunctor(int _flags) : flags(_flags)
{ {
} }
inline bool operator()(CardItem *a, CardItem *b) const inline bool operator()(CardItem *a, CardItem *b) const
{ {
if (flags & SortByType) { if (flags & SortByType) {
QString t1 = a->getInfo()->getMainCardType(); QString t1 = a->getInfo()->getMainCardType();
QString t2 = b->getInfo()->getMainCardType(); QString t2 = b->getInfo()->getMainCardType();
if ((t1 == t2) && (flags & SortByName)) if ((t1 == t2) && (flags & SortByName))
return a->getName() < b->getName(); return a->getName() < b->getName();
return t1 < t2; return t1 < t2;
} else } else
return a->getName() < b->getName(); return a->getName() < b->getName();
} }
}; };
void CardList::sort(int flags) void CardList::sort(int flags)
{ {
compareFunctor cf(flags); compareFunctor cf(flags);
qSort(begin(), end(), cf); qSort(begin(), end(), cf);
} }
...@@ -7,15 +7,15 @@ class CardItem; ...@@ -7,15 +7,15 @@ class CardItem;
class CardList : public QList<CardItem *> { class CardList : public QList<CardItem *> {
private: private:
class compareFunctor; class compareFunctor;
protected: protected:
bool contentsKnown; bool contentsKnown;
public: public:
enum SortFlags { SortByName = 1, SortByType = 2 }; enum SortFlags { SortByName = 1, SortByType = 2 };
CardList(bool _contentsKnown); CardList(bool _contentsKnown);
CardItem *findCard(const int id, const bool remove, int *position = NULL); CardItem *findCard(const int id, const bool remove, int *position = NULL);
bool getContentsKnown() const { return contentsKnown; } bool getContentsKnown() const { return contentsKnown; }
void sort(int flags = SortByName); void sort(int flags = SortByName);
}; };
#endif #endif
This diff is collapsed.
...@@ -14,56 +14,56 @@ class QPainter; ...@@ -14,56 +14,56 @@ class QPainter;
class CardDragItem; class CardDragItem;
class CardZone : public AbstractGraphicsItem { class CardZone : public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
protected: protected:
Player *player; Player *player;
QString name; QString name;
CardList cards; CardList cards;
ZoneViewZone *view; ZoneViewZone *view;
QMenu *menu; QMenu *menu;
QAction *doubleClickAction; QAction *doubleClickAction;
bool hasCardAttr; bool hasCardAttr;
bool isShufflable; bool isShufflable;
bool isView; bool isView;
bool alwaysRevealTopCard; bool alwaysRevealTopCard;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void addCardImpl(CardItem *card, int x, int y) = 0; virtual void addCardImpl(CardItem *card, int x, int y) = 0;
signals: signals:
void cardCountChanged(); void cardCountChanged();
public slots: public slots:
void moveAllToZone(); void moveAllToZone();
bool showContextMenu(const QPoint &screenPos); bool showContextMenu(const QPoint &screenPos);
public: public:
enum { Type = typeZone }; enum { Type = typeZone };
int type() const { return Type; } int type() const { return Type; }
virtual void handleDropEvent(const QList<CardDragItem *> &dragItem, CardZone *startZone, const QPoint &dropPoint) = 0; virtual void handleDropEvent(const QList<CardDragItem *> &dragItem, CardZone *startZone, const QPoint &dropPoint) = 0;
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool _isView = false); CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool _isView = false);
~CardZone(); ~CardZone();
void retranslateUi(); void retranslateUi();
void clearContents(); void clearContents();
bool getHasCardAttr() const { return hasCardAttr; } bool getHasCardAttr() const { return hasCardAttr; }
bool getIsShufflable() const { return isShufflable; } bool getIsShufflable() const { return isShufflable; }
QMenu *getMenu() const { return menu; } QMenu *getMenu() const { return menu; }
void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; } void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; }
QString getName() const { return name; } QString getName() const { return name; }
QString getTranslatedName(bool hisOwn, GrammaticalCase gc) const; QString getTranslatedName(bool hisOwn, GrammaticalCase gc) const;
Player *getPlayer() const { return player; } Player *getPlayer() const { return player; }
bool contentsKnown() const { return cards.getContentsKnown(); } bool contentsKnown() const { return cards.getContentsKnown(); }
const CardList &getCards() const { return cards; } const CardList &getCards() const { return cards; }
void addCard(CardItem *card, bool reorganize, int x, int y = -1); void addCard(CardItem *card, bool reorganize, int x, int y = -1);
// getCard() finds a card by id. // getCard() finds a card by id.
CardItem *getCard(int cardId, const QString &cardName); CardItem *getCard(int cardId, const QString &cardName);
// takeCard() finds a card by position and removes it from the zone and from all of its views. // takeCard() finds a card by position and removes it from the zone and from all of its views.
virtual CardItem *takeCard(int position, int cardId, bool canResize = true); virtual CardItem *takeCard(int position, int cardId, bool canResize = true);
void removeCard(CardItem *card); void removeCard(CardItem *card);
ZoneViewZone *getView() const { return view; } ZoneViewZone *getView() const { return view; }
void setView(ZoneViewZone *_view) { view = _view; } void setView(ZoneViewZone *_view) { view = _view; }
virtual void reorganizeCards() = 0; virtual void reorganizeCards() = 0;
virtual QPointF closestGridPoint(const QPointF &point); virtual QPointF closestGridPoint(const QPointF &point);
bool getIsView() const { return isView; } bool getIsView() const { return isView; }
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; } bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; } void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
}; };
#endif #endif
This diff is collapsed.
...@@ -14,40 +14,40 @@ class TabSupervisor; ...@@ -14,40 +14,40 @@ class TabSupervisor;
class TabGame; class TabGame;
class ChatView : public QTextBrowser { class ChatView : public QTextBrowser {
Q_OBJECT Q_OBJECT
protected: protected:
const TabSupervisor * const tabSupervisor; const TabSupervisor * const tabSupervisor;
TabGame * const game; TabGame * const game;
private: private:
enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser }; enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser };
UserContextMenu *userContextMenu; UserContextMenu *userContextMenu;
QString lastSender; QString lastSender;
bool evenNumber; bool evenNumber;
bool showTimestamps; bool showTimestamps;
HoveredItemType hoveredItemType; HoveredItemType hoveredItemType;
QString hoveredContent; QString hoveredContent;
QTextFragment getFragmentUnderMouse(const QPoint &pos) const; QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
QTextCursor prepareBlock(bool same = false); QTextCursor prepareBlock(bool same = false);
void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendCardTag(QTextCursor &cursor, const QString &cardName);
void appendUrlTag(QTextCursor &cursor, QString url); void appendUrlTag(QTextCursor &cursor, QString url);
private slots: private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);
public: public:
ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = 0); ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = 0);
void retranslateUi(); void retranslateUi();
void appendHtml(const QString &html); void appendHtml(const QString &html);
void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false); void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
protected: protected:
void enterEvent(QEvent *event); void enterEvent(QEvent *event);
void leaveEvent(QEvent *event); void leaveEvent(QEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
signals: signals:
void openMessageDialog(const QString &userName, bool focus); void openMessageDialog(const QString &userName, bool focus);
void cardNameHovered(QString cardName); void cardNameHovered(QString cardName);
void showCardInfoPopup(QPoint pos, QString cardName); void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup(QString cardName); void deleteCardInfoPopup(QString cardName);
}; };
#endif #endif
...@@ -3,34 +3,34 @@ ...@@ -3,34 +3,34 @@
#include <QPainter> #include <QPainter>
GeneralCounter::GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent) GeneralCounter::GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent)
: AbstractCounter(_player, _id, _name, true, _value, parent), color(_color), radius(_radius) : AbstractCounter(_player, _id, _name, true, _value, parent), color(_color), radius(_radius)
{ {
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
} }
QRectF GeneralCounter::boundingRect() const QRectF GeneralCounter::boundingRect() const
{ {
return QRectF(0, 0, radius * 2, radius * 2); return QRectF(0, 0, radius * 2, radius * 2);
} }
void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
QRectF mapRect = painter->combinedTransform().mapRect(boundingRect()); QRectF mapRect = painter->combinedTransform().mapRect(boundingRect());
int translatedHeight = mapRect.size().height(); int translatedHeight = mapRect.size().height();
qreal scaleFactor = translatedHeight / boundingRect().height(); qreal scaleFactor = translatedHeight / boundingRect().height();
QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered); QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
painter->save(); painter->save();
painter->resetTransform(); painter->resetTransform();
painter->drawPixmap(QPoint(0, 0), pixmap); painter->drawPixmap(QPoint(0, 0), pixmap);
if (value) { if (value) {
QFont f("Serif"); QFont f("Serif");
f.setPixelSize(qMax((int) (radius * scaleFactor), 10)); f.setPixelSize(qMax((int) (radius * scaleFactor), 10));
f.setWeight(QFont::Bold); f.setWeight(QFont::Bold);
painter->setPen(Qt::black); painter->setPen(Qt::black);
painter->setFont(f); painter->setFont(f);
painter->drawText(mapRect, Qt::AlignCenter, QString::number(value)); painter->drawText(mapRect, Qt::AlignCenter, QString::number(value));
} }
painter->restore(); painter->restore();
} }
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
#include "abstractcounter.h" #include "abstractcounter.h"
class GeneralCounter : public AbstractCounter { class GeneralCounter : public AbstractCounter {
Q_OBJECT Q_OBJECT
private: private:
QColor color; QColor color;
int radius; int radius;
public: public:
GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent = 0); GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent = 0);
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
}; };
#endif #endif
This diff is collapsed.
...@@ -4,30 +4,30 @@ ...@@ -4,30 +4,30 @@
#include "decklist.h" #include "decklist.h"
class DeckLoader : public DeckList { class DeckLoader : public DeckList {
Q_OBJECT Q_OBJECT
signals: signals:
void deckLoaded(); void deckLoaded();
public: public:
enum FileFormat { PlainTextFormat, CockatriceFormat }; enum FileFormat { PlainTextFormat, CockatriceFormat };
static const QStringList fileNameFilters; static const QStringList fileNameFilters;
private: private:
QString lastFileName; QString lastFileName;
FileFormat lastFileFormat; FileFormat lastFileFormat;
int lastRemoteDeckId; int lastRemoteDeckId;
public: public:
DeckLoader(); DeckLoader();
DeckLoader(const QString &nativeString); DeckLoader(const QString &nativeString);
DeckLoader(const DeckList &other); DeckLoader(const DeckList &other);
DeckLoader(const DeckLoader &other); DeckLoader(const DeckLoader &other);
const QString &getLastFileName() const { return lastFileName; } const QString &getLastFileName() const { return lastFileName; }
FileFormat getLastFileFormat() const { return lastFileFormat; } FileFormat getLastFileFormat() const { return lastFileFormat; }
int getLastRemoteDeckId() const { return lastRemoteDeckId; } int getLastRemoteDeckId() const { return lastRemoteDeckId; }
static FileFormat getFormatFromNameFilter(const QString &selectedNameFilter); static FileFormat getFormatFromName(const QString &fileName);
bool loadFromFile(const QString &fileName, FileFormat fmt); bool loadFromFile(const QString &fileName, FileFormat fmt);
bool loadFromRemote(const QString &nativeString, int remoteDeckId); bool loadFromRemote(const QString &nativeString, int remoteDeckId);
bool saveToFile(const QString &fileName, FileFormat fmt); bool saveToFile(const QString &fileName, FileFormat fmt);
}; };
#endif #endif
...@@ -45,7 +45,6 @@ public: ...@@ -45,7 +45,6 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role); bool setData(const QModelIndex &index, const QVariant &value, int role);
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
QModelIndex findCard(const QString &cardName, const QString &zoneName) const; QModelIndex findCard(const QString &cardName, const QString &zoneName) const;
QModelIndex addCard(const QString &cardName, const QString &zoneName); QModelIndex addCard(const QString &cardName, const QString &zoneName);
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
......
This diff is collapsed.
...@@ -8,14 +8,14 @@ class QNetworkReply; ...@@ -8,14 +8,14 @@ class QNetworkReply;
class DeckList; class DeckList;
class DeckStatsInterface : public QObject { class DeckStatsInterface : public QObject {
Q_OBJECT Q_OBJECT
private: private:
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
private slots: private slots:
void queryFinished(QNetworkReply *reply); void queryFinished(QNetworkReply *reply);
public: public:
DeckStatsInterface(QObject *parent = 0); DeckStatsInterface(QObject *parent = 0);
void analyzeDeck(DeckList *deck); void analyzeDeck(DeckList *deck);
}; };
#endif #endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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