Commit 1bc48a78 authored by Matt Kelly's avatar Matt Kelly
Browse files

Convert rest of source to 4-space indent

parent a171df74
......@@ -5,47 +5,47 @@
#include <QDebug>
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
{
if (parentDrag) {
parentDrag->addChildDrag(this);
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
} else {
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF();
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
}
setCursor(Qt::ClosedHandCursor);
setZValue(2000000007);
}
if (item->getTapped())
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
if (parentDrag) {
parentDrag->addChildDrag(this);
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
} else {
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF();
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
}
setCursor(Qt::ClosedHandCursor);
setZValue(2000000007);
}
if (item->getTapped())
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
setCacheMode(DeviceCoordinateCache);
setCacheMode(DeviceCoordinateCache);
}
AbstractCardDragItem::~AbstractCardDragItem()
{
qDebug("CardDragItem destructor");
for (int i = 0; i < childDrags.size(); i++)
delete childDrags[i];
qDebug("CardDragItem destructor");
for (int i = 0; i < childDrags.size(); i++)
delete childDrags[i];
}
void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
item->paint(painter, option, widget);
item->paint(painter, option, widget);
}
void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
updatePosition(event->scenePos());
event->accept();
updatePosition(event->scenePos());
}
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
{
childDrags << child;
childDrags << child;
}
......@@ -8,24 +8,24 @@ class CardZone;
class CardInfo;
class AbstractCardDragItem : public QObject, public QGraphicsItem {
Q_OBJECT
Q_OBJECT
protected:
AbstractCardItem *item;
QPointF hotSpot;
QList<AbstractCardDragItem *> childDrags;
AbstractCardItem *item;
QPointF hotSpot;
QList<AbstractCardDragItem *> childDrags;
public:
enum { Type = typeCardDrag };
int type() const { return Type; }
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
~AbstractCardDragItem();
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
AbstractCardItem *getItem() const { return item; }
QPointF getHotSpot() const { return hotSpot; }
void addChildDrag(AbstractCardDragItem *child);
virtual void updatePosition(const QPointF &cursorScenePos) = 0;
enum { Type = typeCardDrag };
int type() const { return Type; }
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
~AbstractCardDragItem();
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
AbstractCardItem *getItem() const { return item; }
QPointF getHotSpot() const { return hotSpot; }
void addChildDrag(AbstractCardDragItem *child);
virtual void updatePosition(const QPointF &cursorScenePos) = 0;
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
};
#endif
......@@ -12,245 +12,245 @@
#include <QDebug>
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
: ArrowTarget(_owner, parent), infoWidget(0), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), isHovered(false), realZValue(0)
: ArrowTarget(_owner, parent), infoWidget(0), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), isHovered(false), realZValue(0)
{
setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable);
setCacheMode(DeviceCoordinateCache);
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
cardInfoUpdated();
setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable);
setCacheMode(DeviceCoordinateCache);
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
cardInfoUpdated();
}
AbstractCardItem::~AbstractCardItem()
{
emit deleteCardInfoPopup(name);
emit deleteCardInfoPopup(name);
}
QRectF AbstractCardItem::boundingRect() const
{
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
}
void AbstractCardItem::pixmapUpdated()
{
update();
emit sigPixmapUpdated();
update();
emit sigPixmapUpdated();
}
void AbstractCardItem::cardInfoUpdated()
{
info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
}
void AbstractCardItem::setRealZValue(qreal _zValue)
{
realZValue = _zValue;
setZValue(_zValue);
realZValue = _zValue;
setZValue(_zValue);
}
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
{
return QSizeF(
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
);
return QSizeF(
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
);
}
void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
{
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
painter->resetTransform();
QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform);
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
painter->resetTransform();
QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform);
QFont f;
int fontSize = round(translatedSize.height() / 8);
if (fontSize < 9)
fontSize = 9;
if (fontSize > 10)
fontSize = 10;
f.setPixelSize(fontSize);
QFont f;
int fontSize = round(translatedSize.height() / 8);
if (fontSize < 9)
fontSize = 9;
if (fontSize > 10)
fontSize = 10;
f.setPixelSize(fontSize);
painter->setFont(f);
painter->setFont(f);
}
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
{
qreal scaleFactor = translatedSize.width() / boundingRect().width();
CardInfo *imageSource = facedown ? db->getCard() : info;
QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
painter->save();
QColor bgColor = Qt::transparent;
if (translatedPixmap) {
painter->save();
transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
painter->restore();
} else {
QString colorStr;
if (!color.isEmpty())
colorStr = color;
else if (info->getColors().size() > 1)
colorStr = "m";
else if (!info->getColors().isEmpty())
colorStr = info->getColors().first().toLower();
if (colorStr == "b")
bgColor = QColor(0, 0, 0);
else if (colorStr == "u")
bgColor = QColor(0, 140, 180);
else if (colorStr == "w")
bgColor = QColor(255, 250, 140);
else if (colorStr == "r")
bgColor = QColor(230, 0, 0);
else if (colorStr == "g")
bgColor = QColor(0, 160, 0);
else if (colorStr == "m")
bgColor = QColor(250, 190, 30);
else
bgColor = QColor(230, 230, 230);
}
painter->setBrush(bgColor);
QPen pen(Qt::black);
pen.setWidth(2);
painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
painter->save();
transformPainter(painter, translatedSize, angle);
painter->setPen(Qt::white);
painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode);
QString nameStr;
if (facedown)
nameStr = "# " + QString::number(id);
else
nameStr = name;
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr);
painter->restore();
}
painter->restore();
qreal scaleFactor = translatedSize.width() / boundingRect().width();
CardInfo *imageSource = facedown ? db->getCard() : info;
QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
painter->save();
QColor bgColor = Qt::transparent;
if (translatedPixmap) {
painter->save();
transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
painter->restore();
} else {
QString colorStr;
if (!color.isEmpty())
colorStr = color;
else if (info->getColors().size() > 1)
colorStr = "m";
else if (!info->getColors().isEmpty())
colorStr = info->getColors().first().toLower();
if (colorStr == "b")
bgColor = QColor(0, 0, 0);
else if (colorStr == "u")
bgColor = QColor(0, 140, 180);
else if (colorStr == "w")
bgColor = QColor(255, 250, 140);
else if (colorStr == "r")
bgColor = QColor(230, 0, 0);
else if (colorStr == "g")
bgColor = QColor(0, 160, 0);
else if (colorStr == "m")
bgColor = QColor(250, 190, 30);
else
bgColor = QColor(230, 230, 230);
}
painter->setBrush(bgColor);
QPen pen(Qt::black);
pen.setWidth(2);
painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
painter->save();
transformPainter(painter, translatedSize, angle);
painter->setPen(Qt::white);
painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode);
QString nameStr;
if (facedown)
nameStr = "# " + QString::number(id);
else
nameStr = name;
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr);
painter->restore();
}
painter->restore();
}
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
painter->save();
painter->save();
QSizeF translatedSize = getTranslatedSize(painter);
paintPicture(painter, translatedSize, tapAngle);
painter->save();
painter->setRenderHint(QPainter::Antialiasing, false);
transformPainter(painter, translatedSize, tapAngle);
if (isSelected()) {
painter->setPen(Qt::red);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
} else if (isHovered) {
painter->setPen(Qt::yellow);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
}
painter->restore();
QSizeF translatedSize = getTranslatedSize(painter);
paintPicture(painter, translatedSize, tapAngle);
painter->save();
painter->setRenderHint(QPainter::Antialiasing, false);
transformPainter(painter, translatedSize, tapAngle);
if (isSelected()) {
painter->setPen(Qt::red);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
} else if (isHovered) {
painter->setPen(Qt::yellow);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
}
painter->restore();
painter->restore();
painter->restore();
}
void AbstractCardItem::setName(const QString &_name)
{
if (name == _name)
return;
emit deleteCardInfoPopup(name);
disconnect(info, 0, this, 0);
name = _name;
info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
update();
if (name == _name)
return;
emit deleteCardInfoPopup(name);
disconnect(info, 0, this, 0);
name = _name;
info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
update();
}
void AbstractCardItem::setHovered(bool _hovered)
{
if (isHovered == _hovered)
return;
if (_hovered)
processHoverEvent();
isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue);
update();
if (isHovered == _hovered)
return;
if (_hovered)
processHoverEvent();
isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue);
update();
}
void AbstractCardItem::setColor(const QString &_color)
{
color = _color;
update();
color = _color;
update();
}
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
{
if (tapped == _tapped)
return;
tapped = _tapped;
if (settingsCache->getTapAnimation() && canAnimate)
static_cast<GameScene *>(scene())->registerAnimationItem(this);
else {
tapAngle = tapped ? 90 : 0;
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
update();
}
if (tapped == _tapped)
return;
tapped = _tapped;
if (settingsCache->getTapAnimation() && canAnimate)
static_cast<GameScene *>(scene())->registerAnimationItem(this);
else {
tapAngle = tapped ? 90 : 0;
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
update();
}
}
void AbstractCardItem::setFaceDown(bool _facedown)
{
facedown = _facedown;
update();
emit updateCardMenu(this);
facedown = _facedown;
update();
emit updateCardMenu(this);
}
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!isSelected()) {
scene()->clearSelection();
setSelected(true);
}
if (event->button() == Qt::LeftButton)
setCursor(Qt::ClosedHandCursor);
else if (event->button() == Qt::MidButton)
emit showCardInfoPopup(event->screenPos(), name);
event->accept();
if (!isSelected()) {
scene()->clearSelection();
setSelected(true);
}
if (event->button() == Qt::LeftButton)
setCursor(Qt::ClosedHandCursor);
else if (event->button() == Qt::MidButton)
emit showCardInfoPopup(event->screenPos(), name);
event->accept();
}
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::MidButton)
emit deleteCardInfoPopup(name);
// This function ensures the parent function doesn't mess around with our selection.
event->accept();
if (event->button() == Qt::MidButton)
emit deleteCardInfoPopup(name);
// This function ensures the parent function doesn't mess around with our selection.
event->accept();
}
void AbstractCardItem::processHoverEvent()
{
emit hovered(this);
emit hovered(this);
}
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change == ItemSelectedHasChanged) {
update();
return value;
} else
return QGraphicsItem::itemChange(change, value);
if (change == ItemSelectedHasChanged) {
update();
return value;
} else
return QGraphicsItem::itemChange(change, value);
}
......@@ -12,59 +12,59 @@ const int CARD_WIDTH = 72;
const int CARD_HEIGHT = 102;
class AbstractCardItem : public ArrowTarget {
Q_OBJECT
Q_OBJECT
protected:
CardInfo *info;
CardInfoWidget *infoWidget;
int id;
QString name;
bool tapped;
bool facedown;
int tapAngle;
QString color;
CardInfo *info;
CardInfoWidget *infoWidget;
int id;
QString name;
bool tapped;
bool facedown;
int tapAngle;
QString color;
private:
bool isHovered;
qreal realZValue;
bool isHovered;
qreal realZValue;
private slots:
void pixmapUpdated();
void cardInfoUpdated();
void callUpdate() { update(); }
void pixmapUpdated();
void cardInfoUpdated();
void callUpdate() { update(); }
signals:
void hovered(AbstractCardItem *card);
void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup(QString cardName);
void updateCardMenu(AbstractCardItem *card);
void sigPixmapUpdated();
void hovered(AbstractCardItem *card);
void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup(QString cardName);
void updateCardMenu(AbstractCardItem *card);
void sigPixmapUpdated();
public:
enum { Type = typeCard };
int type() const { return Type; }
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0);
~AbstractCardItem();
QRectF boundingRect() const;
QSizeF getTranslatedSize(QPainter *painter) const;
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
CardInfo *getInfo() const { return info; }
int getId() const { return id; }
void setId(int _id) { id = _id; }
QString getName() const { return name; }
void setName(const QString &_name = QString());
qreal getRealZValue() const { return realZValue; }
void setRealZValue(qreal _zValue);
void setHovered(bool _hovered);
QString getColor() const { return color; }
void setColor(const QString &_color);
bool getTapped() const { return tapped; }
void setTapped(bool _tapped, bool canAnimate = false);
bool getFaceDown() const { return facedown; }
void setFaceDown(bool _facedown);
void processHoverEvent();
void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); }
enum { Type = typeCard };
int type() const { return Type; }
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0);
~AbstractCardItem();
QRectF boundingRect() const;
QSizeF getTranslatedSize(QPainter *painter) const;
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
CardInfo *getInfo() const { return info; }
int getId() const { return id; }
void setId(int _id) { id = _id; }
QString getName() const { return name; }
void setName(const QString &_name = QString());
qreal getRealZValue() const { return realZValue; }
void setRealZValue(qreal _zValue);
void setHovered(bool _hovered);
QString getColor() const { return color; }
void setColor(const QString &_color);
bool getTapped() const { return tapped; }
void setTapped(bool _tapped, bool canAnimate = false);
bool getFaceDown() const { return facedown; }
void setFaceDown(bool _facedown);
void processHoverEvent();
void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); }
protected:
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
};
#endif
......@@ -26,67 +26,67 @@ class Event_ServerShutdown;
class Event_ReplayAdded;
enum ClientStatus {
StatusDisconnected,
StatusDisconnecting,
StatusConnecting,
StatusAwaitingWelcome,
StatusLoggingIn,
StatusLoggedIn,
StatusDisconnected,
StatusDisconnecting,
StatusConnecting,
StatusAwaitingWelcome,
StatusLoggingIn,
StatusLoggedIn,
};
class AbstractClient : public QObject {
Q_OBJECT
Q_OBJECT
signals:
void statusChanged(ClientStatus _status);
// Room events
void roomEventReceived(const RoomEvent &event);
// Game events
void gameEventContainerReceived(const GameEventContainer &event);
// Session events
void serverIdentificationEventReceived(const Event_ServerIdentification &event);
void connectionClosedEventReceived(const Event_ConnectionClosed &event);
void serverShutdownEventReceived(const Event_ServerShutdown &event);
void addToListEventReceived(const Event_AddToList &event);
void removeFromListEventReceived(const Event_RemoveFromList &event);
void userJoinedEventReceived(const Event_UserJoined &event);
void userLeftEventReceived(const Event_UserLeft &event);
void serverMessageEventReceived(const Event_ServerMessage &event);
void listRoomsEventReceived(const Event_ListRooms &event);
void gameJoinedEventReceived(const Event_GameJoined &event);
void userMessageEventReceived(const Event_UserMessage &event);
void userInfoChanged(const ServerInfo_User &userInfo);
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
void replayAddedEventReceived(const Event_ReplayAdded &event);
void sigQueuePendingCommand(PendingCommand *pend);
void statusChanged(ClientStatus _status);
// Room events
void roomEventReceived(const RoomEvent &event);
// Game events
void gameEventContainerReceived(const GameEventContainer &event);
// Session events
void serverIdentificationEventReceived(const Event_ServerIdentification &event);
void connectionClosedEventReceived(const Event_ConnectionClosed &event);
void serverShutdownEventReceived(const Event_ServerShutdown &event);
void addToListEventReceived(const Event_AddToList &event);
void removeFromListEventReceived(const Event_RemoveFromList &event);
void userJoinedEventReceived(const Event_UserJoined &event);
void userLeftEventReceived(const Event_UserLeft &event);
void serverMessageEventReceived(const Event_ServerMessage &event);
void listRoomsEventReceived(const Event_ListRooms &event);
void gameJoinedEventReceived(const Event_GameJoined &event);
void userMessageEventReceived(const Event_UserMessage &event);
void userInfoChanged(const ServerInfo_User &userInfo);
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
void replayAddedEventReceived(const Event_ReplayAdded &event);
void sigQueuePendingCommand(PendingCommand *pend);
private:
int nextCmdId;
mutable QMutex clientMutex;
ClientStatus status;
int nextCmdId;
mutable QMutex clientMutex;
ClientStatus status;
private slots:
void queuePendingCommand(PendingCommand *pend);
void queuePendingCommand(PendingCommand *pend);
protected slots:
void processProtocolItem(const ServerMessage &item);
void processProtocolItem(const ServerMessage &item);
protected:
QMap<int, PendingCommand *> pendingCommands;
QString userName, password;
void setStatus(ClientStatus _status);
int getNewCmdId() { return nextCmdId++; }
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
QMap<int, PendingCommand *> pendingCommands;
QString userName, password;
void setStatus(ClientStatus _status);
int getNewCmdId() { return nextCmdId++; }
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
public:
AbstractClient(QObject *parent = 0);
~AbstractClient();
ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; }
void sendCommand(const CommandContainer &cont);
void sendCommand(PendingCommand *pend);
static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
AbstractClient(QObject *parent = 0);
~AbstractClient();
ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; }
void sendCommand(const CommandContainer &cont);
void sendCommand(PendingCommand *pend);
static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
};
#endif
......@@ -9,137 +9,137 @@
#include "pb/command_set_counter.pb.h"
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
{
setAcceptsHoverEvents(true);
if (player->getLocal()) {
menu = new QMenu(name);
aSet = new QAction(this);
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
menu->addAction(aSet);
menu->addSeparator();
for (int i = -10; i <= 10; ++i)
if (i == 0)
menu->addSeparator();
else {
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
if (i == -1)
aDec = aIncrement;
else if (i == 1)
aInc = aIncrement;
aIncrement->setData(i);
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
menu->addAction(aIncrement);
}
} else
menu = 0;
retranslateUi();
setAcceptsHoverEvents(true);
if (player->getLocal()) {
menu = new QMenu(name);
aSet = new QAction(this);
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
menu->addAction(aSet);
menu->addSeparator();
for (int i = -10; i <= 10; ++i)
if (i == 0)
menu->addSeparator();
else {
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
if (i == -1)
aDec = aIncrement;
else if (i == 1)
aInc = aIncrement;
aIncrement->setData(i);
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
menu->addAction(aIncrement);
}
} else
menu = 0;
retranslateUi();
}
AbstractCounter::~AbstractCounter()
{
delete menu;
delete menu;
}
void AbstractCounter::delCounter()
{
if (dialogSemaphore)
deleteAfterDialog = true;
else
deleteLater();
if (dialogSemaphore)
deleteAfterDialog = true;
else
deleteLater();
}
void AbstractCounter::retranslateUi()
{
if (menu) {
aSet->setText(tr("&Set counter..."));
}
if (menu) {
aSet->setText(tr("&Set counter..."));
}
}
void AbstractCounter::setShortcutsActive()
{
if (name == "life") {
aSet->setShortcut(tr("Ctrl+L"));
aDec->setShortcut(tr("F11"));
aInc->setShortcut(tr("F12"));
}
if (name == "life") {
aSet->setShortcut(tr("Ctrl+L"));
aDec->setShortcut(tr("F11"));
aInc->setShortcut(tr("F12"));
}
}
void AbstractCounter::setShortcutsInactive()
{
if (name == "life") {
aSet->setShortcut(QKeySequence());
aDec->setShortcut(QKeySequence());
aInc->setShortcut(QKeySequence());
}
if (name == "life") {
aSet->setShortcut(QKeySequence());
aDec->setShortcut(QKeySequence());
aInc->setShortcut(QKeySequence());
}
}
void AbstractCounter::setValue(int _value)
{
value = _value;
update();
value = _value;
update();
}
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(1);
player->sendGameCommand(cmd);
event->accept();
} else if (event->button() == Qt::RightButton) {
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(-1);
player->sendGameCommand(cmd);
event->accept();
} else if (event->button() == Qt::MidButton) {
if (menu)
menu->exec(event->screenPos());
event->accept();
} else
event->ignore();
if (event->button() == Qt::LeftButton) {
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(1);
player->sendGameCommand(cmd);
event->accept();
} else if (event->button() == Qt::RightButton) {
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(-1);
player->sendGameCommand(cmd);
event->accept();
} else if (event->button() == Qt::MidButton) {
if (menu)
menu->exec(event->screenPos());
event->accept();
} else
event->ignore();
}
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
{
hovered = true;
update();
hovered = true;
update();
}
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
{
hovered = false;
update();
hovered = false;
update();
}
void AbstractCounter::incrementCounter()
{
const int delta = static_cast<QAction *>(sender())->data().toInt();
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(delta);
player->sendGameCommand(cmd);
const int delta = static_cast<QAction *>(sender())->data().toInt();
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(delta);
player->sendGameCommand(cmd);
}
void AbstractCounter::setCounter()
{
bool ok;
dialogSemaphore = true;
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
if (deleteAfterDialog) {
deleteLater();
return;
}
dialogSemaphore = false;
if (!ok)
return;
Command_SetCounter cmd;
cmd.set_counter_id(id);
cmd.set_value(newValue);
player->sendGameCommand(cmd);
bool ok;
dialogSemaphore = true;
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
if (deleteAfterDialog) {
deleteLater();
return;
}
dialogSemaphore = false;
if (!ok)
return;
Command_SetCounter cmd;
cmd.set_counter_id(id);
cmd.set_value(newValue);
player->sendGameCommand(cmd);
}
......@@ -8,41 +8,41 @@ class QMenu;
class QAction;
class AbstractCounter : public QObject, public QGraphicsItem {
Q_OBJECT
Q_OBJECT
protected:
Player *player;
int id;
QString name;
int value;
bool hovered;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
Player *player;
int id;
QString name;
int value;
bool hovered;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
private:
QAction *aSet, *aDec, *aInc;
QMenu *menu;
bool dialogSemaphore, deleteAfterDialog;
bool shownInCounterArea;
QAction *aSet, *aDec, *aInc;
QMenu *menu;
bool dialogSemaphore, deleteAfterDialog;
bool shownInCounterArea;
private slots:
void incrementCounter();
void setCounter();
void incrementCounter();
void setCounter();
public:
AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0);
~AbstractCounter();
QMenu *getMenu() const { return menu; }
void retranslateUi();
int getId() const { return id; }
QString getName() const { return name; }
bool getShownInCounterArea() const { return shownInCounterArea; }
int getValue() const { return value; }
void setValue(int _value);
void delCounter();
void setShortcutsActive();
void setShortcutsInactive();
AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0);
~AbstractCounter();
QMenu *getMenu() const { return menu; }
void retranslateUi();
int getId() const { return id; }
QString getName() const { return name; }
bool getShownInCounterArea() const { return shownInCounterArea; }
int getValue() const { return value; }
void setValue(int _value);
void delCounter();
void setShortcutsActive();
void setShortcutsInactive();
};
#endif
......@@ -3,48 +3,48 @@
void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, int count, QPainter *painter)
{
painter->save();
painter->save();
QString numStr = QString::number(number);
QFont font("Serif");
font.setPixelSize(fontSize);
font.setWeight(QFont::Bold);
QFontMetrics fm(font);
double w = fm.width(numStr) * 1.3;
double h = fm.height() * 1.3;
if (w < h)
w = h;
QString numStr = QString::number(number);
QFont font("Serif");
font.setPixelSize(fontSize);
font.setWeight(QFont::Bold);
QFontMetrics fm(font);
double w = fm.width(numStr) * 1.3;
double h = fm.height() * 1.3;
if (w < h)
w = h;
painter->setPen(QColor(255, 255, 255, 0));
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
QColor color1(color), color2(color);
color1.setAlpha(255);
color2.setAlpha(0);
grad.setColorAt(0, color1);
grad.setColorAt(0.8, color1);
grad.setColorAt(1, color2);
painter->setBrush(QBrush(grad));
QRectF textRect;
if (position == -1)
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
else {
qreal xOffset = 10;
qreal yOffset = 20;
qreal spacing = 2;
if (position < 2)
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h);
else
textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset + (spacing + h) * (position / 2), w, h);
}
painter->drawEllipse(textRect);
painter->setPen(QColor(255, 255, 255, 0));
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
QColor color1(color), color2(color);
color1.setAlpha(255);
color2.setAlpha(0);
grad.setColorAt(0, color1);
grad.setColorAt(0.8, color1);
grad.setColorAt(1, color2);
painter->setBrush(QBrush(grad));
QRectF textRect;
if (position == -1)
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
else {
qreal xOffset = 10;
qreal yOffset = 20;
qreal spacing = 2;
if (position < 2)
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h);
else
textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset + (spacing + h) * (position / 2), w, h);
}
painter->drawEllipse(textRect);
painter->setPen(Qt::black);
painter->setFont(font);
painter->drawText(textRect, Qt::AlignCenter, numStr);
painter->setPen(Qt::black);
painter->setFont(font);
painter->drawText(textRect, Qt::AlignCenter, numStr);
painter->restore();
painter->restore();
}
......@@ -4,20 +4,20 @@
#include <QGraphicsItem>
enum GraphicsItemType {
typeCard = QGraphicsItem::UserType + 1,
typeCardDrag = QGraphicsItem::UserType + 2,
typeZone = QGraphicsItem::UserType + 3,
typePlayerTarget = QGraphicsItem::UserType + 4,
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
typeOther = QGraphicsItem::UserType + 6
typeCard = QGraphicsItem::UserType + 1,
typeCardDrag = QGraphicsItem::UserType + 2,
typeZone = QGraphicsItem::UserType + 3,
typePlayerTarget = QGraphicsItem::UserType + 4,
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
typeOther = QGraphicsItem::UserType + 6
};
class AbstractGraphicsItem : public QObject, public QGraphicsItem {
Q_OBJECT
Q_OBJECT
protected:
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
public:
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { }
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { }
};
#endif
......@@ -17,127 +17,127 @@
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
{
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
setZValue(2000000005);
if (startItem)
startItem->addArrowFrom(this);
if (targetItem)
targetItem->addArrowTo(this);
if (startItem && targetItem)
updatePath();
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
setZValue(2000000005);
if (startItem)
startItem->addArrowFrom(this);
if (targetItem)
targetItem->addArrowTo(this);
if (startItem && targetItem)
updatePath();
}
ArrowItem::~ArrowItem()
{
qDebug() << "ArrowItem destructor";
qDebug() << "ArrowItem destructor";
}
void ArrowItem::delArrow()
{
if (startItem) {
startItem->removeArrowFrom(this);
startItem = 0;
}
if (targetItem) {
targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this);
targetItem = 0;
}
player->removeArrow(this);
deleteLater();
if (startItem) {
startItem->removeArrowFrom(this);
startItem = 0;
}
if (targetItem) {
targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this);
targetItem = 0;
}
player->removeArrow(this);
deleteLater();
}
void ArrowItem::updatePath()
{
if (!targetItem)
return;
QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
updatePath(endPoint);
if (!targetItem)
return;
QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
updatePath(endPoint);
}
void ArrowItem::updatePath(const QPointF &endPoint)
{
const double arrowWidth = 15.0;
const double headWidth = 40.0;
const double headLength = headWidth / sqrt(2);
const double phi = 15;
if (!startItem)
return;
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
QLineF line(startPoint, endPoint);
qreal lineLength = line.length();
prepareGeometryChange();
if (lineLength < 30)
path = QPainterPath();
else {
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
QPainterPath centerLine;
centerLine.moveTo(0, 0);
centerLine.quadTo(c, QPointF(lineLength, 0));
double percentage = 1 - headLength / lineLength;
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
qreal alpha = testLine.angle() - 90;
QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.quadTo(c, endPoint1);
path.lineTo(point1);
path.lineTo(QPointF(lineLength, 0));
path.lineTo(point2);
path.lineTo(endPoint2);
path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
}
setPos(startPoint);
setTransform(QTransform().rotate(-line.angle()));
const double arrowWidth = 15.0;
const double headWidth = 40.0;
const double headLength = headWidth / sqrt(2);
const double phi = 15;
if (!startItem)
return;
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
QLineF line(startPoint, endPoint);
qreal lineLength = line.length();
prepareGeometryChange();
if (lineLength < 30)
path = QPainterPath();
else {
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
QPainterPath centerLine;
centerLine.moveTo(0, 0);
centerLine.quadTo(c, QPointF(lineLength, 0));
double percentage = 1 - headLength / lineLength;
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
qreal alpha = testLine.angle() - 90;
QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.quadTo(c, endPoint1);
path.lineTo(point1);
path.lineTo(QPointF(lineLength, 0));
path.lineTo(point2);
path.lineTo(endPoint2);
path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
}
setPos(startPoint);
setTransform(QTransform().rotate(-line.angle()));
}
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
QColor paintColor(color);
if (fullColor)
paintColor.setAlpha(200);
else
paintColor.setAlpha(150);
painter->setBrush(paintColor);
painter->drawPath(path);
QColor paintColor(color);
if (fullColor)
paintColor.setAlpha(200);
else
paintColor.setAlpha(150);
painter->setBrush(paintColor);
painter->drawPath(path);
}
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!player->getLocal()) {
event->ignore();
return;
}
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
for (int i = 0; i < colliding.size(); ++i)
if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
event->ignore();
return;
}
event->accept();
if (event->button() == Qt::RightButton) {
Command_DeleteArrow cmd;
cmd.set_arrow_id(id);
player->sendGameCommand(cmd);
}
if (!player->getLocal()) {
event->ignore();
return;
}
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
for (int i = 0; i < colliding.size(); ++i)
if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
event->ignore();
return;
}
event->accept();
if (event->button() == Qt::RightButton) {
Command_DeleteArrow cmd;
cmd.set_arrow_id(id);
player->sendGameCommand(cmd);
}
}
ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color)
......@@ -147,85 +147,85 @@ ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QCol
void ArrowDragItem::addChildArrow(ArrowDragItem *childArrow)
{
childArrows.append(childArrow);
childArrows.append(childArrow);
}
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
// This ensures that if a mouse move event happens after a call to delArrow(),
// the event will be discarded as it would create some stray pointers.
if (!startItem)
return;
QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue();
}
if ((cursorItem != targetItem) && targetItem) {
targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this);
}
// This ensures that if a mouse move event happens after a call to delArrow(),
// the event will be discarded as it would create some stray pointers.
if (!startItem)
return;
QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue();
}
if ((cursorItem != targetItem) && targetItem) {
targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this);
}
if (!cursorItem) {
fullColor = false;
targetItem = 0;
updatePath(endPos);
} else {
if (cursorItem != targetItem) {
fullColor = true;
if (cursorItem != startItem) {
cursorItem->setBeingPointedAt(true);
cursorItem->addArrowTo(this);
}
targetItem = cursorItem;
}
updatePath();
}
update();
for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseMoveEvent(event);
fullColor = false;
targetItem = 0;
updatePath(endPos);
} else {
if (cursorItem != targetItem) {
fullColor = true;
if (cursorItem != startItem) {
cursorItem->setBeingPointedAt(true);
cursorItem->addArrowTo(this);
}
targetItem = cursorItem;
}
updatePath();
}
update();
for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseMoveEvent(event);
}
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (!startItem)
return;
if (targetItem && (targetItem != startItem)) {
CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
// For now, we can safely assume that the start item is always a card.
// The target item can be a player as well.
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
if (!startItem)
return;
if (targetItem && (targetItem != startItem)) {
CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
// For now, we can safely assume that the start item is always a card.
// The target item can be a player as well.
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
Command_CreateArrow cmd;
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_start_card_id(startCard->getId());
Command_CreateArrow cmd;
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_start_card_id(startCard->getId());
if (targetCard) {
CardZone *targetZone = targetCard->getZone();
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
} else {
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
cmd.set_target_player_id(targetPlayer->getOwner()->getId());
}
player->sendGameCommand(cmd);
}
delArrow();
if (targetCard) {
CardZone *targetZone = targetCard->getZone();
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
} else {
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
cmd.set_target_player_id(targetPlayer->getOwner()->getId());
}
player->sendGameCommand(cmd);
}
delArrow();
for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseReleaseEvent(event);
for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseReleaseEvent(event);
}
ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
......@@ -235,57 +235,57 @@ ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!startItem)
return;
if (!startItem)
return;
QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos);
QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1;
qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue();
}
if ((cursorItem != targetItem) && targetItem)
targetItem->setBeingPointedAt(false);
if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue();
}
if ((cursorItem != targetItem) && targetItem)
targetItem->setBeingPointedAt(false);
if (!cursorItem) {
fullColor = false;
targetItem = 0;
updatePath(endPos);
} else {
fullColor = true;
if (cursorItem != startItem)
cursorItem->setBeingPointedAt(true);
targetItem = cursorItem;
updatePath();
}
update();
fullColor = false;
targetItem = 0;
updatePath(endPos);
} else {
fullColor = true;
if (cursorItem != startItem)
cursorItem->setBeingPointedAt(true);
targetItem = cursorItem;
updatePath();
}
update();
}
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
{
if (!startItem)
return;
if (!startItem)
return;
if (targetItem && (targetItem != startItem)) {
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardZone *startZone = startCard->getZone();
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
CardZone *targetZone = targetCard->getZone();
Command_AttachCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_card_id(startCard->getId());
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
if (targetItem && (targetItem != startItem)) {
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardZone *startZone = startCard->getZone();
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
CardZone *targetZone = targetCard->getZone();
Command_AttachCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_card_id(startCard->getId());
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
player->sendGameCommand(cmd);
}
delArrow();
player->sendGameCommand(cmd);
}
delArrow();
}
......@@ -10,54 +10,54 @@ class Player;
class ArrowTarget;
class ArrowItem : public QObject, public QGraphicsItem {
Q_OBJECT
Q_OBJECT
private:
QPainterPath path;
QMenu *menu;
QPainterPath path;
QMenu *menu;
protected:
Player *player;
int id;
ArrowTarget *startItem, *targetItem;
QColor color;
bool fullColor;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
Player *player;
int id;
ArrowTarget *startItem, *targetItem;
QColor color;
bool fullColor;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
public:
ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
~ArrowItem();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const { return path.boundingRect(); }
QPainterPath shape() const { return path; }
void updatePath();
void updatePath(const QPointF &endPoint);
int getId() const { return id; }
Player *getPlayer() const { return player; }
void setStartItem(ArrowTarget *_item) { startItem = _item; }
void setTargetItem(ArrowTarget *_item) { targetItem = _item; }
ArrowTarget *getStartItem() const { return startItem; }
ArrowTarget *getTargetItem() const { return targetItem; }
void delArrow();
ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
~ArrowItem();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const { return path.boundingRect(); }
QPainterPath shape() const { return path; }
void updatePath();
void updatePath(const QPointF &endPoint);
int getId() const { return id; }
Player *getPlayer() const { return player; }
void setStartItem(ArrowTarget *_item) { startItem = _item; }
void setTargetItem(ArrowTarget *_item) { targetItem = _item; }
ArrowTarget *getStartItem() const { return startItem; }
ArrowTarget *getTargetItem() const { return targetItem; }
void delArrow();
};
class ArrowDragItem : public ArrowItem {
Q_OBJECT
Q_OBJECT
private:
QList<ArrowDragItem *> childArrows;
QList<ArrowDragItem *> childArrows;
public:
ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color);
void addChildArrow(ArrowDragItem *childArrow);
ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color);
void addChildArrow(ArrowDragItem *childArrow);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};
class ArrowAttachItem : public ArrowItem {
Q_OBJECT
Q_OBJECT
public:
ArrowAttachItem(ArrowTarget *_startItem);
ArrowAttachItem(ArrowTarget *_startItem);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};
#endif // ARROWITEM_H
......@@ -3,24 +3,24 @@
#include "player.h"
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
{
}
ArrowTarget::~ArrowTarget()
{
for (int i = 0; i < arrowsFrom.size(); ++i) {
arrowsFrom[i]->setStartItem(0);
arrowsFrom[i]->delArrow();
}
for (int i = 0; i < arrowsTo.size(); ++i) {
arrowsTo[i]->setTargetItem(0);
arrowsTo[i]->delArrow();
}
for (int i = 0; i < arrowsFrom.size(); ++i) {
arrowsFrom[i]->setStartItem(0);
arrowsFrom[i]->delArrow();
}
for (int i = 0; i < arrowsTo.size(); ++i) {
arrowsTo[i]->setTargetItem(0);
arrowsTo[i]->delArrow();
}
}
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
{
beingPointedAt = _beingPointedAt;
update();
beingPointedAt = _beingPointedAt;
update();
}
......@@ -8,28 +8,28 @@ class Player;
class ArrowItem;
class ArrowTarget : public AbstractGraphicsItem {
Q_OBJECT
Q_OBJECT
protected:
Player *owner;
Player *owner;
private:
bool beingPointedAt;
QList<ArrowItem *> arrowsFrom, arrowsTo;
bool beingPointedAt;
QList<ArrowItem *> arrowsFrom, arrowsTo;
public:
ArrowTarget(Player *_owner, QGraphicsItem *parent = 0);
~ArrowTarget();
Player *getOwner() const { return owner; }
void setBeingPointedAt(bool _beingPointedAt);
bool getBeingPointedAt() const { return beingPointedAt; }
const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; }
void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); }
void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); }
const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; }
void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); }
void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); }
ArrowTarget(Player *_owner, QGraphicsItem *parent = 0);
~ArrowTarget();
Player *getOwner() const { return owner; }
void setBeingPointedAt(bool _beingPointedAt);
bool getBeingPointedAt() const { return beingPointedAt; }
const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; }
void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); }
void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); }
const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; }
void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); }
void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); }
};
#endif
This diff is collapsed.
......@@ -22,191 +22,191 @@ typedef QMap<QString, QString> QStringMap;
class CardSet : public QList<CardInfo *> {
private:
QString shortName, longName;
unsigned int sortKey;
QString shortName, longName;
unsigned int sortKey;
public:
CardSet(const QString &_shortName = QString(), const QString &_longName = QString());
QString getShortName() const { return shortName; }
QString getLongName() const { return longName; }
int getSortKey() const { return sortKey; }
void setSortKey(unsigned int _sortKey);
void updateSortKey();
CardSet(const QString &_shortName = QString(), const QString &_longName = QString());
QString getShortName() const { return shortName; }
QString getLongName() const { return longName; }
int getSortKey() const { return sortKey; }
void setSortKey(unsigned int _sortKey);
void updateSortKey();
};
class SetList : public QList<CardSet *> {
private:
class CompareFunctor;
class CompareFunctor;
public:
void sortByKey();
void sortByKey();
};
class PictureToLoad {
private:
CardInfo *card;
bool stripped;
SetList sortedSets;
int setIndex;
bool hq;
CardInfo *card;
bool stripped;
SetList sortedSets;
int setIndex;
bool hq;
public:
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
CardInfo *getCard() const { return card; }
bool getStripped() const { return stripped; }
QString getSetName() const { return sortedSets[setIndex]->getShortName(); }
bool nextSet();
bool getHq() const { return hq; }
void setHq(bool _hq) { hq = _hq; }
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
CardInfo *getCard() const { return card; }
bool getStripped() const { return stripped; }
QString getSetName() const { return sortedSets[setIndex]->getShortName(); }
bool nextSet();
bool getHq() const { return hq; }
void setHq(bool _hq) { hq = _hq; }
};
class PictureLoader : public QObject {
Q_OBJECT
Q_OBJECT
private:
QString _picsPath;
QList<PictureToLoad> loadQueue;
QMutex mutex;
QNetworkAccessManager *networkManager;
QList<PictureToLoad> cardsToDownload;
PictureToLoad cardBeingDownloaded;
bool picDownload, downloadRunning, loadQueueRunning;
void startNextPicDownload();
QString _picsPath;
QList<PictureToLoad> loadQueue;
QMutex mutex;
QNetworkAccessManager *networkManager;
QList<PictureToLoad> cardsToDownload;
PictureToLoad cardBeingDownloaded;
bool picDownload, downloadRunning, loadQueueRunning;
void startNextPicDownload();
public:
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
~PictureLoader();
void setPicsPath(const QString &path);
void setPicDownload(bool _picDownload);
void loadImage(CardInfo *card, bool stripped);
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
~PictureLoader();
void setPicsPath(const QString &path);
void setPicDownload(bool _picDownload);
void loadImage(CardInfo *card, bool stripped);
private slots:
void picDownloadFinished(QNetworkReply *reply);
void picDownloadFinished(QNetworkReply *reply);
public slots:
void processLoadQueue();
void processLoadQueue();
signals:
void startLoadQueue();
void imageLoaded(CardInfo *card, const QImage &image);
void startLoadQueue();
void imageLoaded(CardInfo *card, const QImage &image);
};
class CardInfo : public QObject {
Q_OBJECT
Q_OBJECT
private:
CardDatabase *db;
CardDatabase *db;
QString name;
bool isToken;
SetList sets;
QString manacost;
QString cardtype;
QString powtough;
QString text;
QStringList colors;
int loyalty;
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
bool cipt;
int tableRow;
QPixmap *pixmap;
QMap<int, QPixmap *> scaledPixmapCache;
QString name;
bool isToken;
SetList sets;
QString manacost;
QString cardtype;
QString powtough;
QString text;
QStringList colors;
int loyalty;
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
bool cipt;
int tableRow;
QPixmap *pixmap;
QMap<int, QPixmap *> scaledPixmapCache;
public:
CardInfo(CardDatabase *_db,
const QString &_name = QString(),
bool _isToken = false,
const QString &_manacost = QString(),
const QString &_cardtype = QString(),
const QString &_powtough = QString(),
const QString &_text = QString(),
const QStringList &_colors = QStringList(),
int _loyalty = 0,
bool _cipt = false,
int _tableRow = 0,
const SetList &_sets = SetList(),
const QStringMap &_picURLs = QStringMap(),
const QStringMap &_picURLsHq = QStringMap(),
const QStringMap &_picURLsSt = QStringMap());
~CardInfo();
const QString &getName() const { return name; }
bool getIsToken() const { return isToken; }
const SetList &getSets() const { return sets; }
const QString &getManaCost() const { return manacost; }
const QString &getCardType() const { return cardtype; }
const QString &getPowTough() const { return powtough; }
const QString &getText() const { return text; }
const int &getLoyalty() const { return loyalty; }
bool getCipt() const { return cipt; }
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); }
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
const QStringList &getColors() const { return colors; }
QString getPicURL(const QString &set) const { return picURLs.value(set); }
QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); }
QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); }
QString getPicURL() const;
const QMap<QString, QString> &getPicURLs() const { return picURLs; }
QString getMainCardType() const;
QString getCorrectedName() const;
int getTableRow() const { return tableRow; }
void setTableRow(int _tableRow) { tableRow = _tableRow; }
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); }
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
void addToSet(CardSet *set);
QPixmap *loadPixmap();
QPixmap *getPixmap(QSize size);
void clearPixmapCache();
void clearPixmapCacheMiss();
void imageLoaded(const QImage &image);
CardInfo(CardDatabase *_db,
const QString &_name = QString(),
bool _isToken = false,
const QString &_manacost = QString(),
const QString &_cardtype = QString(),
const QString &_powtough = QString(),
const QString &_text = QString(),
const QStringList &_colors = QStringList(),
int _loyalty = 0,
bool _cipt = false,
int _tableRow = 0,
const SetList &_sets = SetList(),
const QStringMap &_picURLs = QStringMap(),
const QStringMap &_picURLsHq = QStringMap(),
const QStringMap &_picURLsSt = QStringMap());
~CardInfo();
const QString &getName() const { return name; }
bool getIsToken() const { return isToken; }
const SetList &getSets() const { return sets; }
const QString &getManaCost() const { return manacost; }
const QString &getCardType() const { return cardtype; }
const QString &getPowTough() const { return powtough; }
const QString &getText() const { return text; }
const int &getLoyalty() const { return loyalty; }
bool getCipt() const { return cipt; }
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); }
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
const QStringList &getColors() const { return colors; }
QString getPicURL(const QString &set) const { return picURLs.value(set); }
QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); }
QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); }
QString getPicURL() const;
const QMap<QString, QString> &getPicURLs() const { return picURLs; }
QString getMainCardType() const;
QString getCorrectedName() const;
int getTableRow() const { return tableRow; }
void setTableRow(int _tableRow) { tableRow = _tableRow; }
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); }
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
void addToSet(CardSet *set);
QPixmap *loadPixmap();
QPixmap *getPixmap(QSize size);
void clearPixmapCache();
void clearPixmapCacheMiss();
void imageLoaded(const QImage &image);
public slots:
void updatePixmapCache();
void updatePixmapCache();
signals:
void pixmapUpdated();
void cardInfoChanged(CardInfo *card);
void pixmapUpdated();
void cardInfoChanged(CardInfo *card);
};
class CardDatabase : public QObject {
Q_OBJECT
Q_OBJECT
protected:
QHash<QString, CardInfo *> cardHash;
QHash<QString, CardSet *> setHash;
bool loadSuccess;
CardInfo *noCard;
QThread *pictureLoaderThread;
PictureLoader *pictureLoader;
QHash<QString, CardInfo *> cardHash;
QHash<QString, CardSet *> setHash;
bool loadSuccess;
CardInfo *noCard;
QThread *pictureLoaderThread;
PictureLoader *pictureLoader;
private:
static const int versionNeeded;
void loadCardsFromXml(QXmlStreamReader &xml);
void loadSetsFromXml(QXmlStreamReader &xml);
static const int versionNeeded;
void loadCardsFromXml(QXmlStreamReader &xml);
void loadSetsFromXml(QXmlStreamReader &xml);
public:
CardDatabase(QObject *parent = 0);
~CardDatabase();
void clear();
void addCard(CardInfo *card);
void removeCard(CardInfo *card);
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
CardSet *getSet(const QString &setName);
QList<CardInfo *> getCardList() const { return cardHash.values(); }
SetList getSetList() const;
bool loadFromFile(const QString &fileName, bool tokens = false);
bool saveToFile(const QString &fileName, bool tokens = false);
QStringList getAllColors() const;
QStringList getAllMainCardTypes() const;
bool getLoadSuccess() const { return loadSuccess; }
void cacheCardPixmaps(const QStringList &cardNames);
void loadImage(CardInfo *card);
CardDatabase(QObject *parent = 0);
~CardDatabase();
void clear();
void addCard(CardInfo *card);
void removeCard(CardInfo *card);
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
CardSet *getSet(const QString &setName);
QList<CardInfo *> getCardList() const { return cardHash.values(); }
SetList getSetList() const;
bool loadFromFile(const QString &fileName, bool tokens = false);
bool saveToFile(const QString &fileName, bool tokens = false);
QStringList getAllColors() const;
QStringList getAllMainCardTypes() const;
bool getLoadSuccess() const { return loadSuccess; }
void cacheCardPixmaps(const QStringList &cardNames);
void loadImage(CardInfo *card);
public slots:
void clearPixmapCache();
bool loadCardDatabase(const QString &path, bool tokens = false);
void clearPixmapCache();
bool loadCardDatabase(const QString &path, bool tokens = false);
private slots:
void imageLoaded(CardInfo *card, QImage image);
void picDownloadChanged();
void picsPathChanged();
void loadCardDatabase();
void loadTokenDatabase();
void imageLoaded(CardInfo *card, QImage image);
void picDownloadChanged();
void picsPathChanged();
void loadCardDatabase();
void loadTokenDatabase();
signals:
void cardListChanged();
void cardAdded(CardInfo *card);
void cardRemoved(CardInfo *card);
void cardListChanged();
void cardAdded(CardInfo *card);
void cardRemoved(CardInfo *card);
};
#endif
#include "carddatabasemodel.h"
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
: QAbstractListModel(parent), db(_db)
: QAbstractListModel(parent), db(_db)
{
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
updateCardList();
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
updateCardList();
}
CardDatabaseModel::~CardDatabaseModel()
......@@ -15,143 +15,143 @@ CardDatabaseModel::~CardDatabaseModel()
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
{
return cardList.size();
return cardList.size();
}
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
{
return 5;
return 5;
}
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if ((index.row() >= cardList.size()) || (index.column() >= 5))
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
if (!index.isValid())
return QVariant();
if ((index.row() >= cardList.size()) || (index.column() >= 5))
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
CardInfo *card = cardList.at(index.row());
switch (index.column()){
case 0: return card->getName();
case 1: {
QStringList setList;
const QList<CardSet *> &sets = card->getSets();
for (int i = 0; i < sets.size(); i++)
setList << sets[i]->getShortName();
return setList.join(", ");
}
case 2: return card->getManaCost();
case 3: return card->getCardType();
case 4: return card->getPowTough();
default: return QVariant();
}
CardInfo *card = cardList.at(index.row());
switch (index.column()){
case 0: return card->getName();
case 1: {
QStringList setList;
const QList<CardSet *> &sets = card->getSets();
for (int i = 0; i < sets.size(); i++)
setList << sets[i]->getShortName();
return setList.join(", ");
}
case 2: return card->getManaCost();
case 3: return card->getCardType();
case 4: return card->getPowTough();
default: return QVariant();
}
}
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation != Qt::Horizontal)
return QVariant();
switch (section) {
case 0: return QString(tr("Name"));
case 1: return QString(tr("Sets"));
case 2: return QString(tr("Mana cost"));
case 3: return QString(tr("Card type"));
case 4: return QString(tr("P/T"));
default: return QVariant();
}
if (role != Qt::DisplayRole)
return QVariant();
if (orientation != Qt::Horizontal)
return QVariant();
switch (section) {
case 0: return QString(tr("Name"));
case 1: return QString(tr("Sets"));
case 2: return QString(tr("Mana cost"));
case 3: return QString(tr("Card type"));
case 4: return QString(tr("P/T"));
default: return QVariant();
}
}
void CardDatabaseModel::updateCardList()
{
for (int i = 0; i < cardList.size(); ++i)
disconnect(cardList[i], 0, this, 0);
cardList = db->getCardList();
for (int i = 0; i < cardList.size(); ++i)
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
reset();
for (int i = 0; i < cardList.size(); ++i)
disconnect(cardList[i], 0, this, 0);
cardList = db->getCardList();
for (int i = 0; i < cardList.size(); ++i)
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
reset();
}
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
{
const int row = cardList.indexOf(card);
if (row == -1)
return;
emit dataChanged(index(row, 0), index(row, 4));
const int row = cardList.indexOf(card);
if (row == -1)
return;
emit dataChanged(index(row, 0), index(row, 4));
}
void CardDatabaseModel::cardAdded(CardInfo *card)
{
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
cardList.append(card);
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
endInsertRows();
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
cardList.append(card);
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
endInsertRows();
}
void CardDatabaseModel::cardRemoved(CardInfo *card)
{
const int row = cardList.indexOf(card);
if (row == -1)
return;
beginRemoveRows(QModelIndex(), row, row);
cardList.removeAt(row);
endRemoveRows();
const int row = cardList.indexOf(card);
if (row == -1)
return;
beginRemoveRows(QModelIndex(), row, row);
cardList.removeAt(row);
endRemoveRows();
}
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
: QSortFilterProxyModel(parent),
isToken(ShowAll)
: QSortFilterProxyModel(parent),
isToken(ShowAll)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSortCaseSensitivity(Qt::CaseInsensitive);
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSortCaseSensitivity(Qt::CaseInsensitive);
}
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
{
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
return false;
if (!cardNameBeginning.isEmpty())
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
return false;
if (!cardName.isEmpty())
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
return false;
if (!cardNameSet.isEmpty())
if (!cardNameSet.contains(info->getName()))
return false;
if (!cardText.isEmpty())
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
return false;
if (!cardColors.isEmpty())
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
return false;
if (!cardTypes.isEmpty())
if (!cardTypes.contains(info->getMainCardType()))
return false;
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
return false;
if (!cardNameBeginning.isEmpty())
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
return false;
if (!cardName.isEmpty())
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
return false;
if (!cardNameSet.isEmpty())
if (!cardNameSet.contains(info->getName()))
return false;
if (!cardText.isEmpty())
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
return false;
if (!cardColors.isEmpty())
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
return false;
if (!cardTypes.isEmpty())
if (!cardTypes.contains(info->getMainCardType()))
return false;
return true;
return true;
}
void CardDatabaseDisplayModel::clearSearch()
{
cardName.clear();
cardText.clear();
cardTypes.clear();
cardColors.clear();
invalidateFilter();
cardName.clear();
cardText.clear();
cardTypes.clear();
cardColors.clear();
invalidateFilter();
}
......@@ -8,46 +8,46 @@
#include "carddatabase.h"
class CardDatabaseModel : public QAbstractListModel {
Q_OBJECT
Q_OBJECT
public:
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
~CardDatabaseModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
CardDatabase *getDatabase() const { return db; }
CardInfo *getCard(int index) const { return cardList[index]; }
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
~CardDatabaseModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
CardDatabase *getDatabase() const { return db; }
CardInfo *getCard(int index) const { return cardList[index]; }
private:
QList<CardInfo *> cardList;
CardDatabase *db;
QList<CardInfo *> cardList;
CardDatabase *db;
private slots:
void updateCardList();
void cardAdded(CardInfo *card);
void cardRemoved(CardInfo *card);
void cardInfoChanged(CardInfo *card);
void updateCardList();
void cardAdded(CardInfo *card);
void cardRemoved(CardInfo *card);
void cardInfoChanged(CardInfo *card);
};
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
Q_OBJECT
Q_OBJECT
public:
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
private:
FilterBool isToken;
QString cardNameBeginning, cardName, cardText;
QSet<QString> cardNameSet, cardTypes, cardColors;
FilterBool isToken;
QString cardNameBeginning, cardName, cardText;
QSet<QString> cardNameSet, cardTypes, cardColors;
public:
CardDatabaseDisplayModel(QObject *parent = 0);
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
void clearSearch();
CardDatabaseDisplayModel(QObject *parent = 0);
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
void clearSearch();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
#endif
......@@ -9,82 +9,82 @@
#include <QPainter>
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag)
: AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), occupied(false), currentZone(0)
: AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), occupied(false), currentZone(0)
{
}
void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
AbstractCardDragItem::paint(painter, option, widget);
if (occupied)
painter->fillRect(boundingRect(), QColor(200, 0, 0, 100));
AbstractCardDragItem::paint(painter, option, widget);
if (occupied)
painter->fillRect(boundingRect(), QColor(200, 0, 0, 100));
}
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
{
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, static_cast<GameScene *>(scene())->getViewTransform());
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, static_cast<GameScene *>(scene())->getViewTransform());
CardZone *cardZone = 0;
ZoneViewZone *zoneViewZone = 0;
for (int i = colliding.size() - 1; i >= 0; i--) {
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
if (!cardZone)
cardZone = temp;
if (!zoneViewZone)
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
}
CardZone *cursorZone = 0;
if (zoneViewZone)
cursorZone = zoneViewZone;
else if (cardZone)
cursorZone = cardZone;
if (!cursorZone)
return;
currentZone = cursorZone;
QPointF zonePos = currentZone->scenePos();
QPointF cursorPosInZone = cursorScenePos - zonePos;
QPointF cardTopLeft = cursorPosInZone - hotSpot;
QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft);
QPointF newPos = zonePos + closestGridPoint;
if (newPos != pos()) {
for (int i = 0; i < childDrags.size(); i++)
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
setPos(newPos);
bool newOccupied = false;
TableZone *table = qobject_cast<TableZone *>(cursorZone);
if (table)
if (table->getCardFromCoords(closestGridPoint))
newOccupied = true;
if (newOccupied != occupied) {
occupied = newOccupied;
update();
}
}
CardZone *cardZone = 0;
ZoneViewZone *zoneViewZone = 0;
for (int i = colliding.size() - 1; i >= 0; i--) {
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
if (!cardZone)
cardZone = temp;
if (!zoneViewZone)
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
}
CardZone *cursorZone = 0;
if (zoneViewZone)
cursorZone = zoneViewZone;
else if (cardZone)
cursorZone = cardZone;
if (!cursorZone)
return;
currentZone = cursorZone;
QPointF zonePos = currentZone->scenePos();
QPointF cursorPosInZone = cursorScenePos - zonePos;
QPointF cardTopLeft = cursorPosInZone - hotSpot;
QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft);
QPointF newPos = zonePos + closestGridPoint;
if (newPos != pos()) {
for (int i = 0; i < childDrags.size(); i++)
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
setPos(newPos);
bool newOccupied = false;
TableZone *table = qobject_cast<TableZone *>(cursorZone);
if (table)
if (table->getCardFromCoords(closestGridPoint))
newOccupied = true;
if (newOccupied != occupied) {
occupied = newOccupied;
update();
}
}
}
void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
setCursor(Qt::OpenHandCursor);
QGraphicsScene *sc = scene();
QPointF sp = pos();
sc->removeItem(this);
setCursor(Qt::OpenHandCursor);
QGraphicsScene *sc = scene();
QPointF sp = pos();
sc->removeItem(this);
QList<CardDragItem *> dragItemList;
CardZone *startZone = static_cast<CardItem *>(item)->getZone();
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
dragItemList.append(this);
for (int i = 0; i < childDrags.size(); i++) {
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
dragItemList.append(c);
sc->removeItem(c);
}
}
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
QList<CardDragItem *> dragItemList;
CardZone *startZone = static_cast<CardItem *>(item)->getZone();
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
dragItemList.append(this);
for (int i = 0; i < childDrags.size(); i++) {
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
dragItemList.append(c);
sc->removeItem(c);
}
}
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
event->accept();
event->accept();
}
......@@ -6,20 +6,20 @@
class CardItem;
class CardDragItem : public AbstractCardDragItem {
Q_OBJECT
Q_OBJECT
private:
int id;
bool faceDown;
bool occupied;
CardZone *currentZone;
int id;
bool faceDown;
bool occupied;
CardZone *currentZone;
public:
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
int getId() const { return id; }
bool getFaceDown() const { return faceDown; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void updatePosition(const QPointF &cursorScenePos);
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
int getId() const { return id; }
bool getFaceDown() const { return faceDown; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void updatePosition(const QPointF &cursorScenePos);
protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};
#endif
......@@ -12,209 +12,209 @@
#include "settingscache.h"
CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags)
, pixmapWidth(0)
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
, mode(_mode)
, info(0)
: QFrame(parent, flags)
, pixmapWidth(0)
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
, mode(_mode)
, info(0)
{
if (mode == ModeGameTab) {
// Create indexed list of status views for card.
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.
dropList = new QComboBox();
dropList->addItems(cardInfoStatus);
dropList->setCurrentIndex(minimized);
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
}
cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter);
nameLabel1 = new QLabel;
nameLabel2 = new QLabel;
nameLabel2->setWordWrap(true);
manacostLabel1 = new QLabel;
manacostLabel2 = new QLabel;
manacostLabel2->setWordWrap(true);
cardtypeLabel1 = new QLabel;
cardtypeLabel2 = new QLabel;
cardtypeLabel2->setWordWrap(true);
powtoughLabel1 = new QLabel;
powtoughLabel2 = new QLabel;
loyaltyLabel1 = new QLabel;
loyaltyLabel2 = new QLabel;
textLabel = new QTextEdit();
textLabel->setReadOnly(true);
QGridLayout *grid = new QGridLayout(this);
int row = 0;
if (mode == ModeGameTab)
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
grid->addWidget(cardPicture, row++, 0, 1, 2);
grid->addWidget(nameLabel1, row, 0);
grid->addWidget(nameLabel2, row++, 1);
grid->addWidget(manacostLabel1, row, 0);
grid->addWidget(manacostLabel2, row++, 1);
grid->addWidget(cardtypeLabel1, row, 0);
grid->addWidget(cardtypeLabel2, row++, 1);
grid->addWidget(powtoughLabel1, row, 0);
grid->addWidget(powtoughLabel2, row++, 1);
grid->addWidget(loyaltyLabel1, row, 0);
grid->addWidget(loyaltyLabel2, row++, 1);
grid->addWidget(textLabel, row, 0, -1, 2);
grid->setRowStretch(row, 1);
grid->setColumnStretch(1, 1);
retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised);
if (mode == ModeGameTab) {
textLabel->setMinimumHeight(100);
setFixedWidth(sizeHint().width());
} else if (mode == ModePopUp) {
QDesktopWidget desktopWidget;
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
setFixedWidth(pixmapWidth + 150);
} else
setFixedWidth(250);
setCard(db->getCard(cardName));
setMinimized(settingsCache->getCardInfoMinimized());
if (mode == ModeGameTab) {
// Create indexed list of status views for card.
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.
dropList = new QComboBox();
dropList->addItems(cardInfoStatus);
dropList->setCurrentIndex(minimized);
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
}
cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter);
nameLabel1 = new QLabel;
nameLabel2 = new QLabel;
nameLabel2->setWordWrap(true);
manacostLabel1 = new QLabel;
manacostLabel2 = new QLabel;
manacostLabel2->setWordWrap(true);
cardtypeLabel1 = new QLabel;
cardtypeLabel2 = new QLabel;
cardtypeLabel2->setWordWrap(true);
powtoughLabel1 = new QLabel;
powtoughLabel2 = new QLabel;
loyaltyLabel1 = new QLabel;
loyaltyLabel2 = new QLabel;
textLabel = new QTextEdit();
textLabel->setReadOnly(true);
QGridLayout *grid = new QGridLayout(this);
int row = 0;
if (mode == ModeGameTab)
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
grid->addWidget(cardPicture, row++, 0, 1, 2);
grid->addWidget(nameLabel1, row, 0);
grid->addWidget(nameLabel2, row++, 1);
grid->addWidget(manacostLabel1, row, 0);
grid->addWidget(manacostLabel2, row++, 1);
grid->addWidget(cardtypeLabel1, row, 0);
grid->addWidget(cardtypeLabel2, row++, 1);
grid->addWidget(powtoughLabel1, row, 0);
grid->addWidget(powtoughLabel2, row++, 1);
grid->addWidget(loyaltyLabel1, row, 0);
grid->addWidget(loyaltyLabel2, row++, 1);
grid->addWidget(textLabel, row, 0, -1, 2);
grid->setRowStretch(row, 1);
grid->setColumnStretch(1, 1);
retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised);
if (mode == ModeGameTab) {
textLabel->setMinimumHeight(100);
setFixedWidth(sizeHint().width());
} else if (mode == ModePopUp) {
QDesktopWidget desktopWidget;
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
setFixedWidth(pixmapWidth + 150);
} else
setFixedWidth(250);
setCard(db->getCard(cardName));
setMinimized(settingsCache->getCardInfoMinimized());
}
void CardInfoWidget::minimizeClicked(int newMinimized)
{
// Set new status, and store it in the settings cache.
setMinimized(newMinimized);
settingsCache->setCardInfoMinimized(newMinimized);
// Set new status, and store it in the settings cache.
setMinimized(newMinimized);
settingsCache->setCardInfoMinimized(newMinimized);
}
bool CardInfoWidget::shouldShowPowTough()
{
// return (!info->getPowTough().isEmpty() && (minimized != 0));
return (minimized != 0);
// return (!info->getPowTough().isEmpty() && (minimized != 0));
return (minimized != 0);
}
bool CardInfoWidget::shouldShowLoyalty()
{
// return ((info->getLoyalty() > 0) && (minimized != 0));
return (minimized != 0);
// return ((info->getLoyalty() > 0) && (minimized != 0));
return (minimized != 0);
}
void CardInfoWidget::setMinimized(int _minimized)
{
minimized = _minimized;
// Toggle oracle fields according to selected view.
bool showAll = ((minimized == 1) || (minimized == 2));
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
if (mode == ModeGameTab) {
nameLabel1->setVisible(showAll);
nameLabel2->setVisible(showAll);
manacostLabel1->setVisible(showAll);
manacostLabel2->setVisible(showAll);
cardtypeLabel1->setVisible(showAll);
cardtypeLabel2->setVisible(showAll);
powtoughLabel1->setVisible(showPowTough);
powtoughLabel2->setVisible(showPowTough);
loyaltyLabel1->setVisible(showLoyalty);
loyaltyLabel2->setVisible(showLoyalty);
textLabel->setVisible(showAll);
}
cardPicture->hide();
cardHeightOffset = minimumSizeHint().height() + 10;
// Set the picture to be shown only at "card only" (0) and "full info" (2)
if (mode == ModeGameTab) {
cardPicture->setVisible((minimized == 0) || (minimized == 2));
if (minimized == 0)
setMaximumHeight(cardHeightOffset + width() * aspectRatio);
else
setMaximumHeight(1000000);
} else
cardPicture->show();
resize(width(), sizeHint().height());
minimized = _minimized;
// Toggle oracle fields according to selected view.
bool showAll = ((minimized == 1) || (minimized == 2));
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
if (mode == ModeGameTab) {
nameLabel1->setVisible(showAll);
nameLabel2->setVisible(showAll);
manacostLabel1->setVisible(showAll);
manacostLabel2->setVisible(showAll);
cardtypeLabel1->setVisible(showAll);
cardtypeLabel2->setVisible(showAll);
powtoughLabel1->setVisible(showPowTough);
powtoughLabel2->setVisible(showPowTough);
loyaltyLabel1->setVisible(showLoyalty);
loyaltyLabel2->setVisible(showLoyalty);
textLabel->setVisible(showAll);
}
cardPicture->hide();
cardHeightOffset = minimumSizeHint().height() + 10;
// Set the picture to be shown only at "card only" (0) and "full info" (2)
if (mode == ModeGameTab) {
cardPicture->setVisible((minimized == 0) || (minimized == 2));
if (minimized == 0)
setMaximumHeight(cardHeightOffset + width() * aspectRatio);
else
setMaximumHeight(1000000);
} else
cardPicture->show();
resize(width(), sizeHint().height());
}
void CardInfoWidget::setCard(CardInfo *card)
{
if (info)
disconnect(info, 0, this, 0);
info = card;
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
updatePixmap();
nameLabel2->setText(card->getName());
manacostLabel2->setText(card->getManaCost());
cardtypeLabel2->setText(card->getCardType());
powtoughLabel2->setText(card->getPowTough());
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
textLabel->setText(card->getText());
powtoughLabel1->setVisible(shouldShowPowTough());
powtoughLabel2->setVisible(shouldShowPowTough());
loyaltyLabel1->setVisible(shouldShowLoyalty());
loyaltyLabel2->setVisible(shouldShowLoyalty());
if (info)
disconnect(info, 0, this, 0);
info = card;
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
updatePixmap();
nameLabel2->setText(card->getName());
manacostLabel2->setText(card->getManaCost());
cardtypeLabel2->setText(card->getCardType());
powtoughLabel2->setText(card->getPowTough());
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
textLabel->setText(card->getText());
powtoughLabel1->setVisible(shouldShowPowTough());
powtoughLabel2->setVisible(shouldShowPowTough());
loyaltyLabel1->setVisible(shouldShowLoyalty());
loyaltyLabel2->setVisible(shouldShowLoyalty());
}
void CardInfoWidget::setCard(const QString &cardName)
{
setCard(db->getCard(cardName));
setCard(db->getCard(cardName));
}
void CardInfoWidget::setCard(AbstractCardItem *card)
{
setCard(card->getInfo());
setCard(card->getInfo());
}
void CardInfoWidget::clear()
{
setCard(db->getCard());
setCard(db->getCard());
}
void CardInfoWidget::updatePixmap()
{
if (pixmapWidth == 0)
return;
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
if (resizedPixmap)
cardPicture->setPixmap(*resizedPixmap);
else
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
if (pixmapWidth == 0)
return;
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
if (resizedPixmap)
cardPicture->setPixmap(*resizedPixmap);
else
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
}
void CardInfoWidget::retranslateUi()
{
nameLabel1->setText(tr("Name:"));
manacostLabel1->setText(tr("Mana cost:"));
cardtypeLabel1->setText(tr("Card type:"));
powtoughLabel1->setText(tr("P / T:"));
loyaltyLabel1->setText(tr("Loyalty:"));
nameLabel1->setText(tr("Name:"));
manacostLabel1->setText(tr("Mana cost:"));
cardtypeLabel1->setText(tr("Card type:"));
powtoughLabel1->setText(tr("P / T:"));
loyaltyLabel1->setText(tr("Loyalty:"));
}
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{
if (mode == ModePopUp)
return;
if ((minimized == 1) && (mode == ModeGameTab)) {
pixmapWidth = 0;
return;
}
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
if (newPixmapWidth != pixmapWidth) {
pixmapWidth = newPixmapWidth;
updatePixmap();
}
if (mode == ModePopUp)
return;
if ((minimized == 1) && (mode == ModeGameTab)) {
pixmapWidth = 0;
return;
}
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
if (newPixmapWidth != pixmapWidth) {
pixmapWidth = newPixmapWidth;
updatePixmap();
}
}
QString CardInfoWidget::getCardName() const
{
return nameLabel2->text();
return nameLabel2->text();
}
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