Convert rest of source to 4-space indent
This commit is contained in:
parent
a171df744d
commit
1bc48a7849
146 changed files with 12810 additions and 12810 deletions
|
@ -5,47 +5,47 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
||||||
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
|
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
|
||||||
{
|
{
|
||||||
if (parentDrag) {
|
if (parentDrag) {
|
||||||
parentDrag->addChildDrag(this);
|
parentDrag->addChildDrag(this);
|
||||||
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
||||||
} else {
|
} else {
|
||||||
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
||||||
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
|
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
|
||||||
hotSpot = QPointF();
|
hotSpot = QPointF();
|
||||||
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
|
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
|
||||||
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
|
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
|
||||||
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
setZValue(2000000007);
|
setZValue(2000000007);
|
||||||
}
|
}
|
||||||
if (item->getTapped())
|
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));
|
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()
|
AbstractCardDragItem::~AbstractCardDragItem()
|
||||||
{
|
{
|
||||||
qDebug("CardDragItem destructor");
|
qDebug("CardDragItem destructor");
|
||||||
for (int i = 0; i < childDrags.size(); i++)
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
delete childDrags[i];
|
delete childDrags[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
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)
|
void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
updatePosition(event->scenePos());
|
updatePosition(event->scenePos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
|
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
|
||||||
{
|
{
|
||||||
childDrags << child;
|
childDrags << child;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,24 +8,24 @@ class CardZone;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
||||||
class AbstractCardDragItem : public QObject, public QGraphicsItem {
|
class AbstractCardDragItem : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
AbstractCardItem *item;
|
AbstractCardItem *item;
|
||||||
QPointF hotSpot;
|
QPointF hotSpot;
|
||||||
QList<AbstractCardDragItem *> childDrags;
|
QList<AbstractCardDragItem *> childDrags;
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCardDrag };
|
enum { Type = typeCardDrag };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
||||||
~AbstractCardDragItem();
|
~AbstractCardDragItem();
|
||||||
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
|
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
AbstractCardItem *getItem() const { return item; }
|
AbstractCardItem *getItem() const { return item; }
|
||||||
QPointF getHotSpot() const { return hotSpot; }
|
QPointF getHotSpot() const { return hotSpot; }
|
||||||
void addChildDrag(AbstractCardDragItem *child);
|
void addChildDrag(AbstractCardDragItem *child);
|
||||||
virtual void updatePosition(const QPointF &cursorScenePos) = 0;
|
virtual void updatePosition(const QPointF &cursorScenePos) = 0;
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,245 +12,245 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
|
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);
|
setCursor(Qt::OpenHandCursor);
|
||||||
setFlag(ItemIsSelectable);
|
setFlag(ItemIsSelectable);
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
|
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
|
||||||
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
||||||
cardInfoUpdated();
|
cardInfoUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractCardItem::~AbstractCardItem()
|
AbstractCardItem::~AbstractCardItem()
|
||||||
{
|
{
|
||||||
emit deleteCardInfoPopup(name);
|
emit deleteCardInfoPopup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF AbstractCardItem::boundingRect() const
|
QRectF AbstractCardItem::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::pixmapUpdated()
|
void AbstractCardItem::pixmapUpdated()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
emit sigPixmapUpdated();
|
emit sigPixmapUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::cardInfoUpdated()
|
void AbstractCardItem::cardInfoUpdated()
|
||||||
{
|
{
|
||||||
info = db->getCard(name);
|
info = db->getCard(name);
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setRealZValue(qreal _zValue)
|
void AbstractCardItem::setRealZValue(qreal _zValue)
|
||||||
{
|
{
|
||||||
realZValue = _zValue;
|
realZValue = _zValue;
|
||||||
setZValue(_zValue);
|
setZValue(_zValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
|
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
|
||||||
{
|
{
|
||||||
return QSizeF(
|
return QSizeF(
|
||||||
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
|
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
|
||||||
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
|
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
|
void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
|
||||||
{
|
{
|
||||||
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
|
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
|
||||||
|
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
|
|
||||||
QTransform pixmapTransform;
|
QTransform pixmapTransform;
|
||||||
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
|
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
|
||||||
pixmapTransform.rotate(angle);
|
pixmapTransform.rotate(angle);
|
||||||
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
|
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
|
||||||
painter->setTransform(pixmapTransform);
|
painter->setTransform(pixmapTransform);
|
||||||
|
|
||||||
QFont f;
|
QFont f;
|
||||||
int fontSize = round(translatedSize.height() / 8);
|
int fontSize = round(translatedSize.height() / 8);
|
||||||
if (fontSize < 9)
|
if (fontSize < 9)
|
||||||
fontSize = 9;
|
fontSize = 9;
|
||||||
if (fontSize > 10)
|
if (fontSize > 10)
|
||||||
fontSize = 10;
|
fontSize = 10;
|
||||||
f.setPixelSize(fontSize);
|
f.setPixelSize(fontSize);
|
||||||
|
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
|
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
|
||||||
{
|
{
|
||||||
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
||||||
|
|
||||||
CardInfo *imageSource = facedown ? db->getCard() : info;
|
CardInfo *imageSource = facedown ? db->getCard() : info;
|
||||||
QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
|
QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
|
||||||
painter->save();
|
painter->save();
|
||||||
QColor bgColor = Qt::transparent;
|
QColor bgColor = Qt::transparent;
|
||||||
if (translatedPixmap) {
|
if (translatedPixmap) {
|
||||||
painter->save();
|
painter->save();
|
||||||
transformPainter(painter, translatedSize, angle);
|
transformPainter(painter, translatedSize, angle);
|
||||||
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
|
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
} else {
|
} else {
|
||||||
QString colorStr;
|
QString colorStr;
|
||||||
if (!color.isEmpty())
|
if (!color.isEmpty())
|
||||||
colorStr = color;
|
colorStr = color;
|
||||||
else if (info->getColors().size() > 1)
|
else if (info->getColors().size() > 1)
|
||||||
colorStr = "m";
|
colorStr = "m";
|
||||||
else if (!info->getColors().isEmpty())
|
else if (!info->getColors().isEmpty())
|
||||||
colorStr = info->getColors().first().toLower();
|
colorStr = info->getColors().first().toLower();
|
||||||
|
|
||||||
if (colorStr == "b")
|
if (colorStr == "b")
|
||||||
bgColor = QColor(0, 0, 0);
|
bgColor = QColor(0, 0, 0);
|
||||||
else if (colorStr == "u")
|
else if (colorStr == "u")
|
||||||
bgColor = QColor(0, 140, 180);
|
bgColor = QColor(0, 140, 180);
|
||||||
else if (colorStr == "w")
|
else if (colorStr == "w")
|
||||||
bgColor = QColor(255, 250, 140);
|
bgColor = QColor(255, 250, 140);
|
||||||
else if (colorStr == "r")
|
else if (colorStr == "r")
|
||||||
bgColor = QColor(230, 0, 0);
|
bgColor = QColor(230, 0, 0);
|
||||||
else if (colorStr == "g")
|
else if (colorStr == "g")
|
||||||
bgColor = QColor(0, 160, 0);
|
bgColor = QColor(0, 160, 0);
|
||||||
else if (colorStr == "m")
|
else if (colorStr == "m")
|
||||||
bgColor = QColor(250, 190, 30);
|
bgColor = QColor(250, 190, 30);
|
||||||
else
|
else
|
||||||
bgColor = QColor(230, 230, 230);
|
bgColor = QColor(230, 230, 230);
|
||||||
}
|
}
|
||||||
painter->setBrush(bgColor);
|
painter->setBrush(bgColor);
|
||||||
QPen pen(Qt::black);
|
QPen pen(Qt::black);
|
||||||
pen.setWidth(2);
|
pen.setWidth(2);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
|
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
|
||||||
|
|
||||||
if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
|
if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
|
||||||
painter->save();
|
painter->save();
|
||||||
transformPainter(painter, translatedSize, angle);
|
transformPainter(painter, translatedSize, angle);
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
painter->setBackground(Qt::black);
|
painter->setBackground(Qt::black);
|
||||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
QString nameStr;
|
QString nameStr;
|
||||||
if (facedown)
|
if (facedown)
|
||||||
nameStr = "# " + QString::number(id);
|
nameStr = "# " + QString::number(id);
|
||||||
else
|
else
|
||||||
nameStr = name;
|
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->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();
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QSizeF translatedSize = getTranslatedSize(painter);
|
QSizeF translatedSize = getTranslatedSize(painter);
|
||||||
paintPicture(painter, translatedSize, tapAngle);
|
paintPicture(painter, translatedSize, tapAngle);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||||
transformPainter(painter, translatedSize, tapAngle);
|
transformPainter(painter, translatedSize, tapAngle);
|
||||||
if (isSelected()) {
|
if (isSelected()) {
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
|
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
|
||||||
} else if (isHovered) {
|
} else if (isHovered) {
|
||||||
painter->setPen(Qt::yellow);
|
painter->setPen(Qt::yellow);
|
||||||
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
|
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setName(const QString &_name)
|
void AbstractCardItem::setName(const QString &_name)
|
||||||
{
|
{
|
||||||
if (name == _name)
|
if (name == _name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit deleteCardInfoPopup(name);
|
emit deleteCardInfoPopup(name);
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, 0, this, 0);
|
||||||
name = _name;
|
name = _name;
|
||||||
info = db->getCard(name);
|
info = db->getCard(name);
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setHovered(bool _hovered)
|
void AbstractCardItem::setHovered(bool _hovered)
|
||||||
{
|
{
|
||||||
if (isHovered == _hovered)
|
if (isHovered == _hovered)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_hovered)
|
if (_hovered)
|
||||||
processHoverEvent();
|
processHoverEvent();
|
||||||
isHovered = _hovered;
|
isHovered = _hovered;
|
||||||
setZValue(_hovered ? 2000000004 : realZValue);
|
setZValue(_hovered ? 2000000004 : realZValue);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setColor(const QString &_color)
|
void AbstractCardItem::setColor(const QString &_color)
|
||||||
{
|
{
|
||||||
color = _color;
|
color = _color;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
||||||
{
|
{
|
||||||
if (tapped == _tapped)
|
if (tapped == _tapped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tapped = _tapped;
|
tapped = _tapped;
|
||||||
if (settingsCache->getTapAnimation() && canAnimate)
|
if (settingsCache->getTapAnimation() && canAnimate)
|
||||||
static_cast<GameScene *>(scene())->registerAnimationItem(this);
|
static_cast<GameScene *>(scene())->registerAnimationItem(this);
|
||||||
else {
|
else {
|
||||||
tapAngle = tapped ? 90 : 0;
|
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));
|
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setFaceDown(bool _facedown)
|
void AbstractCardItem::setFaceDown(bool _facedown)
|
||||||
{
|
{
|
||||||
facedown = _facedown;
|
facedown = _facedown;
|
||||||
update();
|
update();
|
||||||
emit updateCardMenu(this);
|
emit updateCardMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!isSelected()) {
|
if (!isSelected()) {
|
||||||
scene()->clearSelection();
|
scene()->clearSelection();
|
||||||
setSelected(true);
|
setSelected(true);
|
||||||
}
|
}
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
else if (event->button() == Qt::MidButton)
|
else if (event->button() == Qt::MidButton)
|
||||||
emit showCardInfoPopup(event->screenPos(), name);
|
emit showCardInfoPopup(event->screenPos(), name);
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::MidButton)
|
if (event->button() == Qt::MidButton)
|
||||||
emit deleteCardInfoPopup(name);
|
emit deleteCardInfoPopup(name);
|
||||||
|
|
||||||
// This function ensures the parent function doesn't mess around with our selection.
|
// This function ensures the parent function doesn't mess around with our selection.
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::processHoverEvent()
|
void AbstractCardItem::processHoverEvent()
|
||||||
{
|
{
|
||||||
emit hovered(this);
|
emit hovered(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||||
{
|
{
|
||||||
if (change == ItemSelectedHasChanged) {
|
if (change == ItemSelectedHasChanged) {
|
||||||
update();
|
update();
|
||||||
return value;
|
return value;
|
||||||
} else
|
} else
|
||||||
return QGraphicsItem::itemChange(change, value);
|
return QGraphicsItem::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,59 +12,59 @@ const int CARD_WIDTH = 72;
|
||||||
const int CARD_HEIGHT = 102;
|
const int CARD_HEIGHT = 102;
|
||||||
|
|
||||||
class AbstractCardItem : public ArrowTarget {
|
class AbstractCardItem : public ArrowTarget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
CardInfoWidget *infoWidget;
|
CardInfoWidget *infoWidget;
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
bool tapped;
|
bool tapped;
|
||||||
bool facedown;
|
bool facedown;
|
||||||
int tapAngle;
|
int tapAngle;
|
||||||
QString color;
|
QString color;
|
||||||
private:
|
private:
|
||||||
bool isHovered;
|
bool isHovered;
|
||||||
qreal realZValue;
|
qreal realZValue;
|
||||||
private slots:
|
private slots:
|
||||||
void pixmapUpdated();
|
void pixmapUpdated();
|
||||||
void cardInfoUpdated();
|
void cardInfoUpdated();
|
||||||
void callUpdate() { update(); }
|
void callUpdate() { update(); }
|
||||||
signals:
|
signals:
|
||||||
void hovered(AbstractCardItem *card);
|
void hovered(AbstractCardItem *card);
|
||||||
void showCardInfoPopup(QPoint pos, QString cardName);
|
void showCardInfoPopup(QPoint pos, QString cardName);
|
||||||
void deleteCardInfoPopup(QString cardName);
|
void deleteCardInfoPopup(QString cardName);
|
||||||
void updateCardMenu(AbstractCardItem *card);
|
void updateCardMenu(AbstractCardItem *card);
|
||||||
void sigPixmapUpdated();
|
void sigPixmapUpdated();
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCard };
|
enum { Type = typeCard };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0);
|
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0);
|
||||||
~AbstractCardItem();
|
~AbstractCardItem();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
QSizeF getTranslatedSize(QPainter *painter) const;
|
QSizeF getTranslatedSize(QPainter *painter) const;
|
||||||
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
|
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
CardInfo *getInfo() const { return info; }
|
CardInfo *getInfo() const { return info; }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
void setId(int _id) { id = _id; }
|
void setId(int _id) { id = _id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
void setName(const QString &_name = QString());
|
void setName(const QString &_name = QString());
|
||||||
qreal getRealZValue() const { return realZValue; }
|
qreal getRealZValue() const { return realZValue; }
|
||||||
void setRealZValue(qreal _zValue);
|
void setRealZValue(qreal _zValue);
|
||||||
void setHovered(bool _hovered);
|
void setHovered(bool _hovered);
|
||||||
QString getColor() const { return color; }
|
QString getColor() const { return color; }
|
||||||
void setColor(const QString &_color);
|
void setColor(const QString &_color);
|
||||||
bool getTapped() const { return tapped; }
|
bool getTapped() const { return tapped; }
|
||||||
void setTapped(bool _tapped, bool canAnimate = false);
|
void setTapped(bool _tapped, bool canAnimate = false);
|
||||||
bool getFaceDown() const { return facedown; }
|
bool getFaceDown() const { return facedown; }
|
||||||
void setFaceDown(bool _facedown);
|
void setFaceDown(bool _facedown);
|
||||||
void processHoverEvent();
|
void processHoverEvent();
|
||||||
void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); }
|
void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); }
|
||||||
protected:
|
protected:
|
||||||
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
|
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,67 +26,67 @@ class Event_ServerShutdown;
|
||||||
class Event_ReplayAdded;
|
class Event_ReplayAdded;
|
||||||
|
|
||||||
enum ClientStatus {
|
enum ClientStatus {
|
||||||
StatusDisconnected,
|
StatusDisconnected,
|
||||||
StatusDisconnecting,
|
StatusDisconnecting,
|
||||||
StatusConnecting,
|
StatusConnecting,
|
||||||
StatusAwaitingWelcome,
|
StatusAwaitingWelcome,
|
||||||
StatusLoggingIn,
|
StatusLoggingIn,
|
||||||
StatusLoggedIn,
|
StatusLoggedIn,
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractClient : public QObject {
|
class AbstractClient : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void statusChanged(ClientStatus _status);
|
void statusChanged(ClientStatus _status);
|
||||||
|
|
||||||
// Room events
|
// Room events
|
||||||
void roomEventReceived(const RoomEvent &event);
|
void roomEventReceived(const RoomEvent &event);
|
||||||
// Game events
|
// Game events
|
||||||
void gameEventContainerReceived(const GameEventContainer &event);
|
void gameEventContainerReceived(const GameEventContainer &event);
|
||||||
// Session events
|
// Session events
|
||||||
void serverIdentificationEventReceived(const Event_ServerIdentification &event);
|
void serverIdentificationEventReceived(const Event_ServerIdentification &event);
|
||||||
void connectionClosedEventReceived(const Event_ConnectionClosed &event);
|
void connectionClosedEventReceived(const Event_ConnectionClosed &event);
|
||||||
void serverShutdownEventReceived(const Event_ServerShutdown &event);
|
void serverShutdownEventReceived(const Event_ServerShutdown &event);
|
||||||
void addToListEventReceived(const Event_AddToList &event);
|
void addToListEventReceived(const Event_AddToList &event);
|
||||||
void removeFromListEventReceived(const Event_RemoveFromList &event);
|
void removeFromListEventReceived(const Event_RemoveFromList &event);
|
||||||
void userJoinedEventReceived(const Event_UserJoined &event);
|
void userJoinedEventReceived(const Event_UserJoined &event);
|
||||||
void userLeftEventReceived(const Event_UserLeft &event);
|
void userLeftEventReceived(const Event_UserLeft &event);
|
||||||
void serverMessageEventReceived(const Event_ServerMessage &event);
|
void serverMessageEventReceived(const Event_ServerMessage &event);
|
||||||
void listRoomsEventReceived(const Event_ListRooms &event);
|
void listRoomsEventReceived(const Event_ListRooms &event);
|
||||||
void gameJoinedEventReceived(const Event_GameJoined &event);
|
void gameJoinedEventReceived(const Event_GameJoined &event);
|
||||||
void userMessageEventReceived(const Event_UserMessage &event);
|
void userMessageEventReceived(const Event_UserMessage &event);
|
||||||
void userInfoChanged(const ServerInfo_User &userInfo);
|
void userInfoChanged(const ServerInfo_User &userInfo);
|
||||||
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
|
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
|
||||||
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
|
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
|
||||||
void replayAddedEventReceived(const Event_ReplayAdded &event);
|
void replayAddedEventReceived(const Event_ReplayAdded &event);
|
||||||
|
|
||||||
void sigQueuePendingCommand(PendingCommand *pend);
|
void sigQueuePendingCommand(PendingCommand *pend);
|
||||||
private:
|
private:
|
||||||
int nextCmdId;
|
int nextCmdId;
|
||||||
mutable QMutex clientMutex;
|
mutable QMutex clientMutex;
|
||||||
ClientStatus status;
|
ClientStatus status;
|
||||||
private slots:
|
private slots:
|
||||||
void queuePendingCommand(PendingCommand *pend);
|
void queuePendingCommand(PendingCommand *pend);
|
||||||
protected slots:
|
protected slots:
|
||||||
void processProtocolItem(const ServerMessage &item);
|
void processProtocolItem(const ServerMessage &item);
|
||||||
protected:
|
protected:
|
||||||
QMap<int, PendingCommand *> pendingCommands;
|
QMap<int, PendingCommand *> pendingCommands;
|
||||||
QString userName, password;
|
QString userName, password;
|
||||||
void setStatus(ClientStatus _status);
|
void setStatus(ClientStatus _status);
|
||||||
int getNewCmdId() { return nextCmdId++; }
|
int getNewCmdId() { return nextCmdId++; }
|
||||||
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
|
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
|
||||||
public:
|
public:
|
||||||
AbstractClient(QObject *parent = 0);
|
AbstractClient(QObject *parent = 0);
|
||||||
~AbstractClient();
|
~AbstractClient();
|
||||||
|
|
||||||
ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; }
|
ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; }
|
||||||
void sendCommand(const CommandContainer &cont);
|
void sendCommand(const CommandContainer &cont);
|
||||||
void sendCommand(PendingCommand *pend);
|
void sendCommand(PendingCommand *pend);
|
||||||
|
|
||||||
static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
|
static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
|
||||||
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
|
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
|
||||||
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
|
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
|
||||||
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
|
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,137 +9,137 @@
|
||||||
#include "pb/command_set_counter.pb.h"
|
#include "pb/command_set_counter.pb.h"
|
||||||
|
|
||||||
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
|
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);
|
setAcceptsHoverEvents(true);
|
||||||
|
|
||||||
if (player->getLocal()) {
|
if (player->getLocal()) {
|
||||||
menu = new QMenu(name);
|
menu = new QMenu(name);
|
||||||
aSet = new QAction(this);
|
aSet = new QAction(this);
|
||||||
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
|
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
|
||||||
menu->addAction(aSet);
|
menu->addAction(aSet);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
for (int i = -10; i <= 10; ++i)
|
for (int i = -10; i <= 10; ++i)
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
else {
|
else {
|
||||||
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
|
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
aDec = aIncrement;
|
aDec = aIncrement;
|
||||||
else if (i == 1)
|
else if (i == 1)
|
||||||
aInc = aIncrement;
|
aInc = aIncrement;
|
||||||
aIncrement->setData(i);
|
aIncrement->setData(i);
|
||||||
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
|
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
|
||||||
menu->addAction(aIncrement);
|
menu->addAction(aIncrement);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
menu = 0;
|
menu = 0;
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractCounter::~AbstractCounter()
|
AbstractCounter::~AbstractCounter()
|
||||||
{
|
{
|
||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::delCounter()
|
void AbstractCounter::delCounter()
|
||||||
{
|
{
|
||||||
if (dialogSemaphore)
|
if (dialogSemaphore)
|
||||||
deleteAfterDialog = true;
|
deleteAfterDialog = true;
|
||||||
else
|
else
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::retranslateUi()
|
void AbstractCounter::retranslateUi()
|
||||||
{
|
{
|
||||||
if (menu) {
|
if (menu) {
|
||||||
aSet->setText(tr("&Set counter..."));
|
aSet->setText(tr("&Set counter..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::setShortcutsActive()
|
void AbstractCounter::setShortcutsActive()
|
||||||
{
|
{
|
||||||
if (name == "life") {
|
if (name == "life") {
|
||||||
aSet->setShortcut(tr("Ctrl+L"));
|
aSet->setShortcut(tr("Ctrl+L"));
|
||||||
aDec->setShortcut(tr("F11"));
|
aDec->setShortcut(tr("F11"));
|
||||||
aInc->setShortcut(tr("F12"));
|
aInc->setShortcut(tr("F12"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::setShortcutsInactive()
|
void AbstractCounter::setShortcutsInactive()
|
||||||
{
|
{
|
||||||
if (name == "life") {
|
if (name == "life") {
|
||||||
aSet->setShortcut(QKeySequence());
|
aSet->setShortcut(QKeySequence());
|
||||||
aDec->setShortcut(QKeySequence());
|
aDec->setShortcut(QKeySequence());
|
||||||
aInc->setShortcut(QKeySequence());
|
aInc->setShortcut(QKeySequence());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::setValue(int _value)
|
void AbstractCounter::setValue(int _value)
|
||||||
{
|
{
|
||||||
value = _value;
|
value = _value;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
Command_IncCounter cmd;
|
Command_IncCounter cmd;
|
||||||
cmd.set_counter_id(id);
|
cmd.set_counter_id(id);
|
||||||
cmd.set_delta(1);
|
cmd.set_delta(1);
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->button() == Qt::RightButton) {
|
} else if (event->button() == Qt::RightButton) {
|
||||||
Command_IncCounter cmd;
|
Command_IncCounter cmd;
|
||||||
cmd.set_counter_id(id);
|
cmd.set_counter_id(id);
|
||||||
cmd.set_delta(-1);
|
cmd.set_delta(-1);
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->button() == Qt::MidButton) {
|
} else if (event->button() == Qt::MidButton) {
|
||||||
if (menu)
|
if (menu)
|
||||||
menu->exec(event->screenPos());
|
menu->exec(event->screenPos());
|
||||||
event->accept();
|
event->accept();
|
||||||
} else
|
} else
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
|
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
|
||||||
{
|
{
|
||||||
hovered = true;
|
hovered = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
|
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
|
||||||
{
|
{
|
||||||
hovered = false;
|
hovered = false;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::incrementCounter()
|
void AbstractCounter::incrementCounter()
|
||||||
{
|
{
|
||||||
const int delta = static_cast<QAction *>(sender())->data().toInt();
|
const int delta = static_cast<QAction *>(sender())->data().toInt();
|
||||||
Command_IncCounter cmd;
|
Command_IncCounter cmd;
|
||||||
cmd.set_counter_id(id);
|
cmd.set_counter_id(id);
|
||||||
cmd.set_delta(delta);
|
cmd.set_delta(delta);
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCounter::setCounter()
|
void AbstractCounter::setCounter()
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
dialogSemaphore = true;
|
dialogSemaphore = true;
|
||||||
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
|
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
|
||||||
if (deleteAfterDialog) {
|
if (deleteAfterDialog) {
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dialogSemaphore = false;
|
dialogSemaphore = false;
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command_SetCounter cmd;
|
Command_SetCounter cmd;
|
||||||
cmd.set_counter_id(id);
|
cmd.set_counter_id(id);
|
||||||
cmd.set_value(newValue);
|
cmd.set_value(newValue);
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,41 +8,41 @@ class QMenu;
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
class AbstractCounter : public QObject, public QGraphicsItem {
|
class AbstractCounter : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
int value;
|
int value;
|
||||||
bool hovered;
|
bool hovered;
|
||||||
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
private:
|
private:
|
||||||
QAction *aSet, *aDec, *aInc;
|
QAction *aSet, *aDec, *aInc;
|
||||||
QMenu *menu;
|
QMenu *menu;
|
||||||
bool dialogSemaphore, deleteAfterDialog;
|
bool dialogSemaphore, deleteAfterDialog;
|
||||||
bool shownInCounterArea;
|
bool shownInCounterArea;
|
||||||
private slots:
|
private slots:
|
||||||
void incrementCounter();
|
void incrementCounter();
|
||||||
void setCounter();
|
void setCounter();
|
||||||
public:
|
public:
|
||||||
AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0);
|
AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0);
|
||||||
~AbstractCounter();
|
~AbstractCounter();
|
||||||
|
|
||||||
QMenu *getMenu() const { return menu; }
|
QMenu *getMenu() const { return menu; }
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
bool getShownInCounterArea() const { return shownInCounterArea; }
|
bool getShownInCounterArea() const { return shownInCounterArea; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
void setValue(int _value);
|
void setValue(int _value);
|
||||||
void delCounter();
|
void delCounter();
|
||||||
|
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,48 +3,48 @@
|
||||||
|
|
||||||
void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, int count, QPainter *painter)
|
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);
|
QString numStr = QString::number(number);
|
||||||
QFont font("Serif");
|
QFont font("Serif");
|
||||||
font.setPixelSize(fontSize);
|
font.setPixelSize(fontSize);
|
||||||
font.setWeight(QFont::Bold);
|
font.setWeight(QFont::Bold);
|
||||||
|
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
double w = fm.width(numStr) * 1.3;
|
double w = fm.width(numStr) * 1.3;
|
||||||
double h = fm.height() * 1.3;
|
double h = fm.height() * 1.3;
|
||||||
if (w < h)
|
if (w < h)
|
||||||
w = h;
|
w = h;
|
||||||
|
|
||||||
painter->setPen(QColor(255, 255, 255, 0));
|
painter->setPen(QColor(255, 255, 255, 0));
|
||||||
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
|
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
|
||||||
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
|
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
|
||||||
QColor color1(color), color2(color);
|
QColor color1(color), color2(color);
|
||||||
color1.setAlpha(255);
|
color1.setAlpha(255);
|
||||||
color2.setAlpha(0);
|
color2.setAlpha(0);
|
||||||
grad.setColorAt(0, color1);
|
grad.setColorAt(0, color1);
|
||||||
grad.setColorAt(0.8, color1);
|
grad.setColorAt(0.8, color1);
|
||||||
grad.setColorAt(1, color2);
|
grad.setColorAt(1, color2);
|
||||||
painter->setBrush(QBrush(grad));
|
painter->setBrush(QBrush(grad));
|
||||||
|
|
||||||
QRectF textRect;
|
QRectF textRect;
|
||||||
if (position == -1)
|
if (position == -1)
|
||||||
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
|
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
|
||||||
else {
|
else {
|
||||||
qreal xOffset = 10;
|
qreal xOffset = 10;
|
||||||
qreal yOffset = 20;
|
qreal yOffset = 20;
|
||||||
qreal spacing = 2;
|
qreal spacing = 2;
|
||||||
if (position < 2)
|
if (position < 2)
|
||||||
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h);
|
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h);
|
||||||
else
|
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);
|
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->drawEllipse(textRect);
|
||||||
|
|
||||||
painter->setPen(Qt::black);
|
painter->setPen(Qt::black);
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->drawText(textRect, Qt::AlignCenter, numStr);
|
painter->drawText(textRect, Qt::AlignCenter, numStr);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,20 @@
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
enum GraphicsItemType {
|
enum GraphicsItemType {
|
||||||
typeCard = QGraphicsItem::UserType + 1,
|
typeCard = QGraphicsItem::UserType + 1,
|
||||||
typeCardDrag = QGraphicsItem::UserType + 2,
|
typeCardDrag = QGraphicsItem::UserType + 2,
|
||||||
typeZone = QGraphicsItem::UserType + 3,
|
typeZone = QGraphicsItem::UserType + 3,
|
||||||
typePlayerTarget = QGraphicsItem::UserType + 4,
|
typePlayerTarget = QGraphicsItem::UserType + 4,
|
||||||
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
|
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
|
||||||
typeOther = QGraphicsItem::UserType + 6
|
typeOther = QGraphicsItem::UserType + 6
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractGraphicsItem : public QObject, public QGraphicsItem {
|
class AbstractGraphicsItem : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
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:
|
public:
|
||||||
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { }
|
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,127 +17,127 @@
|
||||||
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
|
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)
|
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
|
||||||
{
|
{
|
||||||
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
|
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
|
||||||
setZValue(2000000005);
|
setZValue(2000000005);
|
||||||
|
|
||||||
if (startItem)
|
if (startItem)
|
||||||
startItem->addArrowFrom(this);
|
startItem->addArrowFrom(this);
|
||||||
if (targetItem)
|
if (targetItem)
|
||||||
targetItem->addArrowTo(this);
|
targetItem->addArrowTo(this);
|
||||||
|
|
||||||
if (startItem && targetItem)
|
if (startItem && targetItem)
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowItem::~ArrowItem()
|
ArrowItem::~ArrowItem()
|
||||||
{
|
{
|
||||||
qDebug() << "ArrowItem destructor";
|
qDebug() << "ArrowItem destructor";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowItem::delArrow()
|
void ArrowItem::delArrow()
|
||||||
{
|
{
|
||||||
if (startItem) {
|
if (startItem) {
|
||||||
startItem->removeArrowFrom(this);
|
startItem->removeArrowFrom(this);
|
||||||
startItem = 0;
|
startItem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetItem) {
|
if (targetItem) {
|
||||||
targetItem->setBeingPointedAt(false);
|
targetItem->setBeingPointedAt(false);
|
||||||
targetItem->removeArrowTo(this);
|
targetItem->removeArrowTo(this);
|
||||||
targetItem = 0;
|
targetItem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
player->removeArrow(this);
|
player->removeArrow(this);
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowItem::updatePath()
|
void ArrowItem::updatePath()
|
||||||
{
|
{
|
||||||
if (!targetItem)
|
if (!targetItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
|
QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
|
||||||
updatePath(endPoint);
|
updatePath(endPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowItem::updatePath(const QPointF &endPoint)
|
void ArrowItem::updatePath(const QPointF &endPoint)
|
||||||
{
|
{
|
||||||
const double arrowWidth = 15.0;
|
const double arrowWidth = 15.0;
|
||||||
const double headWidth = 40.0;
|
const double headWidth = 40.0;
|
||||||
const double headLength = headWidth / sqrt(2);
|
const double headLength = headWidth / sqrt(2);
|
||||||
const double phi = 15;
|
const double phi = 15;
|
||||||
|
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
|
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
|
||||||
QLineF line(startPoint, endPoint);
|
QLineF line(startPoint, endPoint);
|
||||||
qreal lineLength = line.length();
|
qreal lineLength = line.length();
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
if (lineLength < 30)
|
if (lineLength < 30)
|
||||||
path = QPainterPath();
|
path = QPainterPath();
|
||||||
else {
|
else {
|
||||||
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
|
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
|
||||||
|
|
||||||
QPainterPath centerLine;
|
QPainterPath centerLine;
|
||||||
centerLine.moveTo(0, 0);
|
centerLine.moveTo(0, 0);
|
||||||
centerLine.quadTo(c, QPointF(lineLength, 0));
|
centerLine.quadTo(c, QPointF(lineLength, 0));
|
||||||
|
|
||||||
double percentage = 1 - headLength / lineLength;
|
double percentage = 1 - headLength / lineLength;
|
||||||
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
|
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
|
||||||
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
|
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
|
||||||
qreal alpha = testLine.angle() - 90;
|
qreal alpha = testLine.angle() - 90;
|
||||||
QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
|
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 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 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));
|
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 = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
|
||||||
path.quadTo(c, endPoint1);
|
path.quadTo(c, endPoint1);
|
||||||
path.lineTo(point1);
|
path.lineTo(point1);
|
||||||
path.lineTo(QPointF(lineLength, 0));
|
path.lineTo(QPointF(lineLength, 0));
|
||||||
path.lineTo(point2);
|
path.lineTo(point2);
|
||||||
path.lineTo(endPoint2);
|
path.lineTo(endPoint2);
|
||||||
path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
|
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)));
|
path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
|
||||||
}
|
}
|
||||||
|
|
||||||
setPos(startPoint);
|
setPos(startPoint);
|
||||||
setTransform(QTransform().rotate(-line.angle()));
|
setTransform(QTransform().rotate(-line.angle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
QColor paintColor(color);
|
QColor paintColor(color);
|
||||||
if (fullColor)
|
if (fullColor)
|
||||||
paintColor.setAlpha(200);
|
paintColor.setAlpha(200);
|
||||||
else
|
else
|
||||||
paintColor.setAlpha(150);
|
paintColor.setAlpha(150);
|
||||||
painter->setBrush(paintColor);
|
painter->setBrush(paintColor);
|
||||||
painter->drawPath(path);
|
painter->drawPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!player->getLocal()) {
|
if (!player->getLocal()) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
|
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
|
||||||
for (int i = 0; i < colliding.size(); ++i)
|
for (int i = 0; i < colliding.size(); ++i)
|
||||||
if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
|
if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
Command_DeleteArrow cmd;
|
Command_DeleteArrow cmd;
|
||||||
cmd.set_arrow_id(id);
|
cmd.set_arrow_id(id);
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color)
|
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)
|
void ArrowDragItem::addChildArrow(ArrowDragItem *childArrow)
|
||||||
{
|
{
|
||||||
childArrows.append(childArrow);
|
childArrows.append(childArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
// This ensures that if a mouse move event happens after a call to delArrow(),
|
// 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.
|
// the event will be discarded as it would create some stray pointers.
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF endPos = event->scenePos();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
||||||
ArrowTarget *cursorItem = 0;
|
ArrowTarget *cursorItem = 0;
|
||||||
qreal cursorItemZ = -1;
|
qreal cursorItemZ = -1;
|
||||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||||
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
||||||
if (colliding.at(i)->zValue() > cursorItemZ) {
|
if (colliding.at(i)->zValue() > cursorItemZ) {
|
||||||
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
||||||
cursorItemZ = cursorItem->zValue();
|
cursorItemZ = cursorItem->zValue();
|
||||||
}
|
}
|
||||||
if ((cursorItem != targetItem) && targetItem) {
|
if ((cursorItem != targetItem) && targetItem) {
|
||||||
targetItem->setBeingPointedAt(false);
|
targetItem->setBeingPointedAt(false);
|
||||||
targetItem->removeArrowTo(this);
|
targetItem->removeArrowTo(this);
|
||||||
}
|
}
|
||||||
if (!cursorItem) {
|
if (!cursorItem) {
|
||||||
fullColor = false;
|
fullColor = false;
|
||||||
targetItem = 0;
|
targetItem = 0;
|
||||||
updatePath(endPos);
|
updatePath(endPos);
|
||||||
} else {
|
} else {
|
||||||
if (cursorItem != targetItem) {
|
if (cursorItem != targetItem) {
|
||||||
fullColor = true;
|
fullColor = true;
|
||||||
if (cursorItem != startItem) {
|
if (cursorItem != startItem) {
|
||||||
cursorItem->setBeingPointedAt(true);
|
cursorItem->setBeingPointedAt(true);
|
||||||
cursorItem->addArrowTo(this);
|
cursorItem->addArrowTo(this);
|
||||||
}
|
}
|
||||||
targetItem = cursorItem;
|
targetItem = cursorItem;
|
||||||
}
|
}
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
|
|
||||||
for (int i = 0; i < childArrows.size(); ++i)
|
for (int i = 0; i < childArrows.size(); ++i)
|
||||||
childArrows[i]->mouseMoveEvent(event);
|
childArrows[i]->mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (targetItem && (targetItem != startItem)) {
|
if (targetItem && (targetItem != startItem)) {
|
||||||
CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
|
CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
|
||||||
// For now, we can safely assume that the start item is always a card.
|
// For now, we can safely assume that the start item is always a card.
|
||||||
// The target item can be a player as well.
|
// The target item can be a player as well.
|
||||||
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
||||||
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
||||||
|
|
||||||
Command_CreateArrow cmd;
|
Command_CreateArrow cmd;
|
||||||
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
|
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
cmd.set_start_card_id(startCard->getId());
|
cmd.set_start_card_id(startCard->getId());
|
||||||
|
|
||||||
if (targetCard) {
|
if (targetCard) {
|
||||||
CardZone *targetZone = targetCard->getZone();
|
CardZone *targetZone = targetCard->getZone();
|
||||||
cmd.set_target_player_id(targetZone->getPlayer()->getId());
|
cmd.set_target_player_id(targetZone->getPlayer()->getId());
|
||||||
cmd.set_target_zone(targetZone->getName().toStdString());
|
cmd.set_target_zone(targetZone->getName().toStdString());
|
||||||
cmd.set_target_card_id(targetCard->getId());
|
cmd.set_target_card_id(targetCard->getId());
|
||||||
} else {
|
} else {
|
||||||
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
|
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
|
||||||
cmd.set_target_player_id(targetPlayer->getOwner()->getId());
|
cmd.set_target_player_id(targetPlayer->getOwner()->getId());
|
||||||
}
|
}
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
delArrow();
|
delArrow();
|
||||||
|
|
||||||
for (int i = 0; i < childArrows.size(); ++i)
|
for (int i = 0; i < childArrows.size(); ++i)
|
||||||
childArrows[i]->mouseReleaseEvent(event);
|
childArrows[i]->mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
|
ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
|
||||||
|
@ -235,57 +235,57 @@ ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
|
||||||
|
|
||||||
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF endPos = event->scenePos();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
||||||
ArrowTarget *cursorItem = 0;
|
ArrowTarget *cursorItem = 0;
|
||||||
qreal cursorItemZ = -1;
|
qreal cursorItemZ = -1;
|
||||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||||
if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
||||||
if (colliding.at(i)->zValue() > cursorItemZ) {
|
if (colliding.at(i)->zValue() > cursorItemZ) {
|
||||||
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
||||||
cursorItemZ = cursorItem->zValue();
|
cursorItemZ = cursorItem->zValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cursorItem != targetItem) && targetItem)
|
if ((cursorItem != targetItem) && targetItem)
|
||||||
targetItem->setBeingPointedAt(false);
|
targetItem->setBeingPointedAt(false);
|
||||||
if (!cursorItem) {
|
if (!cursorItem) {
|
||||||
fullColor = false;
|
fullColor = false;
|
||||||
targetItem = 0;
|
targetItem = 0;
|
||||||
updatePath(endPos);
|
updatePath(endPos);
|
||||||
} else {
|
} else {
|
||||||
fullColor = true;
|
fullColor = true;
|
||||||
if (cursorItem != startItem)
|
if (cursorItem != startItem)
|
||||||
cursorItem->setBeingPointedAt(true);
|
cursorItem->setBeingPointedAt(true);
|
||||||
targetItem = cursorItem;
|
targetItem = cursorItem;
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||||
{
|
{
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (targetItem && (targetItem != startItem)) {
|
if (targetItem && (targetItem != startItem)) {
|
||||||
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
||||||
CardZone *startZone = startCard->getZone();
|
CardZone *startZone = startCard->getZone();
|
||||||
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
||||||
CardZone *targetZone = targetCard->getZone();
|
CardZone *targetZone = targetCard->getZone();
|
||||||
|
|
||||||
Command_AttachCard cmd;
|
Command_AttachCard cmd;
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
cmd.set_card_id(startCard->getId());
|
cmd.set_card_id(startCard->getId());
|
||||||
cmd.set_target_player_id(targetZone->getPlayer()->getId());
|
cmd.set_target_player_id(targetZone->getPlayer()->getId());
|
||||||
cmd.set_target_zone(targetZone->getName().toStdString());
|
cmd.set_target_zone(targetZone->getName().toStdString());
|
||||||
cmd.set_target_card_id(targetCard->getId());
|
cmd.set_target_card_id(targetCard->getId());
|
||||||
|
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
delArrow();
|
delArrow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,54 +10,54 @@ class Player;
|
||||||
class ArrowTarget;
|
class ArrowTarget;
|
||||||
|
|
||||||
class ArrowItem : public QObject, public QGraphicsItem {
|
class ArrowItem : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
QMenu *menu;
|
QMenu *menu;
|
||||||
protected:
|
protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
int id;
|
int id;
|
||||||
ArrowTarget *startItem, *targetItem;
|
ArrowTarget *startItem, *targetItem;
|
||||||
QColor color;
|
QColor color;
|
||||||
bool fullColor;
|
bool fullColor;
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
public:
|
public:
|
||||||
ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
|
ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
|
||||||
~ArrowItem();
|
~ArrowItem();
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QRectF boundingRect() const { return path.boundingRect(); }
|
QRectF boundingRect() const { return path.boundingRect(); }
|
||||||
QPainterPath shape() const { return path; }
|
QPainterPath shape() const { return path; }
|
||||||
void updatePath();
|
void updatePath();
|
||||||
void updatePath(const QPointF &endPoint);
|
void updatePath(const QPointF &endPoint);
|
||||||
|
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
Player *getPlayer() const { return player; }
|
Player *getPlayer() const { return player; }
|
||||||
void setStartItem(ArrowTarget *_item) { startItem = _item; }
|
void setStartItem(ArrowTarget *_item) { startItem = _item; }
|
||||||
void setTargetItem(ArrowTarget *_item) { targetItem = _item; }
|
void setTargetItem(ArrowTarget *_item) { targetItem = _item; }
|
||||||
ArrowTarget *getStartItem() const { return startItem; }
|
ArrowTarget *getStartItem() const { return startItem; }
|
||||||
ArrowTarget *getTargetItem() const { return targetItem; }
|
ArrowTarget *getTargetItem() const { return targetItem; }
|
||||||
void delArrow();
|
void delArrow();
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArrowDragItem : public ArrowItem {
|
class ArrowDragItem : public ArrowItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QList<ArrowDragItem *> childArrows;
|
QList<ArrowDragItem *> childArrows;
|
||||||
public:
|
public:
|
||||||
ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color);
|
ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color);
|
||||||
void addChildArrow(ArrowDragItem *childArrow);
|
void addChildArrow(ArrowDragItem *childArrow);
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArrowAttachItem : public ArrowItem {
|
class ArrowAttachItem : public ArrowItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ArrowAttachItem(ArrowTarget *_startItem);
|
ArrowAttachItem(ArrowTarget *_startItem);
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ARROWITEM_H
|
#endif // ARROWITEM_H
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
|
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
|
||||||
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
|
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowTarget::~ArrowTarget()
|
ArrowTarget::~ArrowTarget()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < arrowsFrom.size(); ++i) {
|
for (int i = 0; i < arrowsFrom.size(); ++i) {
|
||||||
arrowsFrom[i]->setStartItem(0);
|
arrowsFrom[i]->setStartItem(0);
|
||||||
arrowsFrom[i]->delArrow();
|
arrowsFrom[i]->delArrow();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < arrowsTo.size(); ++i) {
|
for (int i = 0; i < arrowsTo.size(); ++i) {
|
||||||
arrowsTo[i]->setTargetItem(0);
|
arrowsTo[i]->setTargetItem(0);
|
||||||
arrowsTo[i]->delArrow();
|
arrowsTo[i]->delArrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
|
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
|
||||||
{
|
{
|
||||||
beingPointedAt = _beingPointedAt;
|
beingPointedAt = _beingPointedAt;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,28 +8,28 @@ class Player;
|
||||||
class ArrowItem;
|
class ArrowItem;
|
||||||
|
|
||||||
class ArrowTarget : public AbstractGraphicsItem {
|
class ArrowTarget : public AbstractGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
Player *owner;
|
Player *owner;
|
||||||
private:
|
private:
|
||||||
bool beingPointedAt;
|
bool beingPointedAt;
|
||||||
QList<ArrowItem *> arrowsFrom, arrowsTo;
|
QList<ArrowItem *> arrowsFrom, arrowsTo;
|
||||||
public:
|
public:
|
||||||
ArrowTarget(Player *_owner, QGraphicsItem *parent = 0);
|
ArrowTarget(Player *_owner, QGraphicsItem *parent = 0);
|
||||||
~ArrowTarget();
|
~ArrowTarget();
|
||||||
|
|
||||||
Player *getOwner() const { return owner; }
|
Player *getOwner() const { return owner; }
|
||||||
|
|
||||||
void setBeingPointedAt(bool _beingPointedAt);
|
void setBeingPointedAt(bool _beingPointedAt);
|
||||||
bool getBeingPointedAt() const { return beingPointedAt; }
|
bool getBeingPointedAt() const { return beingPointedAt; }
|
||||||
|
|
||||||
const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; }
|
const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; }
|
||||||
void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); }
|
void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); }
|
||||||
void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); }
|
void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); }
|
||||||
|
|
||||||
const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; }
|
const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; }
|
||||||
void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); }
|
void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); }
|
||||||
void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); }
|
void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,191 +22,191 @@ typedef QMap<QString, QString> QStringMap;
|
||||||
|
|
||||||
class CardSet : public QList<CardInfo *> {
|
class CardSet : public QList<CardInfo *> {
|
||||||
private:
|
private:
|
||||||
QString shortName, longName;
|
QString shortName, longName;
|
||||||
unsigned int sortKey;
|
unsigned int sortKey;
|
||||||
public:
|
public:
|
||||||
CardSet(const QString &_shortName = QString(), const QString &_longName = QString());
|
CardSet(const QString &_shortName = QString(), const QString &_longName = QString());
|
||||||
QString getShortName() const { return shortName; }
|
QString getShortName() const { return shortName; }
|
||||||
QString getLongName() const { return longName; }
|
QString getLongName() const { return longName; }
|
||||||
int getSortKey() const { return sortKey; }
|
int getSortKey() const { return sortKey; }
|
||||||
void setSortKey(unsigned int _sortKey);
|
void setSortKey(unsigned int _sortKey);
|
||||||
void updateSortKey();
|
void updateSortKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetList : public QList<CardSet *> {
|
class SetList : public QList<CardSet *> {
|
||||||
private:
|
private:
|
||||||
class CompareFunctor;
|
class CompareFunctor;
|
||||||
public:
|
public:
|
||||||
void sortByKey();
|
void sortByKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
class PictureToLoad {
|
class PictureToLoad {
|
||||||
private:
|
private:
|
||||||
CardInfo *card;
|
CardInfo *card;
|
||||||
bool stripped;
|
bool stripped;
|
||||||
SetList sortedSets;
|
SetList sortedSets;
|
||||||
int setIndex;
|
int setIndex;
|
||||||
bool hq;
|
bool hq;
|
||||||
public:
|
public:
|
||||||
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
|
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
|
||||||
CardInfo *getCard() const { return card; }
|
CardInfo *getCard() const { return card; }
|
||||||
bool getStripped() const { return stripped; }
|
bool getStripped() const { return stripped; }
|
||||||
QString getSetName() const { return sortedSets[setIndex]->getShortName(); }
|
QString getSetName() const { return sortedSets[setIndex]->getShortName(); }
|
||||||
bool nextSet();
|
bool nextSet();
|
||||||
|
|
||||||
bool getHq() const { return hq; }
|
bool getHq() const { return hq; }
|
||||||
void setHq(bool _hq) { hq = _hq; }
|
void setHq(bool _hq) { hq = _hq; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PictureLoader : public QObject {
|
class PictureLoader : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString _picsPath;
|
QString _picsPath;
|
||||||
QList<PictureToLoad> loadQueue;
|
QList<PictureToLoad> loadQueue;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
QNetworkAccessManager *networkManager;
|
QNetworkAccessManager *networkManager;
|
||||||
QList<PictureToLoad> cardsToDownload;
|
QList<PictureToLoad> cardsToDownload;
|
||||||
PictureToLoad cardBeingDownloaded;
|
PictureToLoad cardBeingDownloaded;
|
||||||
bool picDownload, downloadRunning, loadQueueRunning;
|
bool picDownload, downloadRunning, loadQueueRunning;
|
||||||
void startNextPicDownload();
|
void startNextPicDownload();
|
||||||
public:
|
public:
|
||||||
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
|
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
|
||||||
~PictureLoader();
|
~PictureLoader();
|
||||||
void setPicsPath(const QString &path);
|
void setPicsPath(const QString &path);
|
||||||
void setPicDownload(bool _picDownload);
|
void setPicDownload(bool _picDownload);
|
||||||
void loadImage(CardInfo *card, bool stripped);
|
void loadImage(CardInfo *card, bool stripped);
|
||||||
private slots:
|
private slots:
|
||||||
void picDownloadFinished(QNetworkReply *reply);
|
void picDownloadFinished(QNetworkReply *reply);
|
||||||
public slots:
|
public slots:
|
||||||
void processLoadQueue();
|
void processLoadQueue();
|
||||||
signals:
|
signals:
|
||||||
void startLoadQueue();
|
void startLoadQueue();
|
||||||
void imageLoaded(CardInfo *card, const QImage &image);
|
void imageLoaded(CardInfo *card, const QImage &image);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardInfo : public QObject {
|
class CardInfo : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
bool isToken;
|
bool isToken;
|
||||||
SetList sets;
|
SetList sets;
|
||||||
QString manacost;
|
QString manacost;
|
||||||
QString cardtype;
|
QString cardtype;
|
||||||
QString powtough;
|
QString powtough;
|
||||||
QString text;
|
QString text;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
int loyalty;
|
int loyalty;
|
||||||
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
||||||
bool cipt;
|
bool cipt;
|
||||||
int tableRow;
|
int tableRow;
|
||||||
QPixmap *pixmap;
|
QPixmap *pixmap;
|
||||||
QMap<int, QPixmap *> scaledPixmapCache;
|
QMap<int, QPixmap *> scaledPixmapCache;
|
||||||
public:
|
public:
|
||||||
CardInfo(CardDatabase *_db,
|
CardInfo(CardDatabase *_db,
|
||||||
const QString &_name = QString(),
|
const QString &_name = QString(),
|
||||||
bool _isToken = false,
|
bool _isToken = false,
|
||||||
const QString &_manacost = QString(),
|
const QString &_manacost = QString(),
|
||||||
const QString &_cardtype = QString(),
|
const QString &_cardtype = QString(),
|
||||||
const QString &_powtough = QString(),
|
const QString &_powtough = QString(),
|
||||||
const QString &_text = QString(),
|
const QString &_text = QString(),
|
||||||
const QStringList &_colors = QStringList(),
|
const QStringList &_colors = QStringList(),
|
||||||
int _loyalty = 0,
|
int _loyalty = 0,
|
||||||
bool _cipt = false,
|
bool _cipt = false,
|
||||||
int _tableRow = 0,
|
int _tableRow = 0,
|
||||||
const SetList &_sets = SetList(),
|
const SetList &_sets = SetList(),
|
||||||
const QStringMap &_picURLs = QStringMap(),
|
const QStringMap &_picURLs = QStringMap(),
|
||||||
const QStringMap &_picURLsHq = QStringMap(),
|
const QStringMap &_picURLsHq = QStringMap(),
|
||||||
const QStringMap &_picURLsSt = QStringMap());
|
const QStringMap &_picURLsSt = QStringMap());
|
||||||
~CardInfo();
|
~CardInfo();
|
||||||
const QString &getName() const { return name; }
|
const QString &getName() const { return name; }
|
||||||
bool getIsToken() const { return isToken; }
|
bool getIsToken() const { return isToken; }
|
||||||
const SetList &getSets() const { return sets; }
|
const SetList &getSets() const { return sets; }
|
||||||
const QString &getManaCost() const { return manacost; }
|
const QString &getManaCost() const { return manacost; }
|
||||||
const QString &getCardType() const { return cardtype; }
|
const QString &getCardType() const { return cardtype; }
|
||||||
const QString &getPowTough() const { return powtough; }
|
const QString &getPowTough() const { return powtough; }
|
||||||
const QString &getText() const { return text; }
|
const QString &getText() const { return text; }
|
||||||
const int &getLoyalty() const { return loyalty; }
|
const int &getLoyalty() const { return loyalty; }
|
||||||
bool getCipt() const { return cipt; }
|
bool getCipt() const { return cipt; }
|
||||||
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
|
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
|
||||||
void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); }
|
void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); }
|
||||||
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
|
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
|
||||||
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
|
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
|
||||||
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
|
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
|
||||||
const QStringList &getColors() const { return colors; }
|
const QStringList &getColors() const { return colors; }
|
||||||
QString getPicURL(const QString &set) const { return picURLs.value(set); }
|
QString getPicURL(const QString &set) const { return picURLs.value(set); }
|
||||||
QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); }
|
QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); }
|
||||||
QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); }
|
QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); }
|
||||||
QString getPicURL() const;
|
QString getPicURL() const;
|
||||||
const QMap<QString, QString> &getPicURLs() const { return picURLs; }
|
const QMap<QString, QString> &getPicURLs() const { return picURLs; }
|
||||||
QString getMainCardType() const;
|
QString getMainCardType() const;
|
||||||
QString getCorrectedName() const;
|
QString getCorrectedName() const;
|
||||||
int getTableRow() const { return tableRow; }
|
int getTableRow() const { return tableRow; }
|
||||||
void setTableRow(int _tableRow) { tableRow = _tableRow; }
|
void setTableRow(int _tableRow) { tableRow = _tableRow; }
|
||||||
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
|
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
|
||||||
void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
|
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 setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); }
|
||||||
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
|
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
|
||||||
void addToSet(CardSet *set);
|
void addToSet(CardSet *set);
|
||||||
QPixmap *loadPixmap();
|
QPixmap *loadPixmap();
|
||||||
QPixmap *getPixmap(QSize size);
|
QPixmap *getPixmap(QSize size);
|
||||||
void clearPixmapCache();
|
void clearPixmapCache();
|
||||||
void clearPixmapCacheMiss();
|
void clearPixmapCacheMiss();
|
||||||
void imageLoaded(const QImage &image);
|
void imageLoaded(const QImage &image);
|
||||||
public slots:
|
public slots:
|
||||||
void updatePixmapCache();
|
void updatePixmapCache();
|
||||||
signals:
|
signals:
|
||||||
void pixmapUpdated();
|
void pixmapUpdated();
|
||||||
void cardInfoChanged(CardInfo *card);
|
void cardInfoChanged(CardInfo *card);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabase : public QObject {
|
class CardDatabase : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
QHash<QString, CardInfo *> cardHash;
|
QHash<QString, CardInfo *> cardHash;
|
||||||
QHash<QString, CardSet *> setHash;
|
QHash<QString, CardSet *> setHash;
|
||||||
bool loadSuccess;
|
bool loadSuccess;
|
||||||
CardInfo *noCard;
|
CardInfo *noCard;
|
||||||
|
|
||||||
QThread *pictureLoaderThread;
|
QThread *pictureLoaderThread;
|
||||||
PictureLoader *pictureLoader;
|
PictureLoader *pictureLoader;
|
||||||
private:
|
private:
|
||||||
static const int versionNeeded;
|
static const int versionNeeded;
|
||||||
void loadCardsFromXml(QXmlStreamReader &xml);
|
void loadCardsFromXml(QXmlStreamReader &xml);
|
||||||
void loadSetsFromXml(QXmlStreamReader &xml);
|
void loadSetsFromXml(QXmlStreamReader &xml);
|
||||||
public:
|
public:
|
||||||
CardDatabase(QObject *parent = 0);
|
CardDatabase(QObject *parent = 0);
|
||||||
~CardDatabase();
|
~CardDatabase();
|
||||||
void clear();
|
void clear();
|
||||||
void addCard(CardInfo *card);
|
void addCard(CardInfo *card);
|
||||||
void removeCard(CardInfo *card);
|
void removeCard(CardInfo *card);
|
||||||
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
|
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
|
||||||
CardSet *getSet(const QString &setName);
|
CardSet *getSet(const QString &setName);
|
||||||
QList<CardInfo *> getCardList() const { return cardHash.values(); }
|
QList<CardInfo *> getCardList() const { return cardHash.values(); }
|
||||||
SetList getSetList() const;
|
SetList getSetList() const;
|
||||||
bool loadFromFile(const QString &fileName, bool tokens = false);
|
bool loadFromFile(const QString &fileName, bool tokens = false);
|
||||||
bool saveToFile(const QString &fileName, bool tokens = false);
|
bool saveToFile(const QString &fileName, bool tokens = false);
|
||||||
QStringList getAllColors() const;
|
QStringList getAllColors() const;
|
||||||
QStringList getAllMainCardTypes() const;
|
QStringList getAllMainCardTypes() const;
|
||||||
bool getLoadSuccess() const { return loadSuccess; }
|
bool getLoadSuccess() const { return loadSuccess; }
|
||||||
void cacheCardPixmaps(const QStringList &cardNames);
|
void cacheCardPixmaps(const QStringList &cardNames);
|
||||||
void loadImage(CardInfo *card);
|
void loadImage(CardInfo *card);
|
||||||
public slots:
|
public slots:
|
||||||
void clearPixmapCache();
|
void clearPixmapCache();
|
||||||
bool loadCardDatabase(const QString &path, bool tokens = false);
|
bool loadCardDatabase(const QString &path, bool tokens = false);
|
||||||
private slots:
|
private slots:
|
||||||
void imageLoaded(CardInfo *card, QImage image);
|
void imageLoaded(CardInfo *card, QImage image);
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
|
|
||||||
void loadCardDatabase();
|
void loadCardDatabase();
|
||||||
void loadTokenDatabase();
|
void loadTokenDatabase();
|
||||||
signals:
|
signals:
|
||||||
void cardListChanged();
|
void cardListChanged();
|
||||||
void cardAdded(CardInfo *card);
|
void cardAdded(CardInfo *card);
|
||||||
void cardRemoved(CardInfo *card);
|
void cardRemoved(CardInfo *card);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "carddatabasemodel.h"
|
#include "carddatabasemodel.h"
|
||||||
|
|
||||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
||||||
: QAbstractListModel(parent), db(_db)
|
: QAbstractListModel(parent), db(_db)
|
||||||
{
|
{
|
||||||
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
||||||
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
||||||
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
||||||
updateCardList();
|
updateCardList();
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabaseModel::~CardDatabaseModel()
|
CardDatabaseModel::~CardDatabaseModel()
|
||||||
|
@ -15,143 +15,143 @@ CardDatabaseModel::~CardDatabaseModel()
|
||||||
|
|
||||||
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
|
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return cardList.size();
|
return cardList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
|
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if ((index.row() >= cardList.size()) || (index.column() >= 5))
|
if ((index.row() >= cardList.size()) || (index.column() >= 5))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
CardInfo *card = cardList.at(index.row());
|
CardInfo *card = cardList.at(index.row());
|
||||||
switch (index.column()){
|
switch (index.column()){
|
||||||
case 0: return card->getName();
|
case 0: return card->getName();
|
||||||
case 1: {
|
case 1: {
|
||||||
QStringList setList;
|
QStringList setList;
|
||||||
const QList<CardSet *> &sets = card->getSets();
|
const QList<CardSet *> &sets = card->getSets();
|
||||||
for (int i = 0; i < sets.size(); i++)
|
for (int i = 0; i < sets.size(); i++)
|
||||||
setList << sets[i]->getShortName();
|
setList << sets[i]->getShortName();
|
||||||
return setList.join(", ");
|
return setList.join(", ");
|
||||||
}
|
}
|
||||||
case 2: return card->getManaCost();
|
case 2: return card->getManaCost();
|
||||||
case 3: return card->getCardType();
|
case 3: return card->getCardType();
|
||||||
case 4: return card->getPowTough();
|
case 4: return card->getPowTough();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (orientation != Qt::Horizontal)
|
if (orientation != Qt::Horizontal)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return QString(tr("Name"));
|
case 0: return QString(tr("Name"));
|
||||||
case 1: return QString(tr("Sets"));
|
case 1: return QString(tr("Sets"));
|
||||||
case 2: return QString(tr("Mana cost"));
|
case 2: return QString(tr("Mana cost"));
|
||||||
case 3: return QString(tr("Card type"));
|
case 3: return QString(tr("Card type"));
|
||||||
case 4: return QString(tr("P/T"));
|
case 4: return QString(tr("P/T"));
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::updateCardList()
|
void CardDatabaseModel::updateCardList()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
disconnect(cardList[i], 0, this, 0);
|
disconnect(cardList[i], 0, this, 0);
|
||||||
|
|
||||||
cardList = db->getCardList();
|
cardList = db->getCardList();
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit dataChanged(index(row, 0), index(row, 4));
|
emit dataChanged(index(row, 0), index(row, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardAdded(CardInfo *card)
|
void CardDatabaseModel::cardAdded(CardInfo *card)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
||||||
cardList.append(card);
|
cardList.append(card);
|
||||||
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
cardList.removeAt(row);
|
cardList.removeAt(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent),
|
: QSortFilterProxyModel(parent),
|
||||||
isToken(ShowAll)
|
isToken(ShowAll)
|
||||||
{
|
{
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
{
|
{
|
||||||
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
|
|
||||||
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardNameBeginning.isEmpty())
|
if (!cardNameBeginning.isEmpty())
|
||||||
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardName.isEmpty())
|
if (!cardName.isEmpty())
|
||||||
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardNameSet.isEmpty())
|
if (!cardNameSet.isEmpty())
|
||||||
if (!cardNameSet.contains(info->getName()))
|
if (!cardNameSet.contains(info->getName()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardText.isEmpty())
|
if (!cardText.isEmpty())
|
||||||
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardColors.isEmpty())
|
if (!cardColors.isEmpty())
|
||||||
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardTypes.isEmpty())
|
if (!cardTypes.isEmpty())
|
||||||
if (!cardTypes.contains(info->getMainCardType()))
|
if (!cardTypes.contains(info->getMainCardType()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseDisplayModel::clearSearch()
|
void CardDatabaseDisplayModel::clearSearch()
|
||||||
{
|
{
|
||||||
cardName.clear();
|
cardName.clear();
|
||||||
cardText.clear();
|
cardText.clear();
|
||||||
cardTypes.clear();
|
cardTypes.clear();
|
||||||
cardColors.clear();
|
cardColors.clear();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,46 +8,46 @@
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
|
||||||
class CardDatabaseModel : public QAbstractListModel {
|
class CardDatabaseModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
|
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
|
||||||
~CardDatabaseModel();
|
~CardDatabaseModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
CardDatabase *getDatabase() const { return db; }
|
CardDatabase *getDatabase() const { return db; }
|
||||||
CardInfo *getCard(int index) const { return cardList[index]; }
|
CardInfo *getCard(int index) const { return cardList[index]; }
|
||||||
private:
|
private:
|
||||||
QList<CardInfo *> cardList;
|
QList<CardInfo *> cardList;
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
private slots:
|
private slots:
|
||||||
void updateCardList();
|
void updateCardList();
|
||||||
void cardAdded(CardInfo *card);
|
void cardAdded(CardInfo *card);
|
||||||
void cardRemoved(CardInfo *card);
|
void cardRemoved(CardInfo *card);
|
||||||
void cardInfoChanged(CardInfo *card);
|
void cardInfoChanged(CardInfo *card);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
|
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
|
||||||
private:
|
private:
|
||||||
FilterBool isToken;
|
FilterBool isToken;
|
||||||
QString cardNameBeginning, cardName, cardText;
|
QString cardNameBeginning, cardName, cardText;
|
||||||
QSet<QString> cardNameSet, cardTypes, cardColors;
|
QSet<QString> cardNameSet, cardTypes, cardColors;
|
||||||
public:
|
public:
|
||||||
CardDatabaseDisplayModel(QObject *parent = 0);
|
CardDatabaseDisplayModel(QObject *parent = 0);
|
||||||
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
|
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
|
||||||
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
||||||
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
||||||
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
||||||
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
||||||
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
||||||
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
||||||
void clearSearch();
|
void clearSearch();
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,82 +9,82 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag)
|
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)
|
void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
AbstractCardDragItem::paint(painter, option, widget);
|
AbstractCardDragItem::paint(painter, option, widget);
|
||||||
|
|
||||||
if (occupied)
|
if (occupied)
|
||||||
painter->fillRect(boundingRect(), QColor(200, 0, 0, 100));
|
painter->fillRect(boundingRect(), QColor(200, 0, 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
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;
|
CardZone *cardZone = 0;
|
||||||
ZoneViewZone *zoneViewZone = 0;
|
ZoneViewZone *zoneViewZone = 0;
|
||||||
for (int i = colliding.size() - 1; i >= 0; i--) {
|
for (int i = colliding.size() - 1; i >= 0; i--) {
|
||||||
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
|
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
|
||||||
if (!cardZone)
|
if (!cardZone)
|
||||||
cardZone = temp;
|
cardZone = temp;
|
||||||
if (!zoneViewZone)
|
if (!zoneViewZone)
|
||||||
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
|
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
|
||||||
}
|
}
|
||||||
CardZone *cursorZone = 0;
|
CardZone *cursorZone = 0;
|
||||||
if (zoneViewZone)
|
if (zoneViewZone)
|
||||||
cursorZone = zoneViewZone;
|
cursorZone = zoneViewZone;
|
||||||
else if (cardZone)
|
else if (cardZone)
|
||||||
cursorZone = cardZone;
|
cursorZone = cardZone;
|
||||||
if (!cursorZone)
|
if (!cursorZone)
|
||||||
return;
|
return;
|
||||||
currentZone = cursorZone;
|
currentZone = cursorZone;
|
||||||
|
|
||||||
QPointF zonePos = currentZone->scenePos();
|
QPointF zonePos = currentZone->scenePos();
|
||||||
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
||||||
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
||||||
QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft);
|
QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft);
|
||||||
QPointF newPos = zonePos + closestGridPoint;
|
QPointF newPos = zonePos + closestGridPoint;
|
||||||
|
|
||||||
if (newPos != pos()) {
|
if (newPos != pos()) {
|
||||||
for (int i = 0; i < childDrags.size(); i++)
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||||
setPos(newPos);
|
setPos(newPos);
|
||||||
|
|
||||||
bool newOccupied = false;
|
bool newOccupied = false;
|
||||||
TableZone *table = qobject_cast<TableZone *>(cursorZone);
|
TableZone *table = qobject_cast<TableZone *>(cursorZone);
|
||||||
if (table)
|
if (table)
|
||||||
if (table->getCardFromCoords(closestGridPoint))
|
if (table->getCardFromCoords(closestGridPoint))
|
||||||
newOccupied = true;
|
newOccupied = true;
|
||||||
if (newOccupied != occupied) {
|
if (newOccupied != occupied) {
|
||||||
occupied = newOccupied;
|
occupied = newOccupied;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
QGraphicsScene *sc = scene();
|
QGraphicsScene *sc = scene();
|
||||||
QPointF sp = pos();
|
QPointF sp = pos();
|
||||||
sc->removeItem(this);
|
sc->removeItem(this);
|
||||||
|
|
||||||
QList<CardDragItem *> dragItemList;
|
QList<CardDragItem *> dragItemList;
|
||||||
CardZone *startZone = static_cast<CardItem *>(item)->getZone();
|
CardZone *startZone = static_cast<CardItem *>(item)->getZone();
|
||||||
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
|
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
|
||||||
dragItemList.append(this);
|
dragItemList.append(this);
|
||||||
for (int i = 0; i < childDrags.size(); i++) {
|
for (int i = 0; i < childDrags.size(); i++) {
|
||||||
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
|
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
|
||||||
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
|
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
|
||||||
dragItemList.append(c);
|
dragItemList.append(c);
|
||||||
sc->removeItem(c);
|
sc->removeItem(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
|
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
class CardItem;
|
class CardItem;
|
||||||
|
|
||||||
class CardDragItem : public AbstractCardDragItem {
|
class CardDragItem : public AbstractCardDragItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
bool faceDown;
|
bool faceDown;
|
||||||
bool occupied;
|
bool occupied;
|
||||||
CardZone *currentZone;
|
CardZone *currentZone;
|
||||||
public:
|
public:
|
||||||
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
|
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
bool getFaceDown() const { return faceDown; }
|
bool getFaceDown() const { return faceDown; }
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void updatePosition(const QPointF &cursorScenePos);
|
void updatePosition(const QPointF &cursorScenePos);
|
||||||
protected:
|
protected:
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,209 +12,209 @@
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
|
||||||
CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
|
CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
|
||||||
: QFrame(parent, flags)
|
: QFrame(parent, flags)
|
||||||
, pixmapWidth(0)
|
, pixmapWidth(0)
|
||||||
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
|
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
|
||||||
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
|
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
|
||||||
, mode(_mode)
|
, mode(_mode)
|
||||||
, info(0)
|
, info(0)
|
||||||
{
|
{
|
||||||
if (mode == ModeGameTab) {
|
if (mode == ModeGameTab) {
|
||||||
// Create indexed list of status views for card.
|
// Create indexed list of status views for card.
|
||||||
const QStringList cardInfoStatus = QStringList() << tr("Show card only") << tr("Show text only") << tr("Show full info");
|
const QStringList cardInfoStatus = QStringList() << tr("Show card only") << tr("Show text only") << tr("Show full info");
|
||||||
|
|
||||||
// Create droplist for cardinfo view selection, and set right current index.
|
// Create droplist for cardinfo view selection, and set right current index.
|
||||||
dropList = new QComboBox();
|
dropList = new QComboBox();
|
||||||
dropList->addItems(cardInfoStatus);
|
dropList->addItems(cardInfoStatus);
|
||||||
dropList->setCurrentIndex(minimized);
|
dropList->setCurrentIndex(minimized);
|
||||||
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
|
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
cardPicture = new QLabel;
|
cardPicture = new QLabel;
|
||||||
cardPicture->setAlignment(Qt::AlignCenter);
|
cardPicture->setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
nameLabel1 = new QLabel;
|
nameLabel1 = new QLabel;
|
||||||
nameLabel2 = new QLabel;
|
nameLabel2 = new QLabel;
|
||||||
nameLabel2->setWordWrap(true);
|
nameLabel2->setWordWrap(true);
|
||||||
manacostLabel1 = new QLabel;
|
manacostLabel1 = new QLabel;
|
||||||
manacostLabel2 = new QLabel;
|
manacostLabel2 = new QLabel;
|
||||||
manacostLabel2->setWordWrap(true);
|
manacostLabel2->setWordWrap(true);
|
||||||
cardtypeLabel1 = new QLabel;
|
cardtypeLabel1 = new QLabel;
|
||||||
cardtypeLabel2 = new QLabel;
|
cardtypeLabel2 = new QLabel;
|
||||||
cardtypeLabel2->setWordWrap(true);
|
cardtypeLabel2->setWordWrap(true);
|
||||||
powtoughLabel1 = new QLabel;
|
powtoughLabel1 = new QLabel;
|
||||||
powtoughLabel2 = new QLabel;
|
powtoughLabel2 = new QLabel;
|
||||||
loyaltyLabel1 = new QLabel;
|
loyaltyLabel1 = new QLabel;
|
||||||
loyaltyLabel2 = new QLabel;
|
loyaltyLabel2 = new QLabel;
|
||||||
|
|
||||||
textLabel = new QTextEdit();
|
textLabel = new QTextEdit();
|
||||||
textLabel->setReadOnly(true);
|
textLabel->setReadOnly(true);
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout(this);
|
QGridLayout *grid = new QGridLayout(this);
|
||||||
int row = 0;
|
int row = 0;
|
||||||
if (mode == ModeGameTab)
|
if (mode == ModeGameTab)
|
||||||
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
|
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
|
||||||
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
||||||
grid->addWidget(nameLabel1, row, 0);
|
grid->addWidget(nameLabel1, row, 0);
|
||||||
grid->addWidget(nameLabel2, row++, 1);
|
grid->addWidget(nameLabel2, row++, 1);
|
||||||
grid->addWidget(manacostLabel1, row, 0);
|
grid->addWidget(manacostLabel1, row, 0);
|
||||||
grid->addWidget(manacostLabel2, row++, 1);
|
grid->addWidget(manacostLabel2, row++, 1);
|
||||||
grid->addWidget(cardtypeLabel1, row, 0);
|
grid->addWidget(cardtypeLabel1, row, 0);
|
||||||
grid->addWidget(cardtypeLabel2, row++, 1);
|
grid->addWidget(cardtypeLabel2, row++, 1);
|
||||||
grid->addWidget(powtoughLabel1, row, 0);
|
grid->addWidget(powtoughLabel1, row, 0);
|
||||||
grid->addWidget(powtoughLabel2, row++, 1);
|
grid->addWidget(powtoughLabel2, row++, 1);
|
||||||
grid->addWidget(loyaltyLabel1, row, 0);
|
grid->addWidget(loyaltyLabel1, row, 0);
|
||||||
grid->addWidget(loyaltyLabel2, row++, 1);
|
grid->addWidget(loyaltyLabel2, row++, 1);
|
||||||
grid->addWidget(textLabel, row, 0, -1, 2);
|
grid->addWidget(textLabel, row, 0, -1, 2);
|
||||||
grid->setRowStretch(row, 1);
|
grid->setRowStretch(row, 1);
|
||||||
grid->setColumnStretch(1, 1);
|
grid->setColumnStretch(1, 1);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||||
if (mode == ModeGameTab) {
|
if (mode == ModeGameTab) {
|
||||||
textLabel->setMinimumHeight(100);
|
textLabel->setMinimumHeight(100);
|
||||||
setFixedWidth(sizeHint().width());
|
setFixedWidth(sizeHint().width());
|
||||||
} else if (mode == ModePopUp) {
|
} else if (mode == ModePopUp) {
|
||||||
QDesktopWidget desktopWidget;
|
QDesktopWidget desktopWidget;
|
||||||
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
|
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
|
||||||
setFixedWidth(pixmapWidth + 150);
|
setFixedWidth(pixmapWidth + 150);
|
||||||
} else
|
} else
|
||||||
setFixedWidth(250);
|
setFixedWidth(250);
|
||||||
|
|
||||||
setCard(db->getCard(cardName));
|
setCard(db->getCard(cardName));
|
||||||
setMinimized(settingsCache->getCardInfoMinimized());
|
setMinimized(settingsCache->getCardInfoMinimized());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::minimizeClicked(int newMinimized)
|
void CardInfoWidget::minimizeClicked(int newMinimized)
|
||||||
{
|
{
|
||||||
// Set new status, and store it in the settings cache.
|
// Set new status, and store it in the settings cache.
|
||||||
setMinimized(newMinimized);
|
setMinimized(newMinimized);
|
||||||
settingsCache->setCardInfoMinimized(newMinimized);
|
settingsCache->setCardInfoMinimized(newMinimized);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardInfoWidget::shouldShowPowTough()
|
bool CardInfoWidget::shouldShowPowTough()
|
||||||
{
|
{
|
||||||
// return (!info->getPowTough().isEmpty() && (minimized != 0));
|
// return (!info->getPowTough().isEmpty() && (minimized != 0));
|
||||||
return (minimized != 0);
|
return (minimized != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardInfoWidget::shouldShowLoyalty()
|
bool CardInfoWidget::shouldShowLoyalty()
|
||||||
{
|
{
|
||||||
// return ((info->getLoyalty() > 0) && (minimized != 0));
|
// return ((info->getLoyalty() > 0) && (minimized != 0));
|
||||||
return (minimized != 0);
|
return (minimized != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setMinimized(int _minimized)
|
void CardInfoWidget::setMinimized(int _minimized)
|
||||||
{
|
{
|
||||||
minimized = _minimized;
|
minimized = _minimized;
|
||||||
|
|
||||||
// Toggle oracle fields according to selected view.
|
// Toggle oracle fields according to selected view.
|
||||||
bool showAll = ((minimized == 1) || (minimized == 2));
|
bool showAll = ((minimized == 1) || (minimized == 2));
|
||||||
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
|
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
|
||||||
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
|
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
|
||||||
if (mode == ModeGameTab) {
|
if (mode == ModeGameTab) {
|
||||||
nameLabel1->setVisible(showAll);
|
nameLabel1->setVisible(showAll);
|
||||||
nameLabel2->setVisible(showAll);
|
nameLabel2->setVisible(showAll);
|
||||||
manacostLabel1->setVisible(showAll);
|
manacostLabel1->setVisible(showAll);
|
||||||
manacostLabel2->setVisible(showAll);
|
manacostLabel2->setVisible(showAll);
|
||||||
cardtypeLabel1->setVisible(showAll);
|
cardtypeLabel1->setVisible(showAll);
|
||||||
cardtypeLabel2->setVisible(showAll);
|
cardtypeLabel2->setVisible(showAll);
|
||||||
powtoughLabel1->setVisible(showPowTough);
|
powtoughLabel1->setVisible(showPowTough);
|
||||||
powtoughLabel2->setVisible(showPowTough);
|
powtoughLabel2->setVisible(showPowTough);
|
||||||
loyaltyLabel1->setVisible(showLoyalty);
|
loyaltyLabel1->setVisible(showLoyalty);
|
||||||
loyaltyLabel2->setVisible(showLoyalty);
|
loyaltyLabel2->setVisible(showLoyalty);
|
||||||
textLabel->setVisible(showAll);
|
textLabel->setVisible(showAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
cardPicture->hide();
|
cardPicture->hide();
|
||||||
cardHeightOffset = minimumSizeHint().height() + 10;
|
cardHeightOffset = minimumSizeHint().height() + 10;
|
||||||
|
|
||||||
// Set the picture to be shown only at "card only" (0) and "full info" (2)
|
// Set the picture to be shown only at "card only" (0) and "full info" (2)
|
||||||
if (mode == ModeGameTab) {
|
if (mode == ModeGameTab) {
|
||||||
cardPicture->setVisible((minimized == 0) || (minimized == 2));
|
cardPicture->setVisible((minimized == 0) || (minimized == 2));
|
||||||
|
|
||||||
if (minimized == 0)
|
if (minimized == 0)
|
||||||
setMaximumHeight(cardHeightOffset + width() * aspectRatio);
|
setMaximumHeight(cardHeightOffset + width() * aspectRatio);
|
||||||
else
|
else
|
||||||
setMaximumHeight(1000000);
|
setMaximumHeight(1000000);
|
||||||
} else
|
} else
|
||||||
cardPicture->show();
|
cardPicture->show();
|
||||||
resize(width(), sizeHint().height());
|
resize(width(), sizeHint().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(CardInfo *card)
|
void CardInfoWidget::setCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (info)
|
if (info)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, 0, this, 0);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
||||||
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||||
|
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
nameLabel2->setText(card->getName());
|
nameLabel2->setText(card->getName());
|
||||||
manacostLabel2->setText(card->getManaCost());
|
manacostLabel2->setText(card->getManaCost());
|
||||||
cardtypeLabel2->setText(card->getCardType());
|
cardtypeLabel2->setText(card->getCardType());
|
||||||
powtoughLabel2->setText(card->getPowTough());
|
powtoughLabel2->setText(card->getPowTough());
|
||||||
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
||||||
textLabel->setText(card->getText());
|
textLabel->setText(card->getText());
|
||||||
|
|
||||||
powtoughLabel1->setVisible(shouldShowPowTough());
|
powtoughLabel1->setVisible(shouldShowPowTough());
|
||||||
powtoughLabel2->setVisible(shouldShowPowTough());
|
powtoughLabel2->setVisible(shouldShowPowTough());
|
||||||
loyaltyLabel1->setVisible(shouldShowLoyalty());
|
loyaltyLabel1->setVisible(shouldShowLoyalty());
|
||||||
loyaltyLabel2->setVisible(shouldShowLoyalty());
|
loyaltyLabel2->setVisible(shouldShowLoyalty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(const QString &cardName)
|
void CardInfoWidget::setCard(const QString &cardName)
|
||||||
{
|
{
|
||||||
setCard(db->getCard(cardName));
|
setCard(db->getCard(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(AbstractCardItem *card)
|
void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
{
|
{
|
||||||
setCard(card->getInfo());
|
setCard(card->getInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::clear()
|
void CardInfoWidget::clear()
|
||||||
{
|
{
|
||||||
setCard(db->getCard());
|
setCard(db->getCard());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::updatePixmap()
|
void CardInfoWidget::updatePixmap()
|
||||||
{
|
{
|
||||||
if (pixmapWidth == 0)
|
if (pixmapWidth == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
||||||
if (resizedPixmap)
|
if (resizedPixmap)
|
||||||
cardPicture->setPixmap(*resizedPixmap);
|
cardPicture->setPixmap(*resizedPixmap);
|
||||||
else
|
else
|
||||||
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::retranslateUi()
|
void CardInfoWidget::retranslateUi()
|
||||||
{
|
{
|
||||||
nameLabel1->setText(tr("Name:"));
|
nameLabel1->setText(tr("Name:"));
|
||||||
manacostLabel1->setText(tr("Mana cost:"));
|
manacostLabel1->setText(tr("Mana cost:"));
|
||||||
cardtypeLabel1->setText(tr("Card type:"));
|
cardtypeLabel1->setText(tr("Card type:"));
|
||||||
powtoughLabel1->setText(tr("P / T:"));
|
powtoughLabel1->setText(tr("P / T:"));
|
||||||
loyaltyLabel1->setText(tr("Loyalty:"));
|
loyaltyLabel1->setText(tr("Loyalty:"));
|
||||||
}
|
}
|
||||||
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
||||||
{
|
{
|
||||||
if (mode == ModePopUp)
|
if (mode == ModePopUp)
|
||||||
return;
|
return;
|
||||||
if ((minimized == 1) && (mode == ModeGameTab)) {
|
if ((minimized == 1) && (mode == ModeGameTab)) {
|
||||||
pixmapWidth = 0;
|
pixmapWidth = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
|
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
|
||||||
if (newPixmapWidth != pixmapWidth) {
|
if (newPixmapWidth != pixmapWidth) {
|
||||||
pixmapWidth = newPixmapWidth;
|
pixmapWidth = newPixmapWidth;
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CardInfoWidget::getCardName() const
|
QString CardInfoWidget::getCardName() const
|
||||||
{
|
{
|
||||||
return nameLabel2->text();
|
return nameLabel2->text();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,51 +14,51 @@ class QResizeEvent;
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
|
||||||
class CardInfoWidget : public QFrame {
|
class CardInfoWidget : public QFrame {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int pixmapWidth;
|
int pixmapWidth;
|
||||||
qreal cardHeightOffset;
|
qreal cardHeightOffset;
|
||||||
qreal aspectRatio;
|
qreal aspectRatio;
|
||||||
// XXX: Why isn't this an eunm?
|
// XXX: Why isn't this an eunm?
|
||||||
int minimized; // 0 - card, 1 - oracle only, 2 - full
|
int minimized; // 0 - card, 1 - oracle only, 2 - full
|
||||||
ResizeMode mode;
|
ResizeMode mode;
|
||||||
|
|
||||||
QComboBox *dropList;
|
QComboBox *dropList;
|
||||||
QLabel *cardPicture;
|
QLabel *cardPicture;
|
||||||
QLabel *nameLabel1, *nameLabel2;
|
QLabel *nameLabel1, *nameLabel2;
|
||||||
QLabel *manacostLabel1, *manacostLabel2;
|
QLabel *manacostLabel1, *manacostLabel2;
|
||||||
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
||||||
QLabel *powtoughLabel1, *powtoughLabel2;
|
QLabel *powtoughLabel1, *powtoughLabel2;
|
||||||
QLabel *loyaltyLabel1, *loyaltyLabel2;
|
QLabel *loyaltyLabel1, *loyaltyLabel2;
|
||||||
QTextEdit *textLabel;
|
QTextEdit *textLabel;
|
||||||
|
|
||||||
bool shouldShowPowTough();
|
bool shouldShowPowTough();
|
||||||
bool shouldShowLoyalty();
|
bool shouldShowLoyalty();
|
||||||
|
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
void setMinimized(int _minimized);
|
void setMinimized(int _minimized);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
|
CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QString getCardName() const;
|
QString getCardName() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCard(CardInfo *card);
|
void setCard(CardInfo *card);
|
||||||
void setCard(const QString &cardName);
|
void setCard(const QString &cardName);
|
||||||
void setCard(AbstractCardItem *card);
|
void setCard(AbstractCardItem *card);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void clear();
|
void clear();
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
void minimizeClicked(int newMinimized);
|
void minimizeClicked(int newMinimized);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,374 +18,374 @@
|
||||||
#include "pb/serverinfo_card.pb.h"
|
#include "pb/serverinfo_card.pb.h"
|
||||||
|
|
||||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _revealedCard, QGraphicsItem *parent)
|
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _revealedCard, QGraphicsItem *parent)
|
||||||
: AbstractCardItem(_name, _owner, _cardid, parent), zone(0), revealedCard(_revealedCard), attacking(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
: AbstractCardItem(_name, _owner, _cardid, parent), zone(0), revealedCard(_revealedCard), attacking(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||||
{
|
{
|
||||||
owner->addCard(this);
|
owner->addCard(this);
|
||||||
|
|
||||||
cardMenu = new QMenu;
|
cardMenu = new QMenu;
|
||||||
ptMenu = new QMenu;
|
ptMenu = new QMenu;
|
||||||
moveMenu = new QMenu;
|
moveMenu = new QMenu;
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
emit updateCardMenu(this);
|
emit updateCardMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem::~CardItem()
|
CardItem::~CardItem()
|
||||||
{
|
{
|
||||||
prepareDelete();
|
prepareDelete();
|
||||||
|
|
||||||
if (scene())
|
if (scene())
|
||||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||||
|
|
||||||
delete cardMenu;
|
delete cardMenu;
|
||||||
delete ptMenu;
|
delete ptMenu;
|
||||||
delete moveMenu;
|
delete moveMenu;
|
||||||
|
|
||||||
deleteDragItem();
|
deleteDragItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::prepareDelete()
|
void CardItem::prepareDelete()
|
||||||
{
|
{
|
||||||
if (owner) {
|
if (owner) {
|
||||||
if (owner->getCardMenu() == cardMenu) {
|
if (owner->getCardMenu() == cardMenu) {
|
||||||
owner->setCardMenu(0);
|
owner->setCardMenu(0);
|
||||||
owner->getGame()->setActiveCard(0);
|
owner->getGame()->setActiveCard(0);
|
||||||
}
|
}
|
||||||
owner = 0;
|
owner = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!attachedCards.isEmpty()) {
|
while (!attachedCards.isEmpty()) {
|
||||||
attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards()
|
attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards()
|
||||||
attachedCards.first()->setAttachedTo(0);
|
attachedCards.first()->setAttachedTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attachedTo) {
|
if (attachedTo) {
|
||||||
attachedTo->removeAttachedCard(this);
|
attachedTo->removeAttachedCard(this);
|
||||||
attachedTo = 0;
|
attachedTo = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::deleteLater()
|
void CardItem::deleteLater()
|
||||||
{
|
{
|
||||||
prepareDelete();
|
prepareDelete();
|
||||||
AbstractCardItem::deleteLater();
|
AbstractCardItem::deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setZone(CardZone *_zone)
|
void CardItem::setZone(CardZone *_zone)
|
||||||
{
|
{
|
||||||
zone = _zone;
|
zone = _zone;
|
||||||
emit updateCardMenu(this);
|
emit updateCardMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::retranslateUi()
|
void CardItem::retranslateUi()
|
||||||
{
|
{
|
||||||
moveMenu->setTitle(tr("&Move to"));
|
moveMenu->setTitle(tr("&Move to"));
|
||||||
ptMenu->setTitle(tr("&Power / toughness"));
|
ptMenu->setTitle(tr("&Power / toughness"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
AbstractCardItem::paint(painter, option, widget);
|
AbstractCardItem::paint(painter, option, widget);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
QMapIterator<int, int> counterIterator(counters);
|
QMapIterator<int, int> counterIterator(counters);
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
counterIterator.next();
|
counterIterator.next();
|
||||||
QColor color;
|
QColor color;
|
||||||
color.setHsv(counterIterator.key() * 60, 150, 255);
|
color.setHsv(counterIterator.key() * 60, 150, 255);
|
||||||
|
|
||||||
paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter);
|
paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF translatedSize = getTranslatedSize(painter);
|
QSizeF translatedSize = getTranslatedSize(painter);
|
||||||
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
||||||
|
|
||||||
if (!pt.isEmpty()) {
|
if (!pt.isEmpty()) {
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
transformPainter(painter, translatedSize, tapAngle);
|
transformPainter(painter, translatedSize, tapAngle);
|
||||||
painter->setBackground(Qt::black);
|
painter->setBackground(Qt::black);
|
||||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
|
|
||||||
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignRight | Qt::AlignBottom, pt);
|
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignRight | Qt::AlignBottom, pt);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
if (!annotation.isEmpty()) {
|
if (!annotation.isEmpty()) {
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
transformPainter(painter, translatedSize, tapAngle);
|
transformPainter(painter, translatedSize, tapAngle);
|
||||||
painter->setBackground(Qt::black);
|
painter->setBackground(Qt::black);
|
||||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
|
|
||||||
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignCenter | Qt::TextWrapAnywhere, annotation);
|
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignCenter | Qt::TextWrapAnywhere, annotation);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
if (getBeingPointedAt())
|
if (getBeingPointedAt())
|
||||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setAttacking(bool _attacking)
|
void CardItem::setAttacking(bool _attacking)
|
||||||
{
|
{
|
||||||
attacking = _attacking;
|
attacking = _attacking;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setCounter(int _id, int _value)
|
void CardItem::setCounter(int _id, int _value)
|
||||||
{
|
{
|
||||||
if (_value)
|
if (_value)
|
||||||
counters.insert(_id, _value);
|
counters.insert(_id, _value);
|
||||||
else
|
else
|
||||||
counters.remove(_id);
|
counters.remove(_id);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setAnnotation(const QString &_annotation)
|
void CardItem::setAnnotation(const QString &_annotation)
|
||||||
{
|
{
|
||||||
annotation = _annotation;
|
annotation = _annotation;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setDoesntUntap(bool _doesntUntap)
|
void CardItem::setDoesntUntap(bool _doesntUntap)
|
||||||
{
|
{
|
||||||
doesntUntap = _doesntUntap;
|
doesntUntap = _doesntUntap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setPT(const QString &_pt)
|
void CardItem::setPT(const QString &_pt)
|
||||||
{
|
{
|
||||||
pt = _pt;
|
pt = _pt;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setAttachedTo(CardItem *_attachedTo)
|
void CardItem::setAttachedTo(CardItem *_attachedTo)
|
||||||
{
|
{
|
||||||
if (attachedTo)
|
if (attachedTo)
|
||||||
attachedTo->removeAttachedCard(this);
|
attachedTo->removeAttachedCard(this);
|
||||||
|
|
||||||
gridPoint.setX(-1);
|
gridPoint.setX(-1);
|
||||||
attachedTo = _attachedTo;
|
attachedTo = _attachedTo;
|
||||||
if (attachedTo) {
|
if (attachedTo) {
|
||||||
setParentItem(attachedTo->getZone());
|
setParentItem(attachedTo->getZone());
|
||||||
attachedTo->addAttachedCard(this);
|
attachedTo->addAttachedCard(this);
|
||||||
if (zone != attachedTo->getZone())
|
if (zone != attachedTo->getZone())
|
||||||
attachedTo->getZone()->reorganizeCards();
|
attachedTo->getZone()->reorganizeCards();
|
||||||
} else
|
} else
|
||||||
setParentItem(zone);
|
setParentItem(zone);
|
||||||
|
|
||||||
if (zone)
|
if (zone)
|
||||||
zone->reorganizeCards();
|
zone->reorganizeCards();
|
||||||
|
|
||||||
emit updateCardMenu(this);
|
emit updateCardMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::resetState()
|
void CardItem::resetState()
|
||||||
{
|
{
|
||||||
attacking = false;
|
attacking = false;
|
||||||
facedown = false;
|
facedown = false;
|
||||||
counters.clear();
|
counters.clear();
|
||||||
pt.clear();
|
pt.clear();
|
||||||
annotation.clear();
|
annotation.clear();
|
||||||
attachedTo = 0;
|
attachedTo = 0;
|
||||||
attachedCards.clear();
|
attachedCards.clear();
|
||||||
setTapped(false, false);
|
setTapped(false, false);
|
||||||
setDoesntUntap(false);
|
setDoesntUntap(false);
|
||||||
if (scene())
|
if (scene())
|
||||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::processCardInfo(const ServerInfo_Card &info)
|
void CardItem::processCardInfo(const ServerInfo_Card &info)
|
||||||
{
|
{
|
||||||
counters.clear();
|
counters.clear();
|
||||||
const int counterListSize = info.counter_list_size();
|
const int counterListSize = info.counter_list_size();
|
||||||
for (int i = 0; i < counterListSize; ++i) {
|
for (int i = 0; i < counterListSize; ++i) {
|
||||||
const ServerInfo_CardCounter &counterInfo = info.counter_list(i);
|
const ServerInfo_CardCounter &counterInfo = info.counter_list(i);
|
||||||
counters.insert(counterInfo.id(), counterInfo.value());
|
counters.insert(counterInfo.id(), counterInfo.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
setId(info.id());
|
setId(info.id());
|
||||||
setName(QString::fromStdString(info.name()));
|
setName(QString::fromStdString(info.name()));
|
||||||
setAttacking(info.attacking());
|
setAttacking(info.attacking());
|
||||||
setFaceDown(info.face_down());
|
setFaceDown(info.face_down());
|
||||||
setPT(QString::fromStdString(info.pt()));
|
setPT(QString::fromStdString(info.pt()));
|
||||||
setAnnotation(QString::fromStdString(info.annotation()));
|
setAnnotation(QString::fromStdString(info.annotation()));
|
||||||
setColor(QString::fromStdString(info.color()));
|
setColor(QString::fromStdString(info.color()));
|
||||||
setTapped(info.tapped());
|
setTapped(info.tapped());
|
||||||
setDestroyOnZoneChange(info.destroy_on_zone_change());
|
setDestroyOnZoneChange(info.destroy_on_zone_change());
|
||||||
setDoesntUntap(info.doesnt_untap());
|
setDoesntUntap(info.doesnt_untap());
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
||||||
{
|
{
|
||||||
deleteDragItem();
|
deleteDragItem();
|
||||||
dragItem = new CardDragItem(this, _id, _pos, faceDown);
|
dragItem = new CardDragItem(this, _id, _pos, faceDown);
|
||||||
dragItem->setVisible(false);
|
dragItem->setVisible(false);
|
||||||
scene()->addItem(dragItem);
|
scene()->addItem(dragItem);
|
||||||
dragItem->updatePosition(_scenePos);
|
dragItem->updatePosition(_scenePos);
|
||||||
dragItem->setVisible(true);
|
dragItem->setVisible(true);
|
||||||
|
|
||||||
return dragItem;
|
return dragItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::deleteDragItem()
|
void CardItem::deleteDragItem()
|
||||||
{
|
{
|
||||||
dragItem->deleteLater();
|
dragItem->deleteLater();
|
||||||
dragItem = NULL;
|
dragItem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::drawArrow(const QColor &arrowColor)
|
void CardItem::drawArrow(const QColor &arrowColor)
|
||||||
{
|
{
|
||||||
if (static_cast<TabGame *>(owner->parent())->getSpectator())
|
if (static_cast<TabGame *>(owner->parent())->getSpectator())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player *arrowOwner = static_cast<TabGame *>(owner->parent())->getActiveLocalPlayer();
|
Player *arrowOwner = static_cast<TabGame *>(owner->parent())->getActiveLocalPlayer();
|
||||||
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
|
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
|
||||||
scene()->addItem(arrow);
|
scene()->addItem(arrow);
|
||||||
arrow->grabMouse();
|
arrow->grabMouse();
|
||||||
|
|
||||||
QListIterator<QGraphicsItem *> itemIterator(scene()->selectedItems());
|
QListIterator<QGraphicsItem *> itemIterator(scene()->selectedItems());
|
||||||
while (itemIterator.hasNext()) {
|
while (itemIterator.hasNext()) {
|
||||||
CardItem *c = qgraphicsitem_cast<CardItem *>(itemIterator.next());
|
CardItem *c = qgraphicsitem_cast<CardItem *>(itemIterator.next());
|
||||||
if (!c || (c == this))
|
if (!c || (c == this))
|
||||||
continue;
|
continue;
|
||||||
if (c->getZone() != zone)
|
if (c->getZone() != zone)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, c, arrowColor);
|
ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, c, arrowColor);
|
||||||
scene()->addItem(childArrow);
|
scene()->addItem(childArrow);
|
||||||
arrow->addChildArrow(childArrow);
|
arrow->addChildArrow(childArrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons().testFlag(Qt::RightButton)) {
|
if (event->buttons().testFlag(Qt::RightButton)) {
|
||||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QColor arrowColor = Qt::red;
|
QColor arrowColor = Qt::red;
|
||||||
if (event->modifiers().testFlag(Qt::ControlModifier))
|
if (event->modifiers().testFlag(Qt::ControlModifier))
|
||||||
arrowColor = Qt::yellow;
|
arrowColor = Qt::yellow;
|
||||||
else if (event->modifiers().testFlag(Qt::AltModifier))
|
else if (event->modifiers().testFlag(Qt::AltModifier))
|
||||||
arrowColor = Qt::blue;
|
arrowColor = Qt::blue;
|
||||||
else if (event->modifiers().testFlag(Qt::ShiftModifier))
|
else if (event->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
arrowColor = Qt::green;
|
arrowColor = Qt::green;
|
||||||
|
|
||||||
drawArrow(arrowColor);
|
drawArrow(arrowColor);
|
||||||
} else if (event->buttons().testFlag(Qt::LeftButton)) {
|
} else if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||||
return;
|
return;
|
||||||
if (zone->getIsView()) {
|
if (zone->getIsView()) {
|
||||||
const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
|
const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
|
||||||
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
||||||
return;
|
return;
|
||||||
} else if (!owner->getLocal())
|
} else if (!owner->getLocal())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||||
|
|
||||||
createDragItem(id, event->pos(), event->scenePos(), facedown || forceFaceDown);
|
createDragItem(id, event->pos(), event->scenePos(), facedown || forceFaceDown);
|
||||||
dragItem->grabMouse();
|
dragItem->grabMouse();
|
||||||
|
|
||||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i = 0; i < sel.size(); i++) {
|
for (int i = 0; i < sel.size(); i++) {
|
||||||
CardItem *c = (CardItem *) sel.at(i);
|
CardItem *c = (CardItem *) sel.at(i);
|
||||||
if ((c == this) || (c->getZone() != zone))
|
if ((c == this) || (c->getZone() != zone))
|
||||||
continue;
|
continue;
|
||||||
++j;
|
++j;
|
||||||
QPointF childPos;
|
QPointF childPos;
|
||||||
if (zone->getHasCardAttr())
|
if (zone->getHasCardAttr())
|
||||||
childPos = c->pos() - pos();
|
childPos = c->pos() - pos();
|
||||||
else
|
else
|
||||||
childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
||||||
CardDragItem *drag = new CardDragItem(c, c->getId(), childPos, c->getFaceDown() || forceFaceDown, dragItem);
|
CardDragItem *drag = new CardDragItem(c, c->getId(), childPos, c->getFaceDown() || forceFaceDown, dragItem);
|
||||||
drag->setPos(dragItem->pos() + childPos);
|
drag->setPos(dragItem->pos() + childPos);
|
||||||
scene()->addItem(drag);
|
scene()->addItem(drag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::playCard(bool faceDown)
|
void CardItem::playCard(bool faceDown)
|
||||||
{
|
{
|
||||||
// Do nothing if the card belongs to another player
|
// Do nothing if the card belongs to another player
|
||||||
if (!owner->getLocal())
|
if (!owner->getLocal())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TableZone *tz = qobject_cast<TableZone *>(zone);
|
TableZone *tz = qobject_cast<TableZone *>(zone);
|
||||||
if (tz)
|
if (tz)
|
||||||
tz->toggleTapped();
|
tz->toggleTapped();
|
||||||
else
|
else
|
||||||
zone->getPlayer()->playCard(this, faceDown, info->getCipt());
|
zone->getPlayer()->playCard(this, faceDown, info->getCipt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
if (cardMenu)
|
if (cardMenu)
|
||||||
if (!cardMenu->isEmpty())
|
if (!cardMenu->isEmpty())
|
||||||
cardMenu->exec(event->screenPos());
|
cardMenu->exec(event->screenPos());
|
||||||
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay()) {
|
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay()) {
|
||||||
|
|
||||||
bool hideCard = false;
|
bool hideCard = false;
|
||||||
if (zone->getIsView()) {
|
if (zone->getIsView()) {
|
||||||
ZoneViewZone *view = static_cast<ZoneViewZone *>(zone);
|
ZoneViewZone *view = static_cast<ZoneViewZone *>(zone);
|
||||||
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
||||||
hideCard = true;
|
hideCard = true;
|
||||||
}
|
}
|
||||||
if (hideCard)
|
if (hideCard)
|
||||||
zone->removeCard(this);
|
zone->removeCard(this);
|
||||||
else
|
else
|
||||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
AbstractCardItem::mouseReleaseEvent(event);
|
AbstractCardItem::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (settingsCache->getDoubleClickToPlay()) {
|
if (settingsCache->getDoubleClickToPlay()) {
|
||||||
if (revealedCard)
|
if (revealedCard)
|
||||||
zone->removeCard(this);
|
zone->removeCard(this);
|
||||||
else
|
else
|
||||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardItem::animationEvent()
|
bool CardItem::animationEvent()
|
||||||
{
|
{
|
||||||
int delta = 18;
|
int delta = 18;
|
||||||
if (!tapped)
|
if (!tapped)
|
||||||
delta *= -1;
|
delta *= -1;
|
||||||
|
|
||||||
tapAngle += delta;
|
tapAngle += delta;
|
||||||
|
|
||||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||||
setHovered(false);
|
setHovered(false);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
|
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
{
|
{
|
||||||
if ((change == ItemSelectedHasChanged) && owner) {
|
if ((change == ItemSelectedHasChanged) && owner) {
|
||||||
if (value == true) {
|
if (value == true) {
|
||||||
owner->setCardMenu(cardMenu);
|
owner->setCardMenu(cardMenu);
|
||||||
owner->getGame()->setActiveCard(this);
|
owner->getGame()->setActiveCard(this);
|
||||||
} else if (owner->getCardMenu() == cardMenu) {
|
} else if (owner->getCardMenu() == cardMenu) {
|
||||||
owner->setCardMenu(0);
|
owner->setCardMenu(0);
|
||||||
owner->getGame()->setActiveCard(0);
|
owner->getGame()->setActiveCard(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QGraphicsItem::itemChange(change, value);
|
return QGraphicsItem::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,75 +14,75 @@ class QColor;
|
||||||
const int MAX_COUNTERS_ON_CARD = 999;
|
const int MAX_COUNTERS_ON_CARD = 999;
|
||||||
|
|
||||||
class CardItem : public AbstractCardItem {
|
class CardItem : public AbstractCardItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
CardZone *zone;
|
CardZone *zone;
|
||||||
bool revealedCard;
|
bool revealedCard;
|
||||||
bool attacking;
|
bool attacking;
|
||||||
QMap<int, int> counters;
|
QMap<int, int> counters;
|
||||||
QString annotation;
|
QString annotation;
|
||||||
QString pt;
|
QString pt;
|
||||||
bool destroyOnZoneChange;
|
bool destroyOnZoneChange;
|
||||||
bool doesntUntap;
|
bool doesntUntap;
|
||||||
QPoint gridPoint;
|
QPoint gridPoint;
|
||||||
CardDragItem *dragItem;
|
CardDragItem *dragItem;
|
||||||
CardItem *attachedTo;
|
CardItem *attachedTo;
|
||||||
QList<CardItem *> attachedCards;
|
QList<CardItem *> attachedCards;
|
||||||
|
|
||||||
QMenu *cardMenu, *ptMenu, *moveMenu;
|
QMenu *cardMenu, *ptMenu, *moveMenu;
|
||||||
|
|
||||||
void prepareDelete();
|
void prepareDelete();
|
||||||
public slots:
|
public slots:
|
||||||
void deleteLater();
|
void deleteLater();
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCard };
|
enum { Type = typeCard };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
CardItem(Player *_owner, const QString &_name = QString(), int _cardid = -1, bool revealedCard = false, QGraphicsItem *parent = 0);
|
CardItem(Player *_owner, const QString &_name = QString(), int _cardid = -1, bool revealedCard = false, QGraphicsItem *parent = 0);
|
||||||
~CardItem();
|
~CardItem();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
CardZone *getZone() const { return zone; }
|
CardZone *getZone() const { return zone; }
|
||||||
void setZone(CardZone *_zone);
|
void setZone(CardZone *_zone);
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QPoint getGridPoint() const { return gridPoint; }
|
QPoint getGridPoint() const { return gridPoint; }
|
||||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||||
QPoint getGridPos() const { return gridPoint; }
|
QPoint getGridPos() const { return gridPoint; }
|
||||||
Player *getOwner() const { return owner; }
|
Player *getOwner() const { return owner; }
|
||||||
void setOwner(Player *_owner) { owner = _owner; }
|
void setOwner(Player *_owner) { owner = _owner; }
|
||||||
bool getRevealedCard() const { return revealedCard; }
|
bool getRevealedCard() const { return revealedCard; }
|
||||||
bool getAttacking() const { return attacking; }
|
bool getAttacking() const { return attacking; }
|
||||||
void setAttacking(bool _attacking);
|
void setAttacking(bool _attacking);
|
||||||
const QMap<int, int> &getCounters() const { return counters; }
|
const QMap<int, int> &getCounters() const { return counters; }
|
||||||
void setCounter(int _id, int _value);
|
void setCounter(int _id, int _value);
|
||||||
QString getAnnotation() const { return annotation; }
|
QString getAnnotation() const { return annotation; }
|
||||||
void setAnnotation(const QString &_annotation);
|
void setAnnotation(const QString &_annotation);
|
||||||
bool getDoesntUntap() const { return doesntUntap; }
|
bool getDoesntUntap() const { return doesntUntap; }
|
||||||
void setDoesntUntap(bool _doesntUntap);
|
void setDoesntUntap(bool _doesntUntap);
|
||||||
QString getPT() const { return pt; }
|
QString getPT() const { return pt; }
|
||||||
void setPT(const QString &_pt);
|
void setPT(const QString &_pt);
|
||||||
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
||||||
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
||||||
CardItem *getAttachedTo() const { return attachedTo; }
|
CardItem *getAttachedTo() const { return attachedTo; }
|
||||||
void setAttachedTo(CardItem *_attachedTo);
|
void setAttachedTo(CardItem *_attachedTo);
|
||||||
void addAttachedCard(CardItem *card) { attachedCards.append(card); }
|
void addAttachedCard(CardItem *card) { attachedCards.append(card); }
|
||||||
void removeAttachedCard(CardItem *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
void removeAttachedCard(CardItem *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
||||||
const QList<CardItem *> &getAttachedCards() const { return attachedCards; }
|
const QList<CardItem *> &getAttachedCards() const { return attachedCards; }
|
||||||
void resetState();
|
void resetState();
|
||||||
void processCardInfo(const ServerInfo_Card &info);
|
void processCardInfo(const ServerInfo_Card &info);
|
||||||
|
|
||||||
QMenu *getCardMenu() const { return cardMenu; }
|
QMenu *getCardMenu() const { return cardMenu; }
|
||||||
QMenu *getPTMenu() const { return ptMenu; }
|
QMenu *getPTMenu() const { return ptMenu; }
|
||||||
QMenu *getMoveMenu() const { return moveMenu; }
|
QMenu *getMoveMenu() const { return moveMenu; }
|
||||||
|
|
||||||
bool animationEvent();
|
bool animationEvent();
|
||||||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||||
void deleteDragItem();
|
void deleteDragItem();
|
||||||
void drawArrow(const QColor &arrowColor);
|
void drawArrow(const QColor &arrowColor);
|
||||||
void playCard(bool faceDown);
|
void playCard(bool faceDown);
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,57 +3,57 @@
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
|
||||||
CardList::CardList(bool _contentsKnown)
|
CardList::CardList(bool _contentsKnown)
|
||||||
: QList<CardItem *>(), contentsKnown(_contentsKnown)
|
: QList<CardItem *>(), contentsKnown(_contentsKnown)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem *CardList::findCard(const int id, const bool remove, int *position)
|
CardItem *CardList::findCard(const int id, const bool remove, int *position)
|
||||||
{
|
{
|
||||||
if (!contentsKnown) {
|
if (!contentsKnown) {
|
||||||
if (empty())
|
if (empty())
|
||||||
return 0;
|
return 0;
|
||||||
CardItem *temp = at(0);
|
CardItem *temp = at(0);
|
||||||
if (remove)
|
if (remove)
|
||||||
removeAt(0);
|
removeAt(0);
|
||||||
if (position)
|
if (position)
|
||||||
*position = id;
|
*position = id;
|
||||||
return temp;
|
return temp;
|
||||||
} else
|
} else
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
CardItem *temp = at(i);
|
CardItem *temp = at(i);
|
||||||
if (temp->getId() == id) {
|
if (temp->getId() == id) {
|
||||||
if (remove)
|
if (remove)
|
||||||
removeAt(i);
|
removeAt(i);
|
||||||
if (position)
|
if (position)
|
||||||
*position = i;
|
*position = i;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CardList::compareFunctor {
|
class CardList::compareFunctor {
|
||||||
private:
|
private:
|
||||||
int flags;
|
int flags;
|
||||||
public:
|
public:
|
||||||
compareFunctor(int _flags) : flags(_flags)
|
compareFunctor(int _flags) : flags(_flags)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
inline bool operator()(CardItem *a, CardItem *b) const
|
inline bool operator()(CardItem *a, CardItem *b) const
|
||||||
{
|
{
|
||||||
if (flags & SortByType) {
|
if (flags & SortByType) {
|
||||||
QString t1 = a->getInfo()->getMainCardType();
|
QString t1 = a->getInfo()->getMainCardType();
|
||||||
QString t2 = b->getInfo()->getMainCardType();
|
QString t2 = b->getInfo()->getMainCardType();
|
||||||
if ((t1 == t2) && (flags & SortByName))
|
if ((t1 == t2) && (flags & SortByName))
|
||||||
return a->getName() < b->getName();
|
return a->getName() < b->getName();
|
||||||
return t1 < t2;
|
return t1 < t2;
|
||||||
} else
|
} else
|
||||||
return a->getName() < b->getName();
|
return a->getName() < b->getName();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void CardList::sort(int flags)
|
void CardList::sort(int flags)
|
||||||
{
|
{
|
||||||
compareFunctor cf(flags);
|
compareFunctor cf(flags);
|
||||||
qSort(begin(), end(), cf);
|
qSort(begin(), end(), cf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@ class CardItem;
|
||||||
|
|
||||||
class CardList : public QList<CardItem *> {
|
class CardList : public QList<CardItem *> {
|
||||||
private:
|
private:
|
||||||
class compareFunctor;
|
class compareFunctor;
|
||||||
protected:
|
protected:
|
||||||
bool contentsKnown;
|
bool contentsKnown;
|
||||||
public:
|
public:
|
||||||
enum SortFlags { SortByName = 1, SortByType = 2 };
|
enum SortFlags { SortByName = 1, SortByType = 2 };
|
||||||
CardList(bool _contentsKnown);
|
CardList(bool _contentsKnown);
|
||||||
CardItem *findCard(const int id, const bool remove, int *position = NULL);
|
CardItem *findCard(const int id, const bool remove, int *position = NULL);
|
||||||
bool getContentsKnown() const { return contentsKnown; }
|
bool getContentsKnown() const { return contentsKnown; }
|
||||||
void sort(int flags = SortByName);
|
void sort(int flags = SortByName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,56 +14,56 @@ class QPainter;
|
||||||
class CardDragItem;
|
class CardDragItem;
|
||||||
|
|
||||||
class CardZone : public AbstractGraphicsItem {
|
class CardZone : public AbstractGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
QString name;
|
QString name;
|
||||||
CardList cards;
|
CardList cards;
|
||||||
ZoneViewZone *view;
|
ZoneViewZone *view;
|
||||||
QMenu *menu;
|
QMenu *menu;
|
||||||
QAction *doubleClickAction;
|
QAction *doubleClickAction;
|
||||||
bool hasCardAttr;
|
bool hasCardAttr;
|
||||||
bool isShufflable;
|
bool isShufflable;
|
||||||
bool isView;
|
bool isView;
|
||||||
bool alwaysRevealTopCard;
|
bool alwaysRevealTopCard;
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
||||||
signals:
|
signals:
|
||||||
void cardCountChanged();
|
void cardCountChanged();
|
||||||
public slots:
|
public slots:
|
||||||
void moveAllToZone();
|
void moveAllToZone();
|
||||||
bool showContextMenu(const QPoint &screenPos);
|
bool showContextMenu(const QPoint &screenPos);
|
||||||
public:
|
public:
|
||||||
enum { Type = typeZone };
|
enum { Type = typeZone };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
virtual void handleDropEvent(const QList<CardDragItem *> &dragItem, CardZone *startZone, const QPoint &dropPoint) = 0;
|
virtual void handleDropEvent(const QList<CardDragItem *> &dragItem, CardZone *startZone, const QPoint &dropPoint) = 0;
|
||||||
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool _isView = false);
|
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool _isView = false);
|
||||||
~CardZone();
|
~CardZone();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void clearContents();
|
void clearContents();
|
||||||
bool getHasCardAttr() const { return hasCardAttr; }
|
bool getHasCardAttr() const { return hasCardAttr; }
|
||||||
bool getIsShufflable() const { return isShufflable; }
|
bool getIsShufflable() const { return isShufflable; }
|
||||||
QMenu *getMenu() const { return menu; }
|
QMenu *getMenu() const { return menu; }
|
||||||
void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; }
|
void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
QString getTranslatedName(bool hisOwn, GrammaticalCase gc) const;
|
QString getTranslatedName(bool hisOwn, GrammaticalCase gc) const;
|
||||||
Player *getPlayer() const { return player; }
|
Player *getPlayer() const { return player; }
|
||||||
bool contentsKnown() const { return cards.getContentsKnown(); }
|
bool contentsKnown() const { return cards.getContentsKnown(); }
|
||||||
const CardList &getCards() const { return cards; }
|
const CardList &getCards() const { return cards; }
|
||||||
void addCard(CardItem *card, bool reorganize, int x, int y = -1);
|
void addCard(CardItem *card, bool reorganize, int x, int y = -1);
|
||||||
// getCard() finds a card by id.
|
// getCard() finds a card by id.
|
||||||
CardItem *getCard(int cardId, const QString &cardName);
|
CardItem *getCard(int cardId, const QString &cardName);
|
||||||
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
||||||
virtual CardItem *takeCard(int position, int cardId, bool canResize = true);
|
virtual CardItem *takeCard(int position, int cardId, bool canResize = true);
|
||||||
void removeCard(CardItem *card);
|
void removeCard(CardItem *card);
|
||||||
ZoneViewZone *getView() const { return view; }
|
ZoneViewZone *getView() const { return view; }
|
||||||
void setView(ZoneViewZone *_view) { view = _view; }
|
void setView(ZoneViewZone *_view) { view = _view; }
|
||||||
virtual void reorganizeCards() = 0;
|
virtual void reorganizeCards() = 0;
|
||||||
virtual QPointF closestGridPoint(const QPointF &point);
|
virtual QPointF closestGridPoint(const QPointF &point);
|
||||||
bool getIsView() const { return isView; }
|
bool getIsView() const { return isView; }
|
||||||
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
||||||
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,256 +10,256 @@
|
||||||
#include "pixmapgenerator.h"
|
#include "pixmapgenerator.h"
|
||||||
|
|
||||||
ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
||||||
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing)
|
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing)
|
||||||
{
|
{
|
||||||
document()->setDefaultStyleSheet("a { text-decoration: none; color: blue; }");
|
document()->setDefaultStyleSheet("a { text-decoration: none; color: blue; }");
|
||||||
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||||
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
|
|
||||||
viewport()->setCursor(Qt::IBeamCursor);
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
setReadOnly(true);
|
setReadOnly(true);
|
||||||
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||||
setOpenLinks(false);
|
setOpenLinks(false);
|
||||||
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
|
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::retranslateUi()
|
void ChatView::retranslateUi()
|
||||||
{
|
{
|
||||||
userContextMenu->retranslateUi();
|
userContextMenu->retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor ChatView::prepareBlock(bool same)
|
QTextCursor ChatView::prepareBlock(bool same)
|
||||||
{
|
{
|
||||||
lastSender.clear();
|
lastSender.clear();
|
||||||
|
|
||||||
QTextCursor cursor(document()->lastBlock());
|
QTextCursor cursor(document()->lastBlock());
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
if (!same) {
|
if (!same) {
|
||||||
QTextBlockFormat blockFormat;
|
QTextBlockFormat blockFormat;
|
||||||
if ((evenNumber = !evenNumber))
|
if ((evenNumber = !evenNumber))
|
||||||
blockFormat.setBackground(palette().alternateBase());
|
blockFormat.setBackground(palette().alternateBase());
|
||||||
blockFormat.setBottomMargin(2);
|
blockFormat.setBottomMargin(2);
|
||||||
cursor.insertBlock(blockFormat);
|
cursor.insertBlock(blockFormat);
|
||||||
} else
|
} else
|
||||||
cursor.insertHtml("<br>");
|
cursor.insertHtml("<br>");
|
||||||
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::appendHtml(const QString &html)
|
void ChatView::appendHtml(const QString &html)
|
||||||
{
|
{
|
||||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||||
prepareBlock().insertHtml(html);
|
prepareBlock().insertHtml(html);
|
||||||
if (atBottom)
|
if (atBottom)
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
|
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
|
||||||
{
|
{
|
||||||
QTextCharFormat oldFormat = cursor.charFormat();
|
QTextCharFormat oldFormat = cursor.charFormat();
|
||||||
QTextCharFormat anchorFormat = oldFormat;
|
QTextCharFormat anchorFormat = oldFormat;
|
||||||
anchorFormat.setForeground(Qt::blue);
|
anchorFormat.setForeground(Qt::blue);
|
||||||
anchorFormat.setAnchor(true);
|
anchorFormat.setAnchor(true);
|
||||||
anchorFormat.setAnchorHref("card://" + cardName);
|
anchorFormat.setAnchorHref("card://" + cardName);
|
||||||
|
|
||||||
cursor.setCharFormat(anchorFormat);
|
cursor.setCharFormat(anchorFormat);
|
||||||
cursor.insertText(cardName);
|
cursor.insertText(cardName);
|
||||||
cursor.setCharFormat(oldFormat);
|
cursor.setCharFormat(oldFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
|
void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
|
||||||
{
|
{
|
||||||
if (!url.contains("://"))
|
if (!url.contains("://"))
|
||||||
url.prepend("http://");
|
url.prepend("http://");
|
||||||
|
|
||||||
QTextCharFormat oldFormat = cursor.charFormat();
|
QTextCharFormat oldFormat = cursor.charFormat();
|
||||||
QTextCharFormat anchorFormat = oldFormat;
|
QTextCharFormat anchorFormat = oldFormat;
|
||||||
anchorFormat.setForeground(Qt::blue);
|
anchorFormat.setForeground(Qt::blue);
|
||||||
anchorFormat.setAnchor(true);
|
anchorFormat.setAnchor(true);
|
||||||
anchorFormat.setAnchorHref(url);
|
anchorFormat.setAnchorHref(url);
|
||||||
|
|
||||||
cursor.setCharFormat(anchorFormat);
|
cursor.setCharFormat(anchorFormat);
|
||||||
cursor.insertText(url);
|
cursor.insertText(url);
|
||||||
cursor.setCharFormat(oldFormat);
|
cursor.setCharFormat(oldFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold)
|
void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold)
|
||||||
{
|
{
|
||||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||||
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||||
QTextCursor cursor = prepareBlock(sameSender);
|
QTextCursor cursor = prepareBlock(sameSender);
|
||||||
lastSender = sender;
|
lastSender = sender;
|
||||||
|
|
||||||
if (showTimestamps && !sameSender) {
|
if (showTimestamps && !sameSender) {
|
||||||
QTextCharFormat timeFormat;
|
QTextCharFormat timeFormat;
|
||||||
timeFormat.setForeground(Qt::black);
|
timeFormat.setForeground(Qt::black);
|
||||||
cursor.setCharFormat(timeFormat);
|
cursor.setCharFormat(timeFormat);
|
||||||
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
|
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat senderFormat;
|
QTextCharFormat senderFormat;
|
||||||
if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
|
if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
|
||||||
senderFormat.setFontWeight(QFont::Bold);
|
senderFormat.setFontWeight(QFont::Bold);
|
||||||
senderFormat.setForeground(Qt::red);
|
senderFormat.setForeground(Qt::red);
|
||||||
} else {
|
} else {
|
||||||
senderFormat.setForeground(Qt::blue);
|
senderFormat.setForeground(Qt::blue);
|
||||||
if (playerBold)
|
if (playerBold)
|
||||||
senderFormat.setFontWeight(QFont::Bold);
|
senderFormat.setFontWeight(QFont::Bold);
|
||||||
}
|
}
|
||||||
senderFormat.setAnchor(true);
|
senderFormat.setAnchor(true);
|
||||||
senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
|
senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
|
||||||
if (!sameSender) {
|
if (!sameSender) {
|
||||||
if (!sender.isEmpty()) {
|
if (!sender.isEmpty()) {
|
||||||
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
|
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
|
||||||
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel));
|
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel));
|
||||||
cursor.insertText(" ");
|
cursor.insertText(" ");
|
||||||
}
|
}
|
||||||
cursor.setCharFormat(senderFormat);
|
cursor.setCharFormat(senderFormat);
|
||||||
if (!sender.isEmpty())
|
if (!sender.isEmpty())
|
||||||
sender.append(": ");
|
sender.append(": ");
|
||||||
cursor.insertText(sender);
|
cursor.insertText(sender);
|
||||||
} else
|
} else
|
||||||
cursor.insertText(" ");
|
cursor.insertText(" ");
|
||||||
|
|
||||||
QTextCharFormat messageFormat;
|
QTextCharFormat messageFormat;
|
||||||
if (sender.isEmpty())
|
if (sender.isEmpty())
|
||||||
messageFormat.setForeground(Qt::darkGreen);
|
messageFormat.setForeground(Qt::darkGreen);
|
||||||
cursor.setCharFormat(messageFormat);
|
cursor.setCharFormat(messageFormat);
|
||||||
|
|
||||||
int from = 0, index = 0;
|
int from = 0, index = 0;
|
||||||
while ((index = message.indexOf('[', from)) != -1) {
|
while ((index = message.indexOf('[', from)) != -1) {
|
||||||
cursor.insertText(message.left(index));
|
cursor.insertText(message.left(index));
|
||||||
message = message.mid(index);
|
message = message.mid(index);
|
||||||
if (message.isEmpty())
|
if (message.isEmpty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (message.startsWith("[card]")) {
|
if (message.startsWith("[card]")) {
|
||||||
message = message.mid(6);
|
message = message.mid(6);
|
||||||
int closeTagIndex = message.indexOf("[/card]");
|
int closeTagIndex = message.indexOf("[/card]");
|
||||||
QString cardName = message.left(closeTagIndex);
|
QString cardName = message.left(closeTagIndex);
|
||||||
if (closeTagIndex == -1)
|
if (closeTagIndex == -1)
|
||||||
message.clear();
|
message.clear();
|
||||||
else
|
else
|
||||||
message = message.mid(closeTagIndex + 7);
|
message = message.mid(closeTagIndex + 7);
|
||||||
|
|
||||||
appendCardTag(cursor, cardName);
|
appendCardTag(cursor, cardName);
|
||||||
} else if (message.startsWith("[[")) {
|
} else if (message.startsWith("[[")) {
|
||||||
message = message.mid(2);
|
message = message.mid(2);
|
||||||
int closeTagIndex = message.indexOf("]]");
|
int closeTagIndex = message.indexOf("]]");
|
||||||
QString cardName = message.left(closeTagIndex);
|
QString cardName = message.left(closeTagIndex);
|
||||||
if (closeTagIndex == -1)
|
if (closeTagIndex == -1)
|
||||||
message.clear();
|
message.clear();
|
||||||
else
|
else
|
||||||
message = message.mid(closeTagIndex + 2);
|
message = message.mid(closeTagIndex + 2);
|
||||||
|
|
||||||
appendCardTag(cursor, cardName);
|
appendCardTag(cursor, cardName);
|
||||||
} else if (message.startsWith("[url]")) {
|
} else if (message.startsWith("[url]")) {
|
||||||
message = message.mid(5);
|
message = message.mid(5);
|
||||||
int closeTagIndex = message.indexOf("[/url]");
|
int closeTagIndex = message.indexOf("[/url]");
|
||||||
QString url = message.left(closeTagIndex);
|
QString url = message.left(closeTagIndex);
|
||||||
if (closeTagIndex == -1)
|
if (closeTagIndex == -1)
|
||||||
message.clear();
|
message.clear();
|
||||||
else
|
else
|
||||||
message = message.mid(closeTagIndex + 6);
|
message = message.mid(closeTagIndex + 6);
|
||||||
|
|
||||||
appendUrlTag(cursor, url);
|
appendUrlTag(cursor, url);
|
||||||
} else
|
} else
|
||||||
from = 1;
|
from = 1;
|
||||||
}
|
}
|
||||||
if (!message.isEmpty())
|
if (!message.isEmpty())
|
||||||
cursor.insertText(message);
|
cursor.insertText(message);
|
||||||
|
|
||||||
if (atBottom)
|
if (atBottom)
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::enterEvent(QEvent * /*event*/)
|
void ChatView::enterEvent(QEvent * /*event*/)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::leaveEvent(QEvent * /*event*/)
|
void ChatView::leaveEvent(QEvent * /*event*/)
|
||||||
{
|
{
|
||||||
setMouseTracking(false);
|
setMouseTracking(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
|
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
QTextCursor cursor(cursorForPosition(pos));
|
QTextCursor cursor(cursorForPosition(pos));
|
||||||
QTextBlock block(cursor.block());
|
QTextBlock block(cursor.block());
|
||||||
QTextBlock::iterator it;
|
QTextBlock::iterator it;
|
||||||
for (it = block.begin(); !(it.atEnd()); ++it) {
|
for (it = block.begin(); !(it.atEnd()); ++it) {
|
||||||
QTextFragment frag = it.fragment();
|
QTextFragment frag = it.fragment();
|
||||||
if (frag.contains(cursor.position()))
|
if (frag.contains(cursor.position()))
|
||||||
return frag;
|
return frag;
|
||||||
}
|
}
|
||||||
return QTextFragment();
|
return QTextFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::mouseMoveEvent(QMouseEvent *event)
|
void ChatView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QString anchorHref = getFragmentUnderMouse(event->pos()).charFormat().anchorHref();
|
QString anchorHref = getFragmentUnderMouse(event->pos()).charFormat().anchorHref();
|
||||||
if (!anchorHref.isEmpty()) {
|
if (!anchorHref.isEmpty()) {
|
||||||
const int delimiterIndex = anchorHref.indexOf("://");
|
const int delimiterIndex = anchorHref.indexOf("://");
|
||||||
if (delimiterIndex != -1) {
|
if (delimiterIndex != -1) {
|
||||||
const QString scheme = anchorHref.left(delimiterIndex);
|
const QString scheme = anchorHref.left(delimiterIndex);
|
||||||
hoveredContent = anchorHref.mid(delimiterIndex + 3);
|
hoveredContent = anchorHref.mid(delimiterIndex + 3);
|
||||||
if (scheme == "card") {
|
if (scheme == "card") {
|
||||||
hoveredItemType = HoveredCard;
|
hoveredItemType = HoveredCard;
|
||||||
emit cardNameHovered(hoveredContent);
|
emit cardNameHovered(hoveredContent);
|
||||||
} else if (scheme == "user")
|
} else if (scheme == "user")
|
||||||
hoveredItemType = HoveredUser;
|
hoveredItemType = HoveredUser;
|
||||||
else
|
else
|
||||||
hoveredItemType = HoveredUrl;
|
hoveredItemType = HoveredUrl;
|
||||||
viewport()->setCursor(Qt::PointingHandCursor);
|
viewport()->setCursor(Qt::PointingHandCursor);
|
||||||
} else {
|
} else {
|
||||||
hoveredItemType = HoveredNothing;
|
hoveredItemType = HoveredNothing;
|
||||||
viewport()->setCursor(Qt::IBeamCursor);
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hoveredItemType = HoveredNothing;
|
hoveredItemType = HoveredNothing;
|
||||||
viewport()->setCursor(Qt::IBeamCursor);
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextBrowser::mouseMoveEvent(event);
|
QTextBrowser::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::mousePressEvent(QMouseEvent *event)
|
void ChatView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
switch (hoveredItemType) {
|
switch (hoveredItemType) {
|
||||||
case HoveredCard: {
|
case HoveredCard: {
|
||||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
||||||
emit showCardInfoPopup(event->globalPos(), hoveredContent);
|
emit showCardInfoPopup(event->globalPos(), hoveredContent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HoveredUser: {
|
case HoveredUser: {
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
const int delimiterIndex = hoveredContent.indexOf("_");
|
const int delimiterIndex = hoveredContent.indexOf("_");
|
||||||
UserLevelFlags userLevel(hoveredContent.left(delimiterIndex).toInt());
|
UserLevelFlags userLevel(hoveredContent.left(delimiterIndex).toInt());
|
||||||
const QString userName = hoveredContent.mid(delimiterIndex + 1);
|
const QString userName = hoveredContent.mid(delimiterIndex + 1);
|
||||||
|
|
||||||
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
QTextBrowser::mousePressEvent(event);
|
QTextBrowser::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
||||||
emit deleteCardInfoPopup(QString("_"));
|
emit deleteCardInfoPopup(QString("_"));
|
||||||
|
|
||||||
QTextBrowser::mouseReleaseEvent(event);
|
QTextBrowser::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::openLink(const QUrl &link)
|
void ChatView::openLink(const QUrl &link)
|
||||||
{
|
{
|
||||||
if ((link.scheme() == "card") || (link.scheme() == "user"))
|
if ((link.scheme() == "card") || (link.scheme() == "user"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QDesktopServices::openUrl(link);
|
QDesktopServices::openUrl(link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,40 +14,40 @@ class TabSupervisor;
|
||||||
class TabGame;
|
class TabGame;
|
||||||
|
|
||||||
class ChatView : public QTextBrowser {
|
class ChatView : public QTextBrowser {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
const TabSupervisor * const tabSupervisor;
|
const TabSupervisor * const tabSupervisor;
|
||||||
TabGame * const game;
|
TabGame * const game;
|
||||||
private:
|
private:
|
||||||
enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser };
|
enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser };
|
||||||
UserContextMenu *userContextMenu;
|
UserContextMenu *userContextMenu;
|
||||||
QString lastSender;
|
QString lastSender;
|
||||||
bool evenNumber;
|
bool evenNumber;
|
||||||
bool showTimestamps;
|
bool showTimestamps;
|
||||||
HoveredItemType hoveredItemType;
|
HoveredItemType hoveredItemType;
|
||||||
QString hoveredContent;
|
QString hoveredContent;
|
||||||
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
||||||
QTextCursor prepareBlock(bool same = false);
|
QTextCursor prepareBlock(bool same = false);
|
||||||
void appendCardTag(QTextCursor &cursor, const QString &cardName);
|
void appendCardTag(QTextCursor &cursor, const QString &cardName);
|
||||||
void appendUrlTag(QTextCursor &cursor, QString url);
|
void appendUrlTag(QTextCursor &cursor, QString url);
|
||||||
private slots:
|
private slots:
|
||||||
void openLink(const QUrl &link);
|
void openLink(const QUrl &link);
|
||||||
public:
|
public:
|
||||||
ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = 0);
|
ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void appendHtml(const QString &html);
|
void appendHtml(const QString &html);
|
||||||
void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
|
void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
|
||||||
protected:
|
protected:
|
||||||
void enterEvent(QEvent *event);
|
void enterEvent(QEvent *event);
|
||||||
void leaveEvent(QEvent *event);
|
void leaveEvent(QEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
signals:
|
signals:
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
void cardNameHovered(QString cardName);
|
void cardNameHovered(QString cardName);
|
||||||
void showCardInfoPopup(QPoint pos, QString cardName);
|
void showCardInfoPopup(QPoint pos, QString cardName);
|
||||||
void deleteCardInfoPopup(QString cardName);
|
void deleteCardInfoPopup(QString cardName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,34 +3,34 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
GeneralCounter::GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent)
|
GeneralCounter::GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent)
|
||||||
: AbstractCounter(_player, _id, _name, true, _value, parent), color(_color), radius(_radius)
|
: AbstractCounter(_player, _id, _name, true, _value, parent), color(_color), radius(_radius)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF GeneralCounter::boundingRect() const
|
QRectF GeneralCounter::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, radius * 2, radius * 2);
|
return QRectF(0, 0, radius * 2, radius * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
QRectF mapRect = painter->combinedTransform().mapRect(boundingRect());
|
QRectF mapRect = painter->combinedTransform().mapRect(boundingRect());
|
||||||
int translatedHeight = mapRect.size().height();
|
int translatedHeight = mapRect.size().height();
|
||||||
qreal scaleFactor = translatedHeight / boundingRect().height();
|
qreal scaleFactor = translatedHeight / boundingRect().height();
|
||||||
QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
|
QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
painter->drawPixmap(QPoint(0, 0), pixmap);
|
painter->drawPixmap(QPoint(0, 0), pixmap);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
QFont f("Serif");
|
QFont f("Serif");
|
||||||
f.setPixelSize(qMax((int) (radius * scaleFactor), 10));
|
f.setPixelSize(qMax((int) (radius * scaleFactor), 10));
|
||||||
f.setWeight(QFont::Bold);
|
f.setWeight(QFont::Bold);
|
||||||
painter->setPen(Qt::black);
|
painter->setPen(Qt::black);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
painter->drawText(mapRect, Qt::AlignCenter, QString::number(value));
|
painter->drawText(mapRect, Qt::AlignCenter, QString::number(value));
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
#include "abstractcounter.h"
|
#include "abstractcounter.h"
|
||||||
|
|
||||||
class GeneralCounter : public AbstractCounter {
|
class GeneralCounter : public AbstractCounter {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QColor color;
|
QColor color;
|
||||||
int radius;
|
int radius;
|
||||||
public:
|
public:
|
||||||
GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent = 0);
|
GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,96 +4,96 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
const QStringList DeckLoader::fileNameFilters = QStringList()
|
const QStringList DeckLoader::fileNameFilters = QStringList()
|
||||||
<< QObject::tr("Common deck formats (*.cod *.dec *.mwDeck)")
|
<< QObject::tr("Common deck formats (*.cod *.dec *.mwDeck)")
|
||||||
<< QObject::tr("All files (*.*)");
|
<< QObject::tr("All files (*.*)");
|
||||||
|
|
||||||
DeckLoader::DeckLoader()
|
DeckLoader::DeckLoader()
|
||||||
: DeckList(),
|
: DeckList(),
|
||||||
lastFileName(QString()),
|
lastFileName(QString()),
|
||||||
lastFileFormat(CockatriceFormat),
|
lastFileFormat(CockatriceFormat),
|
||||||
lastRemoteDeckId(-1)
|
lastRemoteDeckId(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const QString &nativeString)
|
DeckLoader::DeckLoader(const QString &nativeString)
|
||||||
: DeckList(nativeString),
|
: DeckList(nativeString),
|
||||||
lastFileName(QString()),
|
lastFileName(QString()),
|
||||||
lastFileFormat(CockatriceFormat),
|
lastFileFormat(CockatriceFormat),
|
||||||
lastRemoteDeckId(-1)
|
lastRemoteDeckId(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const DeckList &other)
|
DeckLoader::DeckLoader(const DeckList &other)
|
||||||
: DeckList(other),
|
: DeckList(other),
|
||||||
lastFileName(QString()),
|
lastFileName(QString()),
|
||||||
lastFileFormat(CockatriceFormat),
|
lastFileFormat(CockatriceFormat),
|
||||||
lastRemoteDeckId(-1)
|
lastRemoteDeckId(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const DeckLoader &other)
|
DeckLoader::DeckLoader(const DeckLoader &other)
|
||||||
: DeckList(other),
|
: DeckList(other),
|
||||||
lastFileName(other.lastFileName),
|
lastFileName(other.lastFileName),
|
||||||
lastFileFormat(other.lastFileFormat),
|
lastFileFormat(other.lastFileFormat),
|
||||||
lastRemoteDeckId(other.lastRemoteDeckId)
|
lastRemoteDeckId(other.lastRemoteDeckId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
||||||
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
|
|
||||||
emit deckLoaded();
|
emit deckLoaded();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
||||||
{
|
{
|
||||||
bool result = loadFromString_Native(nativeString);
|
bool result = loadFromString_Native(nativeString);
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = QString();
|
lastFileName = QString();
|
||||||
lastFileFormat = CockatriceFormat;
|
lastFileFormat = CockatriceFormat;
|
||||||
lastRemoteDeckId = remoteDeckId;
|
lastRemoteDeckId = remoteDeckId;
|
||||||
|
|
||||||
emit deckLoaded();
|
emit deckLoaded();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
||||||
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
||||||
return CockatriceFormat;
|
return CockatriceFormat;
|
||||||
}
|
}
|
||||||
return PlainTextFormat;
|
return PlainTextFormat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,30 +4,30 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
class DeckLoader : public DeckList {
|
class DeckLoader : public DeckList {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void deckLoaded();
|
void deckLoaded();
|
||||||
public:
|
public:
|
||||||
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
||||||
static const QStringList fileNameFilters;
|
static const QStringList fileNameFilters;
|
||||||
private:
|
private:
|
||||||
QString lastFileName;
|
QString lastFileName;
|
||||||
FileFormat lastFileFormat;
|
FileFormat lastFileFormat;
|
||||||
int lastRemoteDeckId;
|
int lastRemoteDeckId;
|
||||||
public:
|
public:
|
||||||
DeckLoader();
|
DeckLoader();
|
||||||
DeckLoader(const QString &nativeString);
|
DeckLoader(const QString &nativeString);
|
||||||
DeckLoader(const DeckList &other);
|
DeckLoader(const DeckList &other);
|
||||||
DeckLoader(const DeckLoader &other);
|
DeckLoader(const DeckLoader &other);
|
||||||
const QString &getLastFileName() const { return lastFileName; }
|
const QString &getLastFileName() const { return lastFileName; }
|
||||||
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
||||||
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
||||||
|
|
||||||
static FileFormat getFormatFromName(const QString &fileName);
|
static FileFormat getFormatFromName(const QString &fileName);
|
||||||
|
|
||||||
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||||
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
||||||
bool saveToFile(const QString &fileName, FileFormat fmt);
|
bool saveToFile(const QString &fileName, FileFormat fmt);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,423 +14,423 @@
|
||||||
#include "deck_loader.h"
|
#include "deck_loader.h"
|
||||||
|
|
||||||
DeckListModel::DeckListModel(QObject *parent)
|
DeckListModel::DeckListModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
deckList = new DeckLoader;
|
deckList = new DeckLoader;
|
||||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
||||||
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckListModel::~DeckListModel()
|
DeckListModel::~DeckListModel()
|
||||||
{
|
{
|
||||||
delete root;
|
delete root;
|
||||||
delete deckList;
|
delete deckList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::rebuildTree()
|
void DeckListModel::rebuildTree()
|
||||||
{
|
{
|
||||||
root->clearTree();
|
root->clearTree();
|
||||||
InnerDecklistNode *listRoot = deckList->getRoot();
|
InnerDecklistNode *listRoot = deckList->getRoot();
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
for (int i = 0; i < listRoot->size(); i++) {
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root);
|
InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root);
|
||||||
for (int j = 0; j < currentZone->size(); j++) {
|
for (int j = 0; j < currentZone->size(); j++) {
|
||||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
// XXX better sanity checking
|
// XXX better sanity checking
|
||||||
if (!currentCard)
|
if (!currentCard)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CardInfo *info = db->getCard(currentCard->getName());
|
CardInfo *info = db->getCard(currentCard->getName());
|
||||||
QString cardType;
|
QString cardType;
|
||||||
if (!info)
|
if (!info)
|
||||||
cardType = "unknown";
|
cardType = "unknown";
|
||||||
else
|
else
|
||||||
cardType = info->getMainCardType();
|
cardType = info->getMainCardType();
|
||||||
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
||||||
if (!cardTypeNode)
|
if (!cardTypeNode)
|
||||||
cardTypeNode = new InnerDecklistNode(cardType, node);
|
cardTypeNode = new InnerDecklistNode(cardType, node);
|
||||||
|
|
||||||
new DecklistModelCardNode(currentCard, cardTypeNode);
|
new DecklistModelCardNode(currentCard, cardTypeNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckListModel::rowCount(const QModelIndex &parent) const
|
int DeckListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("rowCount", parent);
|
// debugIndexInfo("rowCount", parent);
|
||||||
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
||||||
if (node)
|
if (node)
|
||||||
return node->size();
|
return node->size();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
return 3;
|
return 3;
|
||||||
else
|
else
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("data", index);
|
// debugIndexInfo("data", index);
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (index.column() >= columnCount())
|
if (index.column() >= columnCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
||||||
DecklistModelCardNode *card = dynamic_cast<DecklistModelCardNode *>(temp);
|
DecklistModelCardNode *card = dynamic_cast<DecklistModelCardNode *>(temp);
|
||||||
if (!card) {
|
if (!card) {
|
||||||
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(temp);
|
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(temp);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::FontRole: {
|
case Qt::FontRole: {
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return node->recursiveCount(true);
|
case 0: return node->recursiveCount(true);
|
||||||
case 1: return node->getVisibleName();
|
case 1: return node->getVisibleName();
|
||||||
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
|
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
case Qt::BackgroundRole: {
|
case Qt::BackgroundRole: {
|
||||||
int color = 90 + 60 * node->depth();
|
int color = 90 + 60 * node->depth();
|
||||||
return QBrush(QColor(color, 255, color));
|
return QBrush(QColor(color, 255, color));
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::EditRole: {
|
case Qt::EditRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return card->getNumber();
|
case 0: return card->getNumber();
|
||||||
case 1: return card->getName();
|
case 1: return card->getName();
|
||||||
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
|
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::BackgroundRole: {
|
case Qt::BackgroundRole: {
|
||||||
int color = 255 - (index.row() % 2) * 30;
|
int color = 255 - (index.row() % 2) * 30;
|
||||||
return QBrush(QColor(color, color, color));
|
return QBrush(QColor(color, color, color));
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (section >= columnCount())
|
if (section >= columnCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return tr("Number");
|
case 0: return tr("Number");
|
||||||
case 1: return tr("Card");
|
case 1: return tr("Card");
|
||||||
case 2: return tr("Price");
|
case 2: return tr("Price");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("index", parent);
|
// debugIndexInfo("index", parent);
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
InnerDecklistNode *parentNode = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *parentNode = getNode<InnerDecklistNode *>(parent);
|
||||||
if (row >= parentNode->size())
|
if (row >= parentNode->size())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(row, column, parentNode->at(row));
|
return createIndex(row, column, parentNode->at(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
||||||
{
|
{
|
||||||
if (!ind.isValid())
|
if (!ind.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return nodeToIndex(static_cast<AbstractDecklistNode *>(ind.internalPointer())->getParent());
|
return nodeToIndex(static_cast<AbstractDecklistNode *>(ind.internalPointer())->getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
||||||
if (getNode<DecklistModelCardNode *>(index))
|
if (getNode<DecklistModelCardNode *>(index))
|
||||||
result |= Qt::ItemIsSelectable;
|
result |= Qt::ItemIsSelectable;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
emitRecursiveUpdates(index.parent());
|
emitRecursiveUpdates(index.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
DecklistModelCardNode *node = getNode<DecklistModelCardNode *>(index);
|
DecklistModelCardNode *node = getNode<DecklistModelCardNode *>(index);
|
||||||
if (!node || (role != Qt::EditRole))
|
if (!node || (role != Qt::EditRole))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: node->setNumber(value.toInt()); break;
|
case 0: node->setNumber(value.toInt()); break;
|
||||||
case 1: node->setName(value.toString()); break;
|
case 1: node->setName(value.toString()); break;
|
||||||
case 2: node->setPrice(value.toFloat()); break;
|
case 2: node->setPrice(value.toFloat()); break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
emitRecursiveUpdates(index);
|
emitRecursiveUpdates(index);
|
||||||
deckList->updateDeckHash();
|
deckList->updateDeckHash();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
||||||
if (!node)
|
if (!node)
|
||||||
return false;
|
return false;
|
||||||
if (row + count > node->size())
|
if (row + count > node->size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(parent, row, row + count - 1);
|
beginRemoveRows(parent, row, row + count - 1);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
AbstractDecklistNode *toDelete = node->takeAt(row);
|
AbstractDecklistNode *toDelete = node->takeAt(row);
|
||||||
if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
|
if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
|
||||||
deckList->deleteNode(temp->getDataNode());
|
deckList->deleteNode(temp->getDataNode());
|
||||||
delete toDelete;
|
delete toDelete;
|
||||||
}
|
}
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
if (!node->size() && (node != root))
|
if (!node->size() && (node != root))
|
||||||
removeRows(parent.row(), 1, parent.parent());
|
removeRows(parent.row(), 1, parent.parent());
|
||||||
else
|
else
|
||||||
emitRecursiveUpdates(parent);
|
emitRecursiveUpdates(parent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
|
InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *newNode = dynamic_cast<InnerDecklistNode *>(parent->findChild(name));
|
InnerDecklistNode *newNode = dynamic_cast<InnerDecklistNode *>(parent->findChild(name));
|
||||||
if (!newNode) {
|
if (!newNode) {
|
||||||
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
||||||
newNode = new InnerDecklistNode(name, parent);
|
newNode = new InnerDecklistNode(name, parent);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName)
|
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||||
|
|
||||||
CardInfo *info = db->getCard(cardName);
|
CardInfo *info = db->getCard(cardName);
|
||||||
QString cardType = info->getMainCardType();
|
QString cardType = info->getMainCardType();
|
||||||
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
||||||
|
|
||||||
DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
||||||
if (!cardNode) {
|
if (!cardNode) {
|
||||||
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
|
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
|
||||||
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
||||||
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
||||||
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
sort(1);
|
sort(1);
|
||||||
emitRecursiveUpdates(parentIndex);
|
emitRecursiveUpdates(parentIndex);
|
||||||
return nodeToIndex(cardNode);
|
return nodeToIndex(cardNode);
|
||||||
} else {
|
} else {
|
||||||
cardNode->setNumber(cardNode->getNumber() + 1);
|
cardNode->setNumber(cardNode->getNumber() + 1);
|
||||||
QModelIndex ind = nodeToIndex(cardNode);
|
QModelIndex ind = nodeToIndex(cardNode);
|
||||||
emitRecursiveUpdates(ind);
|
emitRecursiveUpdates(ind);
|
||||||
deckList->updateDeckHash();
|
deckList->updateDeckHash();
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::nodeToIndex(AbstractDecklistNode *node) const
|
QModelIndex DeckListModel::nodeToIndex(AbstractDecklistNode *node) const
|
||||||
{
|
{
|
||||||
if (node == root)
|
if (node == root)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(node->getParent()->indexOf(node), 0, node);
|
return createIndex(node->getParent()->indexOf(node), 0, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
// Sort children of node and save the information needed to
|
// Sort children of node and save the information needed to
|
||||||
// update the list of persistent indexes.
|
// update the list of persistent indexes.
|
||||||
QVector<QPair<int, int> > sortResult = node->sort(order);
|
QVector<QPair<int, int> > sortResult = node->sort(order);
|
||||||
|
|
||||||
QModelIndexList from, to;
|
QModelIndexList from, to;
|
||||||
for (int i = sortResult.size() - 1; i >= 0; --i) {
|
for (int i = sortResult.size() - 1; i >= 0; --i) {
|
||||||
const int fromRow = sortResult[i].first;
|
const int fromRow = sortResult[i].first;
|
||||||
const int toRow = sortResult[i].second;
|
const int toRow = sortResult[i].second;
|
||||||
AbstractDecklistNode *temp = node->at(toRow);
|
AbstractDecklistNode *temp = node->at(toRow);
|
||||||
for (int j = columnCount(); j; --j) {
|
for (int j = columnCount(); j; --j) {
|
||||||
from << createIndex(fromRow, 0, temp);
|
from << createIndex(fromRow, 0, temp);
|
||||||
to << createIndex(toRow, 0, temp);
|
to << createIndex(toRow, 0, temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changePersistentIndexList(from, to);
|
changePersistentIndexList(from, to);
|
||||||
|
|
||||||
// Recursion
|
// Recursion
|
||||||
for (int i = node->size() - 1; i >= 0; --i) {
|
for (int i = node->size() - 1; i >= 0; --i) {
|
||||||
InnerDecklistNode *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
InnerDecklistNode *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
||||||
if (subNode)
|
if (subNode)
|
||||||
sortHelper(subNode, order);
|
sortHelper(subNode, order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::sort(int /*column*/, Qt::SortOrder order)
|
void DeckListModel::sort(int /*column*/, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
sortHelper(root, order);
|
sortHelper(root, order);
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::cleanList()
|
void DeckListModel::cleanList()
|
||||||
{
|
{
|
||||||
setDeckList(new DeckLoader);
|
setDeckList(new DeckLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::setDeckList(DeckLoader *_deck)
|
void DeckListModel::setDeckList(DeckLoader *_deck)
|
||||||
{
|
{
|
||||||
delete deckList;
|
delete deckList;
|
||||||
deckList = _deck;
|
deckList = _deck;
|
||||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
||||||
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
|
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
|
||||||
|
|
||||||
if (node->height() == 1) {
|
if (node->height() == 1) {
|
||||||
QTextBlockFormat blockFormat;
|
QTextBlockFormat blockFormat;
|
||||||
QTextCharFormat charFormat;
|
QTextCharFormat charFormat;
|
||||||
charFormat.setFontPointSize(11);
|
charFormat.setFontPointSize(11);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
cursor->insertBlock(blockFormat, charFormat);
|
cursor->insertBlock(blockFormat, charFormat);
|
||||||
QString priceStr;
|
QString priceStr;
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
||||||
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat;
|
||||||
tableFormat.setCellPadding(0);
|
tableFormat.setCellPadding(0);
|
||||||
tableFormat.setCellSpacing(0);
|
tableFormat.setCellSpacing(0);
|
||||||
tableFormat.setBorder(0);
|
tableFormat.setBorder(0);
|
||||||
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
||||||
for (int i = 0; i < node->size(); i++) {
|
for (int i = 0; i < node->size(); i++) {
|
||||||
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
||||||
|
|
||||||
QTextCharFormat cellCharFormat;
|
QTextCharFormat cellCharFormat;
|
||||||
cellCharFormat.setFontPointSize(9);
|
cellCharFormat.setFontPointSize(9);
|
||||||
|
|
||||||
QTextTableCell cell = table->cellAt(i, 0);
|
QTextTableCell cell = table->cellAt(i, 0);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
QTextCursor cellCursor = cell.firstCursorPosition();
|
QTextCursor cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
|
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
|
||||||
|
|
||||||
cell = table->cellAt(i, 1);
|
cell = table->cellAt(i, 1);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
cellCursor = cell.firstCursorPosition();
|
cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(card->getName());
|
cellCursor.insertText(card->getName());
|
||||||
|
|
||||||
if (settingsCache->getPriceTagFeature()) {
|
if (settingsCache->getPriceTagFeature()) {
|
||||||
cell = table->cellAt(i, 2);
|
cell = table->cellAt(i, 2);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
cellCursor = cell.firstCursorPosition();
|
cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
|
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node->height() == 2) {
|
} else if (node->height() == 2) {
|
||||||
QTextBlockFormat blockFormat;
|
QTextBlockFormat blockFormat;
|
||||||
QTextCharFormat charFormat;
|
QTextCharFormat charFormat;
|
||||||
charFormat.setFontPointSize(14);
|
charFormat.setFontPointSize(14);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
cursor->insertBlock(blockFormat, charFormat);
|
cursor->insertBlock(blockFormat, charFormat);
|
||||||
QString priceStr;
|
QString priceStr;
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
||||||
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat;
|
||||||
tableFormat.setCellPadding(10);
|
tableFormat.setCellPadding(10);
|
||||||
tableFormat.setCellSpacing(0);
|
tableFormat.setCellSpacing(0);
|
||||||
tableFormat.setBorder(0);
|
tableFormat.setBorder(0);
|
||||||
QVector<QTextLength> constraints;
|
QVector<QTextLength> constraints;
|
||||||
for (int i = 0; i < totalColumns; i++)
|
for (int i = 0; i < totalColumns; i++)
|
||||||
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
|
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
|
||||||
tableFormat.setColumnWidthConstraints(constraints);
|
tableFormat.setColumnWidthConstraints(constraints);
|
||||||
|
|
||||||
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
|
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
|
||||||
for (int i = 0; i < node->size(); i++) {
|
for (int i = 0; i < node->size(); i++) {
|
||||||
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
|
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
|
||||||
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor->movePosition(QTextCursor::End);
|
cursor->movePosition(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckList(QPrinter *printer)
|
void DeckListModel::printDeckList(QPrinter *printer)
|
||||||
{
|
{
|
||||||
QTextDocument doc;
|
QTextDocument doc;
|
||||||
|
|
||||||
QFont font("Serif");
|
QFont font("Serif");
|
||||||
font.setStyleHint(QFont::Serif);
|
font.setStyleHint(QFont::Serif);
|
||||||
doc.setDefaultFont(font);
|
doc.setDefaultFont(font);
|
||||||
|
|
||||||
QTextCursor cursor(&doc);
|
QTextCursor cursor(&doc);
|
||||||
|
|
||||||
QTextBlockFormat headerBlockFormat;
|
QTextBlockFormat headerBlockFormat;
|
||||||
QTextCharFormat headerCharFormat;
|
QTextCharFormat headerCharFormat;
|
||||||
headerCharFormat.setFontPointSize(16);
|
headerCharFormat.setFontPointSize(16);
|
||||||
headerCharFormat.setFontWeight(QFont::Bold);
|
headerCharFormat.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
cursor.insertText(deckList->getName());
|
cursor.insertText(deckList->getName());
|
||||||
|
|
||||||
headerCharFormat.setFontPointSize(12);
|
headerCharFormat.setFontPointSize(12);
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
cursor.insertText(deckList->getComments());
|
cursor.insertText(deckList->getComments());
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++) {
|
for (int i = 0; i < root->size(); i++) {
|
||||||
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
|
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
|
||||||
//cursor.insertHtml("<hr>");
|
//cursor.insertHtml("<hr>");
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.print(printer);
|
doc.print(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::pricesUpdated(InnerDecklistNode *node)
|
void DeckListModel::pricesUpdated(InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
if (!node)
|
if (!node)
|
||||||
node = root;
|
node = root;
|
||||||
|
|
||||||
if (node->isEmpty())
|
if (node->isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit dataChanged(createIndex(0, 2, node->at(0)), createIndex(node->size() - 1, 2, node->last()));
|
emit dataChanged(createIndex(0, 2, node->at(0)), createIndex(node->size() - 1, 2, node->last()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,60 +13,60 @@ class QTextCursor;
|
||||||
|
|
||||||
class DecklistModelCardNode : public AbstractDecklistCardNode {
|
class DecklistModelCardNode : public AbstractDecklistCardNode {
|
||||||
private:
|
private:
|
||||||
DecklistCardNode *dataNode;
|
DecklistCardNode *dataNode;
|
||||||
public:
|
public:
|
||||||
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
|
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
|
||||||
int getNumber() const { return dataNode->getNumber(); }
|
int getNumber() const { return dataNode->getNumber(); }
|
||||||
void setNumber(int _number) { dataNode->setNumber(_number); }
|
void setNumber(int _number) { dataNode->setNumber(_number); }
|
||||||
float getPrice() const { return dataNode->getPrice(); }
|
float getPrice() const { return dataNode->getPrice(); }
|
||||||
void setPrice(float _price) { dataNode->setPrice(_price); }
|
void setPrice(float _price) { dataNode->setPrice(_price); }
|
||||||
QString getName() const { return dataNode->getName(); }
|
QString getName() const { return dataNode->getName(); }
|
||||||
void setName(const QString &_name) { dataNode->setName(_name); }
|
void setName(const QString &_name) { dataNode->setName(_name); }
|
||||||
DecklistCardNode *getDataNode() const { return dataNode; }
|
DecklistCardNode *getDataNode() const { return dataNode; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckListModel : public QAbstractItemModel {
|
class DeckListModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void rebuildTree();
|
void rebuildTree();
|
||||||
public slots:
|
public slots:
|
||||||
void printDeckList(QPrinter *printer);
|
void printDeckList(QPrinter *printer);
|
||||||
signals:
|
signals:
|
||||||
void deckHashChanged();
|
void deckHashChanged();
|
||||||
public:
|
public:
|
||||||
DeckListModel(QObject *parent = 0);
|
DeckListModel(QObject *parent = 0);
|
||||||
~DeckListModel();
|
~DeckListModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||||
QModelIndex addCard(const QString &cardName, const QString &zoneName);
|
QModelIndex addCard(const QString &cardName, const QString &zoneName);
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
void cleanList();
|
void cleanList();
|
||||||
DeckLoader *getDeckList() const { return deckList; }
|
DeckLoader *getDeckList() const { return deckList; }
|
||||||
void setDeckList(DeckLoader *_deck);
|
void setDeckList(DeckLoader *_deck);
|
||||||
void pricesUpdated(InnerDecklistNode *node = 0);
|
void pricesUpdated(InnerDecklistNode *node = 0);
|
||||||
private:
|
private:
|
||||||
DeckLoader *deckList;
|
DeckLoader *deckList;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
||||||
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
||||||
void emitRecursiveUpdates(const QModelIndex &index);
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
|
|
||||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||||
|
|
||||||
template<typename T> T getNode(const QModelIndex &index) const
|
template<typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return dynamic_cast<T>(root);
|
return dynamic_cast<T>(root);
|
||||||
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,46 +8,46 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
DeckStatsInterface::DeckStatsInterface(QObject *parent)
|
DeckStatsInterface::DeckStatsInterface(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
manager = new QNetworkAccessManager(this);
|
manager = new QNetworkAccessManager(this);
|
||||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(queryFinished(QNetworkReply *)));
|
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(queryFinished(QNetworkReply *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckStatsInterface::queryFinished(QNetworkReply *reply)
|
void DeckStatsInterface::queryFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
QMessageBox::critical(0, tr("Error"), reply->errorString());
|
QMessageBox::critical(0, tr("Error"), reply->errorString());
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString data(reply->readAll());
|
QString data(reply->readAll());
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QRegExp rx("id=\"deckstats_deck_url\" value=\"([^\"]+)\"");
|
QRegExp rx("id=\"deckstats_deck_url\" value=\"([^\"]+)\"");
|
||||||
if (!rx.indexIn(data)) {
|
if (!rx.indexIn(data)) {
|
||||||
QMessageBox::critical(0, tr("Error"), tr("The reply from the server could not be parsed."));
|
QMessageBox::critical(0, tr("Error"), tr("The reply from the server could not be parsed."));
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString deckUrl = rx.cap(1);
|
QString deckUrl = rx.cap(1);
|
||||||
QDesktopServices::openUrl(deckUrl);
|
QDesktopServices::openUrl(deckUrl);
|
||||||
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
||||||
{
|
{
|
||||||
QUrl params;
|
QUrl params;
|
||||||
params.addQueryItem("deck", deck->writeToString_Plain());
|
params.addQueryItem("deck", deck->writeToString_Plain());
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
data.append(params.encodedQuery());
|
data.append(params.encodedQuery());
|
||||||
|
|
||||||
QNetworkRequest request(QUrl("http://deckstats.net/index.php"));
|
QNetworkRequest request(QUrl("http://deckstats.net/index.php"));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
manager->post(request, data);
|
manager->post(request, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,14 @@ class QNetworkReply;
|
||||||
class DeckList;
|
class DeckList;
|
||||||
|
|
||||||
class DeckStatsInterface : public QObject {
|
class DeckStatsInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
private slots:
|
private slots:
|
||||||
void queryFinished(QNetworkReply *reply);
|
void queryFinished(QNetworkReply *reply);
|
||||||
public:
|
public:
|
||||||
DeckStatsInterface(QObject *parent = 0);
|
DeckStatsInterface(QObject *parent = 0);
|
||||||
void analyzeDeck(DeckList *deck);
|
void analyzeDeck(DeckList *deck);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,479 +8,479 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
||||||
: AbstractCardDragItem(_item, _hotSpot, parentDrag), currentZone(0)
|
: AbstractCardDragItem(_item, _hotSpot, parentDrag), currentZone(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
|
void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos);
|
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos);
|
||||||
|
|
||||||
DeckViewCardContainer *cursorZone = 0;
|
DeckViewCardContainer *cursorZone = 0;
|
||||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||||
if ((cursorZone = qgraphicsitem_cast<DeckViewCardContainer *>(colliding.at(i))))
|
if ((cursorZone = qgraphicsitem_cast<DeckViewCardContainer *>(colliding.at(i))))
|
||||||
break;
|
break;
|
||||||
if (!cursorZone)
|
if (!cursorZone)
|
||||||
return;
|
return;
|
||||||
currentZone = cursorZone;
|
currentZone = cursorZone;
|
||||||
|
|
||||||
QPointF newPos = cursorScenePos;
|
QPointF newPos = cursorScenePos;
|
||||||
if (newPos != pos()) {
|
if (newPos != pos()) {
|
||||||
for (int i = 0; i < childDrags.size(); i++)
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||||
setPos(newPos);
|
setPos(newPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardDragItem::handleDrop(DeckViewCardContainer *target)
|
void DeckViewCardDragItem::handleDrop(DeckViewCardContainer *target)
|
||||||
{
|
{
|
||||||
DeckViewCard *card = static_cast<DeckViewCard *>(item);
|
DeckViewCard *card = static_cast<DeckViewCard *>(item);
|
||||||
DeckViewCardContainer *start = static_cast<DeckViewCardContainer *>(item->parentItem());
|
DeckViewCardContainer *start = static_cast<DeckViewCardContainer *>(item->parentItem());
|
||||||
start->removeCard(card);
|
start->removeCard(card);
|
||||||
target->addCard(card);
|
target->addCard(card);
|
||||||
card->setParentItem(target);
|
card->setParentItem(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
DeckViewScene *sc = static_cast<DeckViewScene *>(scene());
|
DeckViewScene *sc = static_cast<DeckViewScene *>(scene());
|
||||||
sc->removeItem(this);
|
sc->removeItem(this);
|
||||||
|
|
||||||
if (currentZone) {
|
if (currentZone) {
|
||||||
handleDrop(currentZone);
|
handleDrop(currentZone);
|
||||||
for (int i = 0; i < childDrags.size(); i++) {
|
for (int i = 0; i < childDrags.size(); i++) {
|
||||||
DeckViewCardDragItem *c = static_cast<DeckViewCardDragItem *>(childDrags[i]);
|
DeckViewCardDragItem *c = static_cast<DeckViewCardDragItem *>(childDrags[i]);
|
||||||
c->handleDrop(currentZone);
|
c->handleDrop(currentZone);
|
||||||
sc->removeItem(c);
|
sc->removeItem(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc->updateContents();
|
sc->updateContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent)
|
DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent)
|
||||||
: AbstractCardItem(_name, 0, -1, parent), originZone(_originZone), dragItem(0)
|
: AbstractCardItem(_name, 0, -1, parent), originZone(_originZone), dragItem(0)
|
||||||
{
|
{
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckViewCard::~DeckViewCard()
|
DeckViewCard::~DeckViewCard()
|
||||||
{
|
{
|
||||||
delete dragItem;
|
delete dragItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
AbstractCardItem::paint(painter, option, widget);
|
AbstractCardItem::paint(painter, option, widget);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
QPen pen;//(Qt::DotLine);
|
QPen pen;//(Qt::DotLine);
|
||||||
pen.setWidth(3);
|
pen.setWidth(3);
|
||||||
if (originZone == "main")
|
if (originZone == "main")
|
||||||
pen.setColor(QColor(0, 255, 0));
|
pen.setColor(QColor(0, 255, 0));
|
||||||
else
|
else
|
||||||
pen.setColor(QColor(255, 0, 0));
|
pen.setColor(QColor(255, 0, 0));
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(QRectF(1.5, 1.5, CARD_WIDTH - 3, CARD_HEIGHT - 3));
|
painter->drawRect(QRectF(1.5, 1.5, CARD_WIDTH - 3, CARD_HEIGHT - 3));
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete dragItem;
|
delete dragItem;
|
||||||
dragItem = new DeckViewCardDragItem(this, event->pos());
|
dragItem = new DeckViewCardDragItem(this, event->pos());
|
||||||
scene()->addItem(dragItem);
|
scene()->addItem(dragItem);
|
||||||
dragItem->updatePosition(event->scenePos());
|
dragItem->updatePosition(event->scenePos());
|
||||||
dragItem->grabMouse();
|
dragItem->grabMouse();
|
||||||
|
|
||||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i = 0; i < sel.size(); i++) {
|
for (int i = 0; i < sel.size(); i++) {
|
||||||
DeckViewCard *c = static_cast<DeckViewCard *>(sel.at(i));
|
DeckViewCard *c = static_cast<DeckViewCard *>(sel.at(i));
|
||||||
if (c == this)
|
if (c == this)
|
||||||
continue;
|
continue;
|
||||||
++j;
|
++j;
|
||||||
QPointF childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
QPointF childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
||||||
DeckViewCardDragItem *drag = new DeckViewCardDragItem(c, childPos, dragItem);
|
DeckViewCardDragItem *drag = new DeckViewCardDragItem(c, childPos, dragItem);
|
||||||
drag->setPos(dragItem->pos() + childPos);
|
drag->setPos(dragItem->pos() + childPos);
|
||||||
scene()->addItem(drag);
|
scene()->addItem(drag);
|
||||||
}
|
}
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
processHoverEvent();
|
processHoverEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
||||||
: QGraphicsItem(), name(_name), width(0), height(0)
|
: QGraphicsItem(), name(_name), width(0), height(0)
|
||||||
{
|
{
|
||||||
QString bgPath = settingsCache->getTableBgPath();
|
QString bgPath = settingsCache->getTableBgPath();
|
||||||
if (!bgPath.isEmpty())
|
if (!bgPath.isEmpty())
|
||||||
bgPixmap.load(bgPath);
|
bgPixmap.load(bgPath);
|
||||||
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF DeckViewCardContainer::boundingRect() const
|
QRectF DeckViewCardContainer::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, width, height);
|
return QRectF(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
qreal totalTextWidth = getCardTypeTextWidth();
|
qreal totalTextWidth = getCardTypeTextWidth();
|
||||||
|
|
||||||
if (bgPixmap.isNull())
|
if (bgPixmap.isNull())
|
||||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||||
else
|
else
|
||||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||||
painter->setPen(QColor(255, 255, 255, 100));
|
painter->setPen(QColor(255, 255, 255, 100));
|
||||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||||
|
|
||||||
painter->setPen(QColor(Qt::white));
|
painter->setPen(QColor(Qt::white));
|
||||||
QFont f("Serif");
|
QFont f("Serif");
|
||||||
f.setStyleHint(QFont::Serif);
|
f.setStyleHint(QFont::Serif);
|
||||||
f.setPixelSize(24);
|
f.setPixelSize(24);
|
||||||
f.setWeight(QFont::Bold);
|
f.setWeight(QFont::Bold);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size()));
|
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size()));
|
||||||
|
|
||||||
f.setPixelSize(16);
|
f.setPixelSize(16);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||||
qreal yUntilNow = separatorY + paddingY;
|
qreal yUntilNow = separatorY + paddingY;
|
||||||
for (int i = 0; i < cardTypeList.size(); ++i) {
|
for (int i = 0; i < cardTypeList.size(); ++i) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
painter->setPen(QColor(255, 255, 255, 100));
|
painter->setPen(QColor(255, 255, 255, 100));
|
||||||
painter->drawLine(QPointF(0, yUntilNow - paddingY / 2), QPointF(width, yUntilNow - paddingY / 2));
|
painter->drawLine(QPointF(0, yUntilNow - paddingY / 2), QPointF(width, yUntilNow - paddingY / 2));
|
||||||
}
|
}
|
||||||
qreal thisRowHeight = CARD_HEIGHT * currentRowsAndCols[i].first;
|
qreal thisRowHeight = CARD_HEIGHT * currentRowsAndCols[i].first;
|
||||||
QRectF textRect(0, yUntilNow, totalTextWidth, thisRowHeight);
|
QRectF textRect(0, yUntilNow, totalTextWidth, thisRowHeight);
|
||||||
yUntilNow += thisRowHeight + paddingY;
|
yUntilNow += thisRowHeight + paddingY;
|
||||||
|
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
painter->drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, cardTypeList[i]);
|
painter->drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, cardTypeList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
||||||
{
|
{
|
||||||
cards.append(card);
|
cards.append(card);
|
||||||
cardsByType.insert(card->getInfo()->getMainCardType(), card);
|
cardsByType.insert(card->getInfo()->getMainCardType(), card);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::removeCard(DeckViewCard *card)
|
void DeckViewCardContainer::removeCard(DeckViewCard *card)
|
||||||
{
|
{
|
||||||
cards.removeAt(cards.indexOf(card));
|
cards.removeAt(cards.indexOf(card));
|
||||||
cardsByType.remove(card->getInfo()->getMainCardType(), card);
|
cardsByType.remove(card->getInfo()->getMainCardType(), card);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QPair<int, int> > DeckViewCardContainer::getRowsAndCols() const
|
QList<QPair<int, int> > DeckViewCardContainer::getRowsAndCols() const
|
||||||
{
|
{
|
||||||
QList<QPair<int, int> > result;
|
QList<QPair<int, int> > result;
|
||||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||||
for (int i = 0; i < cardTypeList.size(); ++i)
|
for (int i = 0; i < cardTypeList.size(); ++i)
|
||||||
result.append(QPair<int, int>(1, cardsByType.count(cardTypeList[i])));
|
result.append(QPair<int, int>(1, cardsByType.count(cardTypeList[i])));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckViewCardContainer::getCardTypeTextWidth() const
|
int DeckViewCardContainer::getCardTypeTextWidth() const
|
||||||
{
|
{
|
||||||
QFont f("Serif");
|
QFont f("Serif");
|
||||||
f.setStyleHint(QFont::Serif);
|
f.setStyleHint(QFont::Serif);
|
||||||
f.setPixelSize(16);
|
f.setPixelSize(16);
|
||||||
f.setWeight(QFont::Bold);
|
f.setWeight(QFont::Bold);
|
||||||
QFontMetrics fm(f);
|
QFontMetrics fm(f);
|
||||||
|
|
||||||
int maxCardTypeWidth = 0;
|
int maxCardTypeWidth = 0;
|
||||||
QMapIterator<QString, DeckViewCard *> i(cardsByType);
|
QMapIterator<QString, DeckViewCard *> i(cardsByType);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
int cardTypeWidth = fm.size(Qt::TextSingleLine, i.next().key()).width();
|
int cardTypeWidth = fm.size(Qt::TextSingleLine, i.next().key()).width();
|
||||||
if (cardTypeWidth > maxCardTypeWidth)
|
if (cardTypeWidth > maxCardTypeWidth)
|
||||||
maxCardTypeWidth = cardTypeWidth;
|
maxCardTypeWidth = cardTypeWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
return maxCardTypeWidth + 15;
|
return maxCardTypeWidth + 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int> > &rowsAndCols) const
|
QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int> > &rowsAndCols) const
|
||||||
{
|
{
|
||||||
qreal totalHeight = 0;
|
qreal totalHeight = 0;
|
||||||
qreal totalWidth = 0;
|
qreal totalWidth = 0;
|
||||||
|
|
||||||
// Calculate space needed for cards
|
// Calculate space needed for cards
|
||||||
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
||||||
totalHeight += CARD_HEIGHT * rowsAndCols[i].first + paddingY;
|
totalHeight += CARD_HEIGHT * rowsAndCols[i].first + paddingY;
|
||||||
if (CARD_WIDTH * rowsAndCols[i].second > totalWidth)
|
if (CARD_WIDTH * rowsAndCols[i].second > totalWidth)
|
||||||
totalWidth = CARD_WIDTH * rowsAndCols[i].second;
|
totalWidth = CARD_WIDTH * rowsAndCols[i].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSizeF(getCardTypeTextWidth() + totalWidth, totalHeight + separatorY + paddingY);
|
return QSizeF(getCardTypeTextWidth() + totalWidth, totalHeight + separatorY + paddingY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::rearrangeItems(const QList<QPair<int, int> > &rowsAndCols)
|
void DeckViewCardContainer::rearrangeItems(const QList<QPair<int, int> > &rowsAndCols)
|
||||||
{
|
{
|
||||||
currentRowsAndCols = rowsAndCols;
|
currentRowsAndCols = rowsAndCols;
|
||||||
|
|
||||||
int totalCols = 0, totalRows = 0;
|
int totalCols = 0, totalRows = 0;
|
||||||
qreal yUntilNow = separatorY + paddingY;
|
qreal yUntilNow = separatorY + paddingY;
|
||||||
qreal x = (qreal) getCardTypeTextWidth();
|
qreal x = (qreal) getCardTypeTextWidth();
|
||||||
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
||||||
const int tempRows = rowsAndCols[i].first;
|
const int tempRows = rowsAndCols[i].first;
|
||||||
const int tempCols = rowsAndCols[i].second;
|
const int tempCols = rowsAndCols[i].second;
|
||||||
totalRows += tempRows;
|
totalRows += tempRows;
|
||||||
if (tempCols > totalCols)
|
if (tempCols > totalCols)
|
||||||
totalCols = tempCols;
|
totalCols = tempCols;
|
||||||
|
|
||||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||||
QList<DeckViewCard *> row = cardsByType.values(cardTypeList[i]);
|
QList<DeckViewCard *> row = cardsByType.values(cardTypeList[i]);
|
||||||
for (int j = 0; j < row.size(); ++j) {
|
for (int j = 0; j < row.size(); ++j) {
|
||||||
DeckViewCard *card = row[j];
|
DeckViewCard *card = row[j];
|
||||||
card->setPos(x + (j % tempCols) * CARD_WIDTH, yUntilNow + (j / tempCols) * CARD_HEIGHT);
|
card->setPos(x + (j % tempCols) * CARD_WIDTH, yUntilNow + (j / tempCols) * CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
yUntilNow += tempRows * CARD_HEIGHT + paddingY;
|
yUntilNow += tempRows * CARD_HEIGHT + paddingY;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
QSizeF bRect = calculateBoundingRect(rowsAndCols);
|
QSizeF bRect = calculateBoundingRect(rowsAndCols);
|
||||||
width = bRect.width();
|
width = bRect.width();
|
||||||
height = bRect.height();
|
height = bRect.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::setWidth(qreal _width)
|
void DeckViewCardContainer::setWidth(qreal _width)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
width = _width;
|
width = _width;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckViewScene::DeckViewScene(QObject *parent)
|
DeckViewScene::DeckViewScene(QObject *parent)
|
||||||
: QGraphicsScene(parent), locked(true), deck(0), optimalAspectRatio(1.0)
|
: QGraphicsScene(parent), locked(true), deck(0), optimalAspectRatio(1.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckViewScene::~DeckViewScene()
|
DeckViewScene::~DeckViewScene()
|
||||||
{
|
{
|
||||||
clearContents();
|
clearContents();
|
||||||
delete deck;
|
delete deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::clearContents()
|
void DeckViewScene::clearContents()
|
||||||
{
|
{
|
||||||
QMapIterator<QString, DeckViewCardContainer *> i(cardContainers);
|
QMapIterator<QString, DeckViewCardContainer *> i(cardContainers);
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
delete i.next().value();
|
delete i.next().value();
|
||||||
cardContainers.clear();
|
cardContainers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::setDeck(const DeckList &_deck)
|
void DeckViewScene::setDeck(const DeckList &_deck)
|
||||||
{
|
{
|
||||||
if (deck)
|
if (deck)
|
||||||
delete deck;
|
delete deck;
|
||||||
|
|
||||||
deck = new DeckList(_deck);
|
deck = new DeckList(_deck);
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
applySideboardPlan(deck->getCurrentSideboardPlan());
|
applySideboardPlan(deck->getCurrentSideboardPlan());
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::rebuildTree()
|
void DeckViewScene::rebuildTree()
|
||||||
{
|
{
|
||||||
clearContents();
|
clearContents();
|
||||||
|
|
||||||
if (!deck)
|
if (!deck)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
InnerDecklistNode *listRoot = deck->getRoot();
|
InnerDecklistNode *listRoot = deck->getRoot();
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
for (int i = 0; i < listRoot->size(); i++) {
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
|
|
||||||
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
||||||
if (!container) {
|
if (!container) {
|
||||||
container = new DeckViewCardContainer(currentZone->getName());
|
container = new DeckViewCardContainer(currentZone->getName());
|
||||||
cardContainers.insert(currentZone->getName(), container);
|
cardContainers.insert(currentZone->getName(), container);
|
||||||
addItem(container);
|
addItem(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < currentZone->size(); j++) {
|
for (int j = 0; j < currentZone->size(); j++) {
|
||||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
if (!currentCard)
|
if (!currentCard)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||||
DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), currentZone->getName(), container);
|
DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), currentZone->getName(), container);
|
||||||
container->addCard(newCard);
|
container->addCard(newCard);
|
||||||
emit newCardAdded(newCard);
|
emit newCardAdded(newCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::applySideboardPlan(const QList<MoveCard_ToZone> &plan)
|
void DeckViewScene::applySideboardPlan(const QList<MoveCard_ToZone> &plan)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < plan.size(); ++i) {
|
for (int i = 0; i < plan.size(); ++i) {
|
||||||
const MoveCard_ToZone &m = plan[i];
|
const MoveCard_ToZone &m = plan[i];
|
||||||
DeckViewCardContainer *start = cardContainers.value(QString::fromStdString(m.start_zone()));
|
DeckViewCardContainer *start = cardContainers.value(QString::fromStdString(m.start_zone()));
|
||||||
DeckViewCardContainer *target = cardContainers.value(QString::fromStdString(m.target_zone()));
|
DeckViewCardContainer *target = cardContainers.value(QString::fromStdString(m.target_zone()));
|
||||||
if (!start || !target)
|
if (!start || !target)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DeckViewCard *card = 0;
|
DeckViewCard *card = 0;
|
||||||
const QList<DeckViewCard *> &cardList = start->getCards();
|
const QList<DeckViewCard *> &cardList = start->getCards();
|
||||||
for (int j = 0; j < cardList.size(); ++j)
|
for (int j = 0; j < cardList.size(); ++j)
|
||||||
if (cardList[j]->getName() == QString::fromStdString(m.card_name())) {
|
if (cardList[j]->getName() == QString::fromStdString(m.card_name())) {
|
||||||
card = cardList[j];
|
card = cardList[j];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!card)
|
if (!card)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
start->removeCard(card);
|
start->removeCard(card);
|
||||||
target->addCard(card);
|
target->addCard(card);
|
||||||
card->setParentItem(target);
|
card->setParentItem(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::rearrangeItems()
|
void DeckViewScene::rearrangeItems()
|
||||||
{
|
{
|
||||||
const int spacing = CARD_HEIGHT / 3;
|
const int spacing = CARD_HEIGHT / 3;
|
||||||
QList<DeckViewCardContainer *> contList = cardContainers.values();
|
QList<DeckViewCardContainer *> contList = cardContainers.values();
|
||||||
|
|
||||||
// Initialize space requirements
|
// Initialize space requirements
|
||||||
QList<QList<QPair<int, int> > > rowsAndColsList;
|
QList<QList<QPair<int, int> > > rowsAndColsList;
|
||||||
QList<QList<int> > cardCountList;
|
QList<QList<int> > cardCountList;
|
||||||
for (int i = 0; i < contList.size(); ++i) {
|
for (int i = 0; i < contList.size(); ++i) {
|
||||||
QList<QPair<int, int> > rowsAndCols = contList[i]->getRowsAndCols();
|
QList<QPair<int, int> > rowsAndCols = contList[i]->getRowsAndCols();
|
||||||
rowsAndColsList.append(rowsAndCols);
|
rowsAndColsList.append(rowsAndCols);
|
||||||
|
|
||||||
cardCountList.append(QList<int>());
|
cardCountList.append(QList<int>());
|
||||||
for (int j = 0; j < rowsAndCols.size(); ++j)
|
for (int j = 0; j < rowsAndCols.size(); ++j)
|
||||||
cardCountList[i].append(rowsAndCols[j].second);
|
cardCountList[i].append(rowsAndCols[j].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal totalHeight, totalWidth;
|
qreal totalHeight, totalWidth;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Calculate total size before this iteration
|
// Calculate total size before this iteration
|
||||||
totalHeight = -spacing;
|
totalHeight = -spacing;
|
||||||
totalWidth = 0;
|
totalWidth = 0;
|
||||||
for (int i = 0; i < contList.size(); ++i) {
|
for (int i = 0; i < contList.size(); ++i) {
|
||||||
QSizeF contSize = contList[i]->calculateBoundingRect(rowsAndColsList[i]);
|
QSizeF contSize = contList[i]->calculateBoundingRect(rowsAndColsList[i]);
|
||||||
totalHeight += contSize.height() + spacing;
|
totalHeight += contSize.height() + spacing;
|
||||||
if (contSize.width() > totalWidth)
|
if (contSize.width() > totalWidth)
|
||||||
totalWidth = contSize.width();
|
totalWidth = contSize.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're done when the aspect ratio shifts from too high to too low.
|
// We're done when the aspect ratio shifts from too high to too low.
|
||||||
if (totalWidth / totalHeight <= optimalAspectRatio)
|
if (totalWidth / totalHeight <= optimalAspectRatio)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Find category with highest column count
|
// Find category with highest column count
|
||||||
int maxIndex1 = -1, maxIndex2 = -1, maxCols = 0;
|
int maxIndex1 = -1, maxIndex2 = -1, maxCols = 0;
|
||||||
for (int i = 0; i < rowsAndColsList.size(); ++i)
|
for (int i = 0; i < rowsAndColsList.size(); ++i)
|
||||||
for (int j = 0; j < rowsAndColsList[i].size(); ++j)
|
for (int j = 0; j < rowsAndColsList[i].size(); ++j)
|
||||||
if (rowsAndColsList[i][j].second > maxCols) {
|
if (rowsAndColsList[i][j].second > maxCols) {
|
||||||
maxIndex1 = i;
|
maxIndex1 = i;
|
||||||
maxIndex2 = j;
|
maxIndex2 = j;
|
||||||
maxCols = rowsAndColsList[i][j].second;
|
maxCols = rowsAndColsList[i][j].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add row to category
|
// Add row to category
|
||||||
const int maxRows = rowsAndColsList[maxIndex1][maxIndex2].first;
|
const int maxRows = rowsAndColsList[maxIndex1][maxIndex2].first;
|
||||||
const int maxCardCount = cardCountList[maxIndex1][maxIndex2];
|
const int maxCardCount = cardCountList[maxIndex1][maxIndex2];
|
||||||
rowsAndColsList[maxIndex1][maxIndex2] = QPair<int, int>(maxRows + 1, (int) ceil((qreal) maxCardCount / (qreal) (maxRows + 1)));
|
rowsAndColsList[maxIndex1][maxIndex2] = QPair<int, int>(maxRows + 1, (int) ceil((qreal) maxCardCount / (qreal) (maxRows + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
totalHeight = -spacing;
|
totalHeight = -spacing;
|
||||||
for (int i = 0; i < contList.size(); ++i) {
|
for (int i = 0; i < contList.size(); ++i) {
|
||||||
DeckViewCardContainer *c = contList[i];
|
DeckViewCardContainer *c = contList[i];
|
||||||
c->rearrangeItems(rowsAndColsList[i]);
|
c->rearrangeItems(rowsAndColsList[i]);
|
||||||
c->setPos(0, totalHeight + spacing);
|
c->setPos(0, totalHeight + spacing);
|
||||||
totalHeight += c->boundingRect().height() + spacing;
|
totalHeight += c->boundingRect().height() + spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalWidth = totalHeight * optimalAspectRatio;
|
totalWidth = totalHeight * optimalAspectRatio;
|
||||||
for (int i = 0; i < contList.size(); ++i)
|
for (int i = 0; i < contList.size(); ++i)
|
||||||
contList[i]->setWidth(totalWidth);
|
contList[i]->setWidth(totalWidth);
|
||||||
|
|
||||||
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::updateContents()
|
void DeckViewScene::updateContents()
|
||||||
{
|
{
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
emit sideboardPlanChanged();
|
emit sideboardPlanChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<MoveCard_ToZone> DeckViewScene::getSideboardPlan() const
|
QList<MoveCard_ToZone> DeckViewScene::getSideboardPlan() const
|
||||||
{
|
{
|
||||||
QList<MoveCard_ToZone> result;
|
QList<MoveCard_ToZone> result;
|
||||||
QMapIterator<QString, DeckViewCardContainer *> containerIterator(cardContainers);
|
QMapIterator<QString, DeckViewCardContainer *> containerIterator(cardContainers);
|
||||||
while (containerIterator.hasNext()) {
|
while (containerIterator.hasNext()) {
|
||||||
DeckViewCardContainer *cont = containerIterator.next().value();
|
DeckViewCardContainer *cont = containerIterator.next().value();
|
||||||
const QList<DeckViewCard *> cardList = cont->getCards();
|
const QList<DeckViewCard *> cardList = cont->getCards();
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
if (cardList[i]->getOriginZone() != cont->getName()) {
|
if (cardList[i]->getOriginZone() != cont->getName()) {
|
||||||
MoveCard_ToZone m;
|
MoveCard_ToZone m;
|
||||||
m.set_card_name(cardList[i]->getName().toStdString());
|
m.set_card_name(cardList[i]->getName().toStdString());
|
||||||
m.set_start_zone(cardList[i]->getOriginZone().toStdString());
|
m.set_start_zone(cardList[i]->getOriginZone().toStdString());
|
||||||
m.set_target_zone(cont->getName().toStdString());
|
m.set_target_zone(cont->getName().toStdString());
|
||||||
result.append(m);
|
result.append(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewScene::resetSideboardPlan()
|
void DeckViewScene::resetSideboardPlan()
|
||||||
{
|
{
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckView::DeckView(QWidget *parent)
|
DeckView::DeckView(QWidget *parent)
|
||||||
: QGraphicsView(parent)
|
: QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
deckViewScene = new DeckViewScene(this);
|
deckViewScene = new DeckViewScene(this);
|
||||||
|
|
||||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
setDragMode(RubberBandDrag);
|
setDragMode(RubberBandDrag);
|
||||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||||
setScene(deckViewScene);
|
setScene(deckViewScene);
|
||||||
|
|
||||||
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
connect(deckViewScene, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
connect(deckViewScene, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
||||||
connect(deckViewScene, SIGNAL(sideboardPlanChanged()), this, SIGNAL(sideboardPlanChanged()));
|
connect(deckViewScene, SIGNAL(sideboardPlanChanged()), this, SIGNAL(sideboardPlanChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckView::resizeEvent(QResizeEvent *event)
|
void DeckView::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsView::resizeEvent(event);
|
QGraphicsView::resizeEvent(event);
|
||||||
deckViewScene->setOptimalAspectRatio((qreal) width() / (qreal) height());
|
deckViewScene->setOptimalAspectRatio((qreal) width() / (qreal) height());
|
||||||
deckViewScene->rearrangeItems();
|
deckViewScene->rearrangeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckView::updateSceneRect(const QRectF &rect)
|
void DeckView::updateSceneRect(const QRectF &rect)
|
||||||
{
|
{
|
||||||
fitInView(rect, Qt::KeepAspectRatio);
|
fitInView(rect, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckView::setDeck(const DeckList &_deck)
|
void DeckView::setDeck(const DeckList &_deck)
|
||||||
{
|
{
|
||||||
deckViewScene->setDeck(_deck);
|
deckViewScene->setDeck(_deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckView::resetSideboardPlan()
|
void DeckView::resetSideboardPlan()
|
||||||
{
|
{
|
||||||
deckViewScene->resetSideboardPlan();
|
deckViewScene->resetSideboardPlan();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,101 +19,101 @@ class MoveCardToZone;
|
||||||
|
|
||||||
class DeckViewCard : public AbstractCardItem {
|
class DeckViewCard : public AbstractCardItem {
|
||||||
private:
|
private:
|
||||||
QString originZone;
|
QString originZone;
|
||||||
DeckViewCardDragItem *dragItem;
|
DeckViewCardDragItem *dragItem;
|
||||||
public:
|
public:
|
||||||
DeckViewCard(const QString &_name = QString(), const QString &_originZone = QString(), QGraphicsItem *parent = 0);
|
DeckViewCard(const QString &_name = QString(), const QString &_originZone = QString(), QGraphicsItem *parent = 0);
|
||||||
~DeckViewCard();
|
~DeckViewCard();
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
const QString &getOriginZone() const { return originZone; }
|
const QString &getOriginZone() const { return originZone; }
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckViewCardDragItem : public AbstractCardDragItem {
|
class DeckViewCardDragItem : public AbstractCardDragItem {
|
||||||
private:
|
private:
|
||||||
DeckViewCardContainer *currentZone;
|
DeckViewCardContainer *currentZone;
|
||||||
void handleDrop(DeckViewCardContainer *target);
|
void handleDrop(DeckViewCardContainer *target);
|
||||||
public:
|
public:
|
||||||
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
||||||
void updatePosition(const QPointF &cursorScenePos);
|
void updatePosition(const QPointF &cursorScenePos);
|
||||||
protected:
|
protected:
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckViewCardContainer : public QGraphicsItem {
|
class DeckViewCardContainer : public QGraphicsItem {
|
||||||
private:
|
private:
|
||||||
static const int separatorY = 20;
|
static const int separatorY = 20;
|
||||||
static const int paddingY = 10;
|
static const int paddingY = 10;
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
QList<DeckViewCard *> cards;
|
QList<DeckViewCard *> cards;
|
||||||
QMultiMap<QString, DeckViewCard *> cardsByType;
|
QMultiMap<QString, DeckViewCard *> cardsByType;
|
||||||
QList<QPair<int, int> > currentRowsAndCols;
|
QList<QPair<int, int> > currentRowsAndCols;
|
||||||
qreal width, height;
|
qreal width, height;
|
||||||
QPixmap bgPixmap;
|
QPixmap bgPixmap;
|
||||||
int getCardTypeTextWidth() const;
|
int getCardTypeTextWidth() const;
|
||||||
public:
|
public:
|
||||||
enum { Type = typeDeckViewCardContainer };
|
enum { Type = typeDeckViewCardContainer };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
DeckViewCardContainer(const QString &_name);
|
DeckViewCardContainer(const QString &_name);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(DeckViewCard *card);
|
void addCard(DeckViewCard *card);
|
||||||
void removeCard(DeckViewCard *card);
|
void removeCard(DeckViewCard *card);
|
||||||
const QList<DeckViewCard *> &getCards() const { return cards; }
|
const QList<DeckViewCard *> &getCards() const { return cards; }
|
||||||
const QString &getName() const { return name; }
|
const QString &getName() const { return name; }
|
||||||
void setWidth(qreal _width);
|
void setWidth(qreal _width);
|
||||||
|
|
||||||
QList<QPair<int, int> > getRowsAndCols() const;
|
QList<QPair<int, int> > getRowsAndCols() const;
|
||||||
QSizeF calculateBoundingRect(const QList<QPair<int, int> > &rowsAndCols) const;
|
QSizeF calculateBoundingRect(const QList<QPair<int, int> > &rowsAndCols) const;
|
||||||
void rearrangeItems(const QList<QPair<int, int> > &rowsAndCols);
|
void rearrangeItems(const QList<QPair<int, int> > &rowsAndCols);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckViewScene : public QGraphicsScene {
|
class DeckViewScene : public QGraphicsScene {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
void sideboardPlanChanged();
|
void sideboardPlanChanged();
|
||||||
private:
|
private:
|
||||||
bool locked;
|
bool locked;
|
||||||
DeckList *deck;
|
DeckList *deck;
|
||||||
QMap<QString, DeckViewCardContainer *> cardContainers;
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||||
qreal optimalAspectRatio;
|
qreal optimalAspectRatio;
|
||||||
void clearContents();
|
void clearContents();
|
||||||
void rebuildTree();
|
void rebuildTree();
|
||||||
void applySideboardPlan(const QList<MoveCard_ToZone> &plan);
|
void applySideboardPlan(const QList<MoveCard_ToZone> &plan);
|
||||||
public:
|
public:
|
||||||
DeckViewScene(QObject *parent = 0);
|
DeckViewScene(QObject *parent = 0);
|
||||||
~DeckViewScene();
|
~DeckViewScene();
|
||||||
void setLocked(bool _locked) { locked = _locked; }
|
void setLocked(bool _locked) { locked = _locked; }
|
||||||
bool getLocked() const { return locked; }
|
bool getLocked() const { return locked; }
|
||||||
void setDeck(const DeckList &_deck);
|
void setDeck(const DeckList &_deck);
|
||||||
void setOptimalAspectRatio(qreal _optimalAspectRatio) { optimalAspectRatio = _optimalAspectRatio; }
|
void setOptimalAspectRatio(qreal _optimalAspectRatio) { optimalAspectRatio = _optimalAspectRatio; }
|
||||||
void rearrangeItems();
|
void rearrangeItems();
|
||||||
void updateContents();
|
void updateContents();
|
||||||
QList<MoveCard_ToZone> getSideboardPlan() const;
|
QList<MoveCard_ToZone> getSideboardPlan() const;
|
||||||
void resetSideboardPlan();
|
void resetSideboardPlan();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckView : public QGraphicsView {
|
class DeckView : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
DeckViewScene *deckViewScene;
|
DeckViewScene *deckViewScene;
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
public slots:
|
public slots:
|
||||||
void updateSceneRect(const QRectF &rect);
|
void updateSceneRect(const QRectF &rect);
|
||||||
signals:
|
signals:
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
void sideboardPlanChanged();
|
void sideboardPlanChanged();
|
||||||
public:
|
public:
|
||||||
DeckView(QWidget *parent = 0);
|
DeckView(QWidget *parent = 0);
|
||||||
void setDeck(const DeckList &_deck);
|
void setDeck(const DeckList &_deck);
|
||||||
void setLocked(bool _locked) { deckViewScene->setLocked(_locked); }
|
void setLocked(bool _locked) { deckViewScene->setLocked(_locked); }
|
||||||
QList<MoveCard_ToZone> getSideboardPlan() const { return deckViewScene->getSideboardPlan(); }
|
QList<MoveCard_ToZone> getSideboardPlan() const { return deckViewScene->getSideboardPlan(); }
|
||||||
void resetSideboardPlan();
|
void resetSideboardPlan();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,86 +10,86 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
DlgCardSearch::DlgCardSearch(QWidget *parent)
|
DlgCardSearch::DlgCardSearch(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
QLabel *cardNameLabel = new QLabel(tr("Card name:"));
|
QLabel *cardNameLabel = new QLabel(tr("Card name:"));
|
||||||
cardNameEdit = new QLineEdit;
|
cardNameEdit = new QLineEdit;
|
||||||
|
|
||||||
QLabel *cardTextLabel = new QLabel(tr("Card text:"));
|
QLabel *cardTextLabel = new QLabel(tr("Card text:"));
|
||||||
cardTextEdit = new QLineEdit;
|
cardTextEdit = new QLineEdit;
|
||||||
|
|
||||||
QLabel *cardTypesLabel = new QLabel(tr("Card type (OR):"));
|
QLabel *cardTypesLabel = new QLabel(tr("Card type (OR):"));
|
||||||
const QStringList &cardTypes = db->getAllMainCardTypes();
|
const QStringList &cardTypes = db->getAllMainCardTypes();
|
||||||
QVBoxLayout *cardTypesLayout = new QVBoxLayout;
|
QVBoxLayout *cardTypesLayout = new QVBoxLayout;
|
||||||
for (int i = 0; i < cardTypes.size(); ++i) {
|
for (int i = 0; i < cardTypes.size(); ++i) {
|
||||||
QCheckBox *cardTypeCheckBox = new QCheckBox(cardTypes[i]);
|
QCheckBox *cardTypeCheckBox = new QCheckBox(cardTypes[i]);
|
||||||
cardTypeCheckBox->setChecked(true);
|
cardTypeCheckBox->setChecked(true);
|
||||||
cardTypeCheckBoxes.append(cardTypeCheckBox);
|
cardTypeCheckBoxes.append(cardTypeCheckBox);
|
||||||
cardTypesLayout->addWidget(cardTypeCheckBox);
|
cardTypesLayout->addWidget(cardTypeCheckBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel *cardColorsLabel = new QLabel(tr("Color (OR):"));
|
QLabel *cardColorsLabel = new QLabel(tr("Color (OR):"));
|
||||||
const QStringList &cardColors = db->getAllColors();
|
const QStringList &cardColors = db->getAllColors();
|
||||||
QHBoxLayout *cardColorsLayout = new QHBoxLayout;
|
QHBoxLayout *cardColorsLayout = new QHBoxLayout;
|
||||||
for (int i = 0; i < cardColors.size(); ++i) {
|
for (int i = 0; i < cardColors.size(); ++i) {
|
||||||
QCheckBox *cardColorCheckBox = new QCheckBox(cardColors[i]);
|
QCheckBox *cardColorCheckBox = new QCheckBox(cardColors[i]);
|
||||||
cardColorCheckBox->setChecked(true);
|
cardColorCheckBox->setChecked(true);
|
||||||
cardColorCheckBoxes.append(cardColorCheckBox);
|
cardColorCheckBoxes.append(cardColorCheckBox);
|
||||||
cardColorsLayout->addWidget(cardColorCheckBox);
|
cardColorsLayout->addWidget(cardColorCheckBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton *okButton = new QPushButton(tr("O&K"));
|
QPushButton *okButton = new QPushButton(tr("O&K"));
|
||||||
okButton->setDefault(true);
|
okButton->setDefault(true);
|
||||||
okButton->setAutoDefault(true);
|
okButton->setAutoDefault(true);
|
||||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||||
QHBoxLayout *buttonHBox = new QHBoxLayout;
|
QHBoxLayout *buttonHBox = new QHBoxLayout;
|
||||||
buttonHBox->addStretch();
|
buttonHBox->addStretch();
|
||||||
buttonHBox->addWidget(okButton);
|
buttonHBox->addWidget(okButton);
|
||||||
buttonHBox->addWidget(cancelButton);
|
buttonHBox->addWidget(cancelButton);
|
||||||
|
|
||||||
QGridLayout *optionsLayout = new QGridLayout;
|
QGridLayout *optionsLayout = new QGridLayout;
|
||||||
optionsLayout->addWidget(cardNameLabel, 0, 0);
|
optionsLayout->addWidget(cardNameLabel, 0, 0);
|
||||||
optionsLayout->addWidget(cardNameEdit, 0, 1);
|
optionsLayout->addWidget(cardNameEdit, 0, 1);
|
||||||
optionsLayout->addWidget(cardTextLabel, 1, 0);
|
optionsLayout->addWidget(cardTextLabel, 1, 0);
|
||||||
optionsLayout->addWidget(cardTextEdit, 1, 1);
|
optionsLayout->addWidget(cardTextEdit, 1, 1);
|
||||||
optionsLayout->addWidget(cardTypesLabel, 2, 0);
|
optionsLayout->addWidget(cardTypesLabel, 2, 0);
|
||||||
optionsLayout->addLayout(cardTypesLayout, 2, 1);
|
optionsLayout->addLayout(cardTypesLayout, 2, 1);
|
||||||
optionsLayout->addWidget(cardColorsLabel, 3, 0);
|
optionsLayout->addWidget(cardColorsLabel, 3, 0);
|
||||||
optionsLayout->addLayout(cardColorsLayout, 3, 1);
|
optionsLayout->addLayout(cardColorsLayout, 3, 1);
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(optionsLayout);
|
mainLayout->addLayout(optionsLayout);
|
||||||
mainLayout->addLayout(buttonHBox);
|
mainLayout->addLayout(buttonHBox);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
setWindowTitle(tr("Card search"));
|
setWindowTitle(tr("Card search"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCardSearch::getCardName() const
|
QString DlgCardSearch::getCardName() const
|
||||||
{
|
{
|
||||||
return cardNameEdit->text();
|
return cardNameEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCardSearch::getCardText() const
|
QString DlgCardSearch::getCardText() const
|
||||||
{
|
{
|
||||||
return cardTextEdit->text();
|
return cardTextEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<QString> DlgCardSearch::getCardTypes() const
|
QSet<QString> DlgCardSearch::getCardTypes() const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for (int i = 0; i < cardTypeCheckBoxes.size(); ++i)
|
for (int i = 0; i < cardTypeCheckBoxes.size(); ++i)
|
||||||
if (cardTypeCheckBoxes[i]->isChecked())
|
if (cardTypeCheckBoxes[i]->isChecked())
|
||||||
result.append(cardTypeCheckBoxes[i]->text());
|
result.append(cardTypeCheckBoxes[i]->text());
|
||||||
return QSet<QString>::fromList(result);
|
return QSet<QString>::fromList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<QString> DlgCardSearch::getCardColors() const
|
QSet<QString> DlgCardSearch::getCardColors() const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for (int i = 0; i < cardColorCheckBoxes.size(); ++i)
|
for (int i = 0; i < cardColorCheckBoxes.size(); ++i)
|
||||||
if (cardColorCheckBoxes[i]->isChecked())
|
if (cardColorCheckBoxes[i]->isChecked())
|
||||||
result.append(cardColorCheckBoxes[i]->text());
|
result.append(cardColorCheckBoxes[i]->text());
|
||||||
return QSet<QString>::fromList(result);
|
return QSet<QString>::fromList(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,16 @@ class QLineEdit;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
|
|
||||||
class DlgCardSearch : public QDialog {
|
class DlgCardSearch : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QLineEdit *cardNameEdit, *cardTextEdit;
|
QLineEdit *cardNameEdit, *cardTextEdit;
|
||||||
QList<QCheckBox *> cardTypeCheckBoxes, cardColorCheckBoxes;
|
QList<QCheckBox *> cardTypeCheckBoxes, cardColorCheckBoxes;
|
||||||
public:
|
public:
|
||||||
DlgCardSearch(QWidget *parent = 0);
|
DlgCardSearch(QWidget *parent = 0);
|
||||||
QString getCardName() const;
|
QString getCardName() const;
|
||||||
QString getCardText() const;
|
QString getCardText() const;
|
||||||
QSet<QString> getCardTypes() const;
|
QSet<QString> getCardTypes() const;
|
||||||
QSet<QString> getCardColors() const;
|
QSet<QString> getCardColors() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,66 +7,66 @@
|
||||||
#include "dlg_connect.h"
|
#include "dlg_connect.h"
|
||||||
|
|
||||||
DlgConnect::DlgConnect(QWidget *parent)
|
DlgConnect::DlgConnect(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup("server");
|
settings.beginGroup("server");
|
||||||
|
|
||||||
hostLabel = new QLabel(tr("&Host:"));
|
hostLabel = new QLabel(tr("&Host:"));
|
||||||
hostEdit = new QLineEdit(settings.value("hostname", "cockatrice.woogerworks.com").toString());
|
hostEdit = new QLineEdit(settings.value("hostname", "cockatrice.woogerworks.com").toString());
|
||||||
hostLabel->setBuddy(hostEdit);
|
hostLabel->setBuddy(hostEdit);
|
||||||
|
|
||||||
portLabel = new QLabel(tr("&Port:"));
|
portLabel = new QLabel(tr("&Port:"));
|
||||||
portEdit = new QLineEdit(settings.value("port", "4747").toString());
|
portEdit = new QLineEdit(settings.value("port", "4747").toString());
|
||||||
portLabel->setBuddy(portEdit);
|
portLabel->setBuddy(portEdit);
|
||||||
|
|
||||||
playernameLabel = new QLabel(tr("Player &name:"));
|
playernameLabel = new QLabel(tr("Player &name:"));
|
||||||
playernameEdit = new QLineEdit(settings.value("playername", "Player").toString());
|
playernameEdit = new QLineEdit(settings.value("playername", "Player").toString());
|
||||||
playernameLabel->setBuddy(playernameEdit);
|
playernameLabel->setBuddy(playernameEdit);
|
||||||
|
|
||||||
passwordLabel = new QLabel(tr("P&assword:"));
|
passwordLabel = new QLabel(tr("P&assword:"));
|
||||||
passwordEdit = new QLineEdit(settings.value("password").toString());
|
passwordEdit = new QLineEdit(settings.value("password").toString());
|
||||||
passwordLabel->setBuddy(passwordEdit);
|
passwordLabel->setBuddy(passwordEdit);
|
||||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||||
|
|
||||||
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
||||||
savePasswordCheckBox->setChecked(settings.value("save_password", 1).toInt());
|
savePasswordCheckBox->setChecked(settings.value("save_password", 1).toInt());
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(hostLabel, 0, 0);
|
grid->addWidget(hostLabel, 0, 0);
|
||||||
grid->addWidget(hostEdit, 0, 1);
|
grid->addWidget(hostEdit, 0, 1);
|
||||||
grid->addWidget(portLabel, 1, 0);
|
grid->addWidget(portLabel, 1, 0);
|
||||||
grid->addWidget(portEdit, 1, 1);
|
grid->addWidget(portEdit, 1, 1);
|
||||||
grid->addWidget(playernameLabel, 2, 0);
|
grid->addWidget(playernameLabel, 2, 0);
|
||||||
grid->addWidget(playernameEdit, 2, 1);
|
grid->addWidget(playernameEdit, 2, 1);
|
||||||
grid->addWidget(passwordLabel, 3, 0);
|
grid->addWidget(passwordLabel, 3, 0);
|
||||||
grid->addWidget(passwordEdit, 3, 1);
|
grid->addWidget(passwordEdit, 3, 1);
|
||||||
grid->addWidget(savePasswordCheckBox, 4, 0, 1, 2);
|
grid->addWidget(savePasswordCheckBox, 4, 0, 1, 2);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(grid);
|
mainLayout->addLayout(grid);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Connect to server"));
|
setWindowTitle(tr("Connect to server"));
|
||||||
setFixedHeight(sizeHint().height());
|
setFixedHeight(sizeHint().height());
|
||||||
setMinimumWidth(300);
|
setMinimumWidth(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgConnect::actOk()
|
void DlgConnect::actOk()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup("server");
|
settings.beginGroup("server");
|
||||||
settings.setValue("hostname", hostEdit->text());
|
settings.setValue("hostname", hostEdit->text());
|
||||||
settings.setValue("port", portEdit->text());
|
settings.setValue("port", portEdit->text());
|
||||||
settings.setValue("playername", playernameEdit->text());
|
settings.setValue("playername", playernameEdit->text());
|
||||||
settings.setValue("password", savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
settings.setValue("password", savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
||||||
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,19 @@ class QPushButton;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
|
|
||||||
class DlgConnect : public QDialog {
|
class DlgConnect : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgConnect(QWidget *parent = 0);
|
DlgConnect(QWidget *parent = 0);
|
||||||
QString getHost() const { return hostEdit->text(); }
|
QString getHost() const { return hostEdit->text(); }
|
||||||
int getPort() const { return portEdit->text().toInt(); }
|
int getPort() const { return portEdit->text().toInt(); }
|
||||||
QString getPlayerName() const { return playernameEdit->text(); }
|
QString getPlayerName() const { return playernameEdit->text(); }
|
||||||
QString getPassword() const { return passwordEdit->text(); }
|
QString getPassword() const { return passwordEdit->text(); }
|
||||||
private slots:
|
private slots:
|
||||||
void actOk();
|
void actOk();
|
||||||
private:
|
private:
|
||||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
||||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
||||||
QCheckBox *savePasswordCheckBox;
|
QCheckBox *savePasswordCheckBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,160 +16,160 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
|
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
|
||||||
: QDialog(parent), predefinedTokens(_predefinedTokens)
|
: QDialog(parent), predefinedTokens(_predefinedTokens)
|
||||||
{
|
{
|
||||||
nameLabel = new QLabel(tr("&Name:"));
|
nameLabel = new QLabel(tr("&Name:"));
|
||||||
nameEdit = new QLineEdit(tr("Token"));
|
nameEdit = new QLineEdit(tr("Token"));
|
||||||
nameEdit->selectAll();
|
nameEdit->selectAll();
|
||||||
nameLabel->setBuddy(nameEdit);
|
nameLabel->setBuddy(nameEdit);
|
||||||
|
|
||||||
colorLabel = new QLabel(tr("C&olor:"));
|
colorLabel = new QLabel(tr("C&olor:"));
|
||||||
colorEdit = new QComboBox;
|
colorEdit = new QComboBox;
|
||||||
colorEdit->addItem(tr("white"), "w");
|
colorEdit->addItem(tr("white"), "w");
|
||||||
colorEdit->addItem(tr("blue"), "u");
|
colorEdit->addItem(tr("blue"), "u");
|
||||||
colorEdit->addItem(tr("black"), "b");
|
colorEdit->addItem(tr("black"), "b");
|
||||||
colorEdit->addItem(tr("red"), "r");
|
colorEdit->addItem(tr("red"), "r");
|
||||||
colorEdit->addItem(tr("green"), "g");
|
colorEdit->addItem(tr("green"), "g");
|
||||||
colorEdit->addItem(tr("multicolor"), "m");
|
colorEdit->addItem(tr("multicolor"), "m");
|
||||||
colorEdit->addItem(tr("colorless"), QString());
|
colorEdit->addItem(tr("colorless"), QString());
|
||||||
colorLabel->setBuddy(colorEdit);
|
colorLabel->setBuddy(colorEdit);
|
||||||
|
|
||||||
ptLabel = new QLabel(tr("&P/T:"));
|
ptLabel = new QLabel(tr("&P/T:"));
|
||||||
ptEdit = new QLineEdit;
|
ptEdit = new QLineEdit;
|
||||||
ptLabel->setBuddy(ptEdit);
|
ptLabel->setBuddy(ptEdit);
|
||||||
|
|
||||||
annotationLabel = new QLabel(tr("&Annotation:"));
|
annotationLabel = new QLabel(tr("&Annotation:"));
|
||||||
annotationEdit = new QLineEdit;
|
annotationEdit = new QLineEdit;
|
||||||
annotationLabel->setBuddy(annotationEdit);
|
annotationLabel->setBuddy(annotationEdit);
|
||||||
|
|
||||||
destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
|
destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
|
||||||
destroyCheckBox->setChecked(true);
|
destroyCheckBox->setChecked(true);
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(nameLabel, 0, 0);
|
grid->addWidget(nameLabel, 0, 0);
|
||||||
grid->addWidget(nameEdit, 0, 1);
|
grid->addWidget(nameEdit, 0, 1);
|
||||||
grid->addWidget(colorLabel, 1, 0);
|
grid->addWidget(colorLabel, 1, 0);
|
||||||
grid->addWidget(colorEdit, 1, 1);
|
grid->addWidget(colorEdit, 1, 1);
|
||||||
grid->addWidget(ptLabel, 2, 0);
|
grid->addWidget(ptLabel, 2, 0);
|
||||||
grid->addWidget(ptEdit, 2, 1);
|
grid->addWidget(ptEdit, 2, 1);
|
||||||
grid->addWidget(annotationLabel, 3, 0);
|
grid->addWidget(annotationLabel, 3, 0);
|
||||||
grid->addWidget(annotationEdit, 3, 1);
|
grid->addWidget(annotationEdit, 3, 1);
|
||||||
grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
|
grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
|
||||||
|
|
||||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||||
tokenDataGroupBox->setLayout(grid);
|
tokenDataGroupBox->setLayout(grid);
|
||||||
|
|
||||||
cardDatabaseModel = new CardDatabaseModel(db, this);
|
cardDatabaseModel = new CardDatabaseModel(db, this);
|
||||||
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
|
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
|
||||||
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
||||||
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
||||||
|
|
||||||
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
|
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
|
||||||
connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
|
connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
|
||||||
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
|
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
|
||||||
connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
|
connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
|
||||||
QTreeView *chooseTokenView = new QTreeView;
|
QTreeView *chooseTokenView = new QTreeView;
|
||||||
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
||||||
chooseTokenView->setUniformRowHeights(true);
|
chooseTokenView->setUniformRowHeights(true);
|
||||||
chooseTokenView->setRootIsDecorated(false);
|
chooseTokenView->setRootIsDecorated(false);
|
||||||
chooseTokenView->setAlternatingRowColors(true);
|
chooseTokenView->setAlternatingRowColors(true);
|
||||||
chooseTokenView->setSortingEnabled(true);
|
chooseTokenView->setSortingEnabled(true);
|
||||||
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
||||||
chooseTokenView->resizeColumnToContents(0);
|
chooseTokenView->resizeColumnToContents(0);
|
||||||
chooseTokenView->header()->setStretchLastSection(false);
|
chooseTokenView->header()->setStretchLastSection(false);
|
||||||
chooseTokenView->header()->hideSection(1);
|
chooseTokenView->header()->hideSection(1);
|
||||||
chooseTokenView->header()->hideSection(2);
|
chooseTokenView->header()->hideSection(2);
|
||||||
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||||
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
||||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||||
|
|
||||||
if (predefinedTokens.isEmpty())
|
if (predefinedTokens.isEmpty())
|
||||||
chooseTokenFromAllRadioButton->setChecked(true);
|
chooseTokenFromAllRadioButton->setChecked(true);
|
||||||
else {
|
else {
|
||||||
chooseTokenFromDeckRadioButton->setChecked(true);
|
chooseTokenFromDeckRadioButton->setChecked(true);
|
||||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
|
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
|
||||||
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
|
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
|
||||||
tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
|
tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
|
||||||
tokenChooseLayout->addWidget(chooseTokenView);
|
tokenChooseLayout->addWidget(chooseTokenView);
|
||||||
|
|
||||||
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
|
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
|
||||||
tokenChooseGroupBox->setLayout(tokenChooseLayout);
|
tokenChooseGroupBox->setLayout(tokenChooseLayout);
|
||||||
|
|
||||||
QVBoxLayout *leftVBox = new QVBoxLayout;
|
QVBoxLayout *leftVBox = new QVBoxLayout;
|
||||||
leftVBox->addWidget(tokenDataGroupBox);
|
leftVBox->addWidget(tokenDataGroupBox);
|
||||||
leftVBox->addStretch();
|
leftVBox->addStretch();
|
||||||
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
hbox->addLayout(leftVBox);
|
hbox->addLayout(leftVBox);
|
||||||
hbox->addWidget(tokenChooseGroupBox);
|
hbox->addWidget(tokenChooseGroupBox);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(hbox);
|
mainLayout->addLayout(hbox);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Create token"));
|
setWindowTitle(tr("Create token"));
|
||||||
setFixedHeight(sizeHint().height());
|
setFixedHeight(sizeHint().height());
|
||||||
setMinimumWidth(300);
|
setMinimumWidth(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||||
{
|
{
|
||||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||||
const CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : db->getCard();
|
const CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : db->getCard();
|
||||||
|
|
||||||
nameEdit->setText(cardInfo->getName());
|
nameEdit->setText(cardInfo->getName());
|
||||||
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
||||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||||
ptEdit->setText(cardInfo->getPowTough());
|
ptEdit->setText(cardInfo->getPowTough());
|
||||||
annotationEdit->setText(cardInfo->getText());
|
annotationEdit->setText(cardInfo->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateToken::actChooseTokenFromAll(bool checked)
|
void DlgCreateToken::actChooseTokenFromAll(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
if (checked)
|
||||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>());
|
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateToken::actChooseTokenFromDeck(bool checked)
|
void DlgCreateToken::actChooseTokenFromDeck(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
if (checked)
|
||||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateToken::actOk()
|
void DlgCreateToken::actOk()
|
||||||
{
|
{
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getName() const
|
QString DlgCreateToken::getName() const
|
||||||
{
|
{
|
||||||
return nameEdit->text();
|
return nameEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getColor() const
|
QString DlgCreateToken::getColor() const
|
||||||
{
|
{
|
||||||
return colorEdit->itemData(colorEdit->currentIndex()).toString();
|
return colorEdit->itemData(colorEdit->currentIndex()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getPT() const
|
QString DlgCreateToken::getPT() const
|
||||||
{
|
{
|
||||||
return ptEdit->text();
|
return ptEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getAnnotation() const
|
QString DlgCreateToken::getAnnotation() const
|
||||||
{
|
{
|
||||||
return annotationEdit->text();
|
return annotationEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DlgCreateToken::getDestroy() const
|
bool DlgCreateToken::getDestroy() const
|
||||||
{
|
{
|
||||||
return destroyCheckBox->isChecked();
|
return destroyCheckBox->isChecked();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,28 +15,28 @@ class CardDatabaseModel;
|
||||||
class CardDatabaseDisplayModel;
|
class CardDatabaseDisplayModel;
|
||||||
|
|
||||||
class DlgCreateToken : public QDialog {
|
class DlgCreateToken : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = 0);
|
DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = 0);
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
QString getColor() const;
|
QString getColor() const;
|
||||||
QString getPT() const;
|
QString getPT() const;
|
||||||
QString getAnnotation() const;
|
QString getAnnotation() const;
|
||||||
bool getDestroy() const;
|
bool getDestroy() const;
|
||||||
private slots:
|
private slots:
|
||||||
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void actChooseTokenFromAll(bool checked);
|
void actChooseTokenFromAll(bool checked);
|
||||||
void actChooseTokenFromDeck(bool checked);
|
void actChooseTokenFromDeck(bool checked);
|
||||||
void actOk();
|
void actOk();
|
||||||
private:
|
private:
|
||||||
CardDatabaseModel *cardDatabaseModel;
|
CardDatabaseModel *cardDatabaseModel;
|
||||||
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
|
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
|
||||||
QStringList predefinedTokens;
|
QStringList predefinedTokens;
|
||||||
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
||||||
QComboBox *colorEdit;
|
QComboBox *colorEdit;
|
||||||
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
||||||
QCheckBox *destroyCheckBox;
|
QCheckBox *destroyCheckBox;
|
||||||
QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton;
|
QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,180 +20,180 @@
|
||||||
|
|
||||||
void DlgCreateGame::sharedCtor()
|
void DlgCreateGame::sharedCtor()
|
||||||
{
|
{
|
||||||
descriptionLabel = new QLabel(tr("&Description:"));
|
descriptionLabel = new QLabel(tr("&Description:"));
|
||||||
descriptionEdit = new QLineEdit;
|
descriptionEdit = new QLineEdit;
|
||||||
descriptionLabel->setBuddy(descriptionEdit);
|
descriptionLabel->setBuddy(descriptionEdit);
|
||||||
descriptionEdit->setMaxLength(60);
|
descriptionEdit->setMaxLength(60);
|
||||||
|
|
||||||
maxPlayersLabel = new QLabel(tr("P&layers:"));
|
maxPlayersLabel = new QLabel(tr("P&layers:"));
|
||||||
maxPlayersEdit = new QSpinBox();
|
maxPlayersEdit = new QSpinBox();
|
||||||
maxPlayersEdit->setMinimum(1);
|
maxPlayersEdit->setMinimum(1);
|
||||||
maxPlayersEdit->setMaximum(100);
|
maxPlayersEdit->setMaximum(100);
|
||||||
maxPlayersEdit->setValue(2);
|
maxPlayersEdit->setValue(2);
|
||||||
maxPlayersLabel->setBuddy(maxPlayersEdit);
|
maxPlayersLabel->setBuddy(maxPlayersEdit);
|
||||||
|
|
||||||
QGridLayout *generalGrid = new QGridLayout;
|
QGridLayout *generalGrid = new QGridLayout;
|
||||||
generalGrid->addWidget(descriptionLabel, 0, 0);
|
generalGrid->addWidget(descriptionLabel, 0, 0);
|
||||||
generalGrid->addWidget(descriptionEdit, 0, 1);
|
generalGrid->addWidget(descriptionEdit, 0, 1);
|
||||||
generalGrid->addWidget(maxPlayersLabel, 1, 0);
|
generalGrid->addWidget(maxPlayersLabel, 1, 0);
|
||||||
generalGrid->addWidget(maxPlayersEdit, 1, 1);
|
generalGrid->addWidget(maxPlayersEdit, 1, 1);
|
||||||
|
|
||||||
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
|
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
|
||||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||||
while (gameTypeIterator.hasNext()) {
|
while (gameTypeIterator.hasNext()) {
|
||||||
gameTypeIterator.next();
|
gameTypeIterator.next();
|
||||||
QCheckBox *gameTypeCheckBox = new QCheckBox(gameTypeIterator.value());
|
QCheckBox *gameTypeCheckBox = new QCheckBox(gameTypeIterator.value());
|
||||||
gameTypeLayout->addWidget(gameTypeCheckBox);
|
gameTypeLayout->addWidget(gameTypeCheckBox);
|
||||||
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeCheckBox);
|
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeCheckBox);
|
||||||
}
|
}
|
||||||
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
|
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
|
||||||
gameTypeGroupBox->setLayout(gameTypeLayout);
|
gameTypeGroupBox->setLayout(gameTypeLayout);
|
||||||
|
|
||||||
passwordLabel = new QLabel(tr("&Password:"));
|
passwordLabel = new QLabel(tr("&Password:"));
|
||||||
passwordEdit = new QLineEdit;
|
passwordEdit = new QLineEdit;
|
||||||
passwordLabel->setBuddy(passwordEdit);
|
passwordLabel->setBuddy(passwordEdit);
|
||||||
|
|
||||||
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
||||||
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
||||||
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)
|
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)
|
||||||
onlyRegisteredCheckBox->setChecked(true);
|
onlyRegisteredCheckBox->setChecked(true);
|
||||||
|
|
||||||
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
||||||
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
||||||
joinRestrictionsLayout->addWidget(passwordEdit, 0, 1);
|
joinRestrictionsLayout->addWidget(passwordEdit, 0, 1);
|
||||||
joinRestrictionsLayout->addWidget(onlyBuddiesCheckBox, 1, 0, 1, 2);
|
joinRestrictionsLayout->addWidget(onlyBuddiesCheckBox, 1, 0, 1, 2);
|
||||||
joinRestrictionsLayout->addWidget(onlyRegisteredCheckBox, 2, 0, 1, 2);
|
joinRestrictionsLayout->addWidget(onlyRegisteredCheckBox, 2, 0, 1, 2);
|
||||||
|
|
||||||
QGroupBox *joinRestrictionsGroupBox = new QGroupBox(tr("Joining restrictions"));
|
QGroupBox *joinRestrictionsGroupBox = new QGroupBox(tr("Joining restrictions"));
|
||||||
joinRestrictionsGroupBox->setLayout(joinRestrictionsLayout);
|
joinRestrictionsGroupBox->setLayout(joinRestrictionsLayout);
|
||||||
|
|
||||||
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
|
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
|
||||||
spectatorsAllowedCheckBox->setChecked(true);
|
spectatorsAllowedCheckBox->setChecked(true);
|
||||||
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
|
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
|
||||||
spectatorsNeedPasswordCheckBox = new QCheckBox(tr("Spectators &need a password to join"));
|
spectatorsNeedPasswordCheckBox = new QCheckBox(tr("Spectators &need a password to join"));
|
||||||
spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &chat"));
|
spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &chat"));
|
||||||
spectatorsSeeEverythingCheckBox = new QCheckBox(tr("Spectators see &everything"));
|
spectatorsSeeEverythingCheckBox = new QCheckBox(tr("Spectators see &everything"));
|
||||||
QVBoxLayout *spectatorsLayout = new QVBoxLayout;
|
QVBoxLayout *spectatorsLayout = new QVBoxLayout;
|
||||||
spectatorsLayout->addWidget(spectatorsAllowedCheckBox);
|
spectatorsLayout->addWidget(spectatorsAllowedCheckBox);
|
||||||
spectatorsLayout->addWidget(spectatorsNeedPasswordCheckBox);
|
spectatorsLayout->addWidget(spectatorsNeedPasswordCheckBox);
|
||||||
spectatorsLayout->addWidget(spectatorsCanTalkCheckBox);
|
spectatorsLayout->addWidget(spectatorsCanTalkCheckBox);
|
||||||
spectatorsLayout->addWidget(spectatorsSeeEverythingCheckBox);
|
spectatorsLayout->addWidget(spectatorsSeeEverythingCheckBox);
|
||||||
spectatorsGroupBox = new QGroupBox(tr("Spectators"));
|
spectatorsGroupBox = new QGroupBox(tr("Spectators"));
|
||||||
spectatorsGroupBox->setLayout(spectatorsLayout);
|
spectatorsGroupBox->setLayout(spectatorsLayout);
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addLayout(generalGrid, 0, 0);
|
grid->addLayout(generalGrid, 0, 0);
|
||||||
grid->addWidget(spectatorsGroupBox, 1, 0);
|
grid->addWidget(spectatorsGroupBox, 1, 0);
|
||||||
grid->addWidget(joinRestrictionsGroupBox, 0, 1);
|
grid->addWidget(joinRestrictionsGroupBox, 0, 1);
|
||||||
grid->addWidget(gameTypeGroupBox, 1, 1);
|
grid->addWidget(gameTypeGroupBox, 1, 1);
|
||||||
|
|
||||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(grid);
|
mainLayout->addLayout(grid);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setFixedHeight(sizeHint().height());
|
setFixedHeight(sizeHint().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
||||||
: QDialog(parent), room(_room), gameTypes(_gameTypes)
|
: QDialog(parent), room(_room), gameTypes(_gameTypes)
|
||||||
{
|
{
|
||||||
sharedCtor();
|
sharedCtor();
|
||||||
|
|
||||||
buttonBox->addButton(QDialogButtonBox::Cancel);
|
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
||||||
|
|
||||||
setWindowTitle(tr("Create game"));
|
setWindowTitle(tr("Create game"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
||||||
: QDialog(parent), room(0), gameTypes(_gameTypes)
|
: QDialog(parent), room(0), gameTypes(_gameTypes)
|
||||||
{
|
{
|
||||||
sharedCtor();
|
sharedCtor();
|
||||||
|
|
||||||
descriptionEdit->setEnabled(false);
|
descriptionEdit->setEnabled(false);
|
||||||
maxPlayersEdit->setEnabled(false);
|
maxPlayersEdit->setEnabled(false);
|
||||||
passwordEdit->setEnabled(false);
|
passwordEdit->setEnabled(false);
|
||||||
onlyBuddiesCheckBox->setEnabled(false);
|
onlyBuddiesCheckBox->setEnabled(false);
|
||||||
onlyRegisteredCheckBox->setEnabled(false);
|
onlyRegisteredCheckBox->setEnabled(false);
|
||||||
spectatorsAllowedCheckBox->setEnabled(false);
|
spectatorsAllowedCheckBox->setEnabled(false);
|
||||||
spectatorsNeedPasswordCheckBox->setEnabled(false);
|
spectatorsNeedPasswordCheckBox->setEnabled(false);
|
||||||
spectatorsCanTalkCheckBox->setEnabled(false);
|
spectatorsCanTalkCheckBox->setEnabled(false);
|
||||||
spectatorsSeeEverythingCheckBox->setEnabled(false);
|
spectatorsSeeEverythingCheckBox->setEnabled(false);
|
||||||
|
|
||||||
descriptionEdit->setText(QString::fromStdString(gameInfo.description()));
|
descriptionEdit->setText(QString::fromStdString(gameInfo.description()));
|
||||||
maxPlayersEdit->setValue(gameInfo.max_players());
|
maxPlayersEdit->setValue(gameInfo.max_players());
|
||||||
onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies());
|
onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies());
|
||||||
onlyRegisteredCheckBox->setChecked(gameInfo.only_registered());
|
onlyRegisteredCheckBox->setChecked(gameInfo.only_registered());
|
||||||
spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed());
|
spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed());
|
||||||
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
|
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
|
||||||
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
|
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
|
||||||
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
|
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
|
||||||
|
|
||||||
QSet<int> types;
|
QSet<int> types;
|
||||||
for (int i = 0; i < gameInfo.game_types_size(); ++i)
|
for (int i = 0; i < gameInfo.game_types_size(); ++i)
|
||||||
types.insert(gameInfo.game_types(i));
|
types.insert(gameInfo.game_types(i));
|
||||||
|
|
||||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||||
while (gameTypeIterator.hasNext()) {
|
while (gameTypeIterator.hasNext()) {
|
||||||
gameTypeIterator.next();
|
gameTypeIterator.next();
|
||||||
|
|
||||||
QCheckBox *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key());
|
QCheckBox *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key());
|
||||||
gameTypeCheckBox->setEnabled(false);
|
gameTypeCheckBox->setEnabled(false);
|
||||||
gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key()));
|
gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
|
||||||
setWindowTitle(tr("Game information"));
|
setWindowTitle(tr("Game information"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateGame::actOK()
|
void DlgCreateGame::actOK()
|
||||||
{
|
{
|
||||||
Command_CreateGame cmd;
|
Command_CreateGame cmd;
|
||||||
cmd.set_description(descriptionEdit->text().toStdString());
|
cmd.set_description(descriptionEdit->text().toStdString());
|
||||||
cmd.set_password(passwordEdit->text().toStdString());
|
cmd.set_password(passwordEdit->text().toStdString());
|
||||||
cmd.set_max_players(maxPlayersEdit->value());
|
cmd.set_max_players(maxPlayersEdit->value());
|
||||||
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
|
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
|
||||||
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
|
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
|
||||||
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
|
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
|
||||||
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
|
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
|
||||||
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
|
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
|
||||||
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
|
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
|
||||||
|
|
||||||
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||||
gameTypeCheckBoxIterator.next();
|
gameTypeCheckBoxIterator.next();
|
||||||
if (gameTypeCheckBoxIterator.value()->isChecked())
|
if (gameTypeCheckBoxIterator.value()->isChecked())
|
||||||
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
|
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *pend = room->prepareRoomCommand(cmd);
|
PendingCommand *pend = room->prepareRoomCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
|
||||||
room->sendRoomCommand(pend);
|
room->sendRoomCommand(pend);
|
||||||
|
|
||||||
buttonBox->setEnabled(false);
|
buttonBox->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateGame::checkResponse(const Response &response)
|
void DlgCreateGame::checkResponse(const Response &response)
|
||||||
{
|
{
|
||||||
buttonBox->setEnabled(true);
|
buttonBox->setEnabled(true);
|
||||||
|
|
||||||
if (response.response_code() == Response::RespOk)
|
if (response.response_code() == Response::RespOk)
|
||||||
accept();
|
accept();
|
||||||
else {
|
else {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Server error."));
|
QMessageBox::critical(this, tr("Error"), tr("Server error."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateGame::spectatorsAllowedChanged(int state)
|
void DlgCreateGame::spectatorsAllowedChanged(int state)
|
||||||
{
|
{
|
||||||
spectatorsNeedPasswordCheckBox->setEnabled(state);
|
spectatorsNeedPasswordCheckBox->setEnabled(state);
|
||||||
spectatorsCanTalkCheckBox->setEnabled(state);
|
spectatorsCanTalkCheckBox->setEnabled(state);
|
||||||
spectatorsSeeEverythingCheckBox->setEnabled(state);
|
spectatorsSeeEverythingCheckBox->setEnabled(state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,28 @@ class Response;
|
||||||
class ServerInfo_Game;
|
class ServerInfo_Game;
|
||||||
|
|
||||||
class DlgCreateGame : public QDialog {
|
class DlgCreateGame : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
|
DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
|
||||||
DlgCreateGame(const ServerInfo_Game &game, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
|
DlgCreateGame(const ServerInfo_Game &game, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
|
||||||
private slots:
|
private slots:
|
||||||
void actOK();
|
void actOK();
|
||||||
void checkResponse(const Response &response);
|
void checkResponse(const Response &response);
|
||||||
void spectatorsAllowedChanged(int state);
|
void spectatorsAllowedChanged(int state);
|
||||||
private:
|
private:
|
||||||
TabRoom *room;
|
TabRoom *room;
|
||||||
QMap<int, QString> gameTypes;
|
QMap<int, QString> gameTypes;
|
||||||
QMap<int, QCheckBox *> gameTypeCheckBoxes;
|
QMap<int, QCheckBox *> gameTypeCheckBoxes;
|
||||||
|
|
||||||
QGroupBox *spectatorsGroupBox;
|
QGroupBox *spectatorsGroupBox;
|
||||||
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
||||||
QLineEdit *descriptionEdit, *passwordEdit;
|
QLineEdit *descriptionEdit, *passwordEdit;
|
||||||
QSpinBox *maxPlayersEdit;
|
QSpinBox *maxPlayersEdit;
|
||||||
QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox;
|
QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox;
|
||||||
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox;
|
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox;
|
||||||
QDialogButtonBox *buttonBox;
|
QDialogButtonBox *buttonBox;
|
||||||
|
|
||||||
void sharedCtor();
|
void sharedCtor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,160 +16,160 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent)
|
DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent)
|
||||||
: QDialog(parent), currentCard(0), cardDatabaseModel(_cardDatabaseModel)
|
: QDialog(parent), currentCard(0), cardDatabaseModel(_cardDatabaseModel)
|
||||||
{
|
{
|
||||||
nameLabel = new QLabel(tr("&Name:"));
|
nameLabel = new QLabel(tr("&Name:"));
|
||||||
nameEdit = new QLineEdit;
|
nameEdit = new QLineEdit;
|
||||||
nameEdit->setEnabled(false);
|
nameEdit->setEnabled(false);
|
||||||
nameLabel->setBuddy(nameEdit);
|
nameLabel->setBuddy(nameEdit);
|
||||||
|
|
||||||
colorLabel = new QLabel(tr("C&olor:"));
|
colorLabel = new QLabel(tr("C&olor:"));
|
||||||
colorEdit = new QComboBox;
|
colorEdit = new QComboBox;
|
||||||
colorEdit->addItem(tr("white"), "w");
|
colorEdit->addItem(tr("white"), "w");
|
||||||
colorEdit->addItem(tr("blue"), "u");
|
colorEdit->addItem(tr("blue"), "u");
|
||||||
colorEdit->addItem(tr("black"), "b");
|
colorEdit->addItem(tr("black"), "b");
|
||||||
colorEdit->addItem(tr("red"), "r");
|
colorEdit->addItem(tr("red"), "r");
|
||||||
colorEdit->addItem(tr("green"), "g");
|
colorEdit->addItem(tr("green"), "g");
|
||||||
colorEdit->addItem(tr("multicolor"), "m");
|
colorEdit->addItem(tr("multicolor"), "m");
|
||||||
colorEdit->addItem(tr("colorless"), QString());
|
colorEdit->addItem(tr("colorless"), QString());
|
||||||
colorLabel->setBuddy(colorEdit);
|
colorLabel->setBuddy(colorEdit);
|
||||||
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
||||||
|
|
||||||
ptLabel = new QLabel(tr("&P/T:"));
|
ptLabel = new QLabel(tr("&P/T:"));
|
||||||
ptEdit = new QLineEdit;
|
ptEdit = new QLineEdit;
|
||||||
ptLabel->setBuddy(ptEdit);
|
ptLabel->setBuddy(ptEdit);
|
||||||
connect(ptEdit, SIGNAL(textChanged(QString)), this, SLOT(ptChanged(QString)));
|
connect(ptEdit, SIGNAL(textChanged(QString)), this, SLOT(ptChanged(QString)));
|
||||||
|
|
||||||
annotationLabel = new QLabel(tr("&Annotation:"));
|
annotationLabel = new QLabel(tr("&Annotation:"));
|
||||||
annotationEdit = new QLineEdit;
|
annotationEdit = new QLineEdit;
|
||||||
annotationLabel->setBuddy(annotationEdit);
|
annotationLabel->setBuddy(annotationEdit);
|
||||||
connect(annotationEdit, SIGNAL(textChanged(QString)), this, SLOT(annotationChanged(QString)));
|
connect(annotationEdit, SIGNAL(textChanged(QString)), this, SLOT(annotationChanged(QString)));
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(nameLabel, 0, 0);
|
grid->addWidget(nameLabel, 0, 0);
|
||||||
grid->addWidget(nameEdit, 0, 1);
|
grid->addWidget(nameEdit, 0, 1);
|
||||||
grid->addWidget(colorLabel, 1, 0);
|
grid->addWidget(colorLabel, 1, 0);
|
||||||
grid->addWidget(colorEdit, 1, 1);
|
grid->addWidget(colorEdit, 1, 1);
|
||||||
grid->addWidget(ptLabel, 2, 0);
|
grid->addWidget(ptLabel, 2, 0);
|
||||||
grid->addWidget(ptEdit, 2, 1);
|
grid->addWidget(ptEdit, 2, 1);
|
||||||
grid->addWidget(annotationLabel, 3, 0);
|
grid->addWidget(annotationLabel, 3, 0);
|
||||||
grid->addWidget(annotationEdit, 3, 1);
|
grid->addWidget(annotationEdit, 3, 1);
|
||||||
|
|
||||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||||
tokenDataGroupBox->setLayout(grid);
|
tokenDataGroupBox->setLayout(grid);
|
||||||
|
|
||||||
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
|
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
|
||||||
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
||||||
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
||||||
|
|
||||||
chooseTokenView = new QTreeView;
|
chooseTokenView = new QTreeView;
|
||||||
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
||||||
chooseTokenView->setUniformRowHeights(true);
|
chooseTokenView->setUniformRowHeights(true);
|
||||||
chooseTokenView->setRootIsDecorated(false);
|
chooseTokenView->setRootIsDecorated(false);
|
||||||
chooseTokenView->setAlternatingRowColors(true);
|
chooseTokenView->setAlternatingRowColors(true);
|
||||||
chooseTokenView->setSortingEnabled(true);
|
chooseTokenView->setSortingEnabled(true);
|
||||||
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
||||||
chooseTokenView->resizeColumnToContents(0);
|
chooseTokenView->resizeColumnToContents(0);
|
||||||
chooseTokenView->header()->setStretchLastSection(false);
|
chooseTokenView->header()->setStretchLastSection(false);
|
||||||
chooseTokenView->header()->hideSection(1);
|
chooseTokenView->header()->hideSection(1);
|
||||||
chooseTokenView->header()->hideSection(2);
|
chooseTokenView->header()->hideSection(2);
|
||||||
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||||
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
||||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||||
|
|
||||||
QAction *aAddToken = new QAction(tr("Add token"), this);
|
QAction *aAddToken = new QAction(tr("Add token"), this);
|
||||||
aAddToken->setIcon(QIcon(":/resources/increment.svg"));
|
aAddToken->setIcon(QIcon(":/resources/increment.svg"));
|
||||||
connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken()));
|
connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken()));
|
||||||
QAction *aRemoveToken = new QAction(tr("Remove token"), this);
|
QAction *aRemoveToken = new QAction(tr("Remove token"), this);
|
||||||
aRemoveToken->setIcon(QIcon(":/resources/decrement.svg"));
|
aRemoveToken->setIcon(QIcon(":/resources/decrement.svg"));
|
||||||
connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken()));
|
connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken()));
|
||||||
|
|
||||||
QToolBar *databaseToolBar = new QToolBar;
|
QToolBar *databaseToolBar = new QToolBar;
|
||||||
databaseToolBar->addAction(aAddToken);
|
databaseToolBar->addAction(aAddToken);
|
||||||
databaseToolBar->addAction(aRemoveToken);
|
databaseToolBar->addAction(aRemoveToken);
|
||||||
|
|
||||||
QVBoxLayout *leftVBox = new QVBoxLayout;
|
QVBoxLayout *leftVBox = new QVBoxLayout;
|
||||||
leftVBox->addWidget(chooseTokenView);
|
leftVBox->addWidget(chooseTokenView);
|
||||||
leftVBox->addWidget(databaseToolBar);
|
leftVBox->addWidget(databaseToolBar);
|
||||||
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
hbox->addLayout(leftVBox);
|
hbox->addLayout(leftVBox);
|
||||||
hbox->addWidget(tokenDataGroupBox);
|
hbox->addWidget(tokenDataGroupBox);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(hbox);
|
mainLayout->addLayout(hbox);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
setWindowTitle(tr("Edit tokens"));
|
setWindowTitle(tr("Edit tokens"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||||
CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : cardDatabaseModel->getDatabase()->getCard();
|
CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : cardDatabaseModel->getDatabase()->getCard();
|
||||||
if (!cardInfo->getName().isEmpty())
|
if (!cardInfo->getName().isEmpty())
|
||||||
currentCard = cardInfo;
|
currentCard = cardInfo;
|
||||||
else
|
else
|
||||||
currentCard = 0;
|
currentCard = 0;
|
||||||
|
|
||||||
nameEdit->setText(cardInfo->getName());
|
nameEdit->setText(cardInfo->getName());
|
||||||
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
||||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||||
ptEdit->setText(cardInfo->getPowTough());
|
ptEdit->setText(cardInfo->getPowTough());
|
||||||
annotationEdit->setText(cardInfo->getText());
|
annotationEdit->setText(cardInfo->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::actAddToken()
|
void DlgEditTokens::actAddToken()
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
bool askAgain;
|
bool askAgain;
|
||||||
do {
|
do {
|
||||||
name = QInputDialog::getText(this, tr("Add token"), tr("Please enter the name of the token:"));
|
name = QInputDialog::getText(this, tr("Add token"), tr("Please enter the name of the token:"));
|
||||||
if (!name.isEmpty() && cardDatabaseModel->getDatabase()->getCard(name, false)) {
|
if (!name.isEmpty() && cardDatabaseModel->getDatabase()->getCard(name, false)) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The chosen name conflicts with an existing card or token."));
|
QMessageBox::critical(this, tr("Error"), tr("The chosen name conflicts with an existing card or token."));
|
||||||
askAgain = true;
|
askAgain = true;
|
||||||
} else
|
} else
|
||||||
askAgain = false;
|
askAgain = false;
|
||||||
} while (askAgain);
|
} while (askAgain);
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CardInfo *card = new CardInfo(cardDatabaseModel->getDatabase(), name, true);
|
CardInfo *card = new CardInfo(cardDatabaseModel->getDatabase(), name, true);
|
||||||
card->addToSet(cardDatabaseModel->getDatabase()->getSet("TK"));
|
card->addToSet(cardDatabaseModel->getDatabase()->getSet("TK"));
|
||||||
card->setCardType("Token");
|
card->setCardType("Token");
|
||||||
cardDatabaseModel->getDatabase()->addCard(card);
|
cardDatabaseModel->getDatabase()->addCard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::actRemoveToken()
|
void DlgEditTokens::actRemoveToken()
|
||||||
{
|
{
|
||||||
if (currentCard) {
|
if (currentCard) {
|
||||||
CardInfo *cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
CardInfo *cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
||||||
currentCard = 0;
|
currentCard = 0;
|
||||||
cardDatabaseModel->getDatabase()->removeCard(cardToRemove);
|
cardDatabaseModel->getDatabase()->removeCard(cardToRemove);
|
||||||
delete cardToRemove;
|
delete cardToRemove;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::colorChanged(int colorIndex)
|
void DlgEditTokens::colorChanged(int colorIndex)
|
||||||
{
|
{
|
||||||
if (currentCard)
|
if (currentCard)
|
||||||
currentCard->setColors(QStringList() << colorEdit->itemData(colorIndex).toString());
|
currentCard->setColors(QStringList() << colorEdit->itemData(colorIndex).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::ptChanged(const QString &_pt)
|
void DlgEditTokens::ptChanged(const QString &_pt)
|
||||||
{
|
{
|
||||||
if (currentCard)
|
if (currentCard)
|
||||||
currentCard->setPowTough(_pt);
|
currentCard->setPowTough(_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::annotationChanged(const QString &_annotation)
|
void DlgEditTokens::annotationChanged(const QString &_annotation)
|
||||||
{
|
{
|
||||||
if (currentCard)
|
if (currentCard)
|
||||||
currentCard->setText(_annotation);
|
currentCard->setText(_annotation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,26 +13,26 @@ class QTreeView;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
||||||
class DlgEditTokens : public QDialog {
|
class DlgEditTokens : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void colorChanged(int _colorIndex);
|
void colorChanged(int _colorIndex);
|
||||||
void ptChanged(const QString &_pt);
|
void ptChanged(const QString &_pt);
|
||||||
void annotationChanged(const QString &_annotation);
|
void annotationChanged(const QString &_annotation);
|
||||||
|
|
||||||
void actAddToken();
|
void actAddToken();
|
||||||
void actRemoveToken();
|
void actRemoveToken();
|
||||||
private:
|
private:
|
||||||
CardInfo *currentCard;
|
CardInfo *currentCard;
|
||||||
CardDatabaseModel *cardDatabaseModel;
|
CardDatabaseModel *cardDatabaseModel;
|
||||||
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
|
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
|
||||||
QStringList predefinedTokens;
|
QStringList predefinedTokens;
|
||||||
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
||||||
QComboBox *colorEdit;
|
QComboBox *colorEdit;
|
||||||
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
||||||
QTreeView *chooseTokenView;
|
QTreeView *chooseTokenView;
|
||||||
public:
|
public:
|
||||||
DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent = 0);
|
DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,162 +11,162 @@
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent)
|
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
unavailableGamesVisibleCheckBox = new QCheckBox(tr("Show &unavailable games"));
|
unavailableGamesVisibleCheckBox = new QCheckBox(tr("Show &unavailable games"));
|
||||||
passwordProtectedGamesVisibleCheckBox = new QCheckBox(tr("Show &password protected games"));
|
passwordProtectedGamesVisibleCheckBox = new QCheckBox(tr("Show &password protected games"));
|
||||||
|
|
||||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||||
gameNameFilterEdit = new QLineEdit;
|
gameNameFilterEdit = new QLineEdit;
|
||||||
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
||||||
|
|
||||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||||
creatorNameFilterEdit = new QLineEdit;
|
creatorNameFilterEdit = new QLineEdit;
|
||||||
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
||||||
|
|
||||||
QVBoxLayout *gameTypeFilterLayout = new QVBoxLayout;
|
QVBoxLayout *gameTypeFilterLayout = new QVBoxLayout;
|
||||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||||
while (gameTypesIterator.hasNext()) {
|
while (gameTypesIterator.hasNext()) {
|
||||||
gameTypesIterator.next();
|
gameTypesIterator.next();
|
||||||
QCheckBox *temp = new QCheckBox(gameTypesIterator.value());
|
QCheckBox *temp = new QCheckBox(gameTypesIterator.value());
|
||||||
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
||||||
gameTypeFilterLayout->addWidget(temp);
|
gameTypeFilterLayout->addWidget(temp);
|
||||||
}
|
}
|
||||||
QGroupBox *gameTypeFilterGroupBox;
|
QGroupBox *gameTypeFilterGroupBox;
|
||||||
if (!allGameTypes.isEmpty()) {
|
if (!allGameTypes.isEmpty()) {
|
||||||
gameTypeFilterGroupBox = new QGroupBox(tr("&Game types"));
|
gameTypeFilterGroupBox = new QGroupBox(tr("&Game types"));
|
||||||
gameTypeFilterGroupBox->setLayout(gameTypeFilterLayout);
|
gameTypeFilterGroupBox->setLayout(gameTypeFilterLayout);
|
||||||
} else
|
} else
|
||||||
gameTypeFilterGroupBox = 0;
|
gameTypeFilterGroupBox = 0;
|
||||||
|
|
||||||
QLabel *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
QLabel *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
||||||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||||
maxPlayersFilterMinSpinBox->setMinimum(1);
|
maxPlayersFilterMinSpinBox->setMinimum(1);
|
||||||
maxPlayersFilterMinSpinBox->setMaximum(99);
|
maxPlayersFilterMinSpinBox->setMaximum(99);
|
||||||
maxPlayersFilterMinSpinBox->setValue(1);
|
maxPlayersFilterMinSpinBox->setValue(1);
|
||||||
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
||||||
|
|
||||||
QLabel *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
QLabel *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||||
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
||||||
maxPlayersFilterMaxSpinBox->setMinimum(1);
|
maxPlayersFilterMaxSpinBox->setMinimum(1);
|
||||||
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
||||||
maxPlayersFilterMaxSpinBox->setValue(99);
|
maxPlayersFilterMaxSpinBox->setValue(99);
|
||||||
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
||||||
|
|
||||||
QGridLayout *maxPlayersFilterLayout = new QGridLayout;
|
QGridLayout *maxPlayersFilterLayout = new QGridLayout;
|
||||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinLabel, 0, 0);
|
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinLabel, 0, 0);
|
||||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinSpinBox, 0, 1);
|
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinSpinBox, 0, 1);
|
||||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxLabel, 1, 0);
|
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxLabel, 1, 0);
|
||||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxSpinBox, 1, 1);
|
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxSpinBox, 1, 1);
|
||||||
|
|
||||||
QGroupBox *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
QGroupBox *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
||||||
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
||||||
|
|
||||||
QGridLayout *leftGrid = new QGridLayout;
|
QGridLayout *leftGrid = new QGridLayout;
|
||||||
leftGrid->addWidget(gameNameFilterLabel, 0, 0);
|
leftGrid->addWidget(gameNameFilterLabel, 0, 0);
|
||||||
leftGrid->addWidget(gameNameFilterEdit, 0, 1);
|
leftGrid->addWidget(gameNameFilterEdit, 0, 1);
|
||||||
leftGrid->addWidget(creatorNameFilterLabel, 1, 0);
|
leftGrid->addWidget(creatorNameFilterLabel, 1, 0);
|
||||||
leftGrid->addWidget(creatorNameFilterEdit, 1, 1);
|
leftGrid->addWidget(creatorNameFilterEdit, 1, 1);
|
||||||
leftGrid->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
leftGrid->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
||||||
leftGrid->addWidget(unavailableGamesVisibleCheckBox, 3, 0, 1, 2);
|
leftGrid->addWidget(unavailableGamesVisibleCheckBox, 3, 0, 1, 2);
|
||||||
leftGrid->addWidget(passwordProtectedGamesVisibleCheckBox, 4, 0, 1, 2);
|
leftGrid->addWidget(passwordProtectedGamesVisibleCheckBox, 4, 0, 1, 2);
|
||||||
|
|
||||||
QVBoxLayout *leftColumn = new QVBoxLayout;
|
QVBoxLayout *leftColumn = new QVBoxLayout;
|
||||||
leftColumn->addLayout(leftGrid);
|
leftColumn->addLayout(leftGrid);
|
||||||
leftColumn->addStretch();
|
leftColumn->addStretch();
|
||||||
|
|
||||||
QVBoxLayout *rightColumn = new QVBoxLayout;
|
QVBoxLayout *rightColumn = new QVBoxLayout;
|
||||||
rightColumn->addWidget(gameTypeFilterGroupBox);
|
rightColumn->addWidget(gameTypeFilterGroupBox);
|
||||||
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
hbox->addLayout(leftColumn);
|
hbox->addLayout(leftColumn);
|
||||||
hbox->addLayout(rightColumn);
|
hbox->addLayout(rightColumn);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(hbox);
|
mainLayout->addLayout(hbox);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
setWindowTitle(tr("Filter games"));
|
setWindowTitle(tr("Filter games"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DlgFilterGames::getUnavailableGamesVisible() const
|
bool DlgFilterGames::getUnavailableGamesVisible() const
|
||||||
{
|
{
|
||||||
return unavailableGamesVisibleCheckBox->isChecked();
|
return unavailableGamesVisibleCheckBox->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
void DlgFilterGames::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||||
{
|
{
|
||||||
unavailableGamesVisibleCheckBox->setChecked(_unavailableGamesVisible);
|
unavailableGamesVisibleCheckBox->setChecked(_unavailableGamesVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DlgFilterGames::getPasswordProtectedGamesVisible() const
|
bool DlgFilterGames::getPasswordProtectedGamesVisible() const
|
||||||
{
|
{
|
||||||
return passwordProtectedGamesVisibleCheckBox->isChecked();
|
return passwordProtectedGamesVisibleCheckBox->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible)
|
void DlgFilterGames::setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible)
|
||||||
{
|
{
|
||||||
passwordProtectedGamesVisibleCheckBox->setChecked(_passwordProtectedGamesVisible);
|
passwordProtectedGamesVisibleCheckBox->setChecked(_passwordProtectedGamesVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgFilterGames::getGameNameFilter() const
|
QString DlgFilterGames::getGameNameFilter() const
|
||||||
{
|
{
|
||||||
return gameNameFilterEdit->text();
|
return gameNameFilterEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setGameNameFilter(const QString &_gameNameFilter)
|
void DlgFilterGames::setGameNameFilter(const QString &_gameNameFilter)
|
||||||
{
|
{
|
||||||
gameNameFilterEdit->setText(_gameNameFilter);
|
gameNameFilterEdit->setText(_gameNameFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgFilterGames::getCreatorNameFilter() const
|
QString DlgFilterGames::getCreatorNameFilter() const
|
||||||
{
|
{
|
||||||
return creatorNameFilterEdit->text();
|
return creatorNameFilterEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setCreatorNameFilter(const QString &_creatorNameFilter)
|
void DlgFilterGames::setCreatorNameFilter(const QString &_creatorNameFilter)
|
||||||
{
|
{
|
||||||
creatorNameFilterEdit->setText(_creatorNameFilter);
|
creatorNameFilterEdit->setText(_creatorNameFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<int> DlgFilterGames::getGameTypeFilter() const
|
QSet<int> DlgFilterGames::getGameTypeFilter() const
|
||||||
{
|
{
|
||||||
QSet<int> result;
|
QSet<int> result;
|
||||||
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
if (i.value()->isChecked())
|
if (i.value()->isChecked())
|
||||||
result.insert(i.key());
|
result.insert(i.key());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
void DlgFilterGames::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
||||||
{
|
{
|
||||||
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
i.value()->setChecked(_gameTypeFilter.contains(i.key()));
|
i.value()->setChecked(_gameTypeFilter.contains(i.key()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DlgFilterGames::getMaxPlayersFilterMin() const
|
int DlgFilterGames::getMaxPlayersFilterMin() const
|
||||||
{
|
{
|
||||||
return maxPlayersFilterMinSpinBox->value();
|
return maxPlayersFilterMinSpinBox->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DlgFilterGames::getMaxPlayersFilterMax() const
|
int DlgFilterGames::getMaxPlayersFilterMax() const
|
||||||
{
|
{
|
||||||
return maxPlayersFilterMaxSpinBox->value();
|
return maxPlayersFilterMaxSpinBox->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgFilterGames::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
void DlgFilterGames::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
||||||
{
|
{
|
||||||
maxPlayersFilterMinSpinBox->setValue(_maxPlayersFilterMin);
|
maxPlayersFilterMinSpinBox->setValue(_maxPlayersFilterMin);
|
||||||
maxPlayersFilterMaxSpinBox->setValue(_maxPlayersFilterMax == -1 ? maxPlayersFilterMaxSpinBox->maximum() : _maxPlayersFilterMax);
|
maxPlayersFilterMaxSpinBox->setValue(_maxPlayersFilterMax == -1 ? maxPlayersFilterMaxSpinBox->maximum() : _maxPlayersFilterMax);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,31 +10,31 @@ class QLineEdit;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
|
|
||||||
class DlgFilterGames : public QDialog {
|
class DlgFilterGames : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QCheckBox *unavailableGamesVisibleCheckBox;
|
QCheckBox *unavailableGamesVisibleCheckBox;
|
||||||
QCheckBox *passwordProtectedGamesVisibleCheckBox;
|
QCheckBox *passwordProtectedGamesVisibleCheckBox;
|
||||||
QLineEdit *gameNameFilterEdit;
|
QLineEdit *gameNameFilterEdit;
|
||||||
QLineEdit *creatorNameFilterEdit;
|
QLineEdit *creatorNameFilterEdit;
|
||||||
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
||||||
QSpinBox *maxPlayersFilterMinSpinBox;
|
QSpinBox *maxPlayersFilterMinSpinBox;
|
||||||
QSpinBox *maxPlayersFilterMaxSpinBox;
|
QSpinBox *maxPlayersFilterMaxSpinBox;
|
||||||
public:
|
public:
|
||||||
DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent = 0);
|
DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent = 0);
|
||||||
|
|
||||||
bool getUnavailableGamesVisible() const;
|
bool getUnavailableGamesVisible() const;
|
||||||
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
||||||
bool getPasswordProtectedGamesVisible() const;
|
bool getPasswordProtectedGamesVisible() const;
|
||||||
void setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible);
|
void setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible);
|
||||||
QString getGameNameFilter() const;
|
QString getGameNameFilter() const;
|
||||||
void setGameNameFilter(const QString &_gameNameFilter);
|
void setGameNameFilter(const QString &_gameNameFilter);
|
||||||
QString getCreatorNameFilter() const;
|
QString getCreatorNameFilter() const;
|
||||||
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
||||||
QSet<int> getGameTypeFilter() const;
|
QSet<int> getGameTypeFilter() const;
|
||||||
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
||||||
int getMaxPlayersFilterMin() const;
|
int getMaxPlayersFilterMin() const;
|
||||||
int getMaxPlayersFilterMax() const;
|
int getMaxPlayersFilterMax() const;
|
||||||
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,47 +12,47 @@
|
||||||
#include "deck_loader.h"
|
#include "deck_loader.h"
|
||||||
|
|
||||||
DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(QWidget *parent)
|
DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(QWidget *parent)
|
||||||
: QDialog(parent), deckList(0)
|
: QDialog(parent), deckList(0)
|
||||||
{
|
{
|
||||||
contentsEdit = new QPlainTextEdit;
|
contentsEdit = new QPlainTextEdit;
|
||||||
|
|
||||||
refreshButton = new QPushButton(tr("&Refresh"));
|
refreshButton = new QPushButton(tr("&Refresh"));
|
||||||
refreshButton->setShortcut(QKeySequence("F5"));
|
refreshButton->setShortcut(QKeySequence("F5"));
|
||||||
connect(refreshButton, SIGNAL(clicked()), this, SLOT(actRefresh()));
|
connect(refreshButton, SIGNAL(clicked()), this, SLOT(actRefresh()));
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
buttonBox->addButton(refreshButton, QDialogButtonBox::ActionRole);
|
buttonBox->addButton(refreshButton, QDialogButtonBox::ActionRole);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(contentsEdit);
|
mainLayout->addWidget(contentsEdit);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Load deck from clipboard"));
|
setWindowTitle(tr("Load deck from clipboard"));
|
||||||
resize(500, 500);
|
resize(500, 500);
|
||||||
|
|
||||||
actRefresh();
|
actRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgLoadDeckFromClipboard::actRefresh()
|
void DlgLoadDeckFromClipboard::actRefresh()
|
||||||
{
|
{
|
||||||
contentsEdit->setPlainText(QApplication::clipboard()->text());
|
contentsEdit->setPlainText(QApplication::clipboard()->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgLoadDeckFromClipboard::actOK()
|
void DlgLoadDeckFromClipboard::actOK()
|
||||||
{
|
{
|
||||||
QString buffer = contentsEdit->toPlainText();
|
QString buffer = contentsEdit->toPlainText();
|
||||||
QTextStream stream(&buffer);
|
QTextStream stream(&buffer);
|
||||||
|
|
||||||
DeckLoader *l = new DeckLoader;
|
DeckLoader *l = new DeckLoader;
|
||||||
if (l->loadFromStream_Plain(stream)) {
|
if (l->loadFromStream_Plain(stream)) {
|
||||||
deckList = l;
|
deckList = l;
|
||||||
accept();
|
accept();
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
||||||
delete l;
|
delete l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,18 +8,18 @@ class QPlainTextEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
class DlgLoadDeckFromClipboard : public QDialog {
|
class DlgLoadDeckFromClipboard : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void actOK();
|
void actOK();
|
||||||
void actRefresh();
|
void actRefresh();
|
||||||
private:
|
private:
|
||||||
DeckLoader *deckList;
|
DeckLoader *deckList;
|
||||||
public:
|
public:
|
||||||
DlgLoadDeckFromClipboard(QWidget *parent = 0);
|
DlgLoadDeckFromClipboard(QWidget *parent = 0);
|
||||||
DeckLoader *getDeckList() const { return deckList; }
|
DeckLoader *getDeckList() const { return deckList; }
|
||||||
private:
|
private:
|
||||||
QPlainTextEdit *contentsEdit;
|
QPlainTextEdit *contentsEdit;
|
||||||
QPushButton *refreshButton;
|
QPushButton *refreshButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,34 +7,34 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
DlgLoadRemoteDeck::DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent)
|
DlgLoadRemoteDeck::DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent)
|
||||||
: QDialog(parent), client(_client)
|
: QDialog(parent), client(_client)
|
||||||
{
|
{
|
||||||
dirView = new RemoteDeckList_TreeWidget(client);
|
dirView = new RemoteDeckList_TreeWidget(client);
|
||||||
|
|
||||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(dirView);
|
mainLayout->addWidget(dirView);
|
||||||
mainLayout->addWidget(buttonBox);
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Load deck"));
|
setWindowTitle(tr("Load deck"));
|
||||||
setMinimumWidth(sizeHint().width());
|
setMinimumWidth(sizeHint().width());
|
||||||
resize(400, 600);
|
resize(400, 600);
|
||||||
|
|
||||||
connect(dirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(currentItemChanged(const QModelIndex &, const QModelIndex &)));
|
connect(dirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(currentItemChanged(const QModelIndex &, const QModelIndex &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgLoadRemoteDeck::currentItemChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
void DlgLoadRemoteDeck::currentItemChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||||
{
|
{
|
||||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(current)));
|
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(current)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int DlgLoadRemoteDeck::getDeckId() const
|
int DlgLoadRemoteDeck::getDeckId() const
|
||||||
{
|
{
|
||||||
return dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(dirView->selectionModel()->currentIndex()))->getId();
|
return dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(dirView->selectionModel()->currentIndex()))->getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@ class QPushButton;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
|
|
||||||
class DlgLoadRemoteDeck: public QDialog {
|
class DlgLoadRemoteDeck: public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
RemoteDeckList_TreeWidget *dirView;
|
RemoteDeckList_TreeWidget *dirView;
|
||||||
QDialogButtonBox *buttonBox;
|
QDialogButtonBox *buttonBox;
|
||||||
private slots:
|
private slots:
|
||||||
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
public:
|
public:
|
||||||
DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent = 0);
|
DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent = 0);
|
||||||
int getDeckId() const;
|
int getDeckId() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -18,123 +18,123 @@ class QSpinBox;
|
||||||
|
|
||||||
class AbstractSettingsPage : public QWidget {
|
class AbstractSettingsPage : public QWidget {
|
||||||
public:
|
public:
|
||||||
virtual void retranslateUi() = 0;
|
virtual void retranslateUi() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeneralSettingsPage : public AbstractSettingsPage {
|
class GeneralSettingsPage : public AbstractSettingsPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GeneralSettingsPage();
|
GeneralSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
private slots:
|
private slots:
|
||||||
void deckPathButtonClicked();
|
void deckPathButtonClicked();
|
||||||
void replaysPathButtonClicked();
|
void replaysPathButtonClicked();
|
||||||
void picsPathButtonClicked();
|
void picsPathButtonClicked();
|
||||||
void cardDatabasePathButtonClicked();
|
void cardDatabasePathButtonClicked();
|
||||||
void tokenDatabasePathButtonClicked();
|
void tokenDatabasePathButtonClicked();
|
||||||
void languageBoxChanged(int index);
|
void languageBoxChanged(int index);
|
||||||
private:
|
private:
|
||||||
QStringList findQmFiles();
|
QStringList findQmFiles();
|
||||||
QString languageName(const QString &qmFile);
|
QString languageName(const QString &qmFile);
|
||||||
QLineEdit *deckPathEdit, *replaysPathEdit, *picsPathEdit, *cardDatabasePathEdit, *tokenDatabasePathEdit;
|
QLineEdit *deckPathEdit, *replaysPathEdit, *picsPathEdit, *cardDatabasePathEdit, *tokenDatabasePathEdit;
|
||||||
QGroupBox *personalGroupBox, *pathsGroupBox;
|
QGroupBox *personalGroupBox, *pathsGroupBox;
|
||||||
QComboBox *languageBox;
|
QComboBox *languageBox;
|
||||||
QCheckBox *picDownloadCheckBox;
|
QCheckBox *picDownloadCheckBox;
|
||||||
QLabel *languageLabel, *deckPathLabel, *replaysPathLabel, *picsPathLabel, *cardDatabasePathLabel, *tokenDatabasePathLabel;
|
QLabel *languageLabel, *deckPathLabel, *replaysPathLabel, *picsPathLabel, *cardDatabasePathLabel, *tokenDatabasePathLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppearanceSettingsPage : public AbstractSettingsPage {
|
class AppearanceSettingsPage : public AbstractSettingsPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void handBgClearButtonClicked();
|
void handBgClearButtonClicked();
|
||||||
void handBgButtonClicked();
|
void handBgButtonClicked();
|
||||||
void stackBgClearButtonClicked();
|
void stackBgClearButtonClicked();
|
||||||
void stackBgButtonClicked();
|
void stackBgButtonClicked();
|
||||||
void tableBgClearButtonClicked();
|
void tableBgClearButtonClicked();
|
||||||
void tableBgButtonClicked();
|
void tableBgButtonClicked();
|
||||||
void playerAreaBgClearButtonClicked();
|
void playerAreaBgClearButtonClicked();
|
||||||
void playerAreaBgButtonClicked();
|
void playerAreaBgButtonClicked();
|
||||||
void cardBackPicturePathClearButtonClicked();
|
void cardBackPicturePathClearButtonClicked();
|
||||||
void cardBackPicturePathButtonClicked();
|
void cardBackPicturePathButtonClicked();
|
||||||
signals:
|
signals:
|
||||||
void handBgChanged(const QString &path);
|
void handBgChanged(const QString &path);
|
||||||
void stackBgChanged(const QString &path);
|
void stackBgChanged(const QString &path);
|
||||||
void tableBgChanged(const QString &path);
|
void tableBgChanged(const QString &path);
|
||||||
void playerAreaBgChanged(const QString &path);
|
void playerAreaBgChanged(const QString &path);
|
||||||
void cardBackPicturePathChanged(const QString &path);
|
void cardBackPicturePathChanged(const QString &path);
|
||||||
private:
|
private:
|
||||||
QLabel *handBgLabel, *stackBgLabel, *tableBgLabel, *playerAreaBgLabel, *cardBackPicturePathLabel, *minPlayersForMultiColumnLayoutLabel;
|
QLabel *handBgLabel, *stackBgLabel, *tableBgLabel, *playerAreaBgLabel, *cardBackPicturePathLabel, *minPlayersForMultiColumnLayoutLabel;
|
||||||
QLineEdit *handBgEdit, *stackBgEdit, *tableBgEdit, *playerAreaBgEdit, *cardBackPicturePathEdit;
|
QLineEdit *handBgEdit, *stackBgEdit, *tableBgEdit, *playerAreaBgEdit, *cardBackPicturePathEdit;
|
||||||
QCheckBox *displayCardNamesCheckBox, *horizontalHandCheckBox, *invertVerticalCoordinateCheckBox, *zoneViewSortByNameCheckBox, *zoneViewSortByTypeCheckBox;
|
QCheckBox *displayCardNamesCheckBox, *horizontalHandCheckBox, *invertVerticalCoordinateCheckBox, *zoneViewSortByNameCheckBox, *zoneViewSortByTypeCheckBox;
|
||||||
QGroupBox *zoneBgGroupBox, *cardsGroupBox, *handGroupBox, *tableGroupBox, *zoneViewGroupBox;
|
QGroupBox *zoneBgGroupBox, *cardsGroupBox, *handGroupBox, *tableGroupBox, *zoneViewGroupBox;
|
||||||
QSpinBox *minPlayersForMultiColumnLayoutEdit;
|
QSpinBox *minPlayersForMultiColumnLayoutEdit;
|
||||||
public:
|
public:
|
||||||
AppearanceSettingsPage();
|
AppearanceSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserInterfaceSettingsPage : public AbstractSettingsPage {
|
class UserInterfaceSettingsPage : public AbstractSettingsPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void soundPathClearButtonClicked();
|
void soundPathClearButtonClicked();
|
||||||
void soundPathButtonClicked();
|
void soundPathButtonClicked();
|
||||||
signals:
|
signals:
|
||||||
void soundPathChanged();
|
void soundPathChanged();
|
||||||
private:
|
private:
|
||||||
QCheckBox *notificationsEnabledCheckBox;
|
QCheckBox *notificationsEnabledCheckBox;
|
||||||
QCheckBox *doubleClickToPlayCheckBox;
|
QCheckBox *doubleClickToPlayCheckBox;
|
||||||
QCheckBox *playToStackCheckBox;
|
QCheckBox *playToStackCheckBox;
|
||||||
QCheckBox *tapAnimationCheckBox;
|
QCheckBox *tapAnimationCheckBox;
|
||||||
QCheckBox *soundEnabledCheckBox;
|
QCheckBox *soundEnabledCheckBox;
|
||||||
QLabel *soundPathLabel;
|
QLabel *soundPathLabel;
|
||||||
QLineEdit *soundPathEdit;
|
QLineEdit *soundPathEdit;
|
||||||
QGroupBox *generalGroupBox, *animationGroupBox, *soundGroupBox;
|
QGroupBox *generalGroupBox, *animationGroupBox, *soundGroupBox;
|
||||||
public:
|
public:
|
||||||
UserInterfaceSettingsPage();
|
UserInterfaceSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckEditorSettingsPage : public AbstractSettingsPage {
|
class DeckEditorSettingsPage : public AbstractSettingsPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DeckEditorSettingsPage();
|
DeckEditorSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
private:
|
private:
|
||||||
QCheckBox *priceTagsCheckBox;
|
QCheckBox *priceTagsCheckBox;
|
||||||
QGroupBox *generalGroupBox;
|
QGroupBox *generalGroupBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessagesSettingsPage : public AbstractSettingsPage {
|
class MessagesSettingsPage : public AbstractSettingsPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MessagesSettingsPage();
|
MessagesSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
private slots:
|
private slots:
|
||||||
void actAdd();
|
void actAdd();
|
||||||
void actRemove();
|
void actRemove();
|
||||||
private:
|
private:
|
||||||
QListWidget *messageList;
|
QListWidget *messageList;
|
||||||
QAction *aAdd, *aRemove;
|
QAction *aAdd, *aRemove;
|
||||||
|
|
||||||
void storeSettings();
|
void storeSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DlgSettings : public QDialog {
|
class DlgSettings : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgSettings(QWidget *parent = 0);
|
DlgSettings(QWidget *parent = 0);
|
||||||
private slots:
|
private slots:
|
||||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
void updateLanguage();
|
void updateLanguage();
|
||||||
private:
|
private:
|
||||||
QListWidget *contentsWidget;
|
QListWidget *contentsWidget;
|
||||||
QStackedWidget *pagesWidget;
|
QStackedWidget *pagesWidget;
|
||||||
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *deckEditorButton, *messagesButton;
|
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *deckEditorButton, *messagesButton;
|
||||||
void createIcons();
|
void createIcons();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *event);
|
void changeEvent(QEvent *event);
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,103 +13,103 @@
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
|
GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
|
||||||
: QGraphicsScene(parent), phasesToolbar(_phasesToolbar), viewSize(QSize())
|
: QGraphicsScene(parent), phasesToolbar(_phasesToolbar), viewSize(QSize())
|
||||||
{
|
{
|
||||||
animationTimer = new QBasicTimer;
|
animationTimer = new QBasicTimer;
|
||||||
addItem(phasesToolbar);
|
addItem(phasesToolbar);
|
||||||
connect(settingsCache, SIGNAL(minPlayersForMultiColumnLayoutChanged()), this, SLOT(rearrange()));
|
connect(settingsCache, SIGNAL(minPlayersForMultiColumnLayoutChanged()), this, SLOT(rearrange()));
|
||||||
|
|
||||||
rearrange();
|
rearrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameScene::~GameScene()
|
GameScene::~GameScene()
|
||||||
{
|
{
|
||||||
delete animationTimer;
|
delete animationTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::retranslateUi()
|
void GameScene::retranslateUi()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < zoneViews.size(); ++i)
|
for (int i = 0; i < zoneViews.size(); ++i)
|
||||||
zoneViews[i]->retranslateUi();
|
zoneViews[i]->retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::addPlayer(Player *player)
|
void GameScene::addPlayer(Player *player)
|
||||||
{
|
{
|
||||||
qDebug("GameScene::addPlayer");
|
qDebug("GameScene::addPlayer");
|
||||||
players << player;
|
players << player;
|
||||||
addItem(player);
|
addItem(player);
|
||||||
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||||
connect(player, SIGNAL(gameConceded()), this, SLOT(rearrange()));
|
connect(player, SIGNAL(gameConceded()), this, SLOT(rearrange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
{
|
{
|
||||||
qDebug("GameScene::removePlayer");
|
qDebug("GameScene::removePlayer");
|
||||||
players.removeAt(players.indexOf(player));
|
players.removeAt(players.indexOf(player));
|
||||||
removeItem(player);
|
removeItem(player);
|
||||||
rearrange();
|
rearrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::rearrange()
|
void GameScene::rearrange()
|
||||||
{
|
{
|
||||||
playersByColumn.clear();
|
playersByColumn.clear();
|
||||||
|
|
||||||
QList<Player *> playersPlaying;
|
QList<Player *> playersPlaying;
|
||||||
int firstPlayer = -1;
|
int firstPlayer = -1;
|
||||||
for (int i = 0; i < players.size(); ++i)
|
for (int i = 0; i < players.size(); ++i)
|
||||||
if (!players[i]->getConceded()) {
|
if (!players[i]->getConceded()) {
|
||||||
playersPlaying.append(players[i]);
|
playersPlaying.append(players[i]);
|
||||||
if ((firstPlayer == -1) && (players[i]->getLocal()))
|
if ((firstPlayer == -1) && (players[i]->getLocal()))
|
||||||
firstPlayer = playersPlaying.size() - 1;
|
firstPlayer = playersPlaying.size() - 1;
|
||||||
}
|
}
|
||||||
if (firstPlayer == -1)
|
if (firstPlayer == -1)
|
||||||
firstPlayer = 0;
|
firstPlayer = 0;
|
||||||
const int playersCount = playersPlaying.size();
|
const int playersCount = playersPlaying.size();
|
||||||
const int columns = playersCount < settingsCache->getMinPlayersForMultiColumnLayout() ? 1 : 2;
|
const int columns = playersCount < settingsCache->getMinPlayersForMultiColumnLayout() ? 1 : 2;
|
||||||
const int rows = ceil((qreal) playersCount / columns);
|
const int rows = ceil((qreal) playersCount / columns);
|
||||||
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
|
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
|
||||||
QList<int> columnWidth;
|
QList<int> columnWidth;
|
||||||
int firstPlayerOfColumn = firstPlayer;
|
int firstPlayerOfColumn = firstPlayer;
|
||||||
for (int col = 0; col < columns; ++col) {
|
for (int col = 0; col < columns; ++col) {
|
||||||
playersByColumn.append(QList<Player *>());
|
playersByColumn.append(QList<Player *>());
|
||||||
columnWidth.append(0);
|
columnWidth.append(0);
|
||||||
qreal thisColumnHeight = -playerAreaSpacing;
|
qreal thisColumnHeight = -playerAreaSpacing;
|
||||||
const int rowsInColumn = rows - (playersCount % columns) * col; // only correct for max. 2 cols
|
const int rowsInColumn = rows - (playersCount % columns) * col; // only correct for max. 2 cols
|
||||||
for (int j = 0; j < rowsInColumn; ++j) {
|
for (int j = 0; j < rowsInColumn; ++j) {
|
||||||
Player *player = playersPlaying[(firstPlayerOfColumn + j) % playersCount];
|
Player *player = playersPlaying[(firstPlayerOfColumn + j) % playersCount];
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
playersByColumn[col].prepend(player);
|
playersByColumn[col].prepend(player);
|
||||||
else
|
else
|
||||||
playersByColumn[col].append(player);
|
playersByColumn[col].append(player);
|
||||||
thisColumnHeight += player->boundingRect().height() + playerAreaSpacing;
|
thisColumnHeight += player->boundingRect().height() + playerAreaSpacing;
|
||||||
if (player->boundingRect().width() > columnWidth[col])
|
if (player->boundingRect().width() > columnWidth[col])
|
||||||
columnWidth[col] = player->boundingRect().width();
|
columnWidth[col] = player->boundingRect().width();
|
||||||
}
|
}
|
||||||
if (thisColumnHeight > sceneHeight)
|
if (thisColumnHeight > sceneHeight)
|
||||||
sceneHeight = thisColumnHeight;
|
sceneHeight = thisColumnHeight;
|
||||||
sceneWidth += columnWidth[col] + playerAreaSpacing;
|
sceneWidth += columnWidth[col] + playerAreaSpacing;
|
||||||
|
|
||||||
firstPlayerOfColumn += rowsInColumn;
|
firstPlayerOfColumn += rowsInColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
phasesToolbar->setHeight(sceneHeight);
|
phasesToolbar->setHeight(sceneHeight);
|
||||||
qreal phasesWidth = phasesToolbar->getWidth();
|
qreal phasesWidth = phasesToolbar->getWidth();
|
||||||
sceneWidth += phasesWidth;
|
sceneWidth += phasesWidth;
|
||||||
|
|
||||||
qreal x = phasesWidth;
|
qreal x = phasesWidth;
|
||||||
for (int col = 0; col < columns; ++col) {
|
for (int col = 0; col < columns; ++col) {
|
||||||
qreal y = 0;
|
qreal y = 0;
|
||||||
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
||||||
Player *player = playersByColumn[col][row];
|
Player *player = playersByColumn[col][row];
|
||||||
player->setPos(x, y);
|
player->setPos(x, y);
|
||||||
player->setMirrored(row != rows - 1);
|
player->setMirrored(row != rows - 1);
|
||||||
y += player->boundingRect().height() + playerAreaSpacing;
|
y += player->boundingRect().height() + playerAreaSpacing;
|
||||||
}
|
}
|
||||||
x += columnWidth[col] + playerAreaSpacing;
|
x += columnWidth[col] + playerAreaSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
||||||
processViewSizeChange(viewSize);
|
processViewSizeChange(viewSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
||||||
|
@ -123,166 +123,166 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneViewWidget *item = new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards, false);
|
ZoneViewWidget *item = new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards, false);
|
||||||
zoneViews.append(item);
|
zoneViews.append(item);
|
||||||
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
||||||
addItem(item);
|
addItem(item);
|
||||||
item->setPos(50, 50);
|
item->setPos(50, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::addRevealedZoneView(Player *player, CardZone *zone, const QList<const ServerInfo_Card *> &cardList, bool withWritePermission)
|
void GameScene::addRevealedZoneView(Player *player, CardZone *zone, const QList<const ServerInfo_Card *> &cardList, bool withWritePermission)
|
||||||
{
|
{
|
||||||
ZoneViewWidget *item = new ZoneViewWidget(player, zone, -2, true, withWritePermission, cardList);
|
ZoneViewWidget *item = new ZoneViewWidget(player, zone, -2, true, withWritePermission, cardList);
|
||||||
zoneViews.append(item);
|
zoneViews.append(item);
|
||||||
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
||||||
addItem(item);
|
addItem(item);
|
||||||
item->setPos(50, 50);
|
item->setPos(50, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::removeZoneView(ZoneViewWidget *item)
|
void GameScene::removeZoneView(ZoneViewWidget *item)
|
||||||
{
|
{
|
||||||
zoneViews.removeAt(zoneViews.indexOf(item));
|
zoneViews.removeAt(zoneViews.indexOf(item));
|
||||||
removeItem(item);
|
removeItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::clearViews()
|
void GameScene::clearViews()
|
||||||
{
|
{
|
||||||
while (!zoneViews.isEmpty())
|
while (!zoneViews.isEmpty())
|
||||||
zoneViews.first()->close();
|
zoneViews.first()->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::closeMostRecentZoneView()
|
void GameScene::closeMostRecentZoneView()
|
||||||
{
|
{
|
||||||
if (!zoneViews.isEmpty())
|
if (!zoneViews.isEmpty())
|
||||||
zoneViews.last()->close();
|
zoneViews.last()->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform GameScene::getViewTransform() const
|
QTransform GameScene::getViewTransform() const
|
||||||
{
|
{
|
||||||
return views().at(0)->transform();
|
return views().at(0)->transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform GameScene::getViewportTransform() const
|
QTransform GameScene::getViewportTransform() const
|
||||||
{
|
{
|
||||||
return views().at(0)->viewportTransform();
|
return views().at(0)->viewportTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::processViewSizeChange(const QSize &newSize)
|
void GameScene::processViewSizeChange(const QSize &newSize)
|
||||||
{
|
{
|
||||||
viewSize = newSize;
|
viewSize = newSize;
|
||||||
|
|
||||||
qreal newRatio = ((qreal) newSize.width()) / newSize.height();
|
qreal newRatio = ((qreal) newSize.width()) / newSize.height();
|
||||||
qreal minWidth = 0;
|
qreal minWidth = 0;
|
||||||
QList<qreal> minWidthByColumn;
|
QList<qreal> minWidthByColumn;
|
||||||
for (int col = 0; col < playersByColumn.size(); ++col) {
|
for (int col = 0; col < playersByColumn.size(); ++col) {
|
||||||
minWidthByColumn.append(0);
|
minWidthByColumn.append(0);
|
||||||
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
||||||
qreal w = playersByColumn[col][row]->getMinimumWidth();
|
qreal w = playersByColumn[col][row]->getMinimumWidth();
|
||||||
if (w > minWidthByColumn[col])
|
if (w > minWidthByColumn[col])
|
||||||
minWidthByColumn[col] = w;
|
minWidthByColumn[col] = w;
|
||||||
}
|
}
|
||||||
minWidth += minWidthByColumn[col];
|
minWidth += minWidthByColumn[col];
|
||||||
}
|
}
|
||||||
minWidth += phasesToolbar->getWidth();
|
minWidth += phasesToolbar->getWidth();
|
||||||
|
|
||||||
qreal minRatio = minWidth / sceneRect().height();
|
qreal minRatio = minWidth / sceneRect().height();
|
||||||
qreal newWidth;
|
qreal newWidth;
|
||||||
if (minRatio > newRatio) {
|
if (minRatio > newRatio) {
|
||||||
// Aspect ratio is dominated by table width.
|
// Aspect ratio is dominated by table width.
|
||||||
newWidth = minWidth;
|
newWidth = minWidth;
|
||||||
} else {
|
} else {
|
||||||
// Aspect ratio is dominated by window dimensions.
|
// Aspect ratio is dominated by window dimensions.
|
||||||
newWidth = newRatio * sceneRect().height();
|
newWidth = newRatio * sceneRect().height();
|
||||||
}
|
}
|
||||||
setSceneRect(0, 0, newWidth, sceneRect().height());
|
setSceneRect(0, 0, newWidth, sceneRect().height());
|
||||||
|
|
||||||
qreal extraWidthPerColumn = (newWidth - minWidth) / playersByColumn.size();
|
qreal extraWidthPerColumn = (newWidth - minWidth) / playersByColumn.size();
|
||||||
for (int col = 0; col < playersByColumn.size(); ++col)
|
for (int col = 0; col < playersByColumn.size(); ++col)
|
||||||
for (int row = 0; row < playersByColumn[col].size(); ++row)
|
for (int row = 0; row < playersByColumn[col].size(); ++row)
|
||||||
playersByColumn[col][row]->processSceneSizeChange(minWidthByColumn[col] + extraWidthPerColumn);
|
playersByColumn[col][row]->processSceneSizeChange(minWidthByColumn[col] + extraWidthPerColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::updateHover(const QPointF &scenePos)
|
void GameScene::updateHover(const QPointF &scenePos)
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem *> itemList = items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
|
QList<QGraphicsItem *> itemList = items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
|
||||||
|
|
||||||
// Search for the topmost zone and ignore all cards not belonging to that zone.
|
// Search for the topmost zone and ignore all cards not belonging to that zone.
|
||||||
CardZone *zone = 0;
|
CardZone *zone = 0;
|
||||||
for (int i = 0; i < itemList.size(); ++i)
|
for (int i = 0; i < itemList.size(); ++i)
|
||||||
if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
|
if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
CardItem *maxZCard = 0;
|
CardItem *maxZCard = 0;
|
||||||
if (zone) {
|
if (zone) {
|
||||||
qreal maxZ = -1;
|
qreal maxZ = -1;
|
||||||
for (int i = 0; i < itemList.size(); ++i) {
|
for (int i = 0; i < itemList.size(); ++i) {
|
||||||
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
|
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
|
||||||
if (!card)
|
if (!card)
|
||||||
continue;
|
continue;
|
||||||
if (card->getAttachedTo()) {
|
if (card->getAttachedTo()) {
|
||||||
if (card->getAttachedTo()->getZone() != zone)
|
if (card->getAttachedTo()->getZone() != zone)
|
||||||
continue;
|
continue;
|
||||||
} else if (card->getZone() != zone)
|
} else if (card->getZone() != zone)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (card->getRealZValue() > maxZ) {
|
if (card->getRealZValue() > maxZ) {
|
||||||
maxZ = card->getRealZValue();
|
maxZ = card->getRealZValue();
|
||||||
maxZCard = card;
|
maxZCard = card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hoveredCard && (maxZCard != hoveredCard))
|
if (hoveredCard && (maxZCard != hoveredCard))
|
||||||
hoveredCard->setHovered(false);
|
hoveredCard->setHovered(false);
|
||||||
if (maxZCard && (maxZCard != hoveredCard))
|
if (maxZCard && (maxZCard != hoveredCard))
|
||||||
maxZCard->setHovered(true);
|
maxZCard->setHovered(true);
|
||||||
hoveredCard = maxZCard;
|
hoveredCard = maxZCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameScene::event(QEvent *event)
|
bool GameScene::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::GraphicsSceneMouseMove)
|
if (event->type() == QEvent::GraphicsSceneMouseMove)
|
||||||
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
|
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
|
||||||
|
|
||||||
return QGraphicsScene::event(event);
|
return QGraphicsScene::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::timerEvent(QTimerEvent * /*event*/)
|
void GameScene::timerEvent(QTimerEvent * /*event*/)
|
||||||
{
|
{
|
||||||
QMutableSetIterator<CardItem *> i(cardsToAnimate);
|
QMutableSetIterator<CardItem *> i(cardsToAnimate);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
if (!i.value()->animationEvent())
|
if (!i.value()->animationEvent())
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
if (cardsToAnimate.isEmpty())
|
if (cardsToAnimate.isEmpty())
|
||||||
animationTimer->stop();
|
animationTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::registerAnimationItem(AbstractCardItem *card)
|
void GameScene::registerAnimationItem(AbstractCardItem *card)
|
||||||
{
|
{
|
||||||
cardsToAnimate.insert(static_cast<CardItem *>(card));
|
cardsToAnimate.insert(static_cast<CardItem *>(card));
|
||||||
if (!animationTimer->isActive())
|
if (!animationTimer->isActive())
|
||||||
animationTimer->start(50, this);
|
animationTimer->start(50, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
|
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
|
||||||
{
|
{
|
||||||
cardsToAnimate.remove(static_cast<CardItem *>(card));
|
cardsToAnimate.remove(static_cast<CardItem *>(card));
|
||||||
if (cardsToAnimate.isEmpty())
|
if (cardsToAnimate.isEmpty())
|
||||||
animationTimer->stop();
|
animationTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::startRubberBand(const QPointF &selectionOrigin)
|
void GameScene::startRubberBand(const QPointF &selectionOrigin)
|
||||||
{
|
{
|
||||||
emit sigStartRubberBand(selectionOrigin);
|
emit sigStartRubberBand(selectionOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::resizeRubberBand(const QPointF &cursorPoint)
|
void GameScene::resizeRubberBand(const QPointF &cursorPoint)
|
||||||
{
|
{
|
||||||
emit sigResizeRubberBand(cursorPoint);
|
emit sigResizeRubberBand(cursorPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::stopRubberBand()
|
void GameScene::stopRubberBand()
|
||||||
{
|
{
|
||||||
emit sigStopRubberBand();
|
emit sigStopRubberBand();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,49 +16,49 @@ class PhasesToolbar;
|
||||||
class QBasicTimer;
|
class QBasicTimer;
|
||||||
|
|
||||||
class GameScene : public QGraphicsScene {
|
class GameScene : public QGraphicsScene {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
static const int playerAreaSpacing = 5;
|
static const int playerAreaSpacing = 5;
|
||||||
|
|
||||||
PhasesToolbar *phasesToolbar;
|
PhasesToolbar *phasesToolbar;
|
||||||
QList<Player *> players;
|
QList<Player *> players;
|
||||||
QList<QList<Player *> > playersByColumn;
|
QList<QList<Player *> > playersByColumn;
|
||||||
QList<ZoneViewWidget *> zoneViews;
|
QList<ZoneViewWidget *> zoneViews;
|
||||||
QSize viewSize;
|
QSize viewSize;
|
||||||
QPointer<CardItem> hoveredCard;
|
QPointer<CardItem> hoveredCard;
|
||||||
QBasicTimer *animationTimer;
|
QBasicTimer *animationTimer;
|
||||||
QSet<CardItem *> cardsToAnimate;
|
QSet<CardItem *> cardsToAnimate;
|
||||||
void updateHover(const QPointF &scenePos);
|
void updateHover(const QPointF &scenePos);
|
||||||
public:
|
public:
|
||||||
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
||||||
~GameScene();
|
~GameScene();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void processViewSizeChange(const QSize &newSize);
|
void processViewSizeChange(const QSize &newSize);
|
||||||
QTransform getViewTransform() const;
|
QTransform getViewTransform() const;
|
||||||
QTransform getViewportTransform() const;
|
QTransform getViewportTransform() const;
|
||||||
|
|
||||||
void startRubberBand(const QPointF &selectionOrigin);
|
void startRubberBand(const QPointF &selectionOrigin);
|
||||||
void resizeRubberBand(const QPointF &cursorPoint);
|
void resizeRubberBand(const QPointF &cursorPoint);
|
||||||
void stopRubberBand();
|
void stopRubberBand();
|
||||||
|
|
||||||
void registerAnimationItem(AbstractCardItem *item);
|
void registerAnimationItem(AbstractCardItem *item);
|
||||||
void unregisterAnimationItem(AbstractCardItem *card);
|
void unregisterAnimationItem(AbstractCardItem *card);
|
||||||
public slots:
|
public slots:
|
||||||
void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
|
void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
|
||||||
void addRevealedZoneView(Player *player, CardZone *zone, const QList<const ServerInfo_Card *> &cardList, bool withWritePermission);
|
void addRevealedZoneView(Player *player, CardZone *zone, const QList<const ServerInfo_Card *> &cardList, bool withWritePermission);
|
||||||
void removeZoneView(ZoneViewWidget *item);
|
void removeZoneView(ZoneViewWidget *item);
|
||||||
void addPlayer(Player *player);
|
void addPlayer(Player *player);
|
||||||
void removePlayer(Player *player);
|
void removePlayer(Player *player);
|
||||||
void clearViews();
|
void clearViews();
|
||||||
void closeMostRecentZoneView();
|
void closeMostRecentZoneView();
|
||||||
void rearrange();
|
void rearrange();
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event);
|
bool event(QEvent *event);
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
signals:
|
signals:
|
||||||
void sigStartRubberBand(const QPointF &selectionOrigin);
|
void sigStartRubberBand(const QPointF &selectionOrigin);
|
||||||
void sigResizeRubberBand(const QPointF &cursorPoint);
|
void sigResizeRubberBand(const QPointF &cursorPoint);
|
||||||
void sigStopRubberBand();
|
void sigStopRubberBand();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,173 +18,173 @@
|
||||||
#include "pb/response.pb.h"
|
#include "pb/response.pb.h"
|
||||||
|
|
||||||
GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
||||||
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
||||||
{
|
{
|
||||||
gameListView = new QTreeView;
|
gameListView = new QTreeView;
|
||||||
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||||
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo());
|
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo());
|
||||||
gameListProxyModel->setSourceModel(gameListModel);
|
gameListProxyModel->setSourceModel(gameListModel);
|
||||||
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
gameListView->setModel(gameListProxyModel);
|
gameListView->setModel(gameListProxyModel);
|
||||||
gameListView->setSortingEnabled(true);
|
gameListView->setSortingEnabled(true);
|
||||||
gameListView->setAlternatingRowColors(true);
|
gameListView->setAlternatingRowColors(true);
|
||||||
gameListView->setRootIsDecorated(true);
|
gameListView->setRootIsDecorated(true);
|
||||||
if (_room)
|
if (_room)
|
||||||
gameListView->header()->hideSection(1);
|
gameListView->header()->hideSection(1);
|
||||||
else
|
else
|
||||||
gameListProxyModel->setUnavailableGamesVisible(true);
|
gameListProxyModel->setUnavailableGamesVisible(true);
|
||||||
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
filterButton = new QPushButton;
|
filterButton = new QPushButton;
|
||||||
filterButton->setIcon(QIcon(":/resources/icon_search.svg"));
|
filterButton->setIcon(QIcon(":/resources/icon_search.svg"));
|
||||||
connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter()));
|
connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter()));
|
||||||
clearFilterButton = new QPushButton;
|
clearFilterButton = new QPushButton;
|
||||||
clearFilterButton->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
|
clearFilterButton->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
|
||||||
clearFilterButton->setEnabled(false);
|
clearFilterButton->setEnabled(false);
|
||||||
connect(clearFilterButton, SIGNAL(clicked()), this, SLOT(actClearFilter()));
|
connect(clearFilterButton, SIGNAL(clicked()), this, SLOT(actClearFilter()));
|
||||||
|
|
||||||
if (room) {
|
if (room) {
|
||||||
createButton = new QPushButton;
|
createButton = new QPushButton;
|
||||||
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
|
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
|
||||||
} else
|
} else
|
||||||
createButton = 0;
|
createButton = 0;
|
||||||
joinButton = new QPushButton;
|
joinButton = new QPushButton;
|
||||||
spectateButton = new QPushButton;
|
spectateButton = new QPushButton;
|
||||||
|
|
||||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||||
buttonLayout->addWidget(filterButton);
|
buttonLayout->addWidget(filterButton);
|
||||||
buttonLayout->addWidget(clearFilterButton);
|
buttonLayout->addWidget(clearFilterButton);
|
||||||
buttonLayout->addStretch();
|
buttonLayout->addStretch();
|
||||||
if (room)
|
if (room)
|
||||||
buttonLayout->addWidget(createButton);
|
buttonLayout->addWidget(createButton);
|
||||||
buttonLayout->addWidget(joinButton);
|
buttonLayout->addWidget(joinButton);
|
||||||
buttonLayout->addWidget(spectateButton);
|
buttonLayout->addWidget(spectateButton);
|
||||||
buttonLayout->setAlignment(Qt::AlignTop);
|
buttonLayout->setAlignment(Qt::AlignTop);
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(gameListView);
|
mainLayout->addWidget(gameListView);
|
||||||
mainLayout->addLayout(buttonLayout);
|
mainLayout->addLayout(buttonLayout);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5);
|
setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5);
|
||||||
setMinimumHeight(200);
|
setMinimumHeight(200);
|
||||||
|
|
||||||
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
|
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
|
||||||
connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin()));
|
connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::actSetFilter()
|
void GameSelector::actSetFilter()
|
||||||
{
|
{
|
||||||
GameTypeMap gameTypeMap;
|
GameTypeMap gameTypeMap;
|
||||||
if (room)
|
if (room)
|
||||||
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
||||||
DlgFilterGames dlg(gameTypeMap, this);
|
DlgFilterGames dlg(gameTypeMap, this);
|
||||||
dlg.setUnavailableGamesVisible(gameListProxyModel->getUnavailableGamesVisible());
|
dlg.setUnavailableGamesVisible(gameListProxyModel->getUnavailableGamesVisible());
|
||||||
dlg.setPasswordProtectedGamesVisible(gameListProxyModel->getPasswordProtectedGamesVisible());
|
dlg.setPasswordProtectedGamesVisible(gameListProxyModel->getPasswordProtectedGamesVisible());
|
||||||
dlg.setGameNameFilter(gameListProxyModel->getGameNameFilter());
|
dlg.setGameNameFilter(gameListProxyModel->getGameNameFilter());
|
||||||
dlg.setCreatorNameFilter(gameListProxyModel->getCreatorNameFilter());
|
dlg.setCreatorNameFilter(gameListProxyModel->getCreatorNameFilter());
|
||||||
dlg.setGameTypeFilter(gameListProxyModel->getGameTypeFilter());
|
dlg.setGameTypeFilter(gameListProxyModel->getGameTypeFilter());
|
||||||
dlg.setMaxPlayersFilter(gameListProxyModel->getMaxPlayersFilterMin(), gameListProxyModel->getMaxPlayersFilterMax());
|
dlg.setMaxPlayersFilter(gameListProxyModel->getMaxPlayersFilterMin(), gameListProxyModel->getMaxPlayersFilterMax());
|
||||||
|
|
||||||
if (!dlg.exec())
|
if (!dlg.exec())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clearFilterButton->setEnabled(true);
|
clearFilterButton->setEnabled(true);
|
||||||
|
|
||||||
gameListProxyModel->setUnavailableGamesVisible(dlg.getUnavailableGamesVisible());
|
gameListProxyModel->setUnavailableGamesVisible(dlg.getUnavailableGamesVisible());
|
||||||
gameListProxyModel->setPasswordProtectedGamesVisible(dlg.getPasswordProtectedGamesVisible());
|
gameListProxyModel->setPasswordProtectedGamesVisible(dlg.getPasswordProtectedGamesVisible());
|
||||||
gameListProxyModel->setGameNameFilter(dlg.getGameNameFilter());
|
gameListProxyModel->setGameNameFilter(dlg.getGameNameFilter());
|
||||||
gameListProxyModel->setCreatorNameFilter(dlg.getCreatorNameFilter());
|
gameListProxyModel->setCreatorNameFilter(dlg.getCreatorNameFilter());
|
||||||
gameListProxyModel->setGameTypeFilter(dlg.getGameTypeFilter());
|
gameListProxyModel->setGameTypeFilter(dlg.getGameTypeFilter());
|
||||||
gameListProxyModel->setMaxPlayersFilter(dlg.getMaxPlayersFilterMin(), dlg.getMaxPlayersFilterMax());
|
gameListProxyModel->setMaxPlayersFilter(dlg.getMaxPlayersFilterMin(), dlg.getMaxPlayersFilterMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::actClearFilter()
|
void GameSelector::actClearFilter()
|
||||||
{
|
{
|
||||||
clearFilterButton->setEnabled(false);
|
clearFilterButton->setEnabled(false);
|
||||||
|
|
||||||
gameListProxyModel->resetFilterParameters();
|
gameListProxyModel->resetFilterParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::actCreate()
|
void GameSelector::actCreate()
|
||||||
{
|
{
|
||||||
DlgCreateGame dlg(room, room->getGameTypes(), this);
|
DlgCreateGame dlg(room, room->getGameTypes(), this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::checkResponse(const Response &response)
|
void GameSelector::checkResponse(const Response &response)
|
||||||
{
|
{
|
||||||
if (createButton)
|
if (createButton)
|
||||||
createButton->setEnabled(true);
|
createButton->setEnabled(true);
|
||||||
joinButton->setEnabled(true);
|
joinButton->setEnabled(true);
|
||||||
spectateButton->setEnabled(true);
|
spectateButton->setEnabled(true);
|
||||||
|
|
||||||
switch (response.response_code()) {
|
switch (response.response_code()) {
|
||||||
case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break;
|
case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break;
|
||||||
case Response::RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break;
|
case Response::RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break;
|
||||||
case Response::RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break;
|
case Response::RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break;
|
||||||
case Response::RespGameFull: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break;
|
case Response::RespGameFull: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break;
|
||||||
case Response::RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break;
|
case Response::RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break;
|
||||||
case Response::RespUserLevelTooLow: QMessageBox::critical(this, tr("Error"), tr("This game is only open to registered users.")); break;
|
case Response::RespUserLevelTooLow: QMessageBox::critical(this, tr("Error"), tr("This game is only open to registered users.")); break;
|
||||||
case Response::RespOnlyBuddies: QMessageBox::critical(this, tr("Error"), tr("This game is only open to its creator's buddies.")); break;
|
case Response::RespOnlyBuddies: QMessageBox::critical(this, tr("Error"), tr("This game is only open to its creator's buddies.")); break;
|
||||||
case Response::RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break;
|
case Response::RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::actJoin()
|
void GameSelector::actJoin()
|
||||||
{
|
{
|
||||||
bool spectator = sender() == spectateButton;
|
bool spectator = sender() == spectateButton;
|
||||||
|
|
||||||
QModelIndex ind = gameListView->currentIndex();
|
QModelIndex ind = gameListView->currentIndex();
|
||||||
if (!ind.isValid())
|
if (!ind.isValid())
|
||||||
return;
|
return;
|
||||||
const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
|
const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
|
||||||
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
|
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
|
||||||
QString password;
|
QString password;
|
||||||
if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) {
|
if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) {
|
||||||
bool ok;
|
bool ok;
|
||||||
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
|
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_JoinGame cmd;
|
Command_JoinGame cmd;
|
||||||
cmd.set_game_id(game.game_id());
|
cmd.set_game_id(game.game_id());
|
||||||
cmd.set_password(password.toStdString());
|
cmd.set_password(password.toStdString());
|
||||||
cmd.set_spectator(spectator);
|
cmd.set_spectator(spectator);
|
||||||
cmd.set_override_restrictions(overrideRestrictions);
|
cmd.set_override_restrictions(overrideRestrictions);
|
||||||
|
|
||||||
TabRoom *r = tabSupervisor->getRoomTabs().value(game.room_id());
|
TabRoom *r = tabSupervisor->getRoomTabs().value(game.room_id());
|
||||||
if (!r) {
|
if (!r) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Please join the respective room first."));
|
QMessageBox::critical(this, tr("Error"), tr("Please join the respective room first."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *pend = r->prepareRoomCommand(cmd);
|
PendingCommand *pend = r->prepareRoomCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
|
||||||
r->sendRoomCommand(pend);
|
r->sendRoomCommand(pend);
|
||||||
|
|
||||||
if (createButton)
|
if (createButton)
|
||||||
createButton->setEnabled(false);
|
createButton->setEnabled(false);
|
||||||
joinButton->setEnabled(false);
|
joinButton->setEnabled(false);
|
||||||
spectateButton->setEnabled(false);
|
spectateButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::retranslateUi()
|
void GameSelector::retranslateUi()
|
||||||
{
|
{
|
||||||
setTitle(tr("Games"));
|
setTitle(tr("Games"));
|
||||||
filterButton->setText(tr("&Filter games"));
|
filterButton->setText(tr("&Filter games"));
|
||||||
clearFilterButton->setText(tr("C&lear filter"));
|
clearFilterButton->setText(tr("C&lear filter"));
|
||||||
if (createButton)
|
if (createButton)
|
||||||
createButton->setText(tr("C&reate"));
|
createButton->setText(tr("C&reate"));
|
||||||
joinButton->setText(tr("&Join"));
|
joinButton->setText(tr("&Join"));
|
||||||
spectateButton->setText(tr("J&oin as spectator"));
|
spectateButton->setText(tr("J&oin as spectator"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSelector::processGameInfo(const ServerInfo_Game &info)
|
void GameSelector::processGameInfo(const ServerInfo_Game &info)
|
||||||
{
|
{
|
||||||
gameListModel->updateGameList(info);
|
gameListModel->updateGameList(info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,28 +16,28 @@ class ServerInfo_Game;
|
||||||
class Response;
|
class Response;
|
||||||
|
|
||||||
class GameSelector : public QGroupBox {
|
class GameSelector : public QGroupBox {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void actSetFilter();
|
void actSetFilter();
|
||||||
void actClearFilter();
|
void actClearFilter();
|
||||||
void actCreate();
|
void actCreate();
|
||||||
void actJoin();
|
void actJoin();
|
||||||
void checkResponse(const Response &response);
|
void checkResponse(const Response &response);
|
||||||
signals:
|
signals:
|
||||||
void gameJoined(int gameId);
|
void gameJoined(int gameId);
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
const TabSupervisor *tabSupervisor;
|
const TabSupervisor *tabSupervisor;
|
||||||
TabRoom *room;
|
TabRoom *room;
|
||||||
|
|
||||||
QTreeView *gameListView;
|
QTreeView *gameListView;
|
||||||
GamesModel *gameListModel;
|
GamesModel *gameListModel;
|
||||||
GamesProxyModel *gameListProxyModel;
|
GamesProxyModel *gameListProxyModel;
|
||||||
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
||||||
public:
|
public:
|
||||||
GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void processGameInfo(const ServerInfo_Game &info);
|
void processGameInfo(const ServerInfo_Game &info);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,187 +3,187 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
||||||
: QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes)
|
: QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant GamesModel::data(const QModelIndex &index, int role) const
|
QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (role == Qt::UserRole)
|
if (role == Qt::UserRole)
|
||||||
return index.row();
|
return index.row();
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
|
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const ServerInfo_Game &g = gameList[index.row()];
|
const ServerInfo_Game &g = gameList[index.row()];
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return QString::fromStdString(g.description());
|
case 0: return QString::fromStdString(g.description());
|
||||||
case 1: return rooms.value(g.room_id());
|
case 1: return rooms.value(g.room_id());
|
||||||
case 2: return QString::fromStdString(g.creator_info().name());
|
case 2: return QString::fromStdString(g.creator_info().name());
|
||||||
case 3: {
|
case 3: {
|
||||||
QStringList result;
|
QStringList result;
|
||||||
GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
|
GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
|
||||||
for (int i = g.game_types_size() - 1; i >= 0; --i)
|
for (int i = g.game_types_size() - 1; i >= 0; --i)
|
||||||
result.append(gameTypeMap.value(g.game_types(i)));
|
result.append(gameTypeMap.value(g.game_types(i)));
|
||||||
return result.join(", ");
|
return result.join(", ");
|
||||||
}
|
}
|
||||||
case 4: return g.with_password() ? ((g.spectators_need_password() || !g.spectators_allowed()) ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
case 4: return g.with_password() ? ((g.spectators_need_password() || !g.spectators_allowed()) ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
||||||
case 5: {
|
case 5: {
|
||||||
QStringList result;
|
QStringList result;
|
||||||
if (g.only_buddies())
|
if (g.only_buddies())
|
||||||
result.append(tr("buddies only"));
|
result.append(tr("buddies only"));
|
||||||
if (g.only_registered())
|
if (g.only_registered())
|
||||||
result.append(tr("reg. users only"));
|
result.append(tr("reg. users only"));
|
||||||
return result.join(", ");
|
return result.join(", ");
|
||||||
}
|
}
|
||||||
case 6: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
case 6: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||||
case 7: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
|
case 7: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return tr("Description");
|
case 0: return tr("Description");
|
||||||
case 1: return tr("Room");
|
case 1: return tr("Room");
|
||||||
case 2: return tr("Creator");
|
case 2: return tr("Creator");
|
||||||
case 3: return tr("Game type");
|
case 3: return tr("Game type");
|
||||||
case 4: return tr("Password");
|
case 4: return tr("Password");
|
||||||
case 5: return tr("Restrictions");
|
case 5: return tr("Restrictions");
|
||||||
case 6: return tr("Players");
|
case 6: return tr("Players");
|
||||||
case 7: return tr("Spectators");
|
case 7: return tr("Spectators");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServerInfo_Game &GamesModel::getGame(int row)
|
const ServerInfo_Game &GamesModel::getGame(int row)
|
||||||
{
|
{
|
||||||
Q_ASSERT(row < gameList.size());
|
Q_ASSERT(row < gameList.size());
|
||||||
return gameList[row];
|
return gameList[row];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesModel::updateGameList(const ServerInfo_Game &game)
|
void GamesModel::updateGameList(const ServerInfo_Game &game)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < gameList.size(); i++)
|
for (int i = 0; i < gameList.size(); i++)
|
||||||
if (gameList[i].game_id() == game.game_id()) {
|
if (gameList[i].game_id() == game.game_id()) {
|
||||||
if (game.closed()) {
|
if (game.closed()) {
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
gameList.removeAt(i);
|
gameList.removeAt(i);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
} else {
|
} else {
|
||||||
gameList[i].MergeFrom(game);
|
gameList[i].MergeFrom(game);
|
||||||
emit dataChanged(index(i, 0), index(i, 7));
|
emit dataChanged(index(i, 0), index(i, 7));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (game.player_count() <= 0)
|
if (game.player_count() <= 0)
|
||||||
return;
|
return;
|
||||||
beginInsertRows(QModelIndex(), gameList.size(), gameList.size());
|
beginInsertRows(QModelIndex(), gameList.size(), gameList.size());
|
||||||
gameList.append(game);
|
gameList.append(game);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
|
GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
|
||||||
: QSortFilterProxyModel(parent),
|
: QSortFilterProxyModel(parent),
|
||||||
ownUser(_ownUser),
|
ownUser(_ownUser),
|
||||||
unavailableGamesVisible(false),
|
unavailableGamesVisible(false),
|
||||||
maxPlayersFilterMin(-1),
|
maxPlayersFilterMin(-1),
|
||||||
maxPlayersFilterMax(-1)
|
maxPlayersFilterMax(-1)
|
||||||
{
|
{
|
||||||
setDynamicSortFilter(true);
|
setDynamicSortFilter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||||
{
|
{
|
||||||
unavailableGamesVisible = _unavailableGamesVisible;
|
unavailableGamesVisible = _unavailableGamesVisible;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible)
|
void GamesProxyModel::setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible)
|
||||||
{
|
{
|
||||||
passwordProtectedGamesVisible = _passwordProtectedGamesVisible;
|
passwordProtectedGamesVisible = _passwordProtectedGamesVisible;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setGameNameFilter(const QString &_gameNameFilter)
|
void GamesProxyModel::setGameNameFilter(const QString &_gameNameFilter)
|
||||||
{
|
{
|
||||||
gameNameFilter = _gameNameFilter;
|
gameNameFilter = _gameNameFilter;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setCreatorNameFilter(const QString &_creatorNameFilter)
|
void GamesProxyModel::setCreatorNameFilter(const QString &_creatorNameFilter)
|
||||||
{
|
{
|
||||||
creatorNameFilter = _creatorNameFilter;
|
creatorNameFilter = _creatorNameFilter;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
void GamesProxyModel::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
||||||
{
|
{
|
||||||
gameTypeFilter = _gameTypeFilter;
|
gameTypeFilter = _gameTypeFilter;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
void GamesProxyModel::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
||||||
{
|
{
|
||||||
maxPlayersFilterMin = _maxPlayersFilterMin;
|
maxPlayersFilterMin = _maxPlayersFilterMin;
|
||||||
maxPlayersFilterMax = _maxPlayersFilterMax;
|
maxPlayersFilterMax = _maxPlayersFilterMax;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesProxyModel::resetFilterParameters()
|
void GamesProxyModel::resetFilterParameters()
|
||||||
{
|
{
|
||||||
unavailableGamesVisible = false;
|
unavailableGamesVisible = false;
|
||||||
passwordProtectedGamesVisible = false;
|
passwordProtectedGamesVisible = false;
|
||||||
gameNameFilter = QString();
|
gameNameFilter = QString();
|
||||||
creatorNameFilter = QString();
|
creatorNameFilter = QString();
|
||||||
gameTypeFilter.clear();
|
gameTypeFilter.clear();
|
||||||
maxPlayersFilterMin = -1;
|
maxPlayersFilterMin = -1;
|
||||||
maxPlayersFilterMax = -1;
|
maxPlayersFilterMax = -1;
|
||||||
|
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const
|
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const
|
||||||
{
|
{
|
||||||
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
||||||
if (!model)
|
if (!model)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ServerInfo_Game &game = model->getGame(sourceRow);
|
const ServerInfo_Game &game = model->getGame(sourceRow);
|
||||||
if (!unavailableGamesVisible) {
|
if (!unavailableGamesVisible) {
|
||||||
if (game.player_count() == game.max_players())
|
if (game.player_count() == game.max_players())
|
||||||
return false;
|
return false;
|
||||||
if (game.started())
|
if (game.started())
|
||||||
return false;
|
return false;
|
||||||
if (!(ownUser->user_level() & ServerInfo_User::IsRegistered))
|
if (!(ownUser->user_level() & ServerInfo_User::IsRegistered))
|
||||||
if (game.only_registered())
|
if (game.only_registered())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!passwordProtectedGamesVisible && game.with_password())
|
if (!passwordProtectedGamesVisible && game.with_password())
|
||||||
return false;
|
return false;
|
||||||
if (!gameNameFilter.isEmpty())
|
if (!gameNameFilter.isEmpty())
|
||||||
if (!QString::fromStdString(game.description()).contains(gameNameFilter, Qt::CaseInsensitive))
|
if (!QString::fromStdString(game.description()).contains(gameNameFilter, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
if (!creatorNameFilter.isEmpty())
|
if (!creatorNameFilter.isEmpty())
|
||||||
if (!QString::fromStdString(game.creator_info().name()).contains(creatorNameFilter, Qt::CaseInsensitive))
|
if (!QString::fromStdString(game.creator_info().name()).contains(creatorNameFilter, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QSet<int> gameTypes;
|
QSet<int> gameTypes;
|
||||||
for (int i = 0; i < game.game_types_size(); ++i)
|
for (int i = 0; i < game.game_types_size(); ++i)
|
||||||
gameTypes.insert(game.game_types(i));
|
gameTypes.insert(game.game_types(i));
|
||||||
if (!gameTypeFilter.isEmpty() && gameTypes.intersect(gameTypeFilter).isEmpty())
|
if (!gameTypeFilter.isEmpty() && gameTypes.intersect(gameTypeFilter).isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((maxPlayersFilterMin != -1) && (game.max_players() < maxPlayersFilterMin))
|
if ((maxPlayersFilterMin != -1) && (game.max_players() < maxPlayersFilterMin))
|
||||||
return false;
|
return false;
|
||||||
if ((maxPlayersFilterMax != -1) && (game.max_players() > maxPlayersFilterMax))
|
if ((maxPlayersFilterMax != -1) && (game.max_players() > maxPlayersFilterMax))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,51 +11,51 @@
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
|
|
||||||
class GamesModel : public QAbstractTableModel {
|
class GamesModel : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QList<ServerInfo_Game> gameList;
|
QList<ServerInfo_Game> gameList;
|
||||||
QMap<int, QString> rooms;
|
QMap<int, QString> rooms;
|
||||||
QMap<int, GameTypeMap> gameTypes;
|
QMap<int, GameTypeMap> gameTypes;
|
||||||
public:
|
public:
|
||||||
GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent = 0);
|
GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent = 0);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
|
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 8; }
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 8; }
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
const ServerInfo_Game &getGame(int row);
|
const ServerInfo_Game &getGame(int row);
|
||||||
void updateGameList(const ServerInfo_Game &game);
|
void updateGameList(const ServerInfo_Game &game);
|
||||||
const QMap<int, GameTypeMap> &getGameTypes() { return gameTypes; }
|
const QMap<int, GameTypeMap> &getGameTypes() { return gameTypes; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class GamesProxyModel : public QSortFilterProxyModel {
|
class GamesProxyModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
ServerInfo_User *ownUser;
|
ServerInfo_User *ownUser;
|
||||||
bool unavailableGamesVisible;
|
bool unavailableGamesVisible;
|
||||||
bool passwordProtectedGamesVisible;
|
bool passwordProtectedGamesVisible;
|
||||||
QString gameNameFilter, creatorNameFilter;
|
QString gameNameFilter, creatorNameFilter;
|
||||||
QSet<int> gameTypeFilter;
|
QSet<int> gameTypeFilter;
|
||||||
int maxPlayersFilterMin, maxPlayersFilterMax;
|
int maxPlayersFilterMin, maxPlayersFilterMax;
|
||||||
public:
|
public:
|
||||||
GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
|
GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
|
||||||
|
|
||||||
bool getUnavailableGamesVisible() const { return unavailableGamesVisible; }
|
bool getUnavailableGamesVisible() const { return unavailableGamesVisible; }
|
||||||
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
||||||
bool getPasswordProtectedGamesVisible() const { return passwordProtectedGamesVisible; }
|
bool getPasswordProtectedGamesVisible() const { return passwordProtectedGamesVisible; }
|
||||||
void setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible);
|
void setPasswordProtectedGamesVisible(bool _passwordProtectedGamesVisible);
|
||||||
QString getGameNameFilter() const { return gameNameFilter; }
|
QString getGameNameFilter() const { return gameNameFilter; }
|
||||||
void setGameNameFilter(const QString &_gameNameFilter);
|
void setGameNameFilter(const QString &_gameNameFilter);
|
||||||
QString getCreatorNameFilter() const { return creatorNameFilter; }
|
QString getCreatorNameFilter() const { return creatorNameFilter; }
|
||||||
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
||||||
QSet<int> getGameTypeFilter() const { return gameTypeFilter; }
|
QSet<int> getGameTypeFilter() const { return gameTypeFilter; }
|
||||||
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
||||||
int getMaxPlayersFilterMin() const { return maxPlayersFilterMin; }
|
int getMaxPlayersFilterMin() const { return maxPlayersFilterMin; }
|
||||||
int getMaxPlayersFilterMax() const { return maxPlayersFilterMax; }
|
int getMaxPlayersFilterMax() const { return maxPlayersFilterMax; }
|
||||||
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
||||||
void resetFilterParameters();
|
void resetFilterParameters();
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,57 +5,57 @@
|
||||||
#include <QRubberBand>
|
#include <QRubberBand>
|
||||||
|
|
||||||
GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
||||||
: QGraphicsView(scene, parent), rubberBand(0)
|
: QGraphicsView(scene, parent), rubberBand(0)
|
||||||
{
|
{
|
||||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing);
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing);
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setViewportUpdateMode(BoundingRectViewportUpdate);
|
setViewportUpdateMode(BoundingRectViewportUpdate);
|
||||||
|
|
||||||
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
|
|
||||||
connect(scene, SIGNAL(sigStartRubberBand(const QPointF &)), this, SLOT(startRubberBand(const QPointF &)));
|
connect(scene, SIGNAL(sigStartRubberBand(const QPointF &)), this, SLOT(startRubberBand(const QPointF &)));
|
||||||
connect(scene, SIGNAL(sigResizeRubberBand(const QPointF &)), this, SLOT(resizeRubberBand(const QPointF &)));
|
connect(scene, SIGNAL(sigResizeRubberBand(const QPointF &)), this, SLOT(resizeRubberBand(const QPointF &)));
|
||||||
connect(scene, SIGNAL(sigStopRubberBand()), this, SLOT(stopRubberBand()));
|
connect(scene, SIGNAL(sigStopRubberBand()), this, SLOT(stopRubberBand()));
|
||||||
|
|
||||||
aCloseMostRecentZoneView = new QAction(this);
|
aCloseMostRecentZoneView = new QAction(this);
|
||||||
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
||||||
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView()));
|
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView()));
|
||||||
addAction(aCloseMostRecentZoneView);
|
addAction(aCloseMostRecentZoneView);
|
||||||
|
|
||||||
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::resizeEvent(QResizeEvent *event)
|
void GameView::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsView::resizeEvent(event);
|
QGraphicsView::resizeEvent(event);
|
||||||
|
|
||||||
GameScene *s = dynamic_cast<GameScene *>(scene());
|
GameScene *s = dynamic_cast<GameScene *>(scene());
|
||||||
if (s)
|
if (s)
|
||||||
s->processViewSizeChange(event->size());
|
s->processViewSizeChange(event->size());
|
||||||
|
|
||||||
updateSceneRect(scene()->sceneRect());
|
updateSceneRect(scene()->sceneRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::updateSceneRect(const QRectF &rect)
|
void GameView::updateSceneRect(const QRectF &rect)
|
||||||
{
|
{
|
||||||
fitInView(rect, Qt::KeepAspectRatio);
|
fitInView(rect, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::startRubberBand(const QPointF &_selectionOrigin)
|
void GameView::startRubberBand(const QPointF &_selectionOrigin)
|
||||||
{
|
{
|
||||||
selectionOrigin = _selectionOrigin;
|
selectionOrigin = _selectionOrigin;
|
||||||
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
|
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
|
||||||
rubberBand->show();
|
rubberBand->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::resizeRubberBand(const QPointF &cursorPoint)
|
void GameView::resizeRubberBand(const QPointF &cursorPoint)
|
||||||
{
|
{
|
||||||
if (rubberBand)
|
if (rubberBand)
|
||||||
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), cursorPoint.toPoint()).normalized());
|
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), cursorPoint.toPoint()).normalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::stopRubberBand()
|
void GameView::stopRubberBand()
|
||||||
{
|
{
|
||||||
rubberBand->hide();
|
rubberBand->hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
class QRubberBand;
|
class QRubberBand;
|
||||||
|
|
||||||
class GameView : public QGraphicsView {
|
class GameView : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QAction *aCloseMostRecentZoneView;
|
QAction *aCloseMostRecentZoneView;
|
||||||
QRubberBand *rubberBand;
|
QRubberBand *rubberBand;
|
||||||
QPointF selectionOrigin;
|
QPointF selectionOrigin;
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
private slots:
|
private slots:
|
||||||
void startRubberBand(const QPointF &selectionOrigin);
|
void startRubberBand(const QPointF &selectionOrigin);
|
||||||
void resizeRubberBand(const QPointF &cursorPoint);
|
void resizeRubberBand(const QPointF &cursorPoint);
|
||||||
void stopRubberBand();
|
void stopRubberBand();
|
||||||
public slots:
|
public slots:
|
||||||
void updateSceneRect(const QRectF &rect);
|
void updateSceneRect(const QRectF &rect);
|
||||||
public:
|
public:
|
||||||
GameView(QGraphicsScene *scene, QWidget *parent = 0);
|
GameView(QGraphicsScene *scene, QWidget *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
|
|
||||||
HandCounter::HandCounter(QGraphicsItem *parent)
|
HandCounter::HandCounter(QGraphicsItem *parent)
|
||||||
: AbstractGraphicsItem(parent), number(0)
|
: AbstractGraphicsItem(parent), number(0)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandCounter::~HandCounter()
|
HandCounter::~HandCounter()
|
||||||
|
@ -17,43 +17,43 @@ HandCounter::~HandCounter()
|
||||||
|
|
||||||
void HandCounter::updateNumber()
|
void HandCounter::updateNumber()
|
||||||
{
|
{
|
||||||
number = static_cast<CardZone *>(sender())->getCards().size();
|
number = static_cast<CardZone *>(sender())->getCards().size();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF HandCounter::boundingRect() const
|
QRectF HandCounter::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, 72, 72);
|
return QRectF(0, 0, 72, 72);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
QSize translatedSize = painter->combinedTransform().mapRect(boundingRect()).size().toSize();
|
QSize translatedSize = painter->combinedTransform().mapRect(boundingRect()).size().toSize();
|
||||||
QPixmap cachedPixmap;
|
QPixmap cachedPixmap;
|
||||||
#if QT_VERSION >= 0x040600
|
#if QT_VERSION >= 0x040600
|
||||||
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), &cachedPixmap)) {
|
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), &cachedPixmap)) {
|
||||||
#else
|
#else
|
||||||
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), cachedPixmap)) {
|
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), cachedPixmap)) {
|
||||||
#endif
|
#endif
|
||||||
QSvgRenderer svg(QString(":/resources/hand.svg"));
|
QSvgRenderer svg(QString(":/resources/hand.svg"));
|
||||||
cachedPixmap = QPixmap(translatedSize);
|
cachedPixmap = QPixmap(translatedSize);
|
||||||
cachedPixmap.fill(Qt::transparent);
|
cachedPixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&cachedPixmap);
|
QPainter painter(&cachedPixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, translatedSize.width(), translatedSize.height()));
|
svg.render(&painter, QRectF(0, 0, translatedSize.width(), translatedSize.height()));
|
||||||
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
|
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
|
||||||
}
|
}
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
|
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
paintNumberEllipse(number, 24, Qt::white, -1, -1, painter);
|
paintNumberEllipse(number, 24, Qt::white, -1, -1, painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void HandCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
emit showContextMenu(event->screenPos());
|
emit showContextMenu(event->screenPos());
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,22 +8,22 @@ class QPainter;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
|
|
||||||
class HandCounter : public AbstractGraphicsItem {
|
class HandCounter : public AbstractGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
int number;
|
int number;
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
public slots:
|
public slots:
|
||||||
void updateNumber();
|
void updateNumber();
|
||||||
signals:
|
signals:
|
||||||
void showContextMenu(const QPoint &screenPos);
|
void showContextMenu(const QPoint &screenPos);
|
||||||
public:
|
public:
|
||||||
enum { Type = typeOther };
|
enum { Type = typeOther };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
HandCounter(QGraphicsItem *parent = 0);
|
HandCounter(QGraphicsItem *parent = 0);
|
||||||
~HandCounter();
|
~HandCounter();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,137 +8,137 @@
|
||||||
#include "pb/command_move_card.pb.h"
|
#include "pb/command_move_card.pb.h"
|
||||||
|
|
||||||
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
|
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
|
||||||
: SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
|
: SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
|
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||||
updateBgPixmap();
|
updateBgPixmap();
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::updateBgPixmap()
|
void HandZone::updateBgPixmap()
|
||||||
{
|
{
|
||||||
QString bgPath = settingsCache->getHandBgPath();
|
QString bgPath = settingsCache->getHandBgPath();
|
||||||
if (!bgPath.isEmpty())
|
if (!bgPath.isEmpty())
|
||||||
bgPixmap.load(bgPath);
|
bgPixmap.load(bgPath);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
x = cards.size();
|
x = cards.size();
|
||||||
cards.insert(x, card);
|
cards.insert(x, card);
|
||||||
|
|
||||||
if (!cards.getContentsKnown()) {
|
if (!cards.getContentsKnown()) {
|
||||||
card->setId(-1);
|
card->setId(-1);
|
||||||
card->setName();
|
card->setName();
|
||||||
}
|
}
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setVisible(true);
|
card->setVisible(true);
|
||||||
card->update();
|
card->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint & dropPoint)
|
void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint & dropPoint)
|
||||||
{
|
{
|
||||||
QPoint point = dropPoint + scenePos().toPoint();
|
QPoint point = dropPoint + scenePos().toPoint();
|
||||||
int x = -1;
|
int x = -1;
|
||||||
if (settingsCache->getHorizontalHand()) {
|
if (settingsCache->getHorizontalHand()) {
|
||||||
for (x = 0; x < cards.size(); x++)
|
for (x = 0; x < cards.size(); x++)
|
||||||
if (point.x() < ((CardItem *) cards.at(x))->scenePos().x())
|
if (point.x() < ((CardItem *) cards.at(x))->scenePos().x())
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
for (x = 0; x < cards.size(); x++)
|
for (x = 0; x < cards.size(); x++)
|
||||||
if (point.y() < ((CardItem *) cards.at(x))->scenePos().y())
|
if (point.y() < ((CardItem *) cards.at(x))->scenePos().y())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_MoveCard cmd;
|
Command_MoveCard cmd;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
cmd.set_target_player_id(player->getId());
|
cmd.set_target_player_id(player->getId());
|
||||||
cmd.set_target_zone(getName().toStdString());
|
cmd.set_target_zone(getName().toStdString());
|
||||||
cmd.set_x(x);
|
cmd.set_x(x);
|
||||||
cmd.set_y(-1);
|
cmd.set_y(-1);
|
||||||
|
|
||||||
for (int i = 0; i < dragItems.size(); ++i)
|
for (int i = 0; i < dragItems.size(); ++i)
|
||||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
||||||
|
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF HandZone::boundingRect() const
|
QRectF HandZone::boundingRect() const
|
||||||
{
|
{
|
||||||
if (settingsCache->getHorizontalHand())
|
if (settingsCache->getHorizontalHand())
|
||||||
return QRectF(0, 0, width, CARD_HEIGHT + 10);
|
return QRectF(0, 0, width, CARD_HEIGHT + 10);
|
||||||
else
|
else
|
||||||
return QRectF(0, 0, 100, zoneHeight);
|
return QRectF(0, 0, 100, zoneHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
if (bgPixmap.isNull())
|
if (bgPixmap.isNull())
|
||||||
painter->fillRect(boundingRect(), Qt::darkGreen);
|
painter->fillRect(boundingRect(), Qt::darkGreen);
|
||||||
else
|
else
|
||||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::reorganizeCards()
|
void HandZone::reorganizeCards()
|
||||||
{
|
{
|
||||||
if (!cards.isEmpty()) {
|
if (!cards.isEmpty()) {
|
||||||
const int cardCount = cards.size();
|
const int cardCount = cards.size();
|
||||||
if (settingsCache->getHorizontalHand()) {
|
if (settingsCache->getHorizontalHand()) {
|
||||||
const int xPadding = 5;
|
const int xPadding = 5;
|
||||||
qreal totalWidth = boundingRect().width() - 2 * xPadding;
|
qreal totalWidth = boundingRect().width() - 2 * xPadding;
|
||||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||||
|
|
||||||
for (int i = 0; i < cardCount; i++) {
|
for (int i = 0; i < cardCount; i++) {
|
||||||
CardItem *c = cards.at(i);
|
CardItem *c = cards.at(i);
|
||||||
|
|
||||||
// If the total width of the cards is smaller than the available width,
|
// If the total width of the cards is smaller than the available width,
|
||||||
// the cards do not need to overlap and are displayed in the center of the area.
|
// the cards do not need to overlap and are displayed in the center of the area.
|
||||||
if (cardWidth * cardCount > totalWidth)
|
if (cardWidth * cardCount > totalWidth)
|
||||||
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
||||||
else
|
else
|
||||||
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
|
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
|
||||||
c->setRealZValue(i);
|
c->setRealZValue(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qreal totalWidth = boundingRect().width();
|
qreal totalWidth = boundingRect().width();
|
||||||
qreal totalHeight = boundingRect().height();
|
qreal totalHeight = boundingRect().height();
|
||||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||||
qreal cardHeight = cards.at(0)->boundingRect().height();
|
qreal cardHeight = cards.at(0)->boundingRect().height();
|
||||||
qreal xspace = 5;
|
qreal xspace = 5;
|
||||||
qreal x1 = xspace;
|
qreal x1 = xspace;
|
||||||
qreal x2 = totalWidth - xspace - cardWidth;
|
qreal x2 = totalWidth - xspace - cardWidth;
|
||||||
|
|
||||||
for (int i = 0; i < cardCount; i++) {
|
for (int i = 0; i < cardCount; i++) {
|
||||||
CardItem *c = cards.at(i);
|
CardItem *c = cards.at(i);
|
||||||
qreal x = i % 2 ? x2 : x1;
|
qreal x = i % 2 ? x2 : x1;
|
||||||
// If the total height of the cards is smaller than the available height,
|
// If the total height of the cards is smaller than the available height,
|
||||||
// the cards do not need to overlap and are displayed in the center of the area.
|
// the cards do not need to overlap and are displayed in the center of the area.
|
||||||
if (cardHeight * cardCount > totalHeight)
|
if (cardHeight * cardCount > totalHeight)
|
||||||
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
||||||
else
|
else
|
||||||
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
||||||
c->setRealZValue(i);
|
c->setRealZValue(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::setWidth(qreal _width)
|
void HandZone::setWidth(qreal _width)
|
||||||
{
|
{
|
||||||
if (settingsCache->getHorizontalHand()) {
|
if (settingsCache->getHorizontalHand()) {
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
width = _width;
|
width = _width;
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::updateOrientation()
|
void HandZone::updateOrientation()
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@
|
||||||
#include "selectzone.h"
|
#include "selectzone.h"
|
||||||
|
|
||||||
class HandZone : public SelectZone {
|
class HandZone : public SelectZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
qreal width, zoneHeight;
|
qreal width, zoneHeight;
|
||||||
QPixmap bgPixmap;
|
QPixmap bgPixmap;
|
||||||
private slots:
|
private slots:
|
||||||
void updateBgPixmap();
|
void updateBgPixmap();
|
||||||
public slots:
|
public slots:
|
||||||
void updateOrientation();
|
void updateOrientation();
|
||||||
public:
|
public:
|
||||||
HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
|
HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
|
||||||
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
|
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void setWidth(qreal _width);
|
void setWidth(qreal _width);
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
#include "pb/session_commands.pb.h"
|
#include "pb/session_commands.pb.h"
|
||||||
|
|
||||||
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent)
|
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent)
|
||||||
: AbstractClient(parent), lsi(_lsi)
|
: AbstractClient(parent), lsi(_lsi)
|
||||||
{
|
{
|
||||||
connect(lsi, SIGNAL(itemToClient(const ServerMessage &)), this, SLOT(itemFromServer(const ServerMessage &)));
|
connect(lsi, SIGNAL(itemToClient(const ServerMessage &)), this, SLOT(itemFromServer(const ServerMessage &)));
|
||||||
|
|
||||||
Command_Login loginCmd;
|
Command_Login loginCmd;
|
||||||
loginCmd.set_user_name(_playerName.toStdString());
|
loginCmd.set_user_name(_playerName.toStdString());
|
||||||
sendCommand(prepareSessionCommand(loginCmd));
|
sendCommand(prepareSessionCommand(loginCmd));
|
||||||
|
|
||||||
Command_JoinRoom joinCmd;
|
Command_JoinRoom joinCmd;
|
||||||
joinCmd.set_room_id(0);
|
joinCmd.set_room_id(0);
|
||||||
sendCommand(prepareSessionCommand(joinCmd));
|
sendCommand(prepareSessionCommand(joinCmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalClient::~LocalClient()
|
LocalClient::~LocalClient()
|
||||||
|
@ -23,10 +23,10 @@ LocalClient::~LocalClient()
|
||||||
|
|
||||||
void LocalClient::sendCommandContainer(const CommandContainer &cont)
|
void LocalClient::sendCommandContainer(const CommandContainer &cont)
|
||||||
{
|
{
|
||||||
lsi->itemFromClient(cont);
|
lsi->itemFromClient(cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalClient::itemFromServer(const ServerMessage &item)
|
void LocalClient::itemFromServer(const ServerMessage &item)
|
||||||
{
|
{
|
||||||
processProtocolItem(item);
|
processProtocolItem(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
class LocalServerInterface;
|
class LocalServerInterface;
|
||||||
|
|
||||||
class LocalClient : public AbstractClient {
|
class LocalClient : public AbstractClient {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
LocalServerInterface *lsi;
|
LocalServerInterface *lsi;
|
||||||
public:
|
public:
|
||||||
LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent = 0);
|
LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent = 0);
|
||||||
~LocalClient();
|
~LocalClient();
|
||||||
|
|
||||||
void sendCommandContainer(const CommandContainer &cont);
|
void sendCommandContainer(const CommandContainer &cont);
|
||||||
private slots:
|
private slots:
|
||||||
void itemFromServer(const ServerMessage &item);
|
void itemFromServer(const ServerMessage &item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,37 +3,37 @@
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
|
|
||||||
LocalServer::LocalServer(QObject *parent)
|
LocalServer::LocalServer(QObject *parent)
|
||||||
: Server(false, parent)
|
: Server(false, parent)
|
||||||
{
|
{
|
||||||
setDatabaseInterface(new LocalServer_DatabaseInterface(this));
|
setDatabaseInterface(new LocalServer_DatabaseInterface(this));
|
||||||
addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
|
addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalServer::~LocalServer()
|
LocalServer::~LocalServer()
|
||||||
{
|
{
|
||||||
prepareDestroy();
|
prepareDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalServerInterface *LocalServer::newConnection()
|
LocalServerInterface *LocalServer::newConnection()
|
||||||
{
|
{
|
||||||
LocalServerInterface *lsi = new LocalServerInterface(this, getDatabaseInterface());
|
LocalServerInterface *lsi = new LocalServerInterface(this, getDatabaseInterface());
|
||||||
addClient(lsi);
|
addClient(lsi);
|
||||||
return lsi;
|
return lsi;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
||||||
: Server_DatabaseInterface(_localServer), localServer(_localServer)
|
: Server_DatabaseInterface(_localServer), localServer(_localServer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User LocalServer_DatabaseInterface::getUserData(const QString &name, bool /*withId*/)
|
ServerInfo_User LocalServer_DatabaseInterface::getUserData(const QString &name, bool /*withId*/)
|
||||||
{
|
{
|
||||||
ServerInfo_User result;
|
ServerInfo_User result;
|
||||||
result.set_name(name.toStdString());
|
result.set_name(name.toStdString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthenticationResult LocalServer_DatabaseInterface::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft)
|
AuthenticationResult LocalServer_DatabaseInterface::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft)
|
||||||
{
|
{
|
||||||
return UnknownUser;
|
return UnknownUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,25 +8,25 @@ class LocalServerInterface;
|
||||||
|
|
||||||
class LocalServer : public Server
|
class LocalServer : public Server
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocalServer(QObject *parent = 0);
|
LocalServer(QObject *parent = 0);
|
||||||
~LocalServer();
|
~LocalServer();
|
||||||
|
|
||||||
LocalServerInterface *newConnection();
|
LocalServerInterface *newConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocalServer_DatabaseInterface : public Server_DatabaseInterface {
|
class LocalServer_DatabaseInterface : public Server_DatabaseInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
LocalServer *localServer;
|
LocalServer *localServer;
|
||||||
protected:
|
protected:
|
||||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||||
public:
|
public:
|
||||||
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
||||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
||||||
int getNextGameId() { return localServer->getNextLocalGameId(); }
|
int getNextGameId() { return localServer->getNextLocalGameId(); }
|
||||||
int getNextReplayId() { return -1; }
|
int getNextReplayId() { return -1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
LocalServerInterface::LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface)
|
LocalServerInterface::LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface)
|
||||||
: Server_ProtocolHandler(_server, _databaseInterface, _server)
|
: Server_ProtocolHandler(_server, _databaseInterface, _server)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@ LocalServerInterface::~LocalServerInterface()
|
||||||
|
|
||||||
void LocalServerInterface::transmitProtocolItem(const ServerMessage &item)
|
void LocalServerInterface::transmitProtocolItem(const ServerMessage &item)
|
||||||
{
|
{
|
||||||
emit itemToClient(item);
|
emit itemToClient(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalServerInterface::itemFromClient(const CommandContainer &item)
|
void LocalServerInterface::itemFromClient(const CommandContainer &item)
|
||||||
{
|
{
|
||||||
processCommandContainer(item);
|
processCommandContainer(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,17 @@ class LocalServer;
|
||||||
|
|
||||||
class LocalServerInterface : public Server_ProtocolHandler
|
class LocalServerInterface : public Server_ProtocolHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface);
|
LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface);
|
||||||
~LocalServerInterface();
|
~LocalServerInterface();
|
||||||
|
|
||||||
QString getAddress() const { return QString(); }
|
QString getAddress() const { return QString(); }
|
||||||
void transmitProtocolItem(const ServerMessage &item);
|
void transmitProtocolItem(const ServerMessage &item);
|
||||||
signals:
|
signals:
|
||||||
void itemToClient(const ServerMessage &item);
|
void itemToClient(const ServerMessage &item);
|
||||||
public slots:
|
public slots:
|
||||||
void itemFromClient(const CommandContainer &item);
|
void itemFromClient(const CommandContainer &item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,118 +56,118 @@ QString translationPath = QString();
|
||||||
|
|
||||||
void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
||||||
{
|
{
|
||||||
static FILE *f = NULL;
|
static FILE *f = NULL;
|
||||||
if (!f)
|
if (!f)
|
||||||
f = fopen("qdebug.txt", "w");
|
f = fopen("qdebug.txt", "w");
|
||||||
fprintf(f, "%s\n", msg);
|
fprintf(f, "%s\n", msg);
|
||||||
fflush(f);
|
fflush(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void installNewTranslator()
|
void installNewTranslator()
|
||||||
{
|
{
|
||||||
QString lang = settingsCache->getLang();
|
QString lang = settingsCache->getLang();
|
||||||
|
|
||||||
qtTranslator->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
qtTranslator->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||||
qApp->installTranslator(qtTranslator);
|
qApp->installTranslator(qtTranslator);
|
||||||
translator->load(translationPrefix + "_" + lang, translationPath);
|
translator->load(translationPrefix + "_" + lang, translationPath);
|
||||||
qApp->installTranslator(translator);
|
qApp->installTranslator(translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
if (app.arguments().contains("--debug-output"))
|
if (app.arguments().contains("--debug-output"))
|
||||||
qInstallMsgHandler(myMessageOutput);
|
qInstallMsgHandler(myMessageOutput);
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QDir baseDir(app.applicationDirPath());
|
QDir baseDir(app.applicationDirPath());
|
||||||
baseDir.cdUp();
|
baseDir.cdUp();
|
||||||
baseDir.cdUp();
|
baseDir.cdUp();
|
||||||
baseDir.cdUp();
|
baseDir.cdUp();
|
||||||
QDir pluginsDir = baseDir;
|
QDir pluginsDir = baseDir;
|
||||||
pluginsDir.cd("PlugIns");
|
pluginsDir.cd("PlugIns");
|
||||||
app.addLibraryPath(pluginsDir.absolutePath());
|
app.addLibraryPath(pluginsDir.absolutePath());
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
app.addLibraryPath(app.applicationDirPath() + "/plugins");
|
app.addLibraryPath(app.applicationDirPath() + "/plugins");
|
||||||
#endif
|
#endif
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("Cockatrice");
|
QCoreApplication::setOrganizationName("Cockatrice");
|
||||||
QCoreApplication::setOrganizationDomain("cockatrice.de");
|
QCoreApplication::setOrganizationDomain("cockatrice.de");
|
||||||
QCoreApplication::setApplicationName("Cockatrice");
|
QCoreApplication::setApplicationName("Cockatrice");
|
||||||
|
|
||||||
if (translationPath.isEmpty()) {
|
if (translationPath.isEmpty()) {
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QDir translationsDir = baseDir;
|
QDir translationsDir = baseDir;
|
||||||
translationsDir.cd("translations");
|
translationsDir.cd("translations");
|
||||||
translationPath = translationsDir.absolutePath();
|
translationPath = translationsDir.absolutePath();
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
translationPath = app.applicationDirPath() + "/translations";
|
translationPath = app.applicationDirPath() + "/translations";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rng = new RNG_SFMT;
|
rng = new RNG_SFMT;
|
||||||
settingsCache = new SettingsCache;
|
settingsCache = new SettingsCache;
|
||||||
db = new CardDatabase;
|
db = new CardDatabase;
|
||||||
|
|
||||||
qtTranslator = new QTranslator;
|
qtTranslator = new QTranslator;
|
||||||
translator = new QTranslator;
|
translator = new QTranslator;
|
||||||
installNewTranslator();
|
installNewTranslator();
|
||||||
|
|
||||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
bool startMainProgram = true;
|
bool startMainProgram = true;
|
||||||
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||||
if (!db->getLoadSuccess())
|
if (!db->getLoadSuccess())
|
||||||
if (db->loadCardDatabase(dataDir + "/cards.xml"))
|
if (db->loadCardDatabase(dataDir + "/cards.xml"))
|
||||||
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
|
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
|
||||||
if (settingsCache->getTokenDatabasePath().isEmpty())
|
if (settingsCache->getTokenDatabasePath().isEmpty())
|
||||||
settingsCache->setTokenDatabasePath(dataDir + "/tokens.xml");
|
settingsCache->setTokenDatabasePath(dataDir + "/tokens.xml");
|
||||||
if (!QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty()) {
|
if (!QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty()) {
|
||||||
QDir().mkpath(dataDir + "/decks");
|
QDir().mkpath(dataDir + "/decks");
|
||||||
settingsCache->setDeckPath(dataDir + "/decks");
|
settingsCache->setDeckPath(dataDir + "/decks");
|
||||||
}
|
}
|
||||||
if (!QDir(settingsCache->getReplaysPath()).exists() || settingsCache->getReplaysPath().isEmpty()) {
|
if (!QDir(settingsCache->getReplaysPath()).exists() || settingsCache->getReplaysPath().isEmpty()) {
|
||||||
QDir().mkpath(dataDir + "/replays");
|
QDir().mkpath(dataDir + "/replays");
|
||||||
settingsCache->setReplaysPath(dataDir + "/replays");
|
settingsCache->setReplaysPath(dataDir + "/replays");
|
||||||
}
|
}
|
||||||
if (!QDir(settingsCache->getPicsPath()).exists() || settingsCache->getPicsPath().isEmpty()) {
|
if (!QDir(settingsCache->getPicsPath()).exists() || settingsCache->getPicsPath().isEmpty()) {
|
||||||
QDir().mkpath(dataDir + "/pics");
|
QDir().mkpath(dataDir + "/pics");
|
||||||
settingsCache->setPicsPath(dataDir + "/pics");
|
settingsCache->setPicsPath(dataDir + "/pics");
|
||||||
}
|
}
|
||||||
if (!db->getLoadSuccess() || !QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty() || settingsCache->getPicsPath().isEmpty() || !QDir(settingsCache->getPicsPath()).exists()) {
|
if (!db->getLoadSuccess() || !QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty() || settingsCache->getPicsPath().isEmpty() || !QDir(settingsCache->getPicsPath()).exists()) {
|
||||||
DlgSettings dlgSettings;
|
DlgSettings dlgSettings;
|
||||||
dlgSettings.show();
|
dlgSettings.show();
|
||||||
app.exec();
|
app.exec();
|
||||||
startMainProgram = (db->getLoadSuccess() && QDir(settingsCache->getDeckPath()).exists() && !settingsCache->getDeckPath().isEmpty() && QDir(settingsCache->getPicsPath()).exists() && !settingsCache->getPicsPath().isEmpty());
|
startMainProgram = (db->getLoadSuccess() && QDir(settingsCache->getDeckPath()).exists() && !settingsCache->getDeckPath().isEmpty() && QDir(settingsCache->getPicsPath()).exists() && !settingsCache->getPicsPath().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startMainProgram) {
|
if (startMainProgram) {
|
||||||
qDebug("main(): starting main program");
|
qDebug("main(): starting main program");
|
||||||
soundEngine = new SoundEngine;
|
soundEngine = new SoundEngine;
|
||||||
qDebug("main(): SoundEngine constructor finished");
|
qDebug("main(): SoundEngine constructor finished");
|
||||||
|
|
||||||
MainWindow ui;
|
MainWindow ui;
|
||||||
qDebug("main(): MainWindow constructor finished");
|
qDebug("main(): MainWindow constructor finished");
|
||||||
|
|
||||||
QIcon icon(":/resources/appicon.svg");
|
QIcon icon(":/resources/appicon.svg");
|
||||||
ui.setWindowIcon(icon);
|
ui.setWindowIcon(icon);
|
||||||
|
|
||||||
ui.show();
|
ui.show();
|
||||||
qDebug("main(): ui.show() finished");
|
qDebug("main(): ui.show() finished");
|
||||||
|
|
||||||
app.exec();
|
app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Event loop finished, terminating...");
|
qDebug("Event loop finished, terminating...");
|
||||||
delete db;
|
delete db;
|
||||||
delete settingsCache;
|
delete settingsCache;
|
||||||
delete rng;
|
delete rng;
|
||||||
PingPixmapGenerator::clear();
|
PingPixmapGenerator::clear();
|
||||||
CountryPixmapGenerator::clear();
|
CountryPixmapGenerator::clear();
|
||||||
UserLevelPixmapGenerator::clear();
|
UserLevelPixmapGenerator::clear();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,81 +12,81 @@ class GameEventContext;
|
||||||
class CardItem;
|
class CardItem;
|
||||||
|
|
||||||
struct LogMoveCard {
|
struct LogMoveCard {
|
||||||
Player *player;
|
Player *player;
|
||||||
CardItem *card;
|
CardItem *card;
|
||||||
QString cardName;
|
QString cardName;
|
||||||
CardZone *startZone;
|
CardZone *startZone;
|
||||||
int oldX;
|
int oldX;
|
||||||
CardZone *targetZone;
|
CardZone *targetZone;
|
||||||
int newX;
|
int newX;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageLogWidget : public ChatView {
|
class MessageLogWidget : public ChatView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
enum MessageContext { MessageContext_None, MessageContext_MoveCard, MessageContext_Mulligan };
|
enum MessageContext { MessageContext_None, MessageContext_MoveCard, MessageContext_Mulligan };
|
||||||
|
|
||||||
QString sanitizeHtml(QString dirty) const;
|
QString sanitizeHtml(QString dirty) const;
|
||||||
QString cardLink(const QString &cardName) const;
|
QString cardLink(const QString &cardName) const;
|
||||||
bool isFemale(Player *player) const;
|
bool isFemale(Player *player) const;
|
||||||
bool userIsFemale() const;
|
bool userIsFemale() const;
|
||||||
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
||||||
MessageContext currentContext;
|
MessageContext currentContext;
|
||||||
|
|
||||||
QList<LogMoveCard> moveCardQueue;
|
QList<LogMoveCard> moveCardQueue;
|
||||||
QMap<CardItem *, QString> moveCardPT;
|
QMap<CardItem *, QString> moveCardPT;
|
||||||
QMap<CardItem *, bool> moveCardTapped;
|
QMap<CardItem *, bool> moveCardTapped;
|
||||||
|
|
||||||
Player *mulliganPlayer;
|
Player *mulliganPlayer;
|
||||||
int mulliganNumber;
|
int mulliganNumber;
|
||||||
public slots:
|
public slots:
|
||||||
void logGameJoined(int gameId);
|
void logGameJoined(int gameId);
|
||||||
void logReplayStarted(int gameId);
|
void logReplayStarted(int gameId);
|
||||||
void logJoin(Player *player);
|
void logJoin(Player *player);
|
||||||
void logLeave(Player *player);
|
void logLeave(Player *player);
|
||||||
void logGameClosed();
|
void logGameClosed();
|
||||||
void logKicked();
|
void logKicked();
|
||||||
void logJoinSpectator(QString name);
|
void logJoinSpectator(QString name);
|
||||||
void logLeaveSpectator(QString name);
|
void logLeaveSpectator(QString name);
|
||||||
void logDeckSelect(Player *player, QString deckHash);
|
void logDeckSelect(Player *player, QString deckHash);
|
||||||
void logReadyStart(Player *player);
|
void logReadyStart(Player *player);
|
||||||
void logNotReadyStart(Player *player);
|
void logNotReadyStart(Player *player);
|
||||||
void logSetSideboardLock(Player *player, bool locked);
|
void logSetSideboardLock(Player *player, bool locked);
|
||||||
void logConcede(Player *player);
|
void logConcede(Player *player);
|
||||||
void logGameStart();
|
void logGameStart();
|
||||||
void logConnectionStateChanged(Player *player, bool connectionState);
|
void logConnectionStateChanged(Player *player, bool connectionState);
|
||||||
void logSay(Player *player, QString message);
|
void logSay(Player *player, QString message);
|
||||||
void logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message);
|
void logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message);
|
||||||
void logShuffle(Player *player, CardZone *zone);
|
void logShuffle(Player *player, CardZone *zone);
|
||||||
void logRollDie(Player *player, int sides, int roll);
|
void logRollDie(Player *player, int sides, int roll);
|
||||||
void logDrawCards(Player *player, int number);
|
void logDrawCards(Player *player, int number);
|
||||||
void logUndoDraw(Player *player, QString cardName);
|
void logUndoDraw(Player *player, QString cardName);
|
||||||
void doMoveCard(LogMoveCard &attributes);
|
void doMoveCard(LogMoveCard &attributes);
|
||||||
void logMoveCard(Player *player, CardItem *card, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
|
void logMoveCard(Player *player, CardItem *card, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
|
||||||
void logMulligan(Player *player, int number);
|
void logMulligan(Player *player, int number);
|
||||||
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
||||||
void logDestroyCard(Player *player, QString cardName);
|
void logDestroyCard(Player *player, QString cardName);
|
||||||
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
||||||
void logUnattachCard(Player *player, QString cardName);
|
void logUnattachCard(Player *player, QString cardName);
|
||||||
void logCreateToken(Player *player, QString cardName, QString pt);
|
void logCreateToken(Player *player, QString cardName, QString pt);
|
||||||
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard, bool playerTarget);
|
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard, bool playerTarget);
|
||||||
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
||||||
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
||||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||||
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
||||||
void logSetPT(Player *player, CardItem *card, QString newPT);
|
void logSetPT(Player *player, CardItem *card, QString newPT);
|
||||||
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
||||||
void logDumpZone(Player *player, CardZone *zone, int numberCards);
|
void logDumpZone(Player *player, CardZone *zone, int numberCards);
|
||||||
void logStopDumpZone(Player *player, CardZone *zone);
|
void logStopDumpZone(Player *player, CardZone *zone);
|
||||||
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
|
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
|
||||||
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
||||||
void logSetActivePlayer(Player *player);
|
void logSetActivePlayer(Player *player);
|
||||||
void logSetActivePhase(int phase);
|
void logSetActivePhase(int phase);
|
||||||
void containerProcessingStarted(const GameEventContext &context);
|
void containerProcessingStarted(const GameEventContext &context);
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
public:
|
public:
|
||||||
void connectToPlayer(Player *player);
|
void connectToPlayer(Player *player);
|
||||||
MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = 0);
|
MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,26 +6,26 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
class PendingCommand : public QObject {
|
class PendingCommand : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void finished(const Response &response, const CommandContainer &commandContainer, const QVariant &extraData);
|
void finished(const Response &response, const CommandContainer &commandContainer, const QVariant &extraData);
|
||||||
void finished(Response::ResponseCode respCode);
|
void finished(Response::ResponseCode respCode);
|
||||||
private:
|
private:
|
||||||
CommandContainer commandContainer;
|
CommandContainer commandContainer;
|
||||||
QVariant extraData;
|
QVariant extraData;
|
||||||
int ticks;
|
int ticks;
|
||||||
public:
|
public:
|
||||||
PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData = QVariant())
|
PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData = QVariant())
|
||||||
: commandContainer(_commandContainer), extraData(_extraData), ticks(0) { }
|
: commandContainer(_commandContainer), extraData(_extraData), ticks(0) { }
|
||||||
CommandContainer &getCommandContainer() { return commandContainer; }
|
CommandContainer &getCommandContainer() { return commandContainer; }
|
||||||
void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
|
void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
|
||||||
QVariant getExtraData() const { return extraData; }
|
QVariant getExtraData() const { return extraData; }
|
||||||
void processResponse(const Response &response)
|
void processResponse(const Response &response)
|
||||||
{
|
{
|
||||||
emit finished(response, commandContainer, extraData);
|
emit finished(response, commandContainer, extraData);
|
||||||
emit finished(response.response_code());
|
emit finished(response.response_code());
|
||||||
}
|
}
|
||||||
int tick() { return ++ticks; }
|
int tick() { return ++ticks; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,239 +13,239 @@
|
||||||
#include "pb/command_draw_cards.pb.h"
|
#include "pb/command_draw_cards.pb.h"
|
||||||
|
|
||||||
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
|
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
|
||||||
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), width(50)
|
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), width(50)
|
||||||
{
|
{
|
||||||
if (highlightable) {
|
if (highlightable) {
|
||||||
activeAnimationTimer = new QTimer(this);
|
activeAnimationTimer = new QTimer(this);
|
||||||
connect(activeAnimationTimer, SIGNAL(timeout()), this, SLOT(updateAnimation()));
|
connect(activeAnimationTimer, SIGNAL(timeout()), this, SLOT(updateAnimation()));
|
||||||
activeAnimationTimer->setSingleShot(false);
|
activeAnimationTimer->setSingleShot(false);
|
||||||
} else
|
} else
|
||||||
activeAnimationCounter = 9.0;
|
activeAnimationCounter = 9.0;
|
||||||
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PhaseButton::boundingRect() const
|
QRectF PhaseButton::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, width, width);
|
return QRectF(0, 0, width, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
QRectF iconRect = boundingRect().adjusted(3, 3, -3, -3);
|
QRectF iconRect = boundingRect().adjusted(3, 3, -3, -3);
|
||||||
QRectF translatedIconRect = painter->combinedTransform().mapRect(iconRect);
|
QRectF translatedIconRect = painter->combinedTransform().mapRect(iconRect);
|
||||||
qreal scaleFactor = translatedIconRect.width() / iconRect.width();
|
qreal scaleFactor = translatedIconRect.width() / iconRect.width();
|
||||||
QPixmap iconPixmap = PhasePixmapGenerator::generatePixmap(round(translatedIconRect.height()), name);
|
QPixmap iconPixmap = PhasePixmapGenerator::generatePixmap(round(translatedIconRect.height()), name);
|
||||||
|
|
||||||
painter->setBrush(QColor(220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0)));
|
painter->setBrush(QColor(220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0)));
|
||||||
painter->setPen(Qt::gray);
|
painter->setPen(Qt::gray);
|
||||||
painter->drawRect(0, 0, width - 1, width - 1);
|
painter->drawRect(0, 0, width - 1, width - 1);
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
painter->drawPixmap(iconPixmap.rect().translated(round(3 * scaleFactor), round(3 * scaleFactor)), iconPixmap, iconPixmap.rect());
|
painter->drawPixmap(iconPixmap.rect().translated(round(3 * scaleFactor), round(3 * scaleFactor)), iconPixmap, iconPixmap.rect());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
painter->setBrush(QColor(0, 0, 0, 255 * ((10 - activeAnimationCounter) / 15.0)));
|
painter->setBrush(QColor(0, 0, 0, 255 * ((10 - activeAnimationCounter) / 15.0)));
|
||||||
painter->setPen(Qt::gray);
|
painter->setPen(Qt::gray);
|
||||||
painter->drawRect(0, 0, width - 1, width - 1);
|
painter->drawRect(0, 0, width - 1, width - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::setWidth(double _width)
|
void PhaseButton::setWidth(double _width)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
width = _width;
|
width = _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::setActive(bool _active)
|
void PhaseButton::setActive(bool _active)
|
||||||
{
|
{
|
||||||
if ((active == _active) || !highlightable)
|
if ((active == _active) || !highlightable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
active = _active;
|
active = _active;
|
||||||
activeAnimationTimer->start(50);
|
activeAnimationTimer->start(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::updateAnimation()
|
void PhaseButton::updateAnimation()
|
||||||
{
|
{
|
||||||
if (!highlightable)
|
if (!highlightable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
if (++activeAnimationCounter >= 10)
|
if (++activeAnimationCounter >= 10)
|
||||||
activeAnimationTimer->stop();
|
activeAnimationTimer->stop();
|
||||||
} else {
|
} else {
|
||||||
if (--activeAnimationCounter <= 0)
|
if (--activeAnimationCounter <= 0)
|
||||||
activeAnimationTimer->stop();
|
activeAnimationTimer->stop();
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::mousePressEvent(QGraphicsSceneMouseEvent * /*event*/)
|
void PhaseButton::mousePressEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||||
{
|
{
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
|
void PhaseButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||||
{
|
{
|
||||||
triggerDoubleClickAction();
|
triggerDoubleClickAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhaseButton::triggerDoubleClickAction()
|
void PhaseButton::triggerDoubleClickAction()
|
||||||
{
|
{
|
||||||
if (doubleClickAction)
|
if (doubleClickAction)
|
||||||
doubleClickAction->trigger();
|
doubleClickAction->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), width(100), height(100)
|
: QGraphicsItem(parent), width(100), height(100)
|
||||||
{
|
{
|
||||||
QAction *aUntapAll = new QAction(this);
|
QAction *aUntapAll = new QAction(this);
|
||||||
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
|
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
|
||||||
QAction *aDrawCard = new QAction(this);
|
QAction *aDrawCard = new QAction(this);
|
||||||
connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard()));
|
connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard()));
|
||||||
|
|
||||||
PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll);
|
PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll);
|
||||||
PhaseButton *upkeepButton = new PhaseButton("upkeep", this);
|
PhaseButton *upkeepButton = new PhaseButton("upkeep", this);
|
||||||
PhaseButton *drawButton = new PhaseButton("draw", this, aDrawCard);
|
PhaseButton *drawButton = new PhaseButton("draw", this, aDrawCard);
|
||||||
PhaseButton *main1Button = new PhaseButton("main1", this);
|
PhaseButton *main1Button = new PhaseButton("main1", this);
|
||||||
PhaseButton *combatStartButton = new PhaseButton("combat_start", this);
|
PhaseButton *combatStartButton = new PhaseButton("combat_start", this);
|
||||||
PhaseButton *combatAttackersButton = new PhaseButton("combat_attackers", this);
|
PhaseButton *combatAttackersButton = new PhaseButton("combat_attackers", this);
|
||||||
PhaseButton *combatBlockersButton = new PhaseButton("combat_blockers", this);
|
PhaseButton *combatBlockersButton = new PhaseButton("combat_blockers", this);
|
||||||
PhaseButton *combatDamageButton = new PhaseButton("combat_damage", this);
|
PhaseButton *combatDamageButton = new PhaseButton("combat_damage", this);
|
||||||
PhaseButton *combatEndButton = new PhaseButton("combat_end", this);
|
PhaseButton *combatEndButton = new PhaseButton("combat_end", this);
|
||||||
PhaseButton *main2Button = new PhaseButton("main2", this);
|
PhaseButton *main2Button = new PhaseButton("main2", this);
|
||||||
PhaseButton *cleanupButton = new PhaseButton("cleanup", this);
|
PhaseButton *cleanupButton = new PhaseButton("cleanup", this);
|
||||||
|
|
||||||
buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton
|
buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton
|
||||||
<< combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton
|
<< combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton
|
||||||
<< main2Button << cleanupButton;
|
<< main2Button << cleanupButton;
|
||||||
|
|
||||||
for (int i = 0; i < buttonList.size(); ++i)
|
for (int i = 0; i < buttonList.size(); ++i)
|
||||||
connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked()));
|
connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked()));
|
||||||
|
|
||||||
nextTurnButton = new PhaseButton("nextturn", this, 0, false);
|
nextTurnButton = new PhaseButton("nextturn", this, 0, false);
|
||||||
connect(nextTurnButton, SIGNAL(clicked()), this, SLOT(actNextTurn()));
|
connect(nextTurnButton, SIGNAL(clicked()), this, SLOT(actNextTurn()));
|
||||||
|
|
||||||
rearrangeButtons();
|
rearrangeButtons();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PhasesToolbar::boundingRect() const
|
QRectF PhasesToolbar::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, width, height);
|
return QRectF(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::retranslateUi()
|
void PhasesToolbar::retranslateUi()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buttonList.size(); ++i)
|
for (int i = 0; i < buttonList.size(); ++i)
|
||||||
buttonList[i]->setToolTip(getLongPhaseName(i));
|
buttonList[i]->setToolTip(getLongPhaseName(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PhasesToolbar::getLongPhaseName(int phase) const
|
QString PhasesToolbar::getLongPhaseName(int phase) const
|
||||||
{
|
{
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
case 0: return tr("Untap step");
|
case 0: return tr("Untap step");
|
||||||
case 1: return tr("Upkeep step");
|
case 1: return tr("Upkeep step");
|
||||||
case 2: return tr("Draw step");
|
case 2: return tr("Draw step");
|
||||||
case 3: return tr("First main phase");
|
case 3: return tr("First main phase");
|
||||||
case 4: return tr("Beginning of combat step");
|
case 4: return tr("Beginning of combat step");
|
||||||
case 5: return tr("Declare attackers step");
|
case 5: return tr("Declare attackers step");
|
||||||
case 6: return tr("Declare blockers step");
|
case 6: return tr("Declare blockers step");
|
||||||
case 7: return tr("Combat damage step");
|
case 7: return tr("Combat damage step");
|
||||||
case 8: return tr("End of combat step");
|
case 8: return tr("End of combat step");
|
||||||
case 9: return tr("Second main phase");
|
case 9: return tr("Second main phase");
|
||||||
case 10: return tr("End of turn step");
|
case 10: return tr("End of turn step");
|
||||||
default: return QString();
|
default: return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PhasesToolbar::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
painter->fillRect(boundingRect(), QColor(50, 50, 50));
|
painter->fillRect(boundingRect(), QColor(50, 50, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
const double PhasesToolbar::marginSize = 3;
|
const double PhasesToolbar::marginSize = 3;
|
||||||
|
|
||||||
void PhasesToolbar::rearrangeButtons()
|
void PhasesToolbar::rearrangeButtons()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buttonList.size(); ++i)
|
for (int i = 0; i < buttonList.size(); ++i)
|
||||||
buttonList[i]->setWidth(symbolSize);
|
buttonList[i]->setWidth(symbolSize);
|
||||||
nextTurnButton->setWidth(symbolSize);
|
nextTurnButton->setWidth(symbolSize);
|
||||||
|
|
||||||
double y = marginSize;
|
double y = marginSize;
|
||||||
buttonList[0]->setPos(marginSize, y);
|
buttonList[0]->setPos(marginSize, y);
|
||||||
buttonList[1]->setPos(marginSize, y += symbolSize);
|
buttonList[1]->setPos(marginSize, y += symbolSize);
|
||||||
buttonList[2]->setPos(marginSize, y += symbolSize);
|
buttonList[2]->setPos(marginSize, y += symbolSize);
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
buttonList[3]->setPos(marginSize, y += symbolSize);
|
buttonList[3]->setPos(marginSize, y += symbolSize);
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
buttonList[4]->setPos(marginSize, y += symbolSize);
|
buttonList[4]->setPos(marginSize, y += symbolSize);
|
||||||
buttonList[5]->setPos(marginSize, y += symbolSize);
|
buttonList[5]->setPos(marginSize, y += symbolSize);
|
||||||
buttonList[6]->setPos(marginSize, y += symbolSize);
|
buttonList[6]->setPos(marginSize, y += symbolSize);
|
||||||
buttonList[7]->setPos(marginSize, y += symbolSize);
|
buttonList[7]->setPos(marginSize, y += symbolSize);
|
||||||
buttonList[8]->setPos(marginSize, y += symbolSize);
|
buttonList[8]->setPos(marginSize, y += symbolSize);
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
buttonList[9]->setPos(marginSize, y += symbolSize);
|
buttonList[9]->setPos(marginSize, y += symbolSize);
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
buttonList[10]->setPos(marginSize, y += symbolSize);
|
buttonList[10]->setPos(marginSize, y += symbolSize);
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
y += ySpacing;
|
y += ySpacing;
|
||||||
nextTurnButton->setPos(marginSize, y += symbolSize);
|
nextTurnButton->setPos(marginSize, y += symbolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::setHeight(double _height)
|
void PhasesToolbar::setHeight(double _height)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
|
||||||
height = _height;
|
height = _height;
|
||||||
ySpacing = (height - 2 * marginSize) / (buttonCount * 5 + spaceCount);
|
ySpacing = (height - 2 * marginSize) / (buttonCount * 5 + spaceCount);
|
||||||
symbolSize = ySpacing * 5;
|
symbolSize = ySpacing * 5;
|
||||||
width = symbolSize + 2 * marginSize;
|
width = symbolSize + 2 * marginSize;
|
||||||
|
|
||||||
rearrangeButtons();
|
rearrangeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::setActivePhase(int phase)
|
void PhasesToolbar::setActivePhase(int phase)
|
||||||
{
|
{
|
||||||
if (phase >= buttonList.size())
|
if (phase >= buttonList.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < buttonList.size(); ++i)
|
for (int i = 0; i < buttonList.size(); ++i)
|
||||||
buttonList[i]->setActive(i == phase);
|
buttonList[i]->setActive(i == phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::phaseButtonClicked()
|
void PhasesToolbar::phaseButtonClicked()
|
||||||
{
|
{
|
||||||
PhaseButton *button = qobject_cast<PhaseButton *>(sender());
|
PhaseButton *button = qobject_cast<PhaseButton *>(sender());
|
||||||
if (button->getActive())
|
if (button->getActive())
|
||||||
button->triggerDoubleClickAction();
|
button->triggerDoubleClickAction();
|
||||||
|
|
||||||
Command_SetActivePhase cmd;
|
Command_SetActivePhase cmd;
|
||||||
cmd.set_phase(buttonList.indexOf(button));
|
cmd.set_phase(buttonList.indexOf(button));
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
emit sendGameCommand(cmd, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::actNextTurn()
|
void PhasesToolbar::actNextTurn()
|
||||||
{
|
{
|
||||||
emit sendGameCommand(Command_NextTurn(), -1);
|
emit sendGameCommand(Command_NextTurn(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::actUntapAll()
|
void PhasesToolbar::actUntapAll()
|
||||||
{
|
{
|
||||||
Command_SetCardAttr cmd;
|
Command_SetCardAttr cmd;
|
||||||
cmd.set_zone("table");
|
cmd.set_zone("table");
|
||||||
cmd.set_attribute(AttrTapped);
|
cmd.set_attribute(AttrTapped);
|
||||||
cmd.set_attr_value("0");
|
cmd.set_attr_value("0");
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
emit sendGameCommand(cmd, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhasesToolbar::actDrawCard()
|
void PhasesToolbar::actDrawCard()
|
||||||
{
|
{
|
||||||
Command_DrawCards cmd;
|
Command_DrawCards cmd;
|
||||||
cmd.set_number(1);
|
cmd.set_number(1);
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
emit sendGameCommand(cmd, -1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,62 +10,62 @@ class Player;
|
||||||
class GameCommand;
|
class GameCommand;
|
||||||
|
|
||||||
class PhaseButton : public QObject, public QGraphicsItem {
|
class PhaseButton : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
bool active, highlightable;
|
bool active, highlightable;
|
||||||
int activeAnimationCounter;
|
int activeAnimationCounter;
|
||||||
QTimer *activeAnimationTimer;
|
QTimer *activeAnimationTimer;
|
||||||
QAction *doubleClickAction;
|
QAction *doubleClickAction;
|
||||||
double width;
|
double width;
|
||||||
|
|
||||||
void updatePixmap(QPixmap &pixmap);
|
void updatePixmap(QPixmap &pixmap);
|
||||||
private slots:
|
private slots:
|
||||||
void updateAnimation();
|
void updateAnimation();
|
||||||
public:
|
public:
|
||||||
PhaseButton(const QString &_name, QGraphicsItem *parent = 0, QAction *_doubleClickAction = 0, bool _highlightable = true);
|
PhaseButton(const QString &_name, QGraphicsItem *parent = 0, QAction *_doubleClickAction = 0, bool _highlightable = true);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void setWidth(double _width);
|
void setWidth(double _width);
|
||||||
void setActive(bool _active);
|
void setActive(bool _active);
|
||||||
bool getActive() const { return active; }
|
bool getActive() const { return active; }
|
||||||
void triggerDoubleClickAction();
|
void triggerDoubleClickAction();
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PhasesToolbar : public QObject, public QGraphicsItem {
|
class PhasesToolbar : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QList<PhaseButton *> buttonList;
|
QList<PhaseButton *> buttonList;
|
||||||
PhaseButton *nextTurnButton;
|
PhaseButton *nextTurnButton;
|
||||||
double width, height, ySpacing, symbolSize;
|
double width, height, ySpacing, symbolSize;
|
||||||
static const int buttonCount = 12;
|
static const int buttonCount = 12;
|
||||||
static const int spaceCount = 6;
|
static const int spaceCount = 6;
|
||||||
static const double marginSize;
|
static const double marginSize;
|
||||||
void rearrangeButtons();
|
void rearrangeButtons();
|
||||||
public:
|
public:
|
||||||
PhasesToolbar(QGraphicsItem *parent = 0);
|
PhasesToolbar(QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void setHeight(double _height);
|
void setHeight(double _height);
|
||||||
double getWidth() const { return width; }
|
double getWidth() const { return width; }
|
||||||
int phaseCount() const { return buttonList.size(); }
|
int phaseCount() const { return buttonList.size(); }
|
||||||
QString getLongPhaseName(int phase) const;
|
QString getLongPhaseName(int phase) const;
|
||||||
public slots:
|
public slots:
|
||||||
void setActivePhase(int phase);
|
void setActivePhase(int phase);
|
||||||
private slots:
|
private slots:
|
||||||
void phaseButtonClicked();
|
void phaseButtonClicked();
|
||||||
void actNextTurn();
|
void actNextTurn();
|
||||||
void actUntapAll();
|
void actUntapAll();
|
||||||
void actDrawCard();
|
void actDrawCard();
|
||||||
signals:
|
signals:
|
||||||
void sendGameCommand(const ::google::protobuf::Message &command, int playerId);
|
void sendGameCommand(const ::google::protobuf::Message &command, int playerId);
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,109 +10,109 @@
|
||||||
#include "pb/command_move_card.pb.h"
|
#include "pb/command_move_card.pb.h"
|
||||||
|
|
||||||
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
||||||
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PileZone::boundingRect() const
|
QRectF PileZone::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
if (!cards.isEmpty())
|
if (!cards.isEmpty())
|
||||||
cards.at(0)->paintPicture(painter, cards.at(0)->getTranslatedSize(painter), 90);
|
cards.at(0)->paintPicture(painter, cards.at(0)->getTranslatedSize(painter), 90);
|
||||||
|
|
||||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||||
|
|
||||||
painter->translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2);
|
painter->translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2);
|
||||||
painter->rotate(-90);
|
painter->rotate(-90);
|
||||||
painter->translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2);
|
painter->translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2);
|
||||||
paintNumberEllipse(cards.size(), 28, Qt::white, -1, -1, painter);
|
paintNumberEllipse(cards.size(), 28, Qt::white, -1, -1, painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
connect(card, SIGNAL(sigPixmapUpdated()), this, SLOT(callUpdate()));
|
connect(card, SIGNAL(sigPixmapUpdated()), this, SLOT(callUpdate()));
|
||||||
cards.insert(x, card);
|
cards.insert(x, card);
|
||||||
card->setPos(0, 0);
|
card->setPos(0, 0);
|
||||||
if (!contentsKnown()) {
|
if (!contentsKnown()) {
|
||||||
card->setName(QString());
|
card->setName(QString());
|
||||||
card->setId(-1);
|
card->setId(-1);
|
||||||
// If we obscure a previously revealed card, its name has to be forgotten
|
// If we obscure a previously revealed card, its name has to be forgotten
|
||||||
if (cards.size() > x + 1)
|
if (cards.size() > x + 1)
|
||||||
cards.at(x + 1)->setName(QString());
|
cards.at(x + 1)->setName(QString());
|
||||||
}
|
}
|
||||||
card->setVisible(false);
|
card->setVisible(false);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
|
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
|
||||||
{
|
{
|
||||||
Command_MoveCard cmd;
|
Command_MoveCard cmd;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
cmd.set_target_player_id(player->getId());
|
cmd.set_target_player_id(player->getId());
|
||||||
cmd.set_target_zone(getName().toStdString());
|
cmd.set_target_zone(getName().toStdString());
|
||||||
cmd.set_x(0);
|
cmd.set_x(0);
|
||||||
cmd.set_y(0);
|
cmd.set_y(0);
|
||||||
|
|
||||||
for (int i = 0; i < dragItems.size(); ++i)
|
for (int i = 0; i < dragItems.size(); ++i)
|
||||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
||||||
|
|
||||||
player->sendGameCommand(cmd);
|
player->sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::reorganizeCards()
|
void PileZone::reorganizeCards()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PileZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
CardZone::mousePressEvent(event);
|
CardZone::mousePressEvent(event);
|
||||||
if (event->isAccepted())
|
if (event->isAccepted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
event->accept();
|
event->accept();
|
||||||
} else
|
} else
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cards.isEmpty())
|
if (cards.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||||
bool bottomCard = event->modifiers().testFlag(Qt::ControlModifier);
|
bool bottomCard = event->modifiers().testFlag(Qt::ControlModifier);
|
||||||
CardItem *card = bottomCard ? cards.last() : cards.first();
|
CardItem *card = bottomCard ? cards.last() : cards.first();
|
||||||
const int cardid = contentsKnown() ? card->getId() : (bottomCard ? cards.size() - 1 : 0);
|
const int cardid = contentsKnown() ? card->getId() : (bottomCard ? cards.size() - 1 : 0);
|
||||||
CardDragItem *drag = card->createDragItem(cardid, event->pos(), event->scenePos(), faceDown);
|
CardDragItem *drag = card->createDragItem(cardid, event->pos(), event->scenePos(), faceDown);
|
||||||
drag->grabMouse();
|
drag->grabMouse();
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (!cards.isEmpty())
|
if (!cards.isEmpty())
|
||||||
cards[0]->processHoverEvent();
|
cards[0]->processHoverEvent();
|
||||||
QGraphicsItem::hoverEnterEvent(event);
|
QGraphicsItem::hoverEnterEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,21 +4,21 @@
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
|
|
||||||
class PileZone : public CardZone {
|
class PileZone : public CardZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void callUpdate() { update(); }
|
void callUpdate() { update(); }
|
||||||
public:
|
public:
|
||||||
PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0);
|
PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
|
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,152 +9,152 @@ QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name)
|
QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name)
|
||||||
{
|
{
|
||||||
QString key = name + QString::number(height);
|
QString key = name + QString::number(height);
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QSvgRenderer svg(QString(":/resources/phases/icon_phase_" + name + ".svg"));
|
QSvgRenderer svg(QString(":/resources/phases/icon_phase_" + name + ".svg"));
|
||||||
|
|
||||||
QPixmap pixmap(height, height);
|
QPixmap pixmap(height, height);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, height, height));
|
svg.render(&painter, QRectF(0, 0, height, height));
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QPixmap> CounterPixmapGenerator::pmCache;
|
QMap<QString, QPixmap> CounterPixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool highlight)
|
QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool highlight)
|
||||||
{
|
{
|
||||||
if (highlight)
|
if (highlight)
|
||||||
name.append("_highlight");
|
name.append("_highlight");
|
||||||
QString key = name + QString::number(height);
|
QString key = name + QString::number(height);
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QSvgRenderer svg(QString(":/resources/counters/" + name + ".svg"));
|
QSvgRenderer svg(QString(":/resources/counters/" + name + ".svg"));
|
||||||
|
|
||||||
if (!svg.isValid()) {
|
if (!svg.isValid()) {
|
||||||
name = "general";
|
name = "general";
|
||||||
if (highlight)
|
if (highlight)
|
||||||
name.append("_highlight");
|
name.append("_highlight");
|
||||||
svg.load(QString(":/resources/counters/" + name + ".svg"));
|
svg.load(QString(":/resources/counters/" + name + ".svg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
||||||
QPixmap pixmap(width, height);
|
QPixmap pixmap(width, height);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, width, height));
|
svg.render(&painter, QRectF(0, 0, width, height));
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
|
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
|
||||||
{
|
{
|
||||||
int key = size * 1000000 + max * 1000 + value;
|
int key = size * 1000000 + max * 1000 + value;
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QPixmap pixmap(size, size);
|
QPixmap pixmap(size, size);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
QColor color;
|
QColor color;
|
||||||
if ((max == -1) || (value == -1))
|
if ((max == -1) || (value == -1))
|
||||||
color = Qt::black;
|
color = Qt::black;
|
||||||
else
|
else
|
||||||
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
|
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
|
||||||
|
|
||||||
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
|
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
|
||||||
g.setColorAt(0, color);
|
g.setColorAt(0, color);
|
||||||
g.setColorAt(1, Qt::transparent);
|
g.setColorAt(1, Qt::transparent);
|
||||||
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
|
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QPixmap> PingPixmapGenerator::pmCache;
|
QMap<int, QPixmap> PingPixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap GenderPixmapGenerator::generatePixmap(int height, int _gender)
|
QPixmap GenderPixmapGenerator::generatePixmap(int height, int _gender)
|
||||||
{
|
{
|
||||||
ServerInfo_User::Gender gender = static_cast<ServerInfo_User::Gender>(_gender);
|
ServerInfo_User::Gender gender = static_cast<ServerInfo_User::Gender>(_gender);
|
||||||
if ((gender != ServerInfo_User::Male) && (gender != ServerInfo_User::Female))
|
if ((gender != ServerInfo_User::Male) && (gender != ServerInfo_User::Female))
|
||||||
gender = ServerInfo_User::GenderUnknown;
|
gender = ServerInfo_User::GenderUnknown;
|
||||||
|
|
||||||
int key = gender * 100000 + height;
|
int key = gender * 100000 + height;
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QString genderStr;
|
QString genderStr;
|
||||||
switch (gender) {
|
switch (gender) {
|
||||||
case ServerInfo_User::Male: genderStr = "male"; break;
|
case ServerInfo_User::Male: genderStr = "male"; break;
|
||||||
case ServerInfo_User::Female: genderStr = "female"; break;
|
case ServerInfo_User::Female: genderStr = "female"; break;
|
||||||
default: genderStr = "unknown";
|
default: genderStr = "unknown";
|
||||||
};
|
};
|
||||||
|
|
||||||
QSvgRenderer svg(QString(":/resources/genders/" + genderStr + ".svg"));
|
QSvgRenderer svg(QString(":/resources/genders/" + genderStr + ".svg"));
|
||||||
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
||||||
QPixmap pixmap(width, height);
|
QPixmap pixmap(width, height);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, width, height));
|
svg.render(&painter, QRectF(0, 0, width, height));
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QPixmap> GenderPixmapGenerator::pmCache;
|
QMap<int, QPixmap> GenderPixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countryCode)
|
QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countryCode)
|
||||||
{
|
{
|
||||||
if (countryCode.size() != 2)
|
if (countryCode.size() != 2)
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
QString key = countryCode + QString::number(height);
|
QString key = countryCode + QString::number(height);
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QSvgRenderer svg(QString(":/resources/countries/" + countryCode + ".svg"));
|
QSvgRenderer svg(QString(":/resources/countries/" + countryCode + ".svg"));
|
||||||
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
||||||
QPixmap pixmap(width, height);
|
QPixmap pixmap(width, height);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, width, height));
|
svg.render(&painter, QRectF(0, 0, width, height));
|
||||||
painter.setPen(Qt::black);
|
painter.setPen(Qt::black);
|
||||||
painter.drawRect(0, 0, width - 1, height - 1);
|
painter.drawRect(0, 0, width - 1, height - 1);
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel)
|
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel)
|
||||||
{
|
{
|
||||||
int key = height * 10000 + (int) userLevel;
|
int key = height * 10000 + (int) userLevel;
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QString levelString;
|
QString levelString;
|
||||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||||
levelString = "admin";
|
levelString = "admin";
|
||||||
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||||
levelString = "moderator";
|
levelString = "moderator";
|
||||||
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||||
levelString = "registered";
|
levelString = "registered";
|
||||||
else
|
else
|
||||||
levelString = "normal";
|
levelString = "normal";
|
||||||
QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg"));
|
QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg"));
|
||||||
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
||||||
QPixmap pixmap(width, height);
|
QPixmap pixmap(width, height);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
svg.render(&painter, QRectF(0, 0, width, height));
|
svg.render(&painter, QRectF(0, 0, width, height));
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QPixmap> UserLevelPixmapGenerator::pmCache;
|
QMap<int, QPixmap> UserLevelPixmapGenerator::pmCache;
|
||||||
|
|
|
@ -8,50 +8,50 @@
|
||||||
|
|
||||||
class PhasePixmapGenerator {
|
class PhasePixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<QString, QPixmap> pmCache;
|
static QMap<QString, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int size, QString name);
|
static QPixmap generatePixmap(int size, QString name);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CounterPixmapGenerator {
|
class CounterPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<QString, QPixmap> pmCache;
|
static QMap<QString, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int size, QString name, bool highlight);
|
static QPixmap generatePixmap(int size, QString name, bool highlight);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class PingPixmapGenerator {
|
class PingPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<int, QPixmap> pmCache;
|
static QMap<int, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int size, int value, int max);
|
static QPixmap generatePixmap(int size, int value, int max);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class GenderPixmapGenerator {
|
class GenderPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<int, QPixmap> pmCache;
|
static QMap<int, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int height, int gender);
|
static QPixmap generatePixmap(int height, int gender);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CountryPixmapGenerator {
|
class CountryPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<QString, QPixmap> pmCache;
|
static QMap<QString, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int height, const QString &countryCode);
|
static QPixmap generatePixmap(int height, const QString &countryCode);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserLevelPixmapGenerator {
|
class UserLevelPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<int, QPixmap> pmCache;
|
static QMap<int, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int height, UserLevelFlags userLevel);
|
static QPixmap generatePixmap(int height, UserLevelFlags userLevel);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,246 +57,246 @@ class Event_ChangeZoneProperties;
|
||||||
class PendingCommand;
|
class PendingCommand;
|
||||||
|
|
||||||
class PlayerArea : public QObject, public QGraphicsItem {
|
class PlayerArea : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QBrush bgPixmapBrush;
|
QBrush bgPixmapBrush;
|
||||||
QRectF bRect;
|
QRectF bRect;
|
||||||
private slots:
|
private slots:
|
||||||
void updateBgPixmap();
|
void updateBgPixmap();
|
||||||
public:
|
public:
|
||||||
enum { Type = typeOther };
|
enum { Type = typeOther };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
|
||||||
PlayerArea(QGraphicsItem *parent = 0);
|
PlayerArea(QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const { return bRect; }
|
QRectF boundingRect() const { return bRect; }
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
void setSize(qreal width, qreal height);
|
void setSize(qreal width, qreal height);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Player : public QObject, public QGraphicsItem {
|
class Player : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void openDeckEditor(const DeckLoader *deck);
|
void openDeckEditor(const DeckLoader *deck);
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
// Log events
|
// Log events
|
||||||
void logSay(Player *player, QString message);
|
void logSay(Player *player, QString message);
|
||||||
void logShuffle(Player *player, CardZone *zone);
|
void logShuffle(Player *player, CardZone *zone);
|
||||||
void logRollDie(Player *player, int sides, int roll);
|
void logRollDie(Player *player, int sides, int roll);
|
||||||
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard, bool _playerTarget);
|
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard, bool _playerTarget);
|
||||||
void logCreateToken(Player *player, QString cardName, QString pt);
|
void logCreateToken(Player *player, QString cardName, QString pt);
|
||||||
void logDrawCards(Player *player, int number);
|
void logDrawCards(Player *player, int number);
|
||||||
void logUndoDraw(Player *player, QString cardName);
|
void logUndoDraw(Player *player, QString cardName);
|
||||||
void logMoveCard(Player *player, CardItem *card, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
|
void logMoveCard(Player *player, CardItem *card, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
|
||||||
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
||||||
void logDestroyCard(Player *player, QString cardName);
|
void logDestroyCard(Player *player, QString cardName);
|
||||||
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
||||||
void logUnattachCard(Player *player, QString cardName);
|
void logUnattachCard(Player *player, QString cardName);
|
||||||
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
||||||
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
||||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||||
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
||||||
void logSetPT(Player *player, CardItem *card, QString newPT);
|
void logSetPT(Player *player, CardItem *card, QString newPT);
|
||||||
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
||||||
void logDumpZone(Player *player, CardZone *zone, int numberCards);
|
void logDumpZone(Player *player, CardZone *zone, int numberCards);
|
||||||
void logStopDumpZone(Player *player, CardZone *zone);
|
void logStopDumpZone(Player *player, CardZone *zone);
|
||||||
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
|
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
|
||||||
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
||||||
|
|
||||||
void sizeChanged();
|
void sizeChanged();
|
||||||
void gameConceded();
|
void gameConceded();
|
||||||
public slots:
|
public slots:
|
||||||
void actUntapAll();
|
void actUntapAll();
|
||||||
void actRollDie();
|
void actRollDie();
|
||||||
void actCreateToken();
|
void actCreateToken();
|
||||||
void actCreateAnotherToken();
|
void actCreateAnotherToken();
|
||||||
void actShuffle();
|
void actShuffle();
|
||||||
void actDrawCard();
|
void actDrawCard();
|
||||||
void actDrawCards();
|
void actDrawCards();
|
||||||
void actUndoDraw();
|
void actUndoDraw();
|
||||||
void actMulligan();
|
void actMulligan();
|
||||||
void actMoveTopCardsToGrave();
|
void actMoveTopCardsToGrave();
|
||||||
void actMoveTopCardsToExile();
|
void actMoveTopCardsToExile();
|
||||||
void actMoveTopCardToBottom();
|
void actMoveTopCardToBottom();
|
||||||
|
|
||||||
void actViewLibrary();
|
void actViewLibrary();
|
||||||
void actViewTopCards();
|
void actViewTopCards();
|
||||||
void actAlwaysRevealTopCard();
|
void actAlwaysRevealTopCard();
|
||||||
void actViewGraveyard();
|
void actViewGraveyard();
|
||||||
void actViewRfg();
|
void actViewRfg();
|
||||||
void actViewSideboard();
|
void actViewSideboard();
|
||||||
|
|
||||||
void actSayMessage();
|
void actSayMessage();
|
||||||
private slots:
|
private slots:
|
||||||
void addPlayer(Player *player);
|
void addPlayer(Player *player);
|
||||||
void removePlayer(Player *player);
|
void removePlayer(Player *player);
|
||||||
void playerListActionTriggered();
|
void playerListActionTriggered();
|
||||||
|
|
||||||
void updateBoundingRect();
|
void updateBoundingRect();
|
||||||
void rearrangeZones();
|
void rearrangeZones();
|
||||||
|
|
||||||
void actOpenDeckInDeckEditor();
|
void actOpenDeckInDeckEditor();
|
||||||
void actCreatePredefinedToken();
|
void actCreatePredefinedToken();
|
||||||
void cardMenuAction();
|
void cardMenuAction();
|
||||||
void actCardCounterTrigger();
|
void actCardCounterTrigger();
|
||||||
void actAttach();
|
void actAttach();
|
||||||
void actUnattach();
|
void actUnattach();
|
||||||
void actDrawArrow();
|
void actDrawArrow();
|
||||||
void actIncPT(int deltaP, int deltaT);
|
void actIncPT(int deltaP, int deltaT);
|
||||||
void actSetPT();
|
void actSetPT();
|
||||||
void actIncP();
|
void actIncP();
|
||||||
void actDecP();
|
void actDecP();
|
||||||
void actIncT();
|
void actIncT();
|
||||||
void actDecT();
|
void actDecT();
|
||||||
void actIncPT();
|
void actIncPT();
|
||||||
void actDecPT();
|
void actDecPT();
|
||||||
void actSetAnnotation();
|
void actSetAnnotation();
|
||||||
void actPlay();
|
void actPlay();
|
||||||
void actHide();
|
void actHide();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TabGame *game;
|
TabGame *game;
|
||||||
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu,
|
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu,
|
||||||
*mRevealLibrary, *mRevealTopCard, *mRevealHand, *mRevealRandomHandCard;
|
*mRevealLibrary, *mRevealTopCard, *mRevealHand, *mRevealRandomHandCard;
|
||||||
QList<QMenu *> playerLists;
|
QList<QMenu *> playerLists;
|
||||||
QList<QAction *> allPlayersActions;
|
QList<QAction *> allPlayersActions;
|
||||||
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
|
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
|
||||||
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg,
|
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg,
|
||||||
*aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave,
|
*aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave,
|
||||||
*aViewLibrary, *aViewTopCards, *aAlwaysRevealTopCard, *aOpenDeckInDeckEditor, *aMoveTopCardsToGrave, *aMoveTopCardsToExile, *aMoveTopCardToBottom,
|
*aViewLibrary, *aViewTopCards, *aAlwaysRevealTopCard, *aOpenDeckInDeckEditor, *aMoveTopCardsToGrave, *aMoveTopCardsToExile, *aMoveTopCardToBottom,
|
||||||
*aViewGraveyard, *aViewRfg, *aViewSideboard,
|
*aViewGraveyard, *aViewRfg, *aViewSideboard,
|
||||||
*aDrawCard, *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle,
|
*aDrawCard, *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle,
|
||||||
*aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken,
|
*aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken,
|
||||||
*aCardMenu;
|
*aCardMenu;
|
||||||
|
|
||||||
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
||||||
QAction *aPlay,
|
QAction *aPlay,
|
||||||
*aHide,
|
*aHide,
|
||||||
*aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aSetAnnotation, *aFlip, *aPeek, *aClone,
|
*aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aSetAnnotation, *aFlip, *aPeek, *aClone,
|
||||||
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile;
|
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile;
|
||||||
|
|
||||||
bool shortcutsActive;
|
bool shortcutsActive;
|
||||||
int defaultNumberTopCards;
|
int defaultNumberTopCards;
|
||||||
QString lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation;
|
QString lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation;
|
||||||
bool lastTokenDestroy;
|
bool lastTokenDestroy;
|
||||||
ServerInfo_User *userInfo;
|
ServerInfo_User *userInfo;
|
||||||
int id;
|
int id;
|
||||||
bool active;
|
bool active;
|
||||||
bool local;
|
bool local;
|
||||||
bool mirrored;
|
bool mirrored;
|
||||||
bool handVisible;
|
bool handVisible;
|
||||||
bool conceded;
|
bool conceded;
|
||||||
|
|
||||||
bool dialogSemaphore;
|
bool dialogSemaphore;
|
||||||
bool clearCardsToDelete();
|
bool clearCardsToDelete();
|
||||||
QList<CardItem *> cardsToDelete;
|
QList<CardItem *> cardsToDelete;
|
||||||
|
|
||||||
DeckLoader *deck;
|
DeckLoader *deck;
|
||||||
QStringList predefinedTokens;
|
QStringList predefinedTokens;
|
||||||
|
|
||||||
PlayerArea *playerArea;
|
PlayerArea *playerArea;
|
||||||
QMap<QString, CardZone *> zones;
|
QMap<QString, CardZone *> zones;
|
||||||
StackZone *stack;
|
StackZone *stack;
|
||||||
TableZone *table;
|
TableZone *table;
|
||||||
HandZone *hand;
|
HandZone *hand;
|
||||||
PlayerTarget *playerTarget;
|
PlayerTarget *playerTarget;
|
||||||
|
|
||||||
void setCardAttrHelper(const GameEventContext &context, CardItem *card, CardAttribute attribute, const QString &avalue, bool allCards);
|
void setCardAttrHelper(const GameEventContext &context, CardItem *card, CardAttribute attribute, const QString &avalue, bool allCards);
|
||||||
|
|
||||||
QRectF bRect;
|
QRectF bRect;
|
||||||
|
|
||||||
QMap<int, AbstractCounter *> counters;
|
QMap<int, AbstractCounter *> counters;
|
||||||
QMap<int, ArrowItem *> arrows;
|
QMap<int, ArrowItem *> arrows;
|
||||||
void rearrangeCounters();
|
void rearrangeCounters();
|
||||||
|
|
||||||
void initSayMenu();
|
void initSayMenu();
|
||||||
|
|
||||||
void eventConnectionStateChanged(const Event_ConnectionStateChanged &event);
|
void eventConnectionStateChanged(const Event_ConnectionStateChanged &event);
|
||||||
void eventGameSay(const Event_GameSay &event);
|
void eventGameSay(const Event_GameSay &event);
|
||||||
void eventShuffle(const Event_Shuffle &event);
|
void eventShuffle(const Event_Shuffle &event);
|
||||||
void eventRollDie(const Event_RollDie &event);
|
void eventRollDie(const Event_RollDie &event);
|
||||||
void eventCreateArrow(const Event_CreateArrow &event);
|
void eventCreateArrow(const Event_CreateArrow &event);
|
||||||
void eventDeleteArrow(const Event_DeleteArrow &event);
|
void eventDeleteArrow(const Event_DeleteArrow &event);
|
||||||
void eventCreateToken(const Event_CreateToken &event);
|
void eventCreateToken(const Event_CreateToken &event);
|
||||||
void eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context);
|
void eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context);
|
||||||
void eventSetCardCounter(const Event_SetCardCounter &event);
|
void eventSetCardCounter(const Event_SetCardCounter &event);
|
||||||
void eventCreateCounter(const Event_CreateCounter &event);
|
void eventCreateCounter(const Event_CreateCounter &event);
|
||||||
void eventSetCounter(const Event_SetCounter &event);
|
void eventSetCounter(const Event_SetCounter &event);
|
||||||
void eventDelCounter(const Event_DelCounter &event);
|
void eventDelCounter(const Event_DelCounter &event);
|
||||||
void eventDumpZone(const Event_DumpZone &event);
|
void eventDumpZone(const Event_DumpZone &event);
|
||||||
void eventStopDumpZone(const Event_StopDumpZone &event);
|
void eventStopDumpZone(const Event_StopDumpZone &event);
|
||||||
void eventMoveCard(const Event_MoveCard &event, const GameEventContext &context);
|
void eventMoveCard(const Event_MoveCard &event, const GameEventContext &context);
|
||||||
void eventFlipCard(const Event_FlipCard &event);
|
void eventFlipCard(const Event_FlipCard &event);
|
||||||
void eventDestroyCard(const Event_DestroyCard &event);
|
void eventDestroyCard(const Event_DestroyCard &event);
|
||||||
void eventAttachCard(const Event_AttachCard &event);
|
void eventAttachCard(const Event_AttachCard &event);
|
||||||
void eventDrawCards(const Event_DrawCards &event);
|
void eventDrawCards(const Event_DrawCards &event);
|
||||||
void eventRevealCards(const Event_RevealCards &event);
|
void eventRevealCards(const Event_RevealCards &event);
|
||||||
void eventChangeZoneProperties(const Event_ChangeZoneProperties &event);
|
void eventChangeZoneProperties(const Event_ChangeZoneProperties &event);
|
||||||
public:
|
public:
|
||||||
static const int counterAreaWidth = 55;
|
static const int counterAreaWidth = 55;
|
||||||
enum CardMenuActionType { cmTap, cmUntap, cmDoesntUntap, cmFlip, cmPeek, cmClone, cmMoveToTopLibrary, cmMoveToBottomLibrary, cmMoveToGraveyard, cmMoveToExile };
|
enum CardMenuActionType { cmTap, cmUntap, cmDoesntUntap, cmFlip, cmPeek, cmClone, cmMoveToTopLibrary, cmMoveToBottomLibrary, cmMoveToGraveyard, cmMoveToExile };
|
||||||
|
|
||||||
enum { Type = typeOther };
|
enum { Type = typeOther };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
void playCard(CardItem *c, bool faceDown, bool tapped);
|
void playCard(CardItem *c, bool faceDown, bool tapped);
|
||||||
void addCard(CardItem *c);
|
void addCard(CardItem *c);
|
||||||
void deleteCard(CardItem *c);
|
void deleteCard(CardItem *c);
|
||||||
void addZone(CardZone *z);
|
void addZone(CardZone *z);
|
||||||
|
|
||||||
AbstractCounter *addCounter(const ServerInfo_Counter &counter);
|
AbstractCounter *addCounter(const ServerInfo_Counter &counter);
|
||||||
AbstractCounter *addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
AbstractCounter *addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
||||||
void delCounter(int counterId);
|
void delCounter(int counterId);
|
||||||
void clearCounters();
|
void clearCounters();
|
||||||
|
|
||||||
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
|
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
|
||||||
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
|
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
|
||||||
void delArrow(int arrowId);
|
void delArrow(int arrowId);
|
||||||
void removeArrow(ArrowItem *arrow);
|
void removeArrow(ArrowItem *arrow);
|
||||||
void clearArrows();
|
void clearArrows();
|
||||||
PlayerTarget *getPlayerTarget() const { return playerTarget; }
|
PlayerTarget *getPlayerTarget() const { return playerTarget; }
|
||||||
|
|
||||||
Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_parent);
|
Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_parent);
|
||||||
~Player();
|
~Player();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void clear();
|
void clear();
|
||||||
TabGame *getGame() const { return game; }
|
TabGame *getGame() const { return game; }
|
||||||
void setDeck(const DeckLoader &_deck);
|
void setDeck(const DeckLoader &_deck);
|
||||||
QMenu *getPlayerMenu() const { return playerMenu; }
|
QMenu *getPlayerMenu() const { return playerMenu; }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||||
bool getLocal() const { return local; }
|
bool getLocal() const { return local; }
|
||||||
bool getMirrored() const { return mirrored; }
|
bool getMirrored() const { return mirrored; }
|
||||||
const QMap<QString, CardZone *> &getZones() const { return zones; }
|
const QMap<QString, CardZone *> &getZones() const { return zones; }
|
||||||
const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
|
const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
|
||||||
void setCardMenu(QMenu *menu);
|
void setCardMenu(QMenu *menu);
|
||||||
QMenu *getCardMenu() const;
|
QMenu *getCardMenu() const;
|
||||||
void updateCardMenu(CardItem *card);
|
void updateCardMenu(CardItem *card);
|
||||||
bool getActive() const { return active; }
|
bool getActive() const { return active; }
|
||||||
void setActive(bool _active);
|
void setActive(bool _active);
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
void updateZones();
|
void updateZones();
|
||||||
|
|
||||||
void setConceded(bool _conceded);
|
void setConceded(bool _conceded);
|
||||||
bool getConceded() const { return conceded; }
|
bool getConceded() const { return conceded; }
|
||||||
|
|
||||||
qreal getMinimumWidth() const;
|
qreal getMinimumWidth() const;
|
||||||
void setMirrored(bool _mirrored);
|
void setMirrored(bool _mirrored);
|
||||||
void processSceneSizeChange(int newPlayerWidth);
|
void processSceneSizeChange(int newPlayerWidth);
|
||||||
|
|
||||||
void processPlayerInfo(const ServerInfo_Player &info);
|
void processPlayerInfo(const ServerInfo_Player &info);
|
||||||
void processCardAttachment(const ServerInfo_Player &info);
|
void processCardAttachment(const ServerInfo_Player &info);
|
||||||
|
|
||||||
void processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context);
|
void processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context);
|
||||||
|
|
||||||
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
||||||
PendingCommand *prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList);
|
PendingCommand *prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList);
|
||||||
void sendGameCommand(PendingCommand *pend);
|
void sendGameCommand(PendingCommand *pend);
|
||||||
void sendGameCommand(const google::protobuf::Message &command);
|
void sendGameCommand(const google::protobuf::Message &command);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,63 +17,63 @@
|
||||||
#include "pb/serverinfo_playerproperties.pb.h"
|
#include "pb/serverinfo_playerproperties.pb.h"
|
||||||
|
|
||||||
PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent)
|
PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
bool PlayerListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
||||||
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
|
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
|
||||||
if (mouseEvent->button() == Qt::RightButton) {
|
if (mouseEvent->button() == Qt::RightButton) {
|
||||||
static_cast<PlayerListWidget *>(parent())->showContextMenu(mouseEvent->globalPos(), index);
|
static_cast<PlayerListWidget *>(parent())->showContextMenu(mouseEvent->globalPos(), index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerListTWI::PlayerListTWI()
|
PlayerListTWI::PlayerListTWI()
|
||||||
: QTreeWidgetItem(Type)
|
: QTreeWidgetItem(Type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
||||||
{
|
{
|
||||||
// Sort by spectator/player
|
// Sort by spectator/player
|
||||||
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole))
|
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole))
|
||||||
return data(1, Qt::UserRole).toBool();
|
return data(1, Qt::UserRole).toBool();
|
||||||
|
|
||||||
// Sort by player ID
|
// Sort by player ID
|
||||||
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
|
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent)
|
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent)
|
||||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
||||||
{
|
{
|
||||||
readyIcon = QIcon(":/resources/icon_ready_start.svg");
|
readyIcon = QIcon(":/resources/icon_ready_start.svg");
|
||||||
notReadyIcon = QIcon(":/resources/icon_not_ready_start.svg");
|
notReadyIcon = QIcon(":/resources/icon_not_ready_start.svg");
|
||||||
concededIcon = QIcon(":/resources/icon_conceded.svg");
|
concededIcon = QIcon(":/resources/icon_conceded.svg");
|
||||||
playerIcon = QIcon(":/resources/icon_player.svg");
|
playerIcon = QIcon(":/resources/icon_player.svg");
|
||||||
spectatorIcon = QIcon(":/resources/icon_spectator.svg");
|
spectatorIcon = QIcon(":/resources/icon_spectator.svg");
|
||||||
lockIcon = QIcon(":/resources/lock.svg");
|
lockIcon = QIcon(":/resources/lock.svg");
|
||||||
|
|
||||||
if (tabSupervisor) {
|
if (tabSupervisor) {
|
||||||
itemDelegate = new PlayerListItemDelegate(this);
|
itemDelegate = new PlayerListItemDelegate(this);
|
||||||
setItemDelegate(itemDelegate);
|
setItemDelegate(itemDelegate);
|
||||||
|
|
||||||
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||||
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
} else
|
} else
|
||||||
userContextMenu = 0;
|
userContextMenu = 0;
|
||||||
|
|
||||||
setMinimumHeight(60);
|
setMinimumHeight(60);
|
||||||
setIconSize(QSize(20, 15));
|
setIconSize(QSize(20, 15));
|
||||||
setColumnCount(6);
|
setColumnCount(6);
|
||||||
setHeaderHidden(true);
|
setHeaderHidden(true);
|
||||||
setRootIsDecorated(false);
|
setRootIsDecorated(false);
|
||||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::retranslateUi()
|
void PlayerListWidget::retranslateUi()
|
||||||
|
@ -82,97 +82,97 @@ void PlayerListWidget::retranslateUi()
|
||||||
|
|
||||||
void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
|
void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *newPlayer = new PlayerListTWI;
|
QTreeWidgetItem *newPlayer = new PlayerListTWI;
|
||||||
players.insert(player.player_id(), newPlayer);
|
players.insert(player.player_id(), newPlayer);
|
||||||
updatePlayerProperties(player);
|
updatePlayerProperties(player);
|
||||||
addTopLevelItem(newPlayer);
|
addTopLevelItem(newPlayer);
|
||||||
sortItems(1, Qt::AscendingOrder);
|
sortItems(1, Qt::AscendingOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId)
|
void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId)
|
||||||
{
|
{
|
||||||
if (playerId == -1)
|
if (playerId == -1)
|
||||||
playerId = prop.player_id();
|
playerId = prop.player_id();
|
||||||
|
|
||||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (prop.has_spectator()) {
|
if (prop.has_spectator()) {
|
||||||
player->setIcon(1, prop.spectator() ? spectatorIcon : playerIcon);
|
player->setIcon(1, prop.spectator() ? spectatorIcon : playerIcon);
|
||||||
player->setData(1, Qt::UserRole, !prop.spectator());
|
player->setData(1, Qt::UserRole, !prop.spectator());
|
||||||
}
|
}
|
||||||
if (prop.has_conceded())
|
if (prop.has_conceded())
|
||||||
player->setData(2, Qt::UserRole, prop.conceded());
|
player->setData(2, Qt::UserRole, prop.conceded());
|
||||||
if (prop.has_ready_start())
|
if (prop.has_ready_start())
|
||||||
player->setData(2, Qt::UserRole + 1, prop.ready_start());
|
player->setData(2, Qt::UserRole + 1, prop.ready_start());
|
||||||
if (prop.has_conceded() || prop.has_ready_start())
|
if (prop.has_conceded() || prop.has_ready_start())
|
||||||
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon));
|
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon));
|
||||||
if (prop.has_user_info()) {
|
if (prop.has_user_info()) {
|
||||||
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
||||||
player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()))));
|
player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()))));
|
||||||
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
||||||
const QString country = QString::fromStdString(prop.user_info().country());
|
const QString country = QString::fromStdString(prop.user_info().country());
|
||||||
if (!country.isEmpty())
|
if (!country.isEmpty())
|
||||||
player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country)));
|
player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country)));
|
||||||
player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name()));
|
player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name()));
|
||||||
}
|
}
|
||||||
if (prop.has_player_id())
|
if (prop.has_player_id())
|
||||||
player->setData(4, Qt::UserRole + 1, prop.player_id());
|
player->setData(4, Qt::UserRole + 1, prop.player_id());
|
||||||
if (prop.has_deck_hash())
|
if (prop.has_deck_hash())
|
||||||
player->setText(5, QString::fromStdString(prop.deck_hash()));
|
player->setText(5, QString::fromStdString(prop.deck_hash()));
|
||||||
if (prop.has_sideboard_locked())
|
if (prop.has_sideboard_locked())
|
||||||
player->setIcon(5, prop.sideboard_locked() ? lockIcon : QIcon());
|
player->setIcon(5, prop.sideboard_locked() ? lockIcon : QIcon());
|
||||||
if (prop.has_ping_seconds())
|
if (prop.has_ping_seconds())
|
||||||
player->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(12, prop.ping_seconds(), 10)));
|
player->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(12, prop.ping_seconds(), 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::removePlayer(int playerId)
|
void PlayerListWidget::removePlayer(int playerId)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
players.remove(playerId);
|
players.remove(playerId);
|
||||||
delete takeTopLevelItem(indexOfTopLevelItem(player));
|
delete takeTopLevelItem(indexOfTopLevelItem(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::setActivePlayer(int playerId)
|
void PlayerListWidget::setActivePlayer(int playerId)
|
||||||
{
|
{
|
||||||
QMapIterator<int, QTreeWidgetItem *> i(players);
|
QMapIterator<int, QTreeWidgetItem *> i(players);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
QTreeWidgetItem *twi = i.value();
|
QTreeWidgetItem *twi = i.value();
|
||||||
QColor c = i.key() == playerId ? QColor(150, 255, 150) : Qt::white;
|
QColor c = i.key() == playerId ? QColor(150, 255, 150) : Qt::white;
|
||||||
twi->setBackground(4, c);
|
twi->setBackground(4, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
|
void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
|
||||||
{
|
{
|
||||||
gameStarted = _gameStarted;
|
gameStarted = _gameStarted;
|
||||||
QMapIterator<int, QTreeWidgetItem *> i(players);
|
QMapIterator<int, QTreeWidgetItem *> i(players);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
QTreeWidgetItem *twi = i.next().value();
|
QTreeWidgetItem *twi = i.next().value();
|
||||||
if (gameStarted) {
|
if (gameStarted) {
|
||||||
if (resuming)
|
if (resuming)
|
||||||
twi->setIcon(2, twi->data(2, Qt::UserRole).toBool() ? concededIcon : QIcon());
|
twi->setIcon(2, twi->data(2, Qt::UserRole).toBool() ? concededIcon : QIcon());
|
||||||
else {
|
else {
|
||||||
twi->setData(2, Qt::UserRole, false);
|
twi->setData(2, Qt::UserRole, false);
|
||||||
twi->setIcon(2, QIcon());
|
twi->setIcon(2, QIcon());
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
twi->setIcon(2, notReadyIcon);
|
twi->setIcon(2, notReadyIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (!userContextMenu)
|
if (!userContextMenu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
||||||
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
||||||
UserLevelFlags userLevel(index.sibling(index.row(), 3).data(Qt::UserRole).toInt());
|
UserLevelFlags userLevel(index.sibling(index.row(), 3).data(Qt::UserRole).toInt());
|
||||||
|
|
||||||
userContextMenu->showContextMenu(pos, userName, userLevel, playerId);
|
userContextMenu->showContextMenu(pos, userName, userLevel, playerId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,38 +14,38 @@ class UserContextMenu;
|
||||||
|
|
||||||
class PlayerListItemDelegate : public QStyledItemDelegate {
|
class PlayerListItemDelegate : public QStyledItemDelegate {
|
||||||
public:
|
public:
|
||||||
PlayerListItemDelegate(QObject *const parent);
|
PlayerListItemDelegate(QObject *const parent);
|
||||||
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerListTWI : public QTreeWidgetItem {
|
class PlayerListTWI : public QTreeWidgetItem {
|
||||||
public:
|
public:
|
||||||
PlayerListTWI();
|
PlayerListTWI();
|
||||||
bool operator<(const QTreeWidgetItem &other) const;
|
bool operator<(const QTreeWidgetItem &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerListWidget : public QTreeWidget {
|
class PlayerListWidget : public QTreeWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
PlayerListItemDelegate *itemDelegate;
|
PlayerListItemDelegate *itemDelegate;
|
||||||
QMap<int, QTreeWidgetItem *> players;
|
QMap<int, QTreeWidgetItem *> players;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
TabGame *game;
|
TabGame *game;
|
||||||
UserContextMenu *userContextMenu;
|
UserContextMenu *userContextMenu;
|
||||||
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, spectatorIcon, lockIcon;
|
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, spectatorIcon, lockIcon;
|
||||||
bool gameStarted;
|
bool gameStarted;
|
||||||
signals:
|
signals:
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
public:
|
public:
|
||||||
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = 0);
|
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void addPlayer(const ServerInfo_PlayerProperties &player);
|
void addPlayer(const ServerInfo_PlayerProperties &player);
|
||||||
void removePlayer(int playerId);
|
void removePlayer(int playerId);
|
||||||
void setActivePlayer(int playerId);
|
void setActivePlayer(int playerId);
|
||||||
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
|
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
|
||||||
void setGameStarted(bool _gameStarted, bool resuming);
|
void setGameStarted(bool _gameStarted, bool resuming);
|
||||||
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,149 +8,149 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
PlayerCounter::PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent)
|
PlayerCounter::PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent)
|
||||||
: AbstractCounter(_player, _id, _name, false, _value, parent)
|
: AbstractCounter(_player, _id, _name, false, _value, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PlayerCounter::boundingRect() const
|
QRectF PlayerCounter::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, 50, 30);
|
return QRectF(0, 0, 50, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
const int radius = 8;
|
const int radius = 8;
|
||||||
const qreal border = 1;
|
const qreal border = 1;
|
||||||
QPainterPath path(QPointF(50 - border / 2, border / 2));
|
QPainterPath path(QPointF(50 - border / 2, border / 2));
|
||||||
path.lineTo(radius, border / 2);
|
path.lineTo(radius, border / 2);
|
||||||
path.arcTo(border / 2, border / 2, 2 * radius, 2 * radius, 90, 90);
|
path.arcTo(border / 2, border / 2, 2 * radius, 2 * radius, 90, 90);
|
||||||
path.lineTo(border / 2, 30 - border / 2);
|
path.lineTo(border / 2, 30 - border / 2);
|
||||||
path.lineTo(50 - border / 2, 30 - border / 2);
|
path.lineTo(50 - border / 2, 30 - border / 2);
|
||||||
path.closeSubpath();
|
path.closeSubpath();
|
||||||
|
|
||||||
QPen pen(QColor(100, 100, 100));
|
QPen pen(QColor(100, 100, 100));
|
||||||
pen.setWidth(border);
|
pen.setWidth(border);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->setBrush(hovered ? QColor(50, 50, 50, 160) : QColor(0, 0, 0, 160));
|
painter->setBrush(hovered ? QColor(50, 50, 50, 160) : QColor(0, 0, 0, 160));
|
||||||
|
|
||||||
painter->drawPath(path);
|
painter->drawPath(path);
|
||||||
|
|
||||||
QRectF translatedRect = painter->combinedTransform().mapRect(boundingRect());
|
QRectF translatedRect = painter->combinedTransform().mapRect(boundingRect());
|
||||||
QSize translatedSize = translatedRect.size().toSize();
|
QSize translatedSize = translatedRect.size().toSize();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
QFont font("Serif");
|
QFont font("Serif");
|
||||||
font.setWeight(QFont::Bold);
|
font.setWeight(QFont::Bold);
|
||||||
font.setPixelSize(qMax((int) round(translatedSize.height() / 1.3), 9));
|
font.setPixelSize(qMax((int) round(translatedSize.height() / 1.3), 9));
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem)
|
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem)
|
||||||
: ArrowTarget(_owner, parentItem), playerCounter(0)
|
: ArrowTarget(_owner, parentItem), playerCounter(0)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
const std::string &bmp = _owner->getUserInfo()->avatar_bmp();
|
const std::string &bmp = _owner->getUserInfo()->avatar_bmp();
|
||||||
if (!fullPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
|
if (!fullPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
|
||||||
fullPixmap = QPixmap();
|
fullPixmap = QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerTarget::~PlayerTarget()
|
PlayerTarget::~PlayerTarget()
|
||||||
{
|
{
|
||||||
// Explicit deletion is necessary in spite of parent/child relationship
|
// Explicit deletion is necessary in spite of parent/child relationship
|
||||||
// as we need this object to be alive to receive the destroyed() signal.
|
// as we need this object to be alive to receive the destroyed() signal.
|
||||||
delete playerCounter;
|
delete playerCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PlayerTarget::boundingRect() const
|
QRectF PlayerTarget::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, 160, 64);
|
return QRectF(0, 0, 160, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
const ServerInfo_User *const info = owner->getUserInfo();
|
const ServerInfo_User *const info = owner->getUserInfo();
|
||||||
|
|
||||||
const qreal border = 2;
|
const qreal border = 2;
|
||||||
|
|
||||||
QRectF avatarBoundingRect = boundingRect().adjusted(border, border, -border, -border);
|
QRectF avatarBoundingRect = boundingRect().adjusted(border, border, -border, -border);
|
||||||
QRectF translatedRect = painter->combinedTransform().mapRect(avatarBoundingRect);
|
QRectF translatedRect = painter->combinedTransform().mapRect(avatarBoundingRect);
|
||||||
QSize translatedSize = translatedRect.size().toSize();
|
QSize translatedSize = translatedRect.size().toSize();
|
||||||
QPixmap cachedPixmap;
|
QPixmap cachedPixmap;
|
||||||
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" + QString::number(info->user_level()) + "_" + QString::number(fullPixmap.cacheKey());
|
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" + QString::number(info->user_level()) + "_" + QString::number(fullPixmap.cacheKey());
|
||||||
#if QT_VERSION >= 0x040600
|
#if QT_VERSION >= 0x040600
|
||||||
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
|
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
|
||||||
#else
|
#else
|
||||||
if (!QPixmapCache::find(cacheKey, cachedPixmap)) {
|
if (!QPixmapCache::find(cacheKey, cachedPixmap)) {
|
||||||
#endif
|
#endif
|
||||||
cachedPixmap = QPixmap(translatedSize.width(), translatedSize.height());
|
cachedPixmap = QPixmap(translatedSize.width(), translatedSize.height());
|
||||||
|
|
||||||
QPainter tempPainter(&cachedPixmap);
|
QPainter tempPainter(&cachedPixmap);
|
||||||
QRadialGradient grad(translatedRect.center(), sqrt(translatedSize.width() * translatedSize.width() + translatedSize.height() * translatedSize.height()) / 2);
|
QRadialGradient grad(translatedRect.center(), sqrt(translatedSize.width() * translatedSize.width() + translatedSize.height() * translatedSize.height()) / 2);
|
||||||
grad.setColorAt(1, Qt::black);
|
grad.setColorAt(1, Qt::black);
|
||||||
grad.setColorAt(0, QColor(180, 180, 180));
|
grad.setColorAt(0, QColor(180, 180, 180));
|
||||||
tempPainter.fillRect(QRectF(0, 0, translatedSize.width(), translatedSize.height()), grad);
|
tempPainter.fillRect(QRectF(0, 0, translatedSize.width(), translatedSize.height()), grad);
|
||||||
|
|
||||||
QPixmap tempPixmap;
|
QPixmap tempPixmap;
|
||||||
if (fullPixmap.isNull())
|
if (fullPixmap.isNull())
|
||||||
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level()));
|
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level()));
|
||||||
else
|
else
|
||||||
tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
|
||||||
tempPainter.drawPixmap((translatedSize.width() - tempPixmap.width()) / 2, (translatedSize.height() - tempPixmap.height()) / 2, tempPixmap);
|
tempPainter.drawPixmap((translatedSize.width() - tempPixmap.width()) / 2, (translatedSize.height() - tempPixmap.height()) / 2, tempPixmap);
|
||||||
QPixmapCache::insert(cacheKey, cachedPixmap);
|
QPixmapCache::insert(cacheKey, cachedPixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
|
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
|
||||||
painter->drawPixmap(translatedRect, cachedPixmap, cachedPixmap.rect());
|
painter->drawPixmap(translatedRect, cachedPixmap, cachedPixmap.rect());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
QRectF nameRect = QRectF(0, boundingRect().height() - 20, 110, 20);
|
QRectF nameRect = QRectF(0, boundingRect().height() - 20, 110, 20);
|
||||||
painter->fillRect(nameRect, QColor(0, 0, 0, 160));
|
painter->fillRect(nameRect, QColor(0, 0, 0, 160));
|
||||||
QRectF translatedNameRect = painter->combinedTransform().mapRect(nameRect);
|
QRectF translatedNameRect = painter->combinedTransform().mapRect(nameRect);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
|
|
||||||
QString name = QString::fromStdString(info->name());
|
QString name = QString::fromStdString(info->name());
|
||||||
if (name.size() > 13)
|
if (name.size() > 13)
|
||||||
name = name.mid(0, 10) + "...";
|
name = name.mid(0, 10) + "...";
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPixelSize(qMax((int) round(translatedNameRect.height() / 1.5), 9));
|
font.setPixelSize(qMax((int) round(translatedNameRect.height() / 1.5), 9));
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
painter->drawText(translatedNameRect, Qt::AlignVCenter | Qt::AlignLeft, " " + name);
|
painter->drawText(translatedNameRect, Qt::AlignVCenter | Qt::AlignLeft, " " + name);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
QPen pen(QColor(100, 100, 100));
|
QPen pen(QColor(100, 100, 100));
|
||||||
pen.setWidth(border);
|
pen.setWidth(border);
|
||||||
pen.setJoinStyle(Qt::RoundJoin);
|
pen.setJoinStyle(Qt::RoundJoin);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(boundingRect().adjusted(border / 2, border / 2, -border / 2, -border / 2));
|
painter->drawRect(boundingRect().adjusted(border / 2, border / 2, -border / 2, -border / 2));
|
||||||
|
|
||||||
if (getBeingPointedAt())
|
if (getBeingPointedAt())
|
||||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, int _value)
|
AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, int _value)
|
||||||
{
|
{
|
||||||
if (playerCounter) {
|
if (playerCounter) {
|
||||||
disconnect(playerCounter, 0, this, 0);
|
disconnect(playerCounter, 0, this, 0);
|
||||||
playerCounter->delCounter();
|
playerCounter->delCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
playerCounter = new PlayerCounter(owner, _counterId, _name, _value, this);
|
playerCounter = new PlayerCounter(owner, _counterId, _name, _value, this);
|
||||||
playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(), boundingRect().height() - playerCounter->boundingRect().height());
|
playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(), boundingRect().height() - playerCounter->boundingRect().height());
|
||||||
connect(playerCounter, SIGNAL(destroyed()), this, SLOT(counterDeleted()));
|
connect(playerCounter, SIGNAL(destroyed()), this, SLOT(counterDeleted()));
|
||||||
|
|
||||||
return playerCounter;
|
return playerCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerTarget::counterDeleted()
|
void PlayerTarget::counterDeleted()
|
||||||
{
|
{
|
||||||
playerCounter = 0;
|
playerCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,30 +9,30 @@
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
class PlayerCounter : public AbstractCounter {
|
class PlayerCounter : public AbstractCounter {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent = 0);
|
PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerTarget : public ArrowTarget {
|
class PlayerTarget : public ArrowTarget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QPixmap fullPixmap;
|
QPixmap fullPixmap;
|
||||||
PlayerCounter *playerCounter;
|
PlayerCounter *playerCounter;
|
||||||
public slots:
|
public slots:
|
||||||
void counterDeleted();
|
void counterDeleted();
|
||||||
public:
|
public:
|
||||||
enum { Type = typePlayerTarget };
|
enum { Type = typePlayerTarget };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
|
||||||
PlayerTarget(Player *_player = 0, QGraphicsItem *parentItem = 0);
|
PlayerTarget(Player *_player = 0, QGraphicsItem *parentItem = 0);
|
||||||
~PlayerTarget();
|
~PlayerTarget();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
AbstractCounter *addCounter(int _counterId, const QString &_name, int _value);
|
AbstractCounter *addCounter(int _counterId, const QString &_name, int _value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -131,30 +131,30 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
||||||
|
|
||||||
str = "[ " + join( values, ", " ) + " ]";
|
str = "[ " + join( values, ", " ) + " ]";
|
||||||
}
|
}
|
||||||
else if(data.type() == QVariant::Hash) // variant is a hash?
|
else if(data.type() == QVariant::Hash) // variant is a hash?
|
||||||
{
|
{
|
||||||
const QVariantHash vhash = data.toHash();
|
const QVariantHash vhash = data.toHash();
|
||||||
QHashIterator<QString, QVariant> it( vhash );
|
QHashIterator<QString, QVariant> it( vhash );
|
||||||
str = "{ ";
|
str = "{ ";
|
||||||
QList<QByteArray> pairs;
|
QList<QByteArray> pairs;
|
||||||
|
|
||||||
while(it.hasNext())
|
while(it.hasNext())
|
||||||
{
|
{
|
||||||
it.next();
|
it.next();
|
||||||
QByteArray serializedValue = serialize(it.value());
|
QByteArray serializedValue = serialize(it.value());
|
||||||
|
|
||||||
if(serializedValue.isNull())
|
if(serializedValue.isNull())
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pairs << sanitizeString(it.key()).toUtf8() + " : " + serializedValue;
|
pairs << sanitizeString(it.key()).toUtf8() + " : " + serializedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
str += join(pairs, ", ");
|
str += join(pairs, ", ");
|
||||||
str += " }";
|
str += " }";
|
||||||
}
|
}
|
||||||
else if(data.type() == QVariant::Map) // variant is a map?
|
else if(data.type() == QVariant::Map) // variant is a map?
|
||||||
{
|
{
|
||||||
const QVariantMap vmap = data.toMap();
|
const QVariantMap vmap = data.toMap();
|
||||||
|
|
|
@ -12,220 +12,220 @@
|
||||||
static const unsigned int protocolVersion = 14;
|
static const unsigned int protocolVersion = 14;
|
||||||
|
|
||||||
RemoteClient::RemoteClient(QObject *parent)
|
RemoteClient::RemoteClient(QObject *parent)
|
||||||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false), messageLength(0)
|
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false), messageLength(0)
|
||||||
{
|
{
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
timer->setInterval(1000);
|
timer->setInterval(1000);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
||||||
|
|
||||||
socket = new QTcpSocket(this);
|
socket = new QTcpSocket(this);
|
||||||
socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||||
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
|
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
||||||
|
|
||||||
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
||||||
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
|
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
|
||||||
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
|
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
|
||||||
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
|
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteClient::~RemoteClient()
|
RemoteClient::~RemoteClient()
|
||||||
{
|
{
|
||||||
doDisconnectFromServer();
|
doDisconnectFromServer();
|
||||||
thread()->quit();
|
thread()->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
||||||
{
|
{
|
||||||
QString errorString = socket->errorString();
|
QString errorString = socket->errorString();
|
||||||
doDisconnectFromServer();
|
doDisconnectFromServer();
|
||||||
emit socketError(errorString);
|
emit socketError(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::slotConnected()
|
void RemoteClient::slotConnected()
|
||||||
{
|
{
|
||||||
timeRunning = lastDataReceived = 0;
|
timeRunning = lastDataReceived = 0;
|
||||||
timer->start();
|
timer->start();
|
||||||
|
|
||||||
// dirty hack to be compatible with v14 server
|
// dirty hack to be compatible with v14 server
|
||||||
sendCommandContainer(CommandContainer());
|
sendCommandContainer(CommandContainer());
|
||||||
getNewCmdId();
|
getNewCmdId();
|
||||||
// end of hack
|
// end of hack
|
||||||
|
|
||||||
setStatus(StatusAwaitingWelcome);
|
setStatus(StatusAwaitingWelcome);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
|
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
|
||||||
{
|
{
|
||||||
if (event.protocol_version() != protocolVersion) {
|
if (event.protocol_version() != protocolVersion) {
|
||||||
emit protocolVersionMismatch(protocolVersion, event.protocol_version());
|
emit protocolVersionMismatch(protocolVersion, event.protocol_version());
|
||||||
setStatus(StatusDisconnecting);
|
setStatus(StatusDisconnecting);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setStatus(StatusLoggingIn);
|
setStatus(StatusLoggingIn);
|
||||||
|
|
||||||
Command_Login cmdLogin;
|
Command_Login cmdLogin;
|
||||||
cmdLogin.set_user_name(userName.toStdString());
|
cmdLogin.set_user_name(userName.toStdString());
|
||||||
cmdLogin.set_password(password.toStdString());
|
cmdLogin.set_password(password.toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = prepareSessionCommand(cmdLogin);
|
PendingCommand *pend = prepareSessionCommand(cmdLogin);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(loginResponse(Response)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(loginResponse(Response)));
|
||||||
sendCommand(pend);
|
sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::processConnectionClosedEvent(const Event_ConnectionClosed & /*event*/)
|
void RemoteClient::processConnectionClosedEvent(const Event_ConnectionClosed & /*event*/)
|
||||||
{
|
{
|
||||||
doDisconnectFromServer();
|
doDisconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::loginResponse(const Response &response)
|
void RemoteClient::loginResponse(const Response &response)
|
||||||
{
|
{
|
||||||
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
||||||
if (response.response_code() == Response::RespOk) {
|
if (response.response_code() == Response::RespOk) {
|
||||||
setStatus(StatusLoggedIn);
|
setStatus(StatusLoggedIn);
|
||||||
emit userInfoChanged(resp.user_info());
|
emit userInfoChanged(resp.user_info());
|
||||||
|
|
||||||
QList<ServerInfo_User> buddyList;
|
QList<ServerInfo_User> buddyList;
|
||||||
for (int i = resp.buddy_list_size() - 1; i >= 0; --i)
|
for (int i = resp.buddy_list_size() - 1; i >= 0; --i)
|
||||||
buddyList.append(resp.buddy_list(i));
|
buddyList.append(resp.buddy_list(i));
|
||||||
emit buddyListReceived(buddyList);
|
emit buddyListReceived(buddyList);
|
||||||
|
|
||||||
QList<ServerInfo_User> ignoreList;
|
QList<ServerInfo_User> ignoreList;
|
||||||
for (int i = resp.ignore_list_size() - 1; i >= 0; --i)
|
for (int i = resp.ignore_list_size() - 1; i >= 0; --i)
|
||||||
ignoreList.append(resp.ignore_list(i));
|
ignoreList.append(resp.ignore_list(i));
|
||||||
emit ignoreListReceived(ignoreList);
|
emit ignoreListReceived(ignoreList);
|
||||||
} else {
|
} else {
|
||||||
emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
|
emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
|
||||||
setStatus(StatusDisconnecting);
|
setStatus(StatusDisconnecting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::readData()
|
void RemoteClient::readData()
|
||||||
{
|
{
|
||||||
lastDataReceived = timeRunning;
|
lastDataReceived = timeRunning;
|
||||||
QByteArray data = socket->readAll();
|
QByteArray data = socket->readAll();
|
||||||
|
|
||||||
inputBuffer.append(data);
|
inputBuffer.append(data);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!messageInProgress) {
|
if (!messageInProgress) {
|
||||||
if (inputBuffer.size() >= 4) {
|
if (inputBuffer.size() >= 4) {
|
||||||
// dirty hack to be compatible with v14 server that sends 60 bytes of garbage at the beginning
|
// dirty hack to be compatible with v14 server that sends 60 bytes of garbage at the beginning
|
||||||
if (!handshakeStarted) {
|
if (!handshakeStarted) {
|
||||||
handshakeStarted = true;
|
handshakeStarted = true;
|
||||||
if (inputBuffer.startsWith("<?xm")) {
|
if (inputBuffer.startsWith("<?xm")) {
|
||||||
messageInProgress = true;
|
messageInProgress = true;
|
||||||
messageLength = 60;
|
messageLength = 60;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// end of hack
|
// end of hack
|
||||||
messageLength = (((quint32) (unsigned char) inputBuffer[0]) << 24)
|
messageLength = (((quint32) (unsigned char) inputBuffer[0]) << 24)
|
||||||
+ (((quint32) (unsigned char) inputBuffer[1]) << 16)
|
+ (((quint32) (unsigned char) inputBuffer[1]) << 16)
|
||||||
+ (((quint32) (unsigned char) inputBuffer[2]) << 8)
|
+ (((quint32) (unsigned char) inputBuffer[2]) << 8)
|
||||||
+ ((quint32) (unsigned char) inputBuffer[3]);
|
+ ((quint32) (unsigned char) inputBuffer[3]);
|
||||||
inputBuffer.remove(0, 4);
|
inputBuffer.remove(0, 4);
|
||||||
messageInProgress = true;
|
messageInProgress = true;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (inputBuffer.size() < messageLength)
|
if (inputBuffer.size() < messageLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ServerMessage newServerMessage;
|
ServerMessage newServerMessage;
|
||||||
newServerMessage.ParseFromArray(inputBuffer.data(), messageLength);
|
newServerMessage.ParseFromArray(inputBuffer.data(), messageLength);
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
qDebug() << "IN" << messageLength << QString::fromStdString(newServerMessage.ShortDebugString());
|
qDebug() << "IN" << messageLength << QString::fromStdString(newServerMessage.ShortDebugString());
|
||||||
#endif
|
#endif
|
||||||
inputBuffer.remove(0, messageLength);
|
inputBuffer.remove(0, messageLength);
|
||||||
messageInProgress = false;
|
messageInProgress = false;
|
||||||
|
|
||||||
processProtocolItem(newServerMessage);
|
processProtocolItem(newServerMessage);
|
||||||
|
|
||||||
if (getStatus() == StatusDisconnecting) // use thread-safe getter
|
if (getStatus() == StatusDisconnecting) // use thread-safe getter
|
||||||
doDisconnectFromServer();
|
doDisconnectFromServer();
|
||||||
} while (!inputBuffer.isEmpty());
|
} while (!inputBuffer.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
||||||
{
|
{
|
||||||
QByteArray buf;
|
QByteArray buf;
|
||||||
unsigned int size = cont.ByteSize();
|
unsigned int size = cont.ByteSize();
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
qDebug() << "OUT" << size << QString::fromStdString(cont.ShortDebugString());
|
qDebug() << "OUT" << size << QString::fromStdString(cont.ShortDebugString());
|
||||||
#endif
|
#endif
|
||||||
buf.resize(size + 4);
|
buf.resize(size + 4);
|
||||||
cont.SerializeToArray(buf.data() + 4, size);
|
cont.SerializeToArray(buf.data() + 4, size);
|
||||||
buf.data()[3] = (unsigned char) size;
|
buf.data()[3] = (unsigned char) size;
|
||||||
buf.data()[2] = (unsigned char) (size >> 8);
|
buf.data()[2] = (unsigned char) (size >> 8);
|
||||||
buf.data()[1] = (unsigned char) (size >> 16);
|
buf.data()[1] = (unsigned char) (size >> 16);
|
||||||
buf.data()[0] = (unsigned char) (size >> 24);
|
buf.data()[0] = (unsigned char) (size >> 24);
|
||||||
|
|
||||||
socket->write(buf);
|
socket->write(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||||
{
|
{
|
||||||
doDisconnectFromServer();
|
doDisconnectFromServer();
|
||||||
|
|
||||||
userName = _userName;
|
userName = _userName;
|
||||||
password = _password;
|
password = _password;
|
||||||
socket->connectToHost(hostname, port);
|
socket->connectToHost(hostname, port);
|
||||||
setStatus(StatusConnecting);
|
setStatus(StatusConnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::doDisconnectFromServer()
|
void RemoteClient::doDisconnectFromServer()
|
||||||
{
|
{
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
|
||||||
messageInProgress = false;
|
messageInProgress = false;
|
||||||
handshakeStarted = false;
|
handshakeStarted = false;
|
||||||
messageLength = 0;
|
messageLength = 0;
|
||||||
|
|
||||||
QList<PendingCommand *> pc = pendingCommands.values();
|
QList<PendingCommand *> pc = pendingCommands.values();
|
||||||
for (int i = 0; i < pc.size(); i++) {
|
for (int i = 0; i < pc.size(); i++) {
|
||||||
Response response;
|
Response response;
|
||||||
response.set_response_code(Response::RespNotConnected);
|
response.set_response_code(Response::RespNotConnected);
|
||||||
response.set_cmd_id(pc[i]->getCommandContainer().cmd_id());
|
response.set_cmd_id(pc[i]->getCommandContainer().cmd_id());
|
||||||
pc[i]->processResponse(response);
|
pc[i]->processResponse(response);
|
||||||
|
|
||||||
delete pc[i];
|
delete pc[i];
|
||||||
}
|
}
|
||||||
pendingCommands.clear();
|
pendingCommands.clear();
|
||||||
|
|
||||||
setStatus(StatusDisconnected);
|
setStatus(StatusDisconnected);
|
||||||
socket->close();
|
socket->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::ping()
|
void RemoteClient::ping()
|
||||||
{
|
{
|
||||||
QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
|
QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
PendingCommand *pend = i.next().value();
|
PendingCommand *pend = i.next().value();
|
||||||
if (pend->tick() > maxTimeout) {
|
if (pend->tick() > maxTimeout) {
|
||||||
i.remove();
|
i.remove();
|
||||||
pend->deleteLater();
|
pend->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxTime = timeRunning - lastDataReceived;
|
int maxTime = timeRunning - lastDataReceived;
|
||||||
emit maxPingTime(maxTime, maxTimeout);
|
emit maxPingTime(maxTime, maxTimeout);
|
||||||
if (maxTime >= maxTimeout) {
|
if (maxTime >= maxTimeout) {
|
||||||
disconnectFromServer();
|
disconnectFromServer();
|
||||||
emit serverTimeout();
|
emit serverTimeout();
|
||||||
} else {
|
} else {
|
||||||
sendCommand(prepareSessionCommand(Command_Ping()));
|
sendCommand(prepareSessionCommand(Command_Ping()));
|
||||||
++timeRunning;
|
++timeRunning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||||
{
|
{
|
||||||
emit sigConnectToServer(hostname, port, _userName, _password);
|
emit sigConnectToServer(hostname, port, _userName, _password);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::disconnectFromServer()
|
void RemoteClient::disconnectFromServer()
|
||||||
{
|
{
|
||||||
emit sigDisconnectFromServer();
|
emit sigDisconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,45 +7,45 @@
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
class RemoteClient : public AbstractClient {
|
class RemoteClient : public AbstractClient {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void maxPingTime(int seconds, int maxSeconds);
|
void maxPingTime(int seconds, int maxSeconds);
|
||||||
void serverTimeout();
|
void serverTimeout();
|
||||||
void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
|
void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
|
||||||
void socketError(const QString &errorString);
|
void socketError(const QString &errorString);
|
||||||
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
||||||
void protocolError();
|
void protocolError();
|
||||||
void sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
void sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
void sigDisconnectFromServer();
|
void sigDisconnectFromServer();
|
||||||
private slots:
|
private slots:
|
||||||
void slotConnected();
|
void slotConnected();
|
||||||
void readData();
|
void readData();
|
||||||
void slotSocketError(QAbstractSocket::SocketError error);
|
void slotSocketError(QAbstractSocket::SocketError error);
|
||||||
void ping();
|
void ping();
|
||||||
void processServerIdentificationEvent(const Event_ServerIdentification &event);
|
void processServerIdentificationEvent(const Event_ServerIdentification &event);
|
||||||
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
|
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
|
||||||
void loginResponse(const Response &response);
|
void loginResponse(const Response &response);
|
||||||
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
void doDisconnectFromServer();
|
void doDisconnectFromServer();
|
||||||
private:
|
private:
|
||||||
static const int maxTimeout = 10;
|
static const int maxTimeout = 10;
|
||||||
int timeRunning, lastDataReceived;
|
int timeRunning, lastDataReceived;
|
||||||
|
|
||||||
QByteArray inputBuffer;
|
QByteArray inputBuffer;
|
||||||
bool messageInProgress;
|
bool messageInProgress;
|
||||||
bool handshakeStarted;
|
bool handshakeStarted;
|
||||||
int messageLength;
|
int messageLength;
|
||||||
|
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
protected slots:
|
protected slots:
|
||||||
void sendCommandContainer(const CommandContainer &cont);
|
void sendCommandContainer(const CommandContainer &cont);
|
||||||
public:
|
public:
|
||||||
RemoteClient(QObject *parent = 0);
|
RemoteClient(QObject *parent = 0);
|
||||||
~RemoteClient();
|
~RemoteClient();
|
||||||
QString peerName() const { return socket->peerName(); }
|
QString peerName() const { return socket->peerName(); }
|
||||||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
void disconnectFromServer();
|
void disconnectFromServer();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,324 +10,324 @@
|
||||||
#include "pb/serverinfo_deckstorage.pb.h"
|
#include "pb/serverinfo_deckstorage.pb.h"
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
|
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
|
||||||
: RemoteDeckList_TreeModel::Node(_name, _parent)
|
: RemoteDeckList_TreeModel::Node(_name, _parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode::~DirectoryNode()
|
RemoteDeckList_TreeModel::DirectoryNode::~DirectoryNode()
|
||||||
{
|
{
|
||||||
clearTree();
|
clearTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::DirectoryNode::clearTree()
|
void RemoteDeckList_TreeModel::DirectoryNode::clearTree()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < size(); ++i)
|
||||||
delete at(i);
|
delete at(i);
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RemoteDeckList_TreeModel::DirectoryNode::getPath() const
|
QString RemoteDeckList_TreeModel::DirectoryNode::getPath() const
|
||||||
{
|
{
|
||||||
if (parent) {
|
if (parent) {
|
||||||
QString parentPath = parent->getPath();
|
QString parentPath = parent->getPath();
|
||||||
if (parentPath.isEmpty())
|
if (parentPath.isEmpty())
|
||||||
return name;
|
return name;
|
||||||
else
|
else
|
||||||
return parentPath + "/" + name;
|
return parentPath + "/" + name;
|
||||||
} else
|
} else
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeByPath(QStringList path)
|
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeByPath(QStringList path)
|
||||||
{
|
{
|
||||||
QString pathItem;
|
QString pathItem;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return this;
|
return this;
|
||||||
pathItem = path.takeFirst();
|
pathItem = path.takeFirst();
|
||||||
if (pathItem.isEmpty() && name.isEmpty())
|
if (pathItem.isEmpty() && name.isEmpty())
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size(); ++i) {
|
for (int i = 0; i < size(); ++i) {
|
||||||
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
|
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
|
||||||
if (!node)
|
if (!node)
|
||||||
continue;
|
continue;
|
||||||
if (node->getName() == pathItem)
|
if (node->getName() == pathItem)
|
||||||
return node->getNodeByPath(path);
|
return node->getNodeByPath(path);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeById(int id) const
|
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeById(int id) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size(); ++i) {
|
for (int i = 0; i < size(); ++i) {
|
||||||
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
|
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
|
||||||
if (node) {
|
if (node) {
|
||||||
FileNode *result = node->getNodeById(id);
|
FileNode *result = node->getNodeById(id);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
FileNode *file = dynamic_cast<FileNode *>(at(i));
|
FileNode *file = dynamic_cast<FileNode *>(at(i));
|
||||||
if (file->getId() == id)
|
if (file->getId() == id)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent)
|
RemoteDeckList_TreeModel::RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent)
|
||||||
: QAbstractItemModel(parent), client(_client)
|
: QAbstractItemModel(parent), client(_client)
|
||||||
{
|
{
|
||||||
QFileIconProvider fip;
|
QFileIconProvider fip;
|
||||||
dirIcon = fip.icon(QFileIconProvider::Folder);
|
dirIcon = fip.icon(QFileIconProvider::Folder);
|
||||||
fileIcon = fip.icon(QFileIconProvider::File);
|
fileIcon = fip.icon(QFileIconProvider::File);
|
||||||
|
|
||||||
root = new DirectoryNode;
|
root = new DirectoryNode;
|
||||||
refreshTree();
|
refreshTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::~RemoteDeckList_TreeModel()
|
RemoteDeckList_TreeModel::~RemoteDeckList_TreeModel()
|
||||||
{
|
{
|
||||||
delete root;
|
delete root;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RemoteDeckList_TreeModel::rowCount(const QModelIndex &parent) const
|
int RemoteDeckList_TreeModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
DirectoryNode *node = getNode<DirectoryNode *>(parent);
|
DirectoryNode *node = getNode<DirectoryNode *>(parent);
|
||||||
if (node)
|
if (node)
|
||||||
return node->size();
|
return node->size();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RemoteDeckList_TreeModel::columnCount(const QModelIndex &/*parent*/) const
|
int RemoteDeckList_TreeModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) const
|
QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (index.column() >= 3)
|
if (index.column() >= 3)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
Node *temp = static_cast<Node *>(index.internalPointer());
|
Node *temp = static_cast<Node *>(index.internalPointer());
|
||||||
FileNode *file = dynamic_cast<FileNode *>(temp);
|
FileNode *file = dynamic_cast<FileNode *>(temp);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
DirectoryNode *node = dynamic_cast<DirectoryNode *>(temp);
|
DirectoryNode *node = dynamic_cast<DirectoryNode *>(temp);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return node->getName();
|
case 0: return node->getName();
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return index.column() == 0 ? dirIcon : QVariant();
|
return index.column() == 0 ? dirIcon : QVariant();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return file->getName();
|
case 0: return file->getName();
|
||||||
case 1: return file->getId();
|
case 1: return file->getId();
|
||||||
case 2: return file->getUploadTime();
|
case 2: return file->getUploadTime();
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return index.column() == 0 ? fileIcon : QVariant();
|
return index.column() == 0 ? fileIcon : QVariant();
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return index.column() == 1 ? Qt::AlignRight : Qt::AlignLeft;
|
return index.column() == 1 ? Qt::AlignRight : Qt::AlignLeft;
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RemoteDeckList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant RemoteDeckList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation != Qt::Horizontal)
|
if (orientation != Qt::Horizontal)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return section == 1 ? Qt::AlignRight : Qt::AlignLeft;
|
return section == 1 ? Qt::AlignRight : Qt::AlignLeft;
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return tr("Name");
|
case 0: return tr("Name");
|
||||||
case 1: return tr("ID");
|
case 1: return tr("ID");
|
||||||
case 2: return tr("Upload time");
|
case 2: return tr("Upload time");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteDeckList_TreeModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex RemoteDeckList_TreeModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
DirectoryNode *parentNode = getNode<DirectoryNode *>(parent);
|
DirectoryNode *parentNode = getNode<DirectoryNode *>(parent);
|
||||||
if (row >= parentNode->size())
|
if (row >= parentNode->size())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(row, column, parentNode->at(row));
|
return createIndex(row, column, parentNode->at(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteDeckList_TreeModel::parent(const QModelIndex &ind) const
|
QModelIndex RemoteDeckList_TreeModel::parent(const QModelIndex &ind) const
|
||||||
{
|
{
|
||||||
if (!ind.isValid())
|
if (!ind.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return nodeToIndex(static_cast<Node *>(ind.internalPointer())->getParent());
|
return nodeToIndex(static_cast<Node *>(ind.internalPointer())->getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags RemoteDeckList_TreeModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags RemoteDeckList_TreeModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteDeckList_TreeModel::nodeToIndex(Node *node) const
|
QModelIndex RemoteDeckList_TreeModel::nodeToIndex(Node *node) const
|
||||||
{
|
{
|
||||||
if (node == root)
|
if (node == root)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(node->getParent()->indexOf(node), 0, node);
|
return createIndex(node->getParent()->indexOf(node), 0, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, DirectoryNode *parent)
|
void RemoteDeckList_TreeModel::addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
const ServerInfo_DeckStorage_File &fileInfo = file.file();
|
const ServerInfo_DeckStorage_File &fileInfo = file.file();
|
||||||
QDateTime time;
|
QDateTime time;
|
||||||
time.setTime_t(fileInfo.creation_time());
|
time.setTime_t(fileInfo.creation_time());
|
||||||
|
|
||||||
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
||||||
parent->append(new FileNode(QString::fromStdString(file.name()), file.id(), time, parent));
|
parent->append(new FileNode(QString::fromStdString(file.name()), file.id(), time, parent));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, DirectoryNode *parent)
|
void RemoteDeckList_TreeModel::addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
DirectoryNode *newItem = addNamedFolderToTree(QString::fromStdString(folder.name()), parent);
|
DirectoryNode *newItem = addNamedFolderToTree(QString::fromStdString(folder.name()), parent);
|
||||||
const ServerInfo_DeckStorage_Folder &folderInfo = folder.folder();
|
const ServerInfo_DeckStorage_Folder &folderInfo = folder.folder();
|
||||||
const int folderItemsSize = folderInfo.items_size();
|
const int folderItemsSize = folderInfo.items_size();
|
||||||
for (int i = 0; i < folderItemsSize; ++i) {
|
for (int i = 0; i < folderItemsSize; ++i) {
|
||||||
const ServerInfo_DeckStorage_TreeItem &subItem = folderInfo.items(i);
|
const ServerInfo_DeckStorage_TreeItem &subItem = folderInfo.items(i);
|
||||||
if (subItem.has_folder())
|
if (subItem.has_folder())
|
||||||
addFolderToTree(subItem, newItem);
|
addFolderToTree(subItem, newItem);
|
||||||
else
|
else
|
||||||
addFileToTree(subItem, newItem);
|
addFileToTree(subItem, newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::addNamedFolderToTree(const QString &name, DirectoryNode *parent)
|
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::addNamedFolderToTree(const QString &name, DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
DirectoryNode *newItem = new DirectoryNode(name, parent);
|
DirectoryNode *newItem = new DirectoryNode(name, parent);
|
||||||
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
||||||
parent->append(newItem);
|
parent->append(newItem);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::removeNode(RemoteDeckList_TreeModel::Node *node)
|
void RemoteDeckList_TreeModel::removeNode(RemoteDeckList_TreeModel::Node *node)
|
||||||
{
|
{
|
||||||
int ind = node->getParent()->indexOf(node);
|
int ind = node->getParent()->indexOf(node);
|
||||||
beginRemoveRows(nodeToIndex(node->getParent()), ind, ind);
|
beginRemoveRows(nodeToIndex(node->getParent()), ind, ind);
|
||||||
node->getParent()->removeAt(ind);
|
node->getParent()->removeAt(ind);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
delete node;
|
delete node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::refreshTree()
|
void RemoteDeckList_TreeModel::refreshTree()
|
||||||
{
|
{
|
||||||
PendingCommand *pend = client->prepareSessionCommand(Command_DeckList());
|
PendingCommand *pend = client->prepareSessionCommand(Command_DeckList());
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(deckListFinished(const Response &)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(deckListFinished(const Response &)));
|
||||||
|
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeModel::deckListFinished(const Response &r)
|
void RemoteDeckList_TreeModel::deckListFinished(const Response &r)
|
||||||
{
|
{
|
||||||
const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext);
|
const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext);
|
||||||
|
|
||||||
root->clearTree();
|
root->clearTree();
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
ServerInfo_DeckStorage_TreeItem tempRoot;
|
ServerInfo_DeckStorage_TreeItem tempRoot;
|
||||||
tempRoot.set_id(0);
|
tempRoot.set_id(0);
|
||||||
tempRoot.mutable_folder()->CopyFrom(resp.root());
|
tempRoot.mutable_folder()->CopyFrom(resp.root());
|
||||||
addFolderToTree(tempRoot, root);
|
addFolderToTree(tempRoot, root);
|
||||||
|
|
||||||
emit treeRefreshed();
|
emit treeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent)
|
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent)
|
||||||
: QTreeView(parent)
|
: QTreeView(parent)
|
||||||
{
|
{
|
||||||
treeModel = new RemoteDeckList_TreeModel(_client, this);
|
treeModel = new RemoteDeckList_TreeModel(_client, this);
|
||||||
proxyModel = new QSortFilterProxyModel(this);
|
proxyModel = new QSortFilterProxyModel(this);
|
||||||
proxyModel->setSourceModel(treeModel);
|
proxyModel->setSourceModel(treeModel);
|
||||||
proxyModel->setDynamicSortFilter(true);
|
proxyModel->setDynamicSortFilter(true);
|
||||||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
setModel(proxyModel);
|
setModel(proxyModel);
|
||||||
connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll()));
|
connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll()));
|
||||||
|
|
||||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
setSortingEnabled(true);
|
setSortingEnabled(true);
|
||||||
proxyModel->sort(0, Qt::AscendingOrder);
|
proxyModel->sort(0, Qt::AscendingOrder);
|
||||||
header()->setSortIndicator(0, Qt::AscendingOrder);
|
header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getNode(const QModelIndex &ind) const
|
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getNode(const QModelIndex &ind) const
|
||||||
{
|
{
|
||||||
return treeModel->getNode<RemoteDeckList_TreeModel::Node *>(proxyModel->mapToSource(ind));
|
return treeModel->getNode<RemoteDeckList_TreeModel::Node *>(proxyModel->mapToSource(ind));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getCurrentItem() const
|
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getCurrentItem() const
|
||||||
{
|
{
|
||||||
return getNode(selectionModel()->currentIndex());
|
return getNode(selectionModel()->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const
|
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const
|
||||||
{
|
{
|
||||||
return treeModel->getRoot()->getNodeByPath(path.split("/"));
|
return treeModel->getRoot()->getNodeByPath(path.split("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeWidget::getNodeById(int id) const
|
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeWidget::getNodeById(int id) const
|
||||||
{
|
{
|
||||||
return treeModel->getRoot()->getNodeById(id);
|
return treeModel->getRoot()->getNodeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
void RemoteDeckList_TreeWidget::addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
treeModel->addFileToTree(file, parent);
|
treeModel->addFileToTree(file, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
void RemoteDeckList_TreeWidget::addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
treeModel->addFolderToTree(folder, parent);
|
treeModel->addFolderToTree(folder, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
void RemoteDeckList_TreeWidget::addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent)
|
||||||
{
|
{
|
||||||
treeModel->addNamedFolderToTree(name, parent);
|
treeModel->addNamedFolderToTree(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::removeNode(RemoteDeckList_TreeModel::Node *node)
|
void RemoteDeckList_TreeWidget::removeNode(RemoteDeckList_TreeModel::Node *node)
|
||||||
{
|
{
|
||||||
treeModel->removeNode(node);
|
treeModel->removeNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::refreshTree()
|
void RemoteDeckList_TreeWidget::refreshTree()
|
||||||
{
|
{
|
||||||
treeModel->refreshTree();
|
treeModel->refreshTree();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,92 +11,92 @@ class QSortFilterProxyModel;
|
||||||
class ServerInfo_DeckStorage_TreeItem;
|
class ServerInfo_DeckStorage_TreeItem;
|
||||||
|
|
||||||
class RemoteDeckList_TreeModel : public QAbstractItemModel {
|
class RemoteDeckList_TreeModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
class DirectoryNode;
|
class DirectoryNode;
|
||||||
class FileNode;
|
class FileNode;
|
||||||
class Node {
|
class Node {
|
||||||
protected:
|
protected:
|
||||||
DirectoryNode *parent;
|
DirectoryNode *parent;
|
||||||
QString name;
|
QString name;
|
||||||
public:
|
public:
|
||||||
Node(const QString &_name, DirectoryNode *_parent = 0)
|
Node(const QString &_name, DirectoryNode *_parent = 0)
|
||||||
: parent(_parent), name(_name) { }
|
: parent(_parent), name(_name) { }
|
||||||
virtual ~Node() { };
|
virtual ~Node() { };
|
||||||
DirectoryNode *getParent() const { return parent; }
|
DirectoryNode *getParent() const { return parent; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
};
|
};
|
||||||
class DirectoryNode : public Node, public QList<Node *> {
|
class DirectoryNode : public Node, public QList<Node *> {
|
||||||
public:
|
public:
|
||||||
DirectoryNode(const QString &_name = QString(), DirectoryNode *_parent = 0);
|
DirectoryNode(const QString &_name = QString(), DirectoryNode *_parent = 0);
|
||||||
~DirectoryNode();
|
~DirectoryNode();
|
||||||
void clearTree();
|
void clearTree();
|
||||||
QString getPath() const;
|
QString getPath() const;
|
||||||
DirectoryNode *getNodeByPath(QStringList path);
|
DirectoryNode *getNodeByPath(QStringList path);
|
||||||
FileNode *getNodeById(int id) const;
|
FileNode *getNodeById(int id) const;
|
||||||
};
|
};
|
||||||
class FileNode : public Node {
|
class FileNode : public Node {
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
QDateTime uploadTime;
|
QDateTime uploadTime;
|
||||||
public:
|
public:
|
||||||
FileNode(const QString &_name, int _id, const QDateTime &_uploadTime, DirectoryNode *_parent = 0)
|
FileNode(const QString &_name, int _id, const QDateTime &_uploadTime, DirectoryNode *_parent = 0)
|
||||||
: Node(_name, _parent), id(_id), uploadTime(_uploadTime) { }
|
: Node(_name, _parent), id(_id), uploadTime(_uploadTime) { }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QDateTime getUploadTime() const { return uploadTime; }
|
QDateTime getUploadTime() const { return uploadTime; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> T getNode(const QModelIndex &index) const
|
template<typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return dynamic_cast<T>(root);
|
return dynamic_cast<T>(root);
|
||||||
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
|
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
DirectoryNode *root;
|
DirectoryNode *root;
|
||||||
|
|
||||||
QIcon fileIcon, dirIcon;
|
QIcon fileIcon, dirIcon;
|
||||||
|
|
||||||
QModelIndex nodeToIndex(Node *node) const;
|
QModelIndex nodeToIndex(Node *node) const;
|
||||||
signals:
|
signals:
|
||||||
void treeRefreshed();
|
void treeRefreshed();
|
||||||
private slots:
|
private slots:
|
||||||
void deckListFinished(const Response &r);
|
void deckListFinished(const Response &r);
|
||||||
public:
|
public:
|
||||||
RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent = 0);
|
RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent = 0);
|
||||||
~RemoteDeckList_TreeModel();
|
~RemoteDeckList_TreeModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
DirectoryNode *getRoot() const { return root; }
|
DirectoryNode *getRoot() const { return root; }
|
||||||
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, DirectoryNode *parent);
|
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, DirectoryNode *parent);
|
||||||
void addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, DirectoryNode *parent);
|
void addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, DirectoryNode *parent);
|
||||||
DirectoryNode *addNamedFolderToTree(const QString &name, DirectoryNode *parent);
|
DirectoryNode *addNamedFolderToTree(const QString &name, DirectoryNode *parent);
|
||||||
void removeNode(Node *node);
|
void removeNode(Node *node);
|
||||||
void refreshTree();
|
void refreshTree();
|
||||||
};
|
};
|
||||||
|
|
||||||
class RemoteDeckList_TreeWidget : public QTreeView {
|
class RemoteDeckList_TreeWidget : public QTreeView {
|
||||||
private:
|
private:
|
||||||
RemoteDeckList_TreeModel *treeModel;
|
RemoteDeckList_TreeModel *treeModel;
|
||||||
QSortFilterProxyModel *proxyModel;
|
QSortFilterProxyModel *proxyModel;
|
||||||
public:
|
public:
|
||||||
RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = 0);
|
RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = 0);
|
||||||
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
||||||
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
||||||
RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const;
|
RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const;
|
||||||
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
||||||
void addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
void addFolderToTree(const ServerInfo_DeckStorage_TreeItem &folder, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
||||||
void addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
void addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
||||||
void removeNode(RemoteDeckList_TreeModel::Node *node);
|
void removeNode(RemoteDeckList_TreeModel::Node *node);
|
||||||
void refreshTree();
|
void refreshTree();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,286 +12,286 @@
|
||||||
const int RemoteReplayList_TreeModel::numberOfColumns = 6;
|
const int RemoteReplayList_TreeModel::numberOfColumns = 6;
|
||||||
|
|
||||||
RemoteReplayList_TreeModel::MatchNode::MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
|
RemoteReplayList_TreeModel::MatchNode::MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
|
||||||
: RemoteReplayList_TreeModel::Node(QString::fromStdString(_matchInfo.game_name())), matchInfo(_matchInfo)
|
: RemoteReplayList_TreeModel::Node(QString::fromStdString(_matchInfo.game_name())), matchInfo(_matchInfo)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < matchInfo.replay_list_size(); ++i)
|
for (int i = 0; i < matchInfo.replay_list_size(); ++i)
|
||||||
append(new ReplayNode(matchInfo.replay_list(i), this));
|
append(new ReplayNode(matchInfo.replay_list(i), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteReplayList_TreeModel::MatchNode::~MatchNode()
|
RemoteReplayList_TreeModel::MatchNode::~MatchNode()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < size(); ++i)
|
||||||
delete at(i);
|
delete at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::MatchNode::updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo)
|
void RemoteReplayList_TreeModel::MatchNode::updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo)
|
||||||
{
|
{
|
||||||
matchInfo.MergeFrom(_matchInfo);
|
matchInfo.MergeFrom(_matchInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent)
|
RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent)
|
||||||
: QAbstractItemModel(parent), client(_client)
|
: QAbstractItemModel(parent), client(_client)
|
||||||
{
|
{
|
||||||
QFileIconProvider fip;
|
QFileIconProvider fip;
|
||||||
dirIcon = fip.icon(QFileIconProvider::Folder);
|
dirIcon = fip.icon(QFileIconProvider::Folder);
|
||||||
fileIcon = fip.icon(QFileIconProvider::File);
|
fileIcon = fip.icon(QFileIconProvider::File);
|
||||||
lockIcon = QIcon(":/resources/lock.svg");
|
lockIcon = QIcon(":/resources/lock.svg");
|
||||||
|
|
||||||
refreshTree();
|
refreshTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel()
|
RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel()
|
||||||
{
|
{
|
||||||
clearTree();
|
clearTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const
|
int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
return replayMatches.size();
|
return replayMatches.size();
|
||||||
|
|
||||||
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
|
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
|
||||||
if (matchNode)
|
if (matchNode)
|
||||||
return matchNode->size();
|
return matchNode->size();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) const
|
QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (index.column() >= numberOfColumns)
|
if (index.column() >= numberOfColumns)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
ReplayNode *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
ReplayNode *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
||||||
if (replayNode) {
|
if (replayNode) {
|
||||||
const ServerInfo_Replay &replayInfo = replayNode->getReplayInfo();
|
const ServerInfo_Replay &replayInfo = replayNode->getReplayInfo();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return index.column() == 0 ? Qt::AlignRight : Qt::AlignLeft;
|
return index.column() == 0 ? Qt::AlignRight : Qt::AlignLeft;
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return replayInfo.replay_id();
|
case 0: return replayInfo.replay_id();
|
||||||
case 1: return QString::fromStdString(replayInfo.replay_name());
|
case 1: return QString::fromStdString(replayInfo.replay_name());
|
||||||
case 5: return replayInfo.duration();
|
case 5: return replayInfo.duration();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return index.column() == 0 ? fileIcon : QVariant();
|
return index.column() == 0 ? fileIcon : QVariant();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
|
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
|
||||||
const ServerInfo_ReplayMatch &matchInfo = matchNode->getMatchInfo();
|
const ServerInfo_ReplayMatch &matchInfo = matchNode->getMatchInfo();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
case 5:
|
case 5:
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
default:
|
default:
|
||||||
return Qt::AlignLeft;
|
return Qt::AlignLeft;
|
||||||
}
|
}
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return matchInfo.game_id();
|
case 0: return matchInfo.game_id();
|
||||||
case 1: return QString::fromStdString(matchInfo.game_name());
|
case 1: return QString::fromStdString(matchInfo.game_name());
|
||||||
case 2: {
|
case 2: {
|
||||||
QStringList playerList;
|
QStringList playerList;
|
||||||
for (int i = 0; i < matchInfo.player_names_size(); ++i)
|
for (int i = 0; i < matchInfo.player_names_size(); ++i)
|
||||||
playerList.append(QString::fromStdString(matchInfo.player_names(i)));
|
playerList.append(QString::fromStdString(matchInfo.player_names(i)));
|
||||||
return playerList.join(", ");
|
return playerList.join(", ");
|
||||||
}
|
}
|
||||||
case 4: return QDateTime::fromTime_t(matchInfo.time_started());
|
case 4: return QDateTime::fromTime_t(matchInfo.time_started());
|
||||||
case 5: return matchInfo.length();
|
case 5: return matchInfo.length();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return dirIcon;
|
case 0: return dirIcon;
|
||||||
case 3: return matchInfo.do_not_hide() ? lockIcon : QVariant();
|
case 3: return matchInfo.do_not_hide() ? lockIcon : QVariant();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RemoteReplayList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant RemoteReplayList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation != Qt::Horizontal)
|
if (orientation != Qt::Horizontal)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0:
|
case 0:
|
||||||
case 5:
|
case 5:
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
default:
|
default:
|
||||||
return Qt::AlignLeft;
|
return Qt::AlignLeft;
|
||||||
}
|
}
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return tr("ID");
|
case 0: return tr("ID");
|
||||||
case 1: return tr("Name");
|
case 1: return tr("Name");
|
||||||
case 2: return tr("Players");
|
case 2: return tr("Players");
|
||||||
case 3: return tr("Keep");
|
case 3: return tr("Keep");
|
||||||
case 4: return tr("Time started");
|
case 4: return tr("Time started");
|
||||||
case 5: return tr("Duration (sec)");
|
case 5: return tr("Duration (sec)");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteReplayList_TreeModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex RemoteReplayList_TreeModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
|
MatchNode *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
|
||||||
if (matchNode) {
|
if (matchNode) {
|
||||||
if (row >= matchNode->size())
|
if (row >= matchNode->size())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(row, column, (void *) matchNode->at(row));
|
return createIndex(row, column, (void *) matchNode->at(row));
|
||||||
} else {
|
} else {
|
||||||
if (row >= replayMatches.size())
|
if (row >= replayMatches.size())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(row, column, (void *) replayMatches[row]);
|
return createIndex(row, column, (void *) replayMatches[row]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteReplayList_TreeModel::parent(const QModelIndex &ind) const
|
QModelIndex RemoteReplayList_TreeModel::parent(const QModelIndex &ind) const
|
||||||
{
|
{
|
||||||
MatchNode const *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(ind.internalPointer()));
|
MatchNode const *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(ind.internalPointer()));
|
||||||
if (matchNode)
|
if (matchNode)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
else {
|
else {
|
||||||
ReplayNode *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(ind.internalPointer()));
|
ReplayNode *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(ind.internalPointer()));
|
||||||
return createIndex(replayNode->getParent()->indexOf(replayNode), 0, replayNode);
|
return createIndex(replayNode->getParent()->indexOf(replayNode), 0, replayNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags RemoteReplayList_TreeModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags RemoteReplayList_TreeModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_Replay const* RemoteReplayList_TreeModel::getReplay(const QModelIndex &index) const
|
ServerInfo_Replay const* RemoteReplayList_TreeModel::getReplay(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ReplayNode *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
ReplayNode *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
||||||
if (!node)
|
if (!node)
|
||||||
return 0;
|
return 0;
|
||||||
return &node->getReplayInfo();
|
return &node->getReplayInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_ReplayMatch const* RemoteReplayList_TreeModel::getReplayMatch(const QModelIndex &index) const
|
ServerInfo_ReplayMatch const* RemoteReplayList_TreeModel::getReplayMatch(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
MatchNode *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
|
MatchNode *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
|
||||||
if (!node) {
|
if (!node) {
|
||||||
ReplayNode *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
ReplayNode *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
|
||||||
if (!node)
|
if (!node)
|
||||||
return 0;
|
return 0;
|
||||||
return &node->getParent()->getMatchInfo();
|
return &node->getParent()->getMatchInfo();
|
||||||
} else
|
} else
|
||||||
return &node->getMatchInfo();
|
return &node->getMatchInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::clearTree()
|
void RemoteReplayList_TreeModel::clearTree()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < replayMatches.size(); ++i)
|
for (int i = 0; i < replayMatches.size(); ++i)
|
||||||
delete replayMatches[i];
|
delete replayMatches[i];
|
||||||
replayMatches.clear();
|
replayMatches.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::refreshTree()
|
void RemoteReplayList_TreeModel::refreshTree()
|
||||||
{
|
{
|
||||||
PendingCommand *pend = client->prepareSessionCommand(Command_ReplayList());
|
PendingCommand *pend = client->prepareSessionCommand(Command_ReplayList());
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(replayListFinished(const Response &)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(replayListFinished(const Response &)));
|
||||||
|
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
|
void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size());
|
beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size());
|
||||||
replayMatches.append(new MatchNode(matchInfo));
|
replayMatches.append(new MatchNode(matchInfo));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
emit treeRefreshed();
|
emit treeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
|
void RemoteReplayList_TreeModel::updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < replayMatches.size(); ++i)
|
for (int i = 0; i < replayMatches.size(); ++i)
|
||||||
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
|
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
|
||||||
replayMatches[i]->updateMatchInfo(matchInfo);
|
replayMatches[i]->updateMatchInfo(matchInfo);
|
||||||
emit dataChanged(createIndex(i, 0, (void *) replayMatches[i]), createIndex(i, numberOfColumns - 1, (void *) replayMatches[i]));
|
emit dataChanged(createIndex(i, 0, (void *) replayMatches[i]), createIndex(i, numberOfColumns - 1, (void *) replayMatches[i]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::removeMatchInfo(int gameId)
|
void RemoteReplayList_TreeModel::removeMatchInfo(int gameId)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < replayMatches.size(); ++i)
|
for (int i = 0; i < replayMatches.size(); ++i)
|
||||||
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
|
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
replayMatches.removeAt(i);
|
replayMatches.removeAt(i);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
|
void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
|
||||||
{
|
{
|
||||||
const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext);
|
const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
clearTree();
|
clearTree();
|
||||||
|
|
||||||
for (int i = 0; i < resp.match_list_size(); ++i)
|
for (int i = 0; i < resp.match_list_size(); ++i)
|
||||||
replayMatches.append(new MatchNode(resp.match_list(i)));
|
replayMatches.append(new MatchNode(resp.match_list(i)));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit treeRefreshed();
|
emit treeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteReplayList_TreeWidget::RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent)
|
RemoteReplayList_TreeWidget::RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent)
|
||||||
: QTreeView(parent)
|
: QTreeView(parent)
|
||||||
{
|
{
|
||||||
treeModel = new RemoteReplayList_TreeModel(_client, this);
|
treeModel = new RemoteReplayList_TreeModel(_client, this);
|
||||||
proxyModel = new QSortFilterProxyModel(this);
|
proxyModel = new QSortFilterProxyModel(this);
|
||||||
proxyModel->setSourceModel(treeModel);
|
proxyModel->setSourceModel(treeModel);
|
||||||
proxyModel->setDynamicSortFilter(true);
|
proxyModel->setDynamicSortFilter(true);
|
||||||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
setModel(proxyModel);
|
setModel(proxyModel);
|
||||||
|
|
||||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
header()->setStretchLastSection(false);
|
header()->setStretchLastSection(false);
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
setSortingEnabled(true);
|
setSortingEnabled(true);
|
||||||
proxyModel->sort(0, Qt::AscendingOrder);
|
proxyModel->sort(0, Qt::AscendingOrder);
|
||||||
header()->setSortIndicator(0, Qt::AscendingOrder);
|
header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_Replay const *RemoteReplayList_TreeWidget::getCurrentReplay() const
|
ServerInfo_Replay const *RemoteReplayList_TreeWidget::getCurrentReplay() const
|
||||||
{
|
{
|
||||||
return treeModel->getReplay(proxyModel->mapToSource(selectionModel()->currentIndex()));
|
return treeModel->getReplay(proxyModel->mapToSource(selectionModel()->currentIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_ReplayMatch const *RemoteReplayList_TreeWidget::getCurrentReplayMatch() const
|
ServerInfo_ReplayMatch const *RemoteReplayList_TreeWidget::getCurrentReplayMatch() const
|
||||||
{
|
{
|
||||||
return treeModel->getReplayMatch(proxyModel->mapToSource(selectionModel()->currentIndex()));
|
return treeModel->getReplayMatch(proxyModel->mapToSource(selectionModel()->currentIndex()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,82 +12,82 @@ class AbstractClient;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
|
||||||
class RemoteReplayList_TreeModel : public QAbstractItemModel {
|
class RemoteReplayList_TreeModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
class MatchNode;
|
class MatchNode;
|
||||||
class ReplayNode;
|
class ReplayNode;
|
||||||
class Node {
|
class Node {
|
||||||
protected:
|
protected:
|
||||||
QString name;
|
QString name;
|
||||||
public:
|
public:
|
||||||
Node(const QString &_name)
|
Node(const QString &_name)
|
||||||
: name(_name) { }
|
: name(_name) { }
|
||||||
virtual ~Node() { };
|
virtual ~Node() { };
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
};
|
};
|
||||||
class MatchNode : public Node, public QList<ReplayNode *> {
|
class MatchNode : public Node, public QList<ReplayNode *> {
|
||||||
private:
|
private:
|
||||||
ServerInfo_ReplayMatch matchInfo;
|
ServerInfo_ReplayMatch matchInfo;
|
||||||
public:
|
public:
|
||||||
MatchNode(const ServerInfo_ReplayMatch &_matchInfo);
|
MatchNode(const ServerInfo_ReplayMatch &_matchInfo);
|
||||||
~MatchNode();
|
~MatchNode();
|
||||||
void clearTree();
|
void clearTree();
|
||||||
const ServerInfo_ReplayMatch &getMatchInfo() { return matchInfo; }
|
const ServerInfo_ReplayMatch &getMatchInfo() { return matchInfo; }
|
||||||
void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo);
|
void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo);
|
||||||
};
|
};
|
||||||
class ReplayNode : public Node {
|
class ReplayNode : public Node {
|
||||||
private:
|
private:
|
||||||
MatchNode *parent;
|
MatchNode *parent;
|
||||||
ServerInfo_Replay replayInfo;
|
ServerInfo_Replay replayInfo;
|
||||||
public:
|
public:
|
||||||
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
|
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
|
||||||
: Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo) { }
|
: Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo) { }
|
||||||
MatchNode *getParent() const { return parent; }
|
MatchNode *getParent() const { return parent; }
|
||||||
const ServerInfo_Replay &getReplayInfo() { return replayInfo; }
|
const ServerInfo_Replay &getReplayInfo() { return replayInfo; }
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
QList<MatchNode *> replayMatches;
|
QList<MatchNode *> replayMatches;
|
||||||
|
|
||||||
QIcon dirIcon, fileIcon, lockIcon;
|
QIcon dirIcon, fileIcon, lockIcon;
|
||||||
void clearTree();
|
void clearTree();
|
||||||
|
|
||||||
static const int numberOfColumns;
|
static const int numberOfColumns;
|
||||||
signals:
|
signals:
|
||||||
void treeRefreshed();
|
void treeRefreshed();
|
||||||
private slots:
|
private slots:
|
||||||
void replayListFinished(const Response &r);
|
void replayListFinished(const Response &r);
|
||||||
public:
|
public:
|
||||||
RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = 0);
|
RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = 0);
|
||||||
~RemoteReplayList_TreeModel();
|
~RemoteReplayList_TreeModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return numberOfColumns; }
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return numberOfColumns; }
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
void refreshTree();
|
void refreshTree();
|
||||||
ServerInfo_Replay const* getReplay(const QModelIndex &index) const;
|
ServerInfo_Replay const* getReplay(const QModelIndex &index) const;
|
||||||
ServerInfo_ReplayMatch const* getReplayMatch(const QModelIndex &index) const;
|
ServerInfo_ReplayMatch const* getReplayMatch(const QModelIndex &index) const;
|
||||||
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
|
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
|
||||||
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
|
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
|
||||||
void removeMatchInfo(int gameId);
|
void removeMatchInfo(int gameId);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RemoteReplayList_TreeWidget : public QTreeView {
|
class RemoteReplayList_TreeWidget : public QTreeView {
|
||||||
private:
|
private:
|
||||||
RemoteReplayList_TreeModel *treeModel;
|
RemoteReplayList_TreeModel *treeModel;
|
||||||
QSortFilterProxyModel *proxyModel;
|
QSortFilterProxyModel *proxyModel;
|
||||||
ServerInfo_Replay const *getNode(const QModelIndex &ind) const;
|
ServerInfo_Replay const *getNode(const QModelIndex &ind) const;
|
||||||
public:
|
public:
|
||||||
RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = 0);
|
RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = 0);
|
||||||
ServerInfo_Replay const *getCurrentReplay() const;
|
ServerInfo_Replay const *getCurrentReplay() const;
|
||||||
ServerInfo_ReplayMatch const *getCurrentReplayMatch() const;
|
ServerInfo_ReplayMatch const *getCurrentReplayMatch() const;
|
||||||
void refreshTree();
|
void refreshTree();
|
||||||
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) { treeModel->addMatchInfo(matchInfo); }
|
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) { treeModel->addMatchInfo(matchInfo); }
|
||||||
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo) { treeModel->updateMatchInfo(gameId, matchInfo); }
|
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo) { treeModel->updateMatchInfo(gameId, matchInfo); }
|
||||||
void removeMatchInfo(int gameId) { treeModel->removeMatchInfo(gameId); }
|
void removeMatchInfo(int gameId) { treeModel->removeMatchInfo(gameId); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,97 +5,97 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent)
|
ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent)
|
||||||
: QWidget(parent), maxBinValue(1), maxTime(1), timeScaleFactor(1.0), currentTime(0), currentEvent(0)
|
: QWidget(parent), maxBinValue(1), maxTime(1), timeScaleFactor(1.0), currentTime(0), currentEvent(0)
|
||||||
{
|
{
|
||||||
replayTimer = new QTimer(this);
|
replayTimer = new QTimer(this);
|
||||||
connect(replayTimer, SIGNAL(timeout()), this, SLOT(replayTimerTimeout()));
|
connect(replayTimer, SIGNAL(timeout()), this, SLOT(replayTimerTimeout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ReplayTimelineWidget::binLength = 5000;
|
const int ReplayTimelineWidget::binLength = 5000;
|
||||||
|
|
||||||
void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
|
void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
|
||||||
{
|
{
|
||||||
replayTimeline = _replayTimeline;
|
replayTimeline = _replayTimeline;
|
||||||
histogram.clear();
|
histogram.clear();
|
||||||
int binEndTime = binLength - 1;
|
int binEndTime = binLength - 1;
|
||||||
int binValue = 0;
|
int binValue = 0;
|
||||||
for (int i = 0; i < replayTimeline.size(); ++i) {
|
for (int i = 0; i < replayTimeline.size(); ++i) {
|
||||||
if (replayTimeline[i] > binEndTime) {
|
if (replayTimeline[i] > binEndTime) {
|
||||||
histogram.append(binValue);
|
histogram.append(binValue);
|
||||||
if (binValue > maxBinValue)
|
if (binValue > maxBinValue)
|
||||||
maxBinValue = binValue;
|
maxBinValue = binValue;
|
||||||
while (replayTimeline[i] > binEndTime + binLength) {
|
while (replayTimeline[i] > binEndTime + binLength) {
|
||||||
histogram.append(0);
|
histogram.append(0);
|
||||||
binEndTime += binLength;
|
binEndTime += binLength;
|
||||||
}
|
}
|
||||||
binValue = 1;
|
binValue = 1;
|
||||||
binEndTime += binLength;
|
binEndTime += binLength;
|
||||||
} else
|
} else
|
||||||
++binValue;
|
++binValue;
|
||||||
}
|
}
|
||||||
histogram.append(binValue);
|
histogram.append(binValue);
|
||||||
if (!replayTimeline.isEmpty())
|
if (!replayTimeline.isEmpty())
|
||||||
maxTime = replayTimeline.last();
|
maxTime = replayTimeline.last();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::paintEvent(QPaintEvent *event)
|
void ReplayTimelineWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||||
|
|
||||||
qreal binWidth = (qreal) width() / histogram.size();
|
qreal binWidth = (qreal) width() / histogram.size();
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.moveTo(0, height() - 1);
|
path.moveTo(0, height() - 1);
|
||||||
for (int i = 0; i < histogram.size(); ++i)
|
for (int i = 0; i < histogram.size(); ++i)
|
||||||
path.lineTo(round(i * binWidth), (height() - 1) * (1.0 - (qreal) histogram[i] / maxBinValue));
|
path.lineTo(round(i * binWidth), (height() - 1) * (1.0 - (qreal) histogram[i] / maxBinValue));
|
||||||
path.lineTo(width() - 1, height() - 1);
|
path.lineTo(width() - 1, height() - 1);
|
||||||
path.lineTo(0, height() - 1);
|
path.lineTo(0, height() - 1);
|
||||||
painter.fillPath(path, Qt::black);
|
painter.fillPath(path, Qt::black);
|
||||||
|
|
||||||
const QColor barColor = QColor::fromHsv(120, 255, 255, 100);
|
const QColor barColor = QColor::fromHsv(120, 255, 255, 100);
|
||||||
painter.fillRect(0, 0, (width() - 1) * currentTime / maxTime, height() - 1, barColor);
|
painter.fillRect(0, 0, (width() - 1) * currentTime / maxTime, height() - 1, barColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize ReplayTimelineWidget::sizeHint() const
|
QSize ReplayTimelineWidget::sizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(-1, 50);
|
return QSize(-1, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize ReplayTimelineWidget::minimumSizeHint() const
|
QSize ReplayTimelineWidget::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(400, 50);
|
return QSize(400, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::replayTimerTimeout()
|
void ReplayTimelineWidget::replayTimerTimeout()
|
||||||
{
|
{
|
||||||
currentTime += 200;
|
currentTime += 200;
|
||||||
while ((currentEvent < replayTimeline.size()) && (replayTimeline[currentEvent] < currentTime)) {
|
while ((currentEvent < replayTimeline.size()) && (replayTimeline[currentEvent] < currentTime)) {
|
||||||
emit processNextEvent();
|
emit processNextEvent();
|
||||||
++currentEvent;
|
++currentEvent;
|
||||||
}
|
}
|
||||||
if (currentEvent == replayTimeline.size()) {
|
if (currentEvent == replayTimeline.size()) {
|
||||||
emit replayFinished();
|
emit replayFinished();
|
||||||
replayTimer->stop();
|
replayTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(currentTime % 1000))
|
if (!(currentTime % 1000))
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
|
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
|
||||||
{
|
{
|
||||||
timeScaleFactor = _timeScaleFactor;
|
timeScaleFactor = _timeScaleFactor;
|
||||||
replayTimer->setInterval(200 / timeScaleFactor);
|
replayTimer->setInterval(200 / timeScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::startReplay()
|
void ReplayTimelineWidget::startReplay()
|
||||||
{
|
{
|
||||||
replayTimer->start(200 / timeScaleFactor);
|
replayTimer->start(200 / timeScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::stopReplay()
|
void ReplayTimelineWidget::stopReplay()
|
||||||
{
|
{
|
||||||
replayTimer->stop();
|
replayTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,33 +8,33 @@ class QPaintEvent;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
class ReplayTimelineWidget : public QWidget {
|
class ReplayTimelineWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void processNextEvent();
|
void processNextEvent();
|
||||||
void replayFinished();
|
void replayFinished();
|
||||||
private:
|
private:
|
||||||
QTimer *replayTimer;
|
QTimer *replayTimer;
|
||||||
QList<int> replayTimeline;
|
QList<int> replayTimeline;
|
||||||
QList<int> histogram;
|
QList<int> histogram;
|
||||||
static const int binLength;
|
static const int binLength;
|
||||||
int maxBinValue, maxTime;
|
int maxBinValue, maxTime;
|
||||||
qreal timeScaleFactor;
|
qreal timeScaleFactor;
|
||||||
int currentTime;
|
int currentTime;
|
||||||
int currentEvent;
|
int currentEvent;
|
||||||
private slots:
|
private slots:
|
||||||
void replayTimerTimeout();
|
void replayTimerTimeout();
|
||||||
public:
|
public:
|
||||||
ReplayTimelineWidget(QWidget *parent = 0);
|
ReplayTimelineWidget(QWidget *parent = 0);
|
||||||
void setTimeline(const QList<int> &_replayTimeline);
|
void setTimeline(const QList<int> &_replayTimeline);
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const;
|
||||||
void setTimeScaleFactor(qreal _timeScaleFactor);
|
void setTimeScaleFactor(qreal _timeScaleFactor);
|
||||||
int getCurrentEvent() const { return currentEvent; }
|
int getCurrentEvent() const { return currentEvent; }
|
||||||
public slots:
|
public slots:
|
||||||
void startReplay();
|
void startReplay();
|
||||||
void stopReplay();
|
void stopReplay();
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,52 +5,52 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
SelectZone::SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView)
|
SelectZone::SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView)
|
||||||
: CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView)
|
: CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons().testFlag(Qt::LeftButton)) {
|
if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
if (pos.x() < 0)
|
if (pos.x() < 0)
|
||||||
pos.setX(0);
|
pos.setX(0);
|
||||||
QRectF br = boundingRect();
|
QRectF br = boundingRect();
|
||||||
if (pos.x() > br.width())
|
if (pos.x() > br.width())
|
||||||
pos.setX(br.width());
|
pos.setX(br.width());
|
||||||
if (pos.y() < 0)
|
if (pos.y() < 0)
|
||||||
pos.setY(0);
|
pos.setY(0);
|
||||||
if (pos.y() > br.height())
|
if (pos.y() > br.height())
|
||||||
pos.setY(br.height());
|
pos.setY(br.height());
|
||||||
|
|
||||||
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
||||||
for (int i = 0; i < cards.size(); ++i) {
|
for (int i = 0; i < cards.size(); ++i) {
|
||||||
if (cards[i]->getAttachedTo())
|
if (cards[i]->getAttachedTo())
|
||||||
if (cards[i]->getAttachedTo()->getZone() != this)
|
if (cards[i]->getAttachedTo()->getZone() != this)
|
||||||
continue;
|
continue;
|
||||||
cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect())));
|
cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect())));
|
||||||
}
|
}
|
||||||
static_cast<GameScene *>(scene())->resizeRubberBand(deviceTransform(static_cast<GameScene *>(scene())->getViewportTransform()).map(pos));
|
static_cast<GameScene *>(scene())->resizeRubberBand(deviceTransform(static_cast<GameScene *>(scene())->getViewportTransform()).map(pos));
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
scene()->clearSelection();
|
scene()->clearSelection();
|
||||||
|
|
||||||
selectionOrigin = event->pos();
|
selectionOrigin = event->pos();
|
||||||
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
|
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
|
||||||
event->accept();
|
event->accept();
|
||||||
} else
|
} else
|
||||||
CardZone::mousePressEvent(event);
|
CardZone::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
selectionOrigin = QPoint();
|
selectionOrigin = QPoint();
|
||||||
static_cast<GameScene *>(scene())->stopRubberBand();
|
static_cast<GameScene *>(scene())->stopRubberBand();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
|
|
||||||
class SelectZone : public CardZone {
|
class SelectZone : public CardZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QPointF selectionOrigin;
|
QPointF selectionOrigin;
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
public:
|
public:
|
||||||
SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false);
|
SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue