Commit 8dcf8165 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

decklist transfer code

parent 63f9206e
...@@ -16,6 +16,7 @@ HEADERS += src/counter.h \ ...@@ -16,6 +16,7 @@ HEADERS += src/counter.h \
src/cardzone.h \ src/cardzone.h \
src/player.h \ src/player.h \
src/cardlist.h \ src/cardlist.h \
src/abstractcarditem.h \
src/carditem.h \ src/carditem.h \
src/tablezone.h \ src/tablezone.h \
src/handzone.h \ src/handzone.h \
...@@ -45,6 +46,7 @@ HEADERS += src/counter.h \ ...@@ -45,6 +46,7 @@ HEADERS += src/counter.h \
src/tab_game.h \ src/tab_game.h \
src/tab_deck_storage.h \ src/tab_deck_storage.h \
src/tab_supervisor.h \ src/tab_supervisor.h \
src/deckview.h \
../common/decklist.h \ ../common/decklist.h \
../common/protocol.h \ ../common/protocol.h \
../common/protocol_items.h \ ../common/protocol_items.h \
...@@ -60,6 +62,7 @@ SOURCES += src/counter.cpp \ ...@@ -60,6 +62,7 @@ SOURCES += src/counter.cpp \
src/player.cpp \ src/player.cpp \
src/cardzone.cpp \ src/cardzone.cpp \
src/cardlist.cpp \ src/cardlist.cpp \
src/abstractcarditem.cpp \
src/carditem.cpp \ src/carditem.cpp \
src/tablezone.cpp \ src/tablezone.cpp \
src/handzone.cpp \ src/handzone.cpp \
...@@ -89,6 +92,7 @@ SOURCES += src/counter.cpp \ ...@@ -89,6 +92,7 @@ SOURCES += src/counter.cpp \
src/tab_game.cpp \ src/tab_game.cpp \
src/tab_deck_storage.cpp \ src/tab_deck_storage.cpp \
src/tab_supervisor.cpp \ src/tab_supervisor.cpp \
src/deckview.cpp \
../common/decklist.cpp \ ../common/decklist.cpp \
../common/protocol.cpp \ ../common/protocol.cpp \
../common/protocol_items.cpp ../common/protocol_items.cpp
......
#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);
}
#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 @@ ...@@ -11,126 +11,24 @@
#include "main.h" #include "main.h"
CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent) 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() CardItem::~CardItem()
{ {
deleteDragItem(); deleteDragItem();
qDebug(QString("CardItem destructor: %1").arg(name).toLatin1());
}
QRectF CardItem::boundingRect() const
{
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
} }
void CardItem::pixmapUpdated() void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
update();
}
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
{ {
painter->save(); painter->save();
AbstractCardItem::paint(painter, option, widget);
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));
}
if (counters) if (counters)
paintNumberEllipse(counters, painter); paintNumberEllipse(counters, painter);
painter->restore(); 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) void CardItem::setAttacking(bool _attacking)
{ {
attacking = _attacking; attacking = _attacking;
...@@ -189,17 +87,6 @@ void CardItem::deleteDragItem() ...@@ -189,17 +87,6 @@ void CardItem::deleteDragItem()
dragItem = NULL; 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) void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->buttons().testFlag(Qt::RightButton)) { if (event->buttons().testFlag(Qt::RightButton)) {
...@@ -278,16 +165,3 @@ void CardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) ...@@ -278,16 +165,3 @@ void CardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this); ((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this);
QGraphicsItem::hoverEnterEvent(event); 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);
}
#ifndef CARDITEM_H #ifndef CARDITEM_H
#define CARDITEM_H #define CARDITEM_H
#include "abstractgraphicsitem.h" #include "abstractcarditem.h"
class CardDatabase; class CardDatabase;
class CardDragItem; class CardDragItem;
class CardZone; class CardZone;
class CardInfo;
const int CARD_WIDTH = 72;
const int CARD_HEIGHT = 102;
const int MAX_COUNTERS_ON_CARD = 999; const int MAX_COUNTERS_ON_CARD = 999;
enum CardItemType { class CardItem : public AbstractCardItem {
typeCard = QGraphicsItem::UserType + 1,
typeCardDrag = QGraphicsItem::UserType + 2,
typeZone = QGraphicsItem::UserType + 3,
typeOther = QGraphicsItem::UserType + 4
};
class CardItem : public QObject, public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
CardInfo *info;
QString name;
int id; int id;
bool tapped;
bool attacking; bool attacking;
bool facedown; bool facedown;
int counters; int counters;
...@@ -34,23 +20,16 @@ private: ...@@ -34,23 +20,16 @@ private:
bool doesntUntap; bool doesntUntap;
QPoint gridPoint; QPoint gridPoint;
CardDragItem *dragItem; CardDragItem *dragItem;
private slots:
void pixmapUpdated();
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } int type() const { return Type; }
CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0); CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
~CardItem(); ~CardItem();
QRectF boundingRect() const;
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; }
int getId() const { return id; } int getId() const { return id; }
void setId(int _id) { id = _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; } bool getAttacking() const { return attacking; }
void setAttacking(bool _attacking); void setAttacking(bool _attacking);
bool getFaceDown() const { return facedown; } bool getFaceDown() const { return facedown; }
...@@ -66,12 +45,10 @@ public: ...@@ -66,12 +45,10 @@ public:
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();
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
}; };
#endif #endif
#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);
}
#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() ...@@ -212,6 +212,7 @@ Player::~Player()
void Player::updateBoundingRect() void Player::updateBoundingRect()
{ {
// XXX! PREPARE GEOMETRY CHANGE
bRect = QRectF(0, 0, CARD_WIDTH + 5 + counterAreaWidth + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height()); bRect = QRectF(0, 0, CARD_WIDTH + 5 + counterAreaWidth + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
emit sizeChanged(); emit sizeChanged();
} }
......
...@@ -25,6 +25,10 @@ TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName) ...@@ -25,6 +25,10 @@ TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
setLayout(hbox); setLayout(hbox);
} }
void TabChatChannel::retranslateUi()
{
}
void TabChatChannel::sendMessage() void TabChatChannel::sendMessage()
{ {
if (sayEdit->text().isEmpty()) if (sayEdit->text().isEmpty())
......
...@@ -31,6 +31,7 @@ private slots: ...@@ -31,6 +31,7 @@ private slots:
void processSayEvent(Event_ChatSay *event); void processSayEvent(Event_ChatSay *event);
public: public:
TabChatChannel(Client *_client, const QString &_channelName); TabChatChannel(Client *_client, const QString &_channelName);
void retranslateUi();
void processChatEvent(ChatEvent *event); void processChatEvent(ChatEvent *event);
}; };
......
...@@ -177,9 +177,8 @@ void TabDeckStorage::actUpload() ...@@ -177,9 +177,8 @@ void TabDeckStorage::actUpload()
curRight = curRight->parent(); curRight = curRight->parent();
if (curRight) if (curRight)
targetPath = curRight->data(0, Qt::UserRole).toString(); 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 *))); connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
client->sendCommand(command); client->sendCommand(command);
} }
...@@ -190,6 +189,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r) ...@@ -190,6 +189,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
if (!resp) if (!resp)
return; return;
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender()); Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
delete cmd->getDeck();
QTreeWidgetItemIterator it(serverDirView); QTreeWidgetItemIterator it(serverDirView);
while (*it) { while (*it) {
...@@ -264,7 +264,6 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp) ...@@ -264,7 +264,6 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
QTreeWidgetItemIterator it(serverDirView); QTreeWidgetItemIterator it(serverDirView);
while (*it) { while (*it) {
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) { if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
qDebug() << "gefunden";
QFileIconProvider fip; QFileIconProvider fip;
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType); QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder)); newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
...@@ -272,8 +271,7 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp) ...@@ -272,8 +271,7 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName()); newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName());
(*it)->addChild(newItem); (*it)->addChild(newItem);
break; break;
} else }
qDebug() << "path = " << (*it)->data(0, Qt::UserRole) << " nicht gefunden";
++it; ++it;
} }
} }
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "zoneviewwidget.h" #include "zoneviewwidget.h"
#include "zoneviewlayout.h" #include "zoneviewlayout.h"
#include "deckview.h"
#include "decklist.h"
#include "main.h" #include "main.h"
TabGame::TabGame(Client *_client, int _gameId) TabGame::TabGame(Client *_client, int _gameId)
...@@ -17,7 +19,15 @@ TabGame::TabGame(Client *_client, int _gameId) ...@@ -17,7 +19,15 @@ TabGame::TabGame(Client *_client, int _gameId)
{ {
zoneLayout = new ZoneViewLayout; zoneLayout = new ZoneViewLayout;
scene = new GameScene(zoneLayout, this); 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); cardInfo = new CardInfoWidget(db);
messageLog = new MessageLogWidget; messageLog = new MessageLogWidget;
...@@ -30,6 +40,7 @@ TabGame::TabGame(Client *_client, int _gameId) ...@@ -30,6 +40,7 @@ TabGame::TabGame(Client *_client, int _gameId)
hLayout->addWidget(sayEdit); hLayout->addWidget(sayEdit);
phasesToolbar = new PhasesToolbar; phasesToolbar = new PhasesToolbar;
phasesToolbar->hide();
QVBoxLayout *verticalLayout = new QVBoxLayout; QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo); verticalLayout->addWidget(cardInfo);
...@@ -38,11 +49,14 @@ TabGame::TabGame(Client *_client, int _gameId) ...@@ -38,11 +49,14 @@ TabGame::TabGame(Client *_client, int _gameId)
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(phasesToolbar); mainLayout->addWidget(phasesToolbar);
mainLayout->addWidget(view, 10); mainLayout->addWidget(gameView, 10);
mainLayout->addWidget(deckView, 10);
mainLayout->addLayout(verticalLayout); 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(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int))); // connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
...@@ -60,7 +74,21 @@ TabGame::TabGame(Client *_client, int _gameId) ...@@ -60,7 +74,21 @@ TabGame::TabGame(Client *_client, int _gameId)
messageLog->connectToGame(game); messageLog->connectToGame(game);
game->queryGameState(); 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) void TabGame::processGameEvent(GameEvent *event)
{ {
......
...@@ -7,6 +7,7 @@ class Client; ...@@ -7,6 +7,7 @@ class Client;
class CardDatabase; class CardDatabase;
class GameEvent; class GameEvent;
class GameView; class GameView;
class DeckView;
class GameScene; class GameScene;
class Game; class Game;
class CardInfoWidget; class CardInfoWidget;
...@@ -30,12 +31,15 @@ private: ...@@ -30,12 +31,15 @@ private:
QLineEdit *sayEdit; QLineEdit *sayEdit;
PhasesToolbar *phasesToolbar; PhasesToolbar *phasesToolbar;
GameScene *scene; GameScene *scene;
GameView *view; GameView *gameView;
DeckView *deckView;
Game *game; Game *game;
ZoneViewLayout *zoneLayout; ZoneViewLayout *zoneLayout;
QAction *aCloseMostRecentZoneView;
private slots: private slots:
public: public:
TabGame(Client *_client, int _gameId); TabGame(Client *_client, int _gameId);
void retranslateUi();
void processGameEvent(GameEvent *event); void processGameEvent(GameEvent *event);
}; };
......
...@@ -244,3 +244,10 @@ TabServer::TabServer(Client *_client, QWidget *parent) ...@@ -244,3 +244,10 @@ TabServer::TabServer(Client *_client, QWidget *parent)
setLayout(mainLayout); setLayout(mainLayout);
} }
void TabServer::retranslateUi()
{
gameSelector->retranslateUi();
chatChannelSelector->retranslateUi();
serverMessageLog->retranslateUi();
}
...@@ -83,6 +83,7 @@ private: ...@@ -83,6 +83,7 @@ private:
ServerMessageLog *serverMessageLog; ServerMessageLog *serverMessageLog;
public: public:
TabServer(Client *_client, QWidget *parent = 0); TabServer(Client *_client, QWidget *parent = 0);
void retranslateUi();
}; };
#endif #endif
...@@ -14,10 +14,22 @@ TabSupervisor:: TabSupervisor(QWidget *parent) ...@@ -14,10 +14,22 @@ TabSupervisor:: TabSupervisor(QWidget *parent)
void TabSupervisor::retranslateUi() void TabSupervisor::retranslateUi()
{ {
if (tabServer) if (tabServer) {
setTabText(0, tr("Server")); setTabText(0, tr("Server"));
if (tabDeckStorage) tabServer->retranslateUi();
}
if (tabDeckStorage) {
setTabText(1, tr("Deck storage")); 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) void TabSupervisor::start(Client *_client)
...@@ -28,7 +40,6 @@ 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 *))); connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
tabServer = new TabServer(client); tabServer = new TabServer(client);
connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int)));
connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &))); connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &)));
addTab(tabServer, QString()); addTab(tabServer, QString());
......
...@@ -201,20 +201,9 @@ void MainWindow::retranslateUi() ...@@ -201,20 +201,9 @@ void MainWindow::retranslateUi()
aFullScreen->setShortcut(tr("Ctrl+F")); aFullScreen->setShortcut(tr("Ctrl+F"));
aSettings->setText(tr("&Settings...")); aSettings->setText(tr("&Settings..."));
aExit->setText(tr("&Exit")); aExit->setText(tr("&Exit"));
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
cockatriceMenu->setTitle(tr("&Cockatrice")); cockatriceMenu->setTitle(tr("&Cockatrice"));
/* }
sayLabel->setText(tr("&Say:"));
cardInfo->retranslateUi();
chatWidget->retranslateUi();
gameSelector->retranslateUi();
if (game)
game->retranslateUi();
zoneLayout->retranslateUi();
*/}
void MainWindow::createActions() void MainWindow::createActions()
{ {
...@@ -238,10 +227,6 @@ void MainWindow::createActions() ...@@ -238,10 +227,6 @@ void MainWindow::createActions()
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings())); connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
aExit = new QAction(this); aExit = new QAction(this);
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit())); connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
aCloseMostRecentZoneView = new QAction(this);
// connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
addAction(aCloseMostRecentZoneView);
} }
void MainWindow::createMenus() void MainWindow::createMenus()
......
...@@ -61,7 +61,6 @@ private: ...@@ -61,7 +61,6 @@ private:
void createMenus(); void createMenus();
QMenu *cockatriceMenu; QMenu *cockatriceMenu;
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
QAction *aCloseMostRecentZoneView;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
PingWidget *pingWidget; PingWidget *pingWidget;
......
...@@ -26,14 +26,19 @@ InnerDecklistNode::~InnerDecklistNode() ...@@ -26,14 +26,19 @@ InnerDecklistNode::~InnerDecklistNode()
clearTree(); clearTree();
} }
QString InnerDecklistNode::getVisibleName() const QString InnerDecklistNode::visibleNameFromName(const QString &_name)
{ {
if (name == "main") if (_name == "main")
return QObject::tr("Maindeck"); return QObject::tr("Maindeck");
else if (name == "side") else if (_name == "side")
return QObject::tr("Sideboard"); return QObject::tr("Sideboard");
else else
return getName(); return _name;
}
QString InnerDecklistNode::getVisibleName() const
{
return visibleNameFromName(name);
} }
void InnerDecklistNode::clearTree() void InnerDecklistNode::clearTree()
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
virtual ~InnerDecklistNode(); virtual ~InnerDecklistNode();
QString getName() const { return name; } QString getName() const { return name; }
void setName(const QString &_name) { name = _name; } void setName(const QString &_name) { name = _name; }
static QString visibleNameFromName(const QString &_name);
virtual QString getVisibleName() const; virtual QString getVisibleName() const;
void clearTree(); void clearTree();
AbstractDecklistNode *findChild(const QString &name); AbstractDecklistNode *findChild(const QString &name);
......
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