mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 10:33:54 -07:00
decklist transfer code
This commit is contained in:
parent
63f9206eb4
commit
8dcf81654e
32 changed files with 694 additions and 260 deletions
148
cockatrice/src/abstractcarditem.cpp
Normal file
148
cockatrice/src/abstractcarditem.cpp
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
#include <QPainter>
|
||||
#include <QGraphicsScene>
|
||||
#include <QCursor>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "carddatabase.h"
|
||||
#include "abstractcarditem.h"
|
||||
#include "main.h"
|
||||
#include <QDebug>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(const QString &_name, QGraphicsItem *parent)
|
||||
: AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), tapped(false)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
setAcceptsHoverEvents(true);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||
}
|
||||
|
||||
AbstractCardItem::~AbstractCardItem()
|
||||
{
|
||||
qDebug(QString("AbstractCardItem destructor: %1").arg(name).toLatin1());
|
||||
}
|
||||
|
||||
QRectF AbstractCardItem::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void AbstractCardItem::pixmapUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
||||
if (tapped)
|
||||
translatedSize.transpose();
|
||||
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
|
||||
painter->save();
|
||||
if (translatedPixmap) {
|
||||
painter->resetTransform();
|
||||
if (tapped) {
|
||||
painter->translate(((qreal) translatedSize.height()) / 2, ((qreal) translatedSize.width()) / 2);
|
||||
painter->rotate(90);
|
||||
painter->translate(-((qreal) translatedSize.width()) / 2, -((qreal) translatedSize.height()) / 2);
|
||||
}
|
||||
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
||||
} else {
|
||||
QFont f("Serif");
|
||||
f.setStyleHint(QFont::Serif);
|
||||
f.setPixelSize(11);
|
||||
painter->setFont(f);
|
||||
painter->setBrush(QColor(230, 230, 230));
|
||||
qDebug() <<"COLORS:::::" << info->getColors();
|
||||
QString color;
|
||||
QPen pen;
|
||||
if(!info->getColors().empty())
|
||||
{
|
||||
color = info->getColors().first();
|
||||
if(color == "B")
|
||||
painter->setBrush(QColor(0,0,0));
|
||||
if(color == "U")
|
||||
painter->setBrush(QColor(0,140,180));
|
||||
if(color == "W")
|
||||
painter->setBrush(QColor(255,250,140));
|
||||
if(color == "R")
|
||||
painter->setBrush(QColor(230,0,0));
|
||||
if(color == "G")
|
||||
painter->setBrush(QColor(0,160,0));
|
||||
if(info->getColors().size() > 1)
|
||||
{
|
||||
painter->setBrush(QColor(250,190,30));
|
||||
color = "M"; // Multicolor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
|
||||
pen.setWidth(3);
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
||||
painter->setPen(Qt::white);
|
||||
if(color == "W" || color == "" || color == "M")
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, name);
|
||||
if(info->getCardType().contains("Creature"))
|
||||
{
|
||||
painter->drawText(QRectF(CARD_WIDTH - 40, CARD_HEIGHT - 25, 30, 30), Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, info->getPowTough());
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
|
||||
if (isSelected()) {
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setName(const QString &_name)
|
||||
{
|
||||
disconnect(info, 0, this, 0);
|
||||
name = _name;
|
||||
info = db->getCard(name);
|
||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setTapped(bool _tapped)
|
||||
{
|
||||
tapped = _tapped;
|
||||
if (tapped)
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
else
|
||||
setTransform(QTransform());
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!isSelected()) {
|
||||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
}
|
||||
if (event->button() == Qt::LeftButton)
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged) {
|
||||
update();
|
||||
return value;
|
||||
} else
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
43
cockatrice/src/abstractcarditem.h
Normal file
43
cockatrice/src/abstractcarditem.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef ABSTRACTCARDITEM_H
|
||||
#define ABSTRACTCARDITEM_H
|
||||
|
||||
#include "abstractgraphicsitem.h"
|
||||
|
||||
class CardInfo;
|
||||
|
||||
const int CARD_WIDTH = 72;
|
||||
const int CARD_HEIGHT = 102;
|
||||
|
||||
enum CardItemType {
|
||||
typeCard = QGraphicsItem::UserType + 1,
|
||||
typeCardDrag = QGraphicsItem::UserType + 2,
|
||||
typeZone = QGraphicsItem::UserType + 3,
|
||||
typeOther = QGraphicsItem::UserType + 4
|
||||
};
|
||||
|
||||
class AbstractCardItem : public QObject, public AbstractGraphicsItem {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
CardInfo *info;
|
||||
QString name;
|
||||
bool tapped;
|
||||
private slots:
|
||||
void pixmapUpdated();
|
||||
public:
|
||||
enum { Type = typeCard };
|
||||
int type() const { return Type; }
|
||||
AbstractCardItem(const QString &_name = QString(), QGraphicsItem *parent = 0);
|
||||
~AbstractCardItem();
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
CardInfo *getInfo() const { return info; }
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name = QString());
|
||||
bool getTapped() const { return tapped; }
|
||||
void setTapped(bool _tapped);
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -11,126 +11,24 @@
|
|||
#include "main.h"
|
||||
|
||||
CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||
: AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
||||
: AbstractCardItem(_name, parent), id(_cardid), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
setAcceptsHoverEvents(true);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||
}
|
||||
|
||||
CardItem::~CardItem()
|
||||
{
|
||||
deleteDragItem();
|
||||
qDebug(QString("CardItem destructor: %1").arg(name).toLatin1());
|
||||
}
|
||||
|
||||
QRectF CardItem::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void CardItem::pixmapUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
||||
if (tapped)
|
||||
translatedSize.transpose();
|
||||
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
|
||||
painter->save();
|
||||
if (translatedPixmap) {
|
||||
painter->resetTransform();
|
||||
if (tapped) {
|
||||
painter->translate(((qreal) translatedSize.height()) / 2, ((qreal) translatedSize.width()) / 2);
|
||||
painter->rotate(90);
|
||||
painter->translate(-((qreal) translatedSize.width()) / 2, -((qreal) translatedSize.height()) / 2);
|
||||
}
|
||||
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
||||
} else {
|
||||
QFont f("Serif");
|
||||
f.setStyleHint(QFont::Serif);
|
||||
f.setPixelSize(11);
|
||||
painter->setFont(f);
|
||||
painter->setBrush(QColor(230, 230, 230));
|
||||
qDebug() <<"COLORS:::::" << info->getColors();
|
||||
QString color;
|
||||
QPen pen;
|
||||
if(!info->getColors().empty())
|
||||
{
|
||||
color = info->getColors().first();
|
||||
if(color == "B")
|
||||
painter->setBrush(QColor(0,0,0));
|
||||
if(color == "U")
|
||||
painter->setBrush(QColor(0,140,180));
|
||||
if(color == "W")
|
||||
painter->setBrush(QColor(255,250,140));
|
||||
if(color == "R")
|
||||
painter->setBrush(QColor(230,0,0));
|
||||
if(color == "G")
|
||||
painter->setBrush(QColor(0,160,0));
|
||||
if(info->getColors().size() > 1)
|
||||
{
|
||||
painter->setBrush(QColor(250,190,30));
|
||||
color = "M"; // Multicolor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
|
||||
pen.setWidth(3);
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
||||
painter->setPen(Qt::white);
|
||||
if(color == "W" || color == "" || color == "M")
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, name);
|
||||
if(info->getCardType().contains("Creature"))
|
||||
{
|
||||
painter->drawText(QRectF(CARD_WIDTH - 40, CARD_HEIGHT - 25, 30, 30), Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, info->getPowTough());
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
|
||||
if (isSelected()) {
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
}
|
||||
AbstractCardItem::paint(painter, option, widget);
|
||||
if (counters)
|
||||
paintNumberEllipse(counters, painter);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void CardItem::setName(const QString &_name)
|
||||
{
|
||||
disconnect(info, 0, this, 0);
|
||||
name = _name;
|
||||
info = db->getCard(name);
|
||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||
update();
|
||||
}
|
||||
|
||||
void CardItem::setTapped(bool _tapped)
|
||||
{
|
||||
tapped = _tapped;
|
||||
if (tapped)
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
else
|
||||
setTransform(QTransform());
|
||||
update();
|
||||
}
|
||||
|
||||
void CardItem::setAttacking(bool _attacking)
|
||||
{
|
||||
attacking = _attacking;
|
||||
|
|
@ -189,17 +87,6 @@ void CardItem::deleteDragItem()
|
|||
dragItem = NULL;
|
||||
}
|
||||
|
||||
void CardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!isSelected()) {
|
||||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
}
|
||||
if (event->button() == Qt::LeftButton)
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->buttons().testFlag(Qt::RightButton)) {
|
||||
|
|
@ -278,16 +165,3 @@ void CardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||
((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this);
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
QVariant CardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedChange) {
|
||||
// XXX
|
||||
return value;
|
||||
} else if (change == ItemSelectedHasChanged) {
|
||||
qDebug("selection changed");
|
||||
update();
|
||||
return value;
|
||||
} else
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,18 @@
|
|||
#ifndef CARDITEM_H
|
||||
#define CARDITEM_H
|
||||
|
||||
#include "abstractgraphicsitem.h"
|
||||
#include "abstractcarditem.h"
|
||||
|
||||
class CardDatabase;
|
||||
class CardDragItem;
|
||||
class CardZone;
|
||||
class CardInfo;
|
||||
|
||||
const int CARD_WIDTH = 72;
|
||||
const int CARD_HEIGHT = 102;
|
||||
|
||||
const int MAX_COUNTERS_ON_CARD = 999;
|
||||
|
||||
enum CardItemType {
|
||||
typeCard = QGraphicsItem::UserType + 1,
|
||||
typeCardDrag = QGraphicsItem::UserType + 2,
|
||||
typeZone = QGraphicsItem::UserType + 3,
|
||||
typeOther = QGraphicsItem::UserType + 4
|
||||
};
|
||||
|
||||
class CardItem : public QObject, public AbstractGraphicsItem {
|
||||
class CardItem : public AbstractCardItem {
|
||||
Q_OBJECT
|
||||
private:
|
||||
CardInfo *info;
|
||||
QString name;
|
||||
int id;
|
||||
bool tapped;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
int counters;
|
||||
|
|
@ -34,23 +20,16 @@ private:
|
|||
bool doesntUntap;
|
||||
QPoint gridPoint;
|
||||
CardDragItem *dragItem;
|
||||
private slots:
|
||||
void pixmapUpdated();
|
||||
public:
|
||||
enum { Type = typeCard };
|
||||
int type() const { return Type; }
|
||||
CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
|
||||
~CardItem();
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
QPoint getGridPoint() const { return gridPoint; }
|
||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||
int getId() const { return id; }
|
||||
void setId(int _id) { id = _id; }
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name = QString());
|
||||
bool getTapped() const { return tapped; }
|
||||
void setTapped(bool _tapped);
|
||||
bool getAttacking() const { return attacking; }
|
||||
void setAttacking(bool _attacking);
|
||||
bool getFaceDown() const { return facedown; }
|
||||
|
|
@ -66,12 +45,10 @@ public:
|
|||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||
void deleteDragItem();
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
168
cockatrice/src/deckview.cpp
Normal file
168
cockatrice/src/deckview.cpp
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
#include <QtGui>
|
||||
#include "deckview.h"
|
||||
#include "decklist.h"
|
||||
#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
#include <QDebug>
|
||||
|
||||
DeckViewCard::DeckViewCard(const QString &_name, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, parent)
|
||||
{
|
||||
}
|
||||
|
||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
||||
: QGraphicsItem(), name(_name), width(0), height(0)
|
||||
{
|
||||
QSettings settings;
|
||||
QString bgPath = settings.value("zonebg/table").toString();
|
||||
if (!bgPath.isEmpty())
|
||||
bgPixmap.load(bgPath);
|
||||
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
}
|
||||
|
||||
QRectF DeckViewCardContainer::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, width, height);
|
||||
}
|
||||
|
||||
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
if (bgPixmap.isNull())
|
||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||
else
|
||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||
painter->setPen(QColor(255, 255, 255, 100));
|
||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||
|
||||
painter->setPen(QColor(Qt::white));
|
||||
QFont f("Serif");
|
||||
f.setStyleHint(QFont::Serif);
|
||||
f.setPixelSize(24);
|
||||
f.setWeight(QFont::Bold);
|
||||
painter->setFont(f);
|
||||
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name));
|
||||
}
|
||||
|
||||
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
||||
{
|
||||
cards.insertMulti(card->getInfo()->getMainCardType(), card);
|
||||
}
|
||||
|
||||
void DeckViewCardContainer::rearrangeItems()
|
||||
{
|
||||
separatorY = 30;
|
||||
|
||||
QList<QString> cardTypeList = cards.uniqueKeys();
|
||||
int rows = cardTypeList.size();
|
||||
int cols = 0;
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
QList<DeckViewCard *> row = cards.values(cardTypeList[i]);
|
||||
if (row.size() > cols)
|
||||
cols = row.size();
|
||||
for (int j = 0; j < row.size(); ++j) {
|
||||
DeckViewCard *card = row[j];
|
||||
card->setPos(j * CARD_WIDTH, separatorY + 10 + i * (CARD_HEIGHT + rowSpacing));
|
||||
}
|
||||
}
|
||||
|
||||
prepareGeometryChange();
|
||||
width = cols * CARD_WIDTH;
|
||||
height = separatorY + 10 + rows * CARD_HEIGHT + rowSpacing * (rows - 1);
|
||||
}
|
||||
|
||||
void DeckViewCardContainer::setWidth(qreal _width)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
width = _width;
|
||||
update();
|
||||
}
|
||||
|
||||
DeckViewScene::DeckViewScene(QObject *parent)
|
||||
: QGraphicsScene(parent), deck(0)
|
||||
{
|
||||
}
|
||||
|
||||
DeckViewScene::~DeckViewScene()
|
||||
{
|
||||
}
|
||||
|
||||
void DeckViewScene::setDeck(DeckList *_deck)
|
||||
{
|
||||
deck = _deck;
|
||||
rebuildTree();
|
||||
rearrangeItems();
|
||||
}
|
||||
|
||||
void DeckViewScene::rebuildTree()
|
||||
{
|
||||
InnerDecklistNode *listRoot = deck->getRoot();
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
|
||||
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
||||
if (!container) {
|
||||
container = new DeckViewCardContainer(currentZone->getName());
|
||||
cardContainers.insert(currentZone->getName(), container);
|
||||
addItem(container);
|
||||
}
|
||||
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard)
|
||||
continue;
|
||||
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k)
|
||||
container->addCard(new DeckViewCard(currentCard->getName(), container));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeckViewScene::rearrangeItems()
|
||||
{
|
||||
const int spacing = CARD_HEIGHT / 3;
|
||||
QList<DeckViewCardContainer *> contList = cardContainers.values();
|
||||
qreal totalHeight = -spacing;
|
||||
qreal totalWidth = 0;
|
||||
for (int i = 0; i < contList.size(); ++i) {
|
||||
DeckViewCardContainer *c = contList[i];
|
||||
c->rearrangeItems();
|
||||
c->setPos(0, totalHeight + spacing);
|
||||
totalHeight += c->boundingRect().height() + spacing;
|
||||
if (c->boundingRect().width() > totalWidth)
|
||||
totalWidth = c->boundingRect().width();
|
||||
}
|
||||
for (int i = 0; i < contList.size(); ++i)
|
||||
contList[i]->setWidth(totalWidth);
|
||||
|
||||
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||
}
|
||||
|
||||
DeckView::DeckView(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
deckViewScene = new DeckViewScene(this);
|
||||
|
||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||
setScene(deckViewScene);
|
||||
|
||||
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||
}
|
||||
|
||||
void DeckView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
updateSceneRect(scene()->sceneRect());
|
||||
}
|
||||
|
||||
void DeckView::updateSceneRect(const QRectF &rect)
|
||||
{
|
||||
qDebug(QString("deckView::updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
|
||||
fitInView(rect, Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void DeckView::setDeck(DeckList *_deck)
|
||||
{
|
||||
deckViewScene->setDeck(_deck);
|
||||
}
|
||||
62
cockatrice/src/deckview.h
Normal file
62
cockatrice/src/deckview.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#ifndef DECKVIEW_H
|
||||
#define DECKVIEW_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QMap>
|
||||
#include <QPixmap>
|
||||
#include "carditem.h"
|
||||
|
||||
class DeckList;
|
||||
class InnerDecklistNode;
|
||||
class CardInfo;
|
||||
|
||||
class DeckViewCard : public AbstractCardItem {
|
||||
public:
|
||||
DeckViewCard(const QString &_name = QString(), QGraphicsItem *parent = 0);
|
||||
};
|
||||
|
||||
class DeckViewCardContainer : public QGraphicsItem {
|
||||
private:
|
||||
QString name;
|
||||
QMap<QString, DeckViewCard *> cards;
|
||||
qreal width, height;
|
||||
qreal separatorY;
|
||||
QPixmap bgPixmap;
|
||||
static const int rowSpacing = 5;
|
||||
public:
|
||||
DeckViewCardContainer(const QString &_name);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
void addCard(DeckViewCard *card);
|
||||
void rearrangeItems();
|
||||
void setWidth(qreal _width);
|
||||
};
|
||||
|
||||
class DeckViewScene : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
private:
|
||||
DeckList *deck;
|
||||
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||
void rebuildTree();
|
||||
void rearrangeItems();
|
||||
public:
|
||||
DeckViewScene(QObject *parent = 0);
|
||||
~DeckViewScene();
|
||||
void setDeck(DeckList *_deck);
|
||||
};
|
||||
|
||||
class DeckView : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
private:
|
||||
DeckViewScene *deckViewScene;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
public slots:
|
||||
void updateSceneRect(const QRectF &rect);
|
||||
public:
|
||||
DeckView(QWidget *parent = 0);
|
||||
void setDeck(DeckList *_deck);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -212,6 +212,7 @@ Player::~Player()
|
|||
|
||||
void Player::updateBoundingRect()
|
||||
{
|
||||
// XXX! PREPARE GEOMETRY CHANGE
|
||||
bRect = QRectF(0, 0, CARD_WIDTH + 5 + counterAreaWidth + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
|
||||
emit sizeChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
|
|||
setLayout(hbox);
|
||||
}
|
||||
|
||||
void TabChatChannel::retranslateUi()
|
||||
{
|
||||
}
|
||||
|
||||
void TabChatChannel::sendMessage()
|
||||
{
|
||||
if (sayEdit->text().isEmpty())
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ private slots:
|
|||
void processSayEvent(Event_ChatSay *event);
|
||||
public:
|
||||
TabChatChannel(Client *_client, const QString &_channelName);
|
||||
void retranslateUi();
|
||||
void processChatEvent(ChatEvent *event);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -177,9 +177,8 @@ void TabDeckStorage::actUpload()
|
|||
curRight = curRight->parent();
|
||||
if (curRight)
|
||||
targetPath = curRight->data(0, Qt::UserRole).toString();
|
||||
qDebug() << "targetPath:" << targetPath;
|
||||
|
||||
Command_DeckUpload *command = new Command_DeckUpload(-1, deck, targetPath);
|
||||
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
|
||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
|
||||
client->sendCommand(command);
|
||||
}
|
||||
|
|
@ -190,6 +189,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
|
|||
if (!resp)
|
||||
return;
|
||||
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
|
||||
delete cmd->getDeck();
|
||||
|
||||
QTreeWidgetItemIterator it(serverDirView);
|
||||
while (*it) {
|
||||
|
|
@ -264,7 +264,6 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
|
|||
QTreeWidgetItemIterator it(serverDirView);
|
||||
while (*it) {
|
||||
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
|
||||
qDebug() << "gefunden";
|
||||
QFileIconProvider fip;
|
||||
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
|
||||
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
|
||||
|
|
@ -272,8 +271,7 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
|
|||
newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName());
|
||||
(*it)->addChild(newItem);
|
||||
break;
|
||||
} else
|
||||
qDebug() << "path = " << (*it)->data(0, Qt::UserRole) << " nicht gefunden";
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#include "zoneviewzone.h"
|
||||
#include "zoneviewwidget.h"
|
||||
#include "zoneviewlayout.h"
|
||||
#include "deckview.h"
|
||||
#include "decklist.h"
|
||||
#include "main.h"
|
||||
|
||||
TabGame::TabGame(Client *_client, int _gameId)
|
||||
|
|
@ -17,7 +19,15 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
{
|
||||
zoneLayout = new ZoneViewLayout;
|
||||
scene = new GameScene(zoneLayout, this);
|
||||
view = new GameView(scene);
|
||||
gameView = new GameView(scene);
|
||||
gameView->hide();
|
||||
|
||||
deckView = new DeckView;
|
||||
|
||||
DeckList *foo = new DeckList;
|
||||
foo->loadFromFile("/home/brukie/cockatrice/decks/adfb.cod", DeckList::CockatriceFormat);
|
||||
deckView->setDeck(foo);
|
||||
// deckView->hide();
|
||||
|
||||
cardInfo = new CardInfoWidget(db);
|
||||
messageLog = new MessageLogWidget;
|
||||
|
|
@ -30,6 +40,7 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
hLayout->addWidget(sayEdit);
|
||||
|
||||
phasesToolbar = new PhasesToolbar;
|
||||
phasesToolbar->hide();
|
||||
|
||||
QVBoxLayout *verticalLayout = new QVBoxLayout;
|
||||
verticalLayout->addWidget(cardInfo);
|
||||
|
|
@ -38,11 +49,14 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(phasesToolbar);
|
||||
mainLayout->addWidget(view, 10);
|
||||
mainLayout->addWidget(gameView, 10);
|
||||
mainLayout->addWidget(deckView, 10);
|
||||
mainLayout->addLayout(verticalLayout);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
aCloseMostRecentZoneView = new QAction(this);
|
||||
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
|
||||
addAction(aCloseMostRecentZoneView);
|
||||
|
||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
|
||||
|
||||
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
|
||||
|
|
@ -60,7 +74,21 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
messageLog->connectToGame(game);
|
||||
|
||||
game->queryGameState();
|
||||
*/}
|
||||
*/
|
||||
retranslateUi();
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void TabGame::retranslateUi()
|
||||
{
|
||||
sayLabel->setText(tr("&Say:"));
|
||||
cardInfo->retranslateUi();
|
||||
// if (game)
|
||||
// game->retranslateUi();
|
||||
zoneLayout->retranslateUi();
|
||||
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
|
||||
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
||||
}
|
||||
|
||||
void TabGame::processGameEvent(GameEvent *event)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Client;
|
|||
class CardDatabase;
|
||||
class GameEvent;
|
||||
class GameView;
|
||||
class DeckView;
|
||||
class GameScene;
|
||||
class Game;
|
||||
class CardInfoWidget;
|
||||
|
|
@ -30,12 +31,15 @@ private:
|
|||
QLineEdit *sayEdit;
|
||||
PhasesToolbar *phasesToolbar;
|
||||
GameScene *scene;
|
||||
GameView *view;
|
||||
GameView *gameView;
|
||||
DeckView *deckView;
|
||||
Game *game;
|
||||
ZoneViewLayout *zoneLayout;
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
private slots:
|
||||
public:
|
||||
TabGame(Client *_client, int _gameId);
|
||||
void retranslateUi();
|
||||
void processGameEvent(GameEvent *event);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -244,3 +244,10 @@ TabServer::TabServer(Client *_client, QWidget *parent)
|
|||
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void TabServer::retranslateUi()
|
||||
{
|
||||
gameSelector->retranslateUi();
|
||||
chatChannelSelector->retranslateUi();
|
||||
serverMessageLog->retranslateUi();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ private:
|
|||
ServerMessageLog *serverMessageLog;
|
||||
public:
|
||||
TabServer(Client *_client, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,10 +14,22 @@ TabSupervisor:: TabSupervisor(QWidget *parent)
|
|||
|
||||
void TabSupervisor::retranslateUi()
|
||||
{
|
||||
if (tabServer)
|
||||
if (tabServer) {
|
||||
setTabText(0, tr("Server"));
|
||||
if (tabDeckStorage)
|
||||
tabServer->retranslateUi();
|
||||
}
|
||||
if (tabDeckStorage) {
|
||||
setTabText(1, tr("Deck storage"));
|
||||
tabDeckStorage->retranslateUi();
|
||||
}
|
||||
|
||||
QMapIterator<QString, TabChatChannel *> chatChannelIterator(chatChannelTabs);
|
||||
while (chatChannelIterator.hasNext())
|
||||
chatChannelIterator.next().value()->retranslateUi();
|
||||
|
||||
QMapIterator<int, TabGame *> gameIterator(gameTabs);
|
||||
while (gameIterator.hasNext())
|
||||
gameIterator.next().value()->retranslateUi();
|
||||
}
|
||||
|
||||
void TabSupervisor::start(Client *_client)
|
||||
|
|
@ -28,7 +40,6 @@ void TabSupervisor::start(Client *_client)
|
|||
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
|
||||
|
||||
tabServer = new TabServer(client);
|
||||
connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int)));
|
||||
connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &)));
|
||||
addTab(tabServer, QString());
|
||||
|
||||
|
|
|
|||
|
|
@ -201,20 +201,9 @@ void MainWindow::retranslateUi()
|
|||
aFullScreen->setShortcut(tr("Ctrl+F"));
|
||||
aSettings->setText(tr("&Settings..."));
|
||||
aExit->setText(tr("&Exit"));
|
||||
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
|
||||
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
||||
|
||||
cockatriceMenu->setTitle(tr("&Cockatrice"));
|
||||
/*
|
||||
sayLabel->setText(tr("&Say:"));
|
||||
|
||||
cardInfo->retranslateUi();
|
||||
chatWidget->retranslateUi();
|
||||
gameSelector->retranslateUi();
|
||||
if (game)
|
||||
game->retranslateUi();
|
||||
zoneLayout->retranslateUi();
|
||||
*/}
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
|
|
@ -238,10 +227,6 @@ void MainWindow::createActions()
|
|||
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
||||
aExit = new QAction(this);
|
||||
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
||||
|
||||
aCloseMostRecentZoneView = new QAction(this);
|
||||
// connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
|
||||
addAction(aCloseMostRecentZoneView);
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ private:
|
|||
void createMenus();
|
||||
QMenu *cockatriceMenu;
|
||||
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
TabSupervisor *tabSupervisor;
|
||||
|
||||
PingWidget *pingWidget;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue