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

Convert rest of source to 4-space indent

parent a171df74
......@@ -5,29 +5,29 @@
#include <QHBoxLayout>
WndSets::WndSets(QWidget *parent)
: QMainWindow(parent)
: QMainWindow(parent)
{
model = new SetsModel(db, this);
view = new QTreeView;
view->setModel(model);
view->setAlternatingRowColors(true);
view->setUniformRowHeights(true);
view->setAllColumnsShowFocus(true);
model = new SetsModel(db, this);
view = new QTreeView;
view->setModel(model);
view->setAlternatingRowColors(true);
view->setUniformRowHeights(true);
view->setAllColumnsShowFocus(true);
view->setDragEnabled(true);
view->setAcceptDrops(true);
view->setDropIndicatorShown(true);
view->setDragDropMode(QAbstractItemView::InternalMove);
view->setDragEnabled(true);
view->setAcceptDrops(true);
view->setDropIndicatorShown(true);
view->setDragDropMode(QAbstractItemView::InternalMove);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
setWindowTitle(tr("Edit sets"));
resize(400, 400);
setWindowTitle(tr("Edit sets"));
resize(400, 400);
}
WndSets::~WndSets()
......
......@@ -8,13 +8,13 @@ class QTreeView;
class CardDatabase;
class WndSets : public QMainWindow {
Q_OBJECT
Q_OBJECT
private:
SetsModel *model;
QTreeView *view;
SetsModel *model;
QTreeView *view;
public:
WndSets(QWidget *parent = 0);
~WndSets();
WndSets(QWidget *parent = 0);
~WndSets();
};
#endif
......@@ -19,197 +19,197 @@
#include "pb/command_shuffle.pb.h"
TitleLabel::TitleLabel()
: QGraphicsWidget(), text(" ")
: QGraphicsWidget(), text(" ")
{
setAcceptHoverEvents(true);
setAcceptHoverEvents(true);
}
void TitleLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
QBrush windowBrush = palette().window();
windowBrush.setColor(windowBrush.color().darker(150));
painter->fillRect(boundingRect(), windowBrush);
painter->drawText(boundingRect(), Qt::AlignLeft | Qt::AlignVCenter, text);
QBrush windowBrush = palette().window();
windowBrush.setColor(windowBrush.color().darker(150));
painter->fillRect(boundingRect(), windowBrush);
painter->drawText(boundingRect(), Qt::AlignLeft | Qt::AlignVCenter, text);
}
QSizeF TitleLabel::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
QFont f;
QFontMetrics fm(f);
if (which == Qt::MaximumSize)
return QSizeF(constraint.width(), fm.size(Qt::TextSingleLine, text).height() + 10);
else
return fm.size(Qt::TextSingleLine, text) + QSizeF(10, 10);
QFont f;
QFontMetrics fm(f);
if (which == Qt::MaximumSize)
return QSizeF(constraint.width(), fm.size(Qt::TextSingleLine, text).height() + 10);
else
return fm.size(Qt::TextSingleLine, text) + QSizeF(10, 10);
}
void TitleLabel::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
buttonDownPos = static_cast<GameScene *>(scene())->getViewTransform().inverted().map(event->pos());
event->accept();
} else
event->ignore();
if (event->button() == Qt::LeftButton) {
buttonDownPos = static_cast<GameScene *>(scene())->getViewTransform().inverted().map(event->pos());
event->accept();
} else
event->ignore();
}
void TitleLabel::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
emit mouseMoved(event->scenePos() - buttonDownPos);
emit mouseMoved(event->scenePos() - buttonDownPos);
}
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, bool _revealZone, bool _writeableRevealZone, const QList<const ServerInfo_Card *> &cardList)
: QGraphicsWidget(0, Qt::Tool | Qt::FramelessWindowHint), player(_player)
: QGraphicsWidget(0, Qt::Tool | Qt::FramelessWindowHint), player(_player)
{
setAcceptHoverEvents(true);
setAttribute(Qt::WA_DeleteOnClose);
setZValue(2000000006);
setFlag(ItemIgnoresTransformations);
QGraphicsLinearLayout *hbox = new QGraphicsLinearLayout(Qt::Horizontal);
titleLabel = new TitleLabel;
connect(titleLabel, SIGNAL(mouseMoved(QPointF)), this, SLOT(moveWidget(QPointF)));
closeButton = new QPushButton("X");
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QGraphicsProxyWidget *closeButtonProxy = new QGraphicsProxyWidget;
closeButtonProxy->setWidget(closeButton);
hbox->addItem(titleLabel);
hbox->addItem(closeButtonProxy);
QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical);
vbox->addItem(hbox);
if (numberCards < 0) {
sortByNameCheckBox = new QCheckBox;
QGraphicsProxyWidget *sortByNameProxy = new QGraphicsProxyWidget;
sortByNameProxy->setWidget(sortByNameCheckBox);
vbox->addItem(sortByNameProxy);
sortByTypeCheckBox = new QCheckBox;
QGraphicsProxyWidget *sortByTypeProxy = new QGraphicsProxyWidget;
sortByTypeProxy->setWidget(sortByTypeCheckBox);
vbox->addItem(sortByTypeProxy);
} else {
sortByNameCheckBox = 0;
sortByTypeCheckBox = 0;
}
if (_origZone->getIsShufflable() && (numberCards == -1)) {
shuffleCheckBox = new QCheckBox;
shuffleCheckBox->setChecked(true);
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget;
shuffleProxy->setWidget(shuffleCheckBox);
vbox->addItem(shuffleProxy);
} else
shuffleCheckBox = 0;
extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
resize(150, 150);
QGraphicsLinearLayout *zoneHBox = new QGraphicsLinearLayout(Qt::Horizontal);
zoneContainer = new QGraphicsWidget(this);
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
zoneContainer->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
zoneHBox->addItem(zoneContainer);
scrollBar = new QScrollBar(Qt::Vertical);
scrollBar->setMinimum(0);
scrollBar->setSingleStep(50);
connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(handleScrollBarChange(int)));
QGraphicsProxyWidget *scrollBarProxy = new QGraphicsProxyWidget;
scrollBarProxy->setWidget(scrollBar);
zoneHBox->addItem(scrollBarProxy);
vbox->addItem(zoneHBox);
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer);
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), this, SLOT(handleWheelEvent(QGraphicsSceneWheelEvent *)));
if (sortByNameCheckBox) {
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
connect(sortByTypeCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByType(int)));
sortByNameCheckBox->setChecked(settingsCache->getZoneViewSortByName());
sortByTypeCheckBox->setChecked(settingsCache->getZoneViewSortByType());
}
retranslateUi();
setLayout(vbox);
connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents()));
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
zone->initializeCards(cardList);
setAcceptHoverEvents(true);
setAttribute(Qt::WA_DeleteOnClose);
setZValue(2000000006);
setFlag(ItemIgnoresTransformations);
QGraphicsLinearLayout *hbox = new QGraphicsLinearLayout(Qt::Horizontal);
titleLabel = new TitleLabel;
connect(titleLabel, SIGNAL(mouseMoved(QPointF)), this, SLOT(moveWidget(QPointF)));
closeButton = new QPushButton("X");
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QGraphicsProxyWidget *closeButtonProxy = new QGraphicsProxyWidget;
closeButtonProxy->setWidget(closeButton);
hbox->addItem(titleLabel);
hbox->addItem(closeButtonProxy);
QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical);
vbox->addItem(hbox);
if (numberCards < 0) {
sortByNameCheckBox = new QCheckBox;
QGraphicsProxyWidget *sortByNameProxy = new QGraphicsProxyWidget;
sortByNameProxy->setWidget(sortByNameCheckBox);
vbox->addItem(sortByNameProxy);
sortByTypeCheckBox = new QCheckBox;
QGraphicsProxyWidget *sortByTypeProxy = new QGraphicsProxyWidget;
sortByTypeProxy->setWidget(sortByTypeCheckBox);
vbox->addItem(sortByTypeProxy);
} else {
sortByNameCheckBox = 0;
sortByTypeCheckBox = 0;
}
if (_origZone->getIsShufflable() && (numberCards == -1)) {
shuffleCheckBox = new QCheckBox;
shuffleCheckBox->setChecked(true);
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget;
shuffleProxy->setWidget(shuffleCheckBox);
vbox->addItem(shuffleProxy);
} else
shuffleCheckBox = 0;
extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
resize(150, 150);
QGraphicsLinearLayout *zoneHBox = new QGraphicsLinearLayout(Qt::Horizontal);
zoneContainer = new QGraphicsWidget(this);
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
zoneContainer->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
zoneHBox->addItem(zoneContainer);
scrollBar = new QScrollBar(Qt::Vertical);
scrollBar->setMinimum(0);
scrollBar->setSingleStep(50);
connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(handleScrollBarChange(int)));
QGraphicsProxyWidget *scrollBarProxy = new QGraphicsProxyWidget;
scrollBarProxy->setWidget(scrollBar);
zoneHBox->addItem(scrollBarProxy);
vbox->addItem(zoneHBox);
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer);
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), this, SLOT(handleWheelEvent(QGraphicsSceneWheelEvent *)));
if (sortByNameCheckBox) {
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
connect(sortByTypeCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByType(int)));
sortByNameCheckBox->setChecked(settingsCache->getZoneViewSortByName());
sortByTypeCheckBox->setChecked(settingsCache->getZoneViewSortByType());
}
retranslateUi();
setLayout(vbox);
connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents()));
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
zone->initializeCards(cardList);
}
void ZoneViewWidget::retranslateUi()
{
titleLabel->setText(zone->getTranslatedName(false, CaseNominative));
if (sortByNameCheckBox)
sortByNameCheckBox->setText(tr("sort by name"));
if (sortByTypeCheckBox)
sortByTypeCheckBox->setText(tr("sort by type"));
if (shuffleCheckBox)
shuffleCheckBox->setText(tr("shuffle when closing"));
titleLabel->setText(zone->getTranslatedName(false, CaseNominative));
if (sortByNameCheckBox)
sortByNameCheckBox->setText(tr("sort by name"));
if (sortByTypeCheckBox)
sortByTypeCheckBox->setText(tr("sort by type"));
if (shuffleCheckBox)
shuffleCheckBox->setText(tr("shuffle when closing"));
}
void ZoneViewWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->fillRect(boundingRect(), palette().color(QPalette::Window));
QGraphicsWidget::paint(painter, option, widget);
painter->fillRect(boundingRect(), palette().color(QPalette::Window));
QGraphicsWidget::paint(painter, option, widget);
}
void ZoneViewWidget::moveWidget(QPointF scenePos)
{
setPos(scenePos);
setPos(scenePos);
}
void ZoneViewWidget::resizeToZoneContents()
{
QRectF zoneRect = zone->getOptimumRect();
qreal totalZoneHeight = zoneRect.height();
if (zoneRect.height() > 500)
zoneRect.setHeight(500);
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + scrollBar->width() + 10), zoneRect.height() + extraHeight + 10);
setMaximumSize(newSize);
resize(newSize);
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
if (layout())
layout()->invalidate();
QRectF zoneRect = zone->getOptimumRect();
qreal totalZoneHeight = zoneRect.height();
if (zoneRect.height() > 500)
zoneRect.setHeight(500);
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + scrollBar->width() + 10), zoneRect.height() + extraHeight + 10);
setMaximumSize(newSize);
resize(newSize);
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
if (layout())
layout()->invalidate();
}
void ZoneViewWidget::handleWheelEvent(QGraphicsSceneWheelEvent *event)
{
QWheelEvent wheelEvent(QPoint(), event->delta(), event->buttons(), event->modifiers(), event->orientation());
scrollBar->event(&wheelEvent);
QWheelEvent wheelEvent(QPoint(), event->delta(), event->buttons(), event->modifiers(), event->orientation());
scrollBar->event(&wheelEvent);
}
void ZoneViewWidget::handleScrollBarChange(int value)
{
zone->setY(-value);
zone->setY(-value);
}
void ZoneViewWidget::closeEvent(QCloseEvent *event)
{
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
if (zone->getNumberCards() != -2) {
Command_StopDumpZone cmd;
cmd.set_player_id(player->getId());
cmd.set_zone_name(zone->getName().toStdString());
player->sendGameCommand(cmd);
}
if (shuffleCheckBox)
if (shuffleCheckBox->isChecked())
player->sendGameCommand(Command_Shuffle());
emit closePressed(this);
deleteLater();
event->accept();
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
if (zone->getNumberCards() != -2) {
Command_StopDumpZone cmd;
cmd.set_player_id(player->getId());
cmd.set_zone_name(zone->getName().toStdString());
player->sendGameCommand(cmd);
}
if (shuffleCheckBox)
if (shuffleCheckBox->isChecked())
player->sendGameCommand(Command_Shuffle());
emit closePressed(this);
deleteLater();
event->accept();
}
void ZoneViewWidget::zoneDeleted()
{
emit closePressed(this);
deleteLater();
emit closePressed(this);
deleteLater();
}
......@@ -17,50 +17,50 @@ class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class TitleLabel : public QGraphicsWidget {
Q_OBJECT
Q_OBJECT
private:
QString text;
QPointF buttonDownPos;
QString text;
QPointF buttonDownPos;
public:
TitleLabel();
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
void setText(const QString &_text) { text = _text; update(); }
TitleLabel();
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
void setText(const QString &_text) { text = _text; update(); }
signals:
void mouseMoved(QPointF scenePos);
void mouseMoved(QPointF scenePos);
protected:
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
class ZoneViewWidget : public QGraphicsWidget {
Q_OBJECT
Q_OBJECT
private:
ZoneViewZone *zone;
QGraphicsWidget *zoneContainer;
TitleLabel *titleLabel;
QPushButton *closeButton;
QScrollBar *scrollBar;
QCheckBox *sortByNameCheckBox, *sortByTypeCheckBox, *shuffleCheckBox;
int extraHeight;
Player *player;
ZoneViewZone *zone;
QGraphicsWidget *zoneContainer;
TitleLabel *titleLabel;
QPushButton *closeButton;
QScrollBar *scrollBar;
QCheckBox *sortByNameCheckBox, *sortByTypeCheckBox, *shuffleCheckBox;
int extraHeight;
Player *player;
signals:
void closePressed(ZoneViewWidget *zv);
void closePressed(ZoneViewWidget *zv);
private slots:
void resizeToZoneContents();
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
void handleScrollBarChange(int value);
void zoneDeleted();
void moveWidget(QPointF scenePos);
void resizeToZoneContents();
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
void handleScrollBarChange(int value);
void zoneDeleted();
void moveWidget(QPointF scenePos);
public:
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, bool _revealZone = false, bool _writeableRevealZone = false, const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
ZoneViewZone *getZone() const { return zone; }
void retranslateUi();
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, bool _revealZone = false, bool _writeableRevealZone = false, const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
ZoneViewZone *getZone() const { return zone; }
void retranslateUi();
protected:
void closeEvent(QCloseEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void closeEvent(QCloseEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};
#endif
......@@ -12,23 +12,23 @@
#include "pending_command.h"
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, bool _revealZone, bool _writeableRevealZone, QGraphicsItem *parent)
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone), writeableRevealZone(_writeableRevealZone), sortByName(false), sortByType(false)
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone), writeableRevealZone(_writeableRevealZone), sortByName(false), sortByType(false)
{
if (!(revealZone && !writeableRevealZone))
origZone->setView(this);
if (!(revealZone && !writeableRevealZone))
origZone->setView(this);
}
ZoneViewZone::~ZoneViewZone()
{
emit beingDeleted();
qDebug("ZoneViewZone destructor");
if (!(revealZone && !writeableRevealZone))
origZone->setView(NULL);
emit beingDeleted();
qDebug("ZoneViewZone destructor");
if (!(revealZone && !writeableRevealZone))
origZone->setView(NULL);
}
QRectF ZoneViewZone::boundingRect() const
{
return bRect;
return bRect;
}
void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
......@@ -37,154 +37,154 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardList)
{
if (!cardList.isEmpty()) {
for (int i = 0; i < cardList.size(); ++i)
addCard(new CardItem(player, QString::fromStdString(cardList[i]->name()), cardList[i]->id(), revealZone, this), false, i);
reorganizeCards();
} else if (!origZone->contentsKnown()) {
Command_DumpZone cmd;
cmd.set_player_id(player->getId());
cmd.set_zone_name(name.toStdString());
cmd.set_number_cards(numberCards);
PendingCommand *pend = player->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(zoneDumpReceived(const Response &)));
player->sendGameCommand(pend);
} else {
const CardList &c = origZone->getCards();
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
for (int i = 0; i < number; i++) {
CardItem *card = c.at(i);
addCard(new CardItem(player, card->getName(), card->getId(), revealZone, this), false, i);
}
reorganizeCards();
}
if (!cardList.isEmpty()) {
for (int i = 0; i < cardList.size(); ++i)
addCard(new CardItem(player, QString::fromStdString(cardList[i]->name()), cardList[i]->id(), revealZone, this), false, i);
reorganizeCards();
} else if (!origZone->contentsKnown()) {
Command_DumpZone cmd;
cmd.set_player_id(player->getId());
cmd.set_zone_name(name.toStdString());
cmd.set_number_cards(numberCards);
PendingCommand *pend = player->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(zoneDumpReceived(const Response &)));
player->sendGameCommand(pend);
} else {
const CardList &c = origZone->getCards();
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
for (int i = 0; i < number; i++) {
CardItem *card = c.at(i);
addCard(new CardItem(player, card->getName(), card->getId(), revealZone, this), false, i);
}
reorganizeCards();
}
}
void ZoneViewZone::zoneDumpReceived(const Response &r)
{
const Response_DumpZone &resp = r.GetExtension(Response_DumpZone::ext);
const int respCardListSize = resp.zone_info().card_list_size();
for (int i = 0; i < respCardListSize; ++i) {
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
CardItem *card = new CardItem(player, QString::fromStdString(cardInfo.name()), cardInfo.id(), revealZone, this);
addCard(card, false, i);
}
reorganizeCards();
const Response_DumpZone &resp = r.GetExtension(Response_DumpZone::ext);
const int respCardListSize = resp.zone_info().card_list_size();
for (int i = 0; i < respCardListSize; ++i) {
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
CardItem *card = new CardItem(player, QString::fromStdString(cardInfo.name()), cardInfo.id(), revealZone, this);
addCard(card, false, i);
}
reorganizeCards();
}
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
void ZoneViewZone::reorganizeCards()
{
int cardCount = cards.size();
if (!origZone->contentsKnown())
for (int i = 0; i < cardCount; ++i)
cards[i]->setId(i);
int cols = floor(sqrt((double) cardCount / 2));
if (cols > 7)
cols = 7;
int rows = ceil((double) cardCount / cols);
if (rows < 1)
rows = 1;
if (minRows == 0)
minRows = rows;
else if (rows < minRows) {
rows = minRows;
cols = ceil((double) cardCount / minRows);
}
if (cols < 2)
cols = 2;
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
CardList cardsToDisplay(cards);
if (sortByName || sortByType)
cardsToDisplay.sort((sortByName ? CardList::SortByName : 0) | (sortByType ? CardList::SortByType : 0));
for (int i = 0; i < cardCount; i++) {
CardItem *c = cardsToDisplay.at(i);
qreal x = (i / rows) * CARD_WIDTH;
qreal y = (i % rows) * CARD_HEIGHT / 3;
c->setPos(x + 5, y + 5);
c->setRealZValue(i);
}
optimumRect = QRectF(0, 0, qMax(cols, 3) * CARD_WIDTH + 10, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT + 10);
updateGeometry();
emit optimumRectChanged();
int cardCount = cards.size();
if (!origZone->contentsKnown())
for (int i = 0; i < cardCount; ++i)
cards[i]->setId(i);
int cols = floor(sqrt((double) cardCount / 2));
if (cols > 7)
cols = 7;
int rows = ceil((double) cardCount / cols);
if (rows < 1)
rows = 1;
if (minRows == 0)
minRows = rows;
else if (rows < minRows) {
rows = minRows;
cols = ceil((double) cardCount / minRows);
}
if (cols < 2)
cols = 2;
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
CardList cardsToDisplay(cards);
if (sortByName || sortByType)
cardsToDisplay.sort((sortByName ? CardList::SortByName : 0) | (sortByType ? CardList::SortByType : 0));
for (int i = 0; i < cardCount; i++) {
CardItem *c = cardsToDisplay.at(i);
qreal x = (i / rows) * CARD_WIDTH;
qreal y = (i % rows) * CARD_HEIGHT / 3;
c->setPos(x + 5, y + 5);
c->setRealZValue(i);
}
optimumRect = QRectF(0, 0, qMax(cols, 3) * CARD_WIDTH + 10, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT + 10);
updateGeometry();
emit optimumRectChanged();
}
void ZoneViewZone::setSortByName(int _sortByName)
{
sortByName = _sortByName;
reorganizeCards();
sortByName = _sortByName;
reorganizeCards();
}
void ZoneViewZone::setSortByType(int _sortByType)
{
sortByType = _sortByType;
reorganizeCards();
sortByType = _sortByType;
reorganizeCards();
}
void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
cards.insert(x, card);
card->setParentItem(this);
card->update();
cards.insert(x, card);
card->setParentItem(this);
card->update();
}
void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
{
Command_MoveCard cmd;
cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(0);
cmd.set_y(0);
for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
Command_MoveCard cmd;
cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(0);
cmd.set_y(0);
for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(cmd);
player->sendGameCommand(cmd);
}
void ZoneViewZone::removeCard(int position)
{
if (position >= cards.size())
return;
if (position >= cards.size())
return;
CardItem *card = cards.takeAt(position);
card->deleteLater();
reorganizeCards();
CardItem *card = cards.takeAt(position);
card->deleteLater();
reorganizeCards();
}
void ZoneViewZone::setGeometry(const QRectF &rect)
{
prepareGeometryChange();
setPos(rect.x(), rect.y());
bRect = QRectF(0, 0, rect.width(), rect.height());
prepareGeometryChange();
setPos(rect.x(), rect.y());
bRect = QRectF(0, 0, rect.width(), rect.height());
}
QSizeF ZoneViewZone::sizeHint(Qt::SizeHint /*which*/, const QSizeF & /*constraint*/) const
{
return optimumRect.size();
return optimumRect.size();
}
void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
{
if (writeableRevealZone && !_writeableRevealZone)
origZone->setView(this);
else if (!writeableRevealZone && _writeableRevealZone)
origZone->setView(NULL);
writeableRevealZone = _writeableRevealZone;
if (writeableRevealZone && !_writeableRevealZone)
origZone->setView(this);
else if (!writeableRevealZone && _writeableRevealZone)
origZone->setView(NULL);
writeableRevealZone = _writeableRevealZone;
}
void ZoneViewZone::wheelEvent(QGraphicsSceneWheelEvent *event)
{
emit wheelEventReceived(event);
emit wheelEventReceived(event);
}
......@@ -10,41 +10,41 @@ class ServerInfo_Card;
class QGraphicsSceneWheelEvent;
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
Q_OBJECT
Q_OBJECT
private:
QRectF bRect, optimumRect;
int minRows, numberCards;
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
CardZone *origZone;
bool revealZone, writeableRevealZone;
bool sortByName, sortByType;
QRectF bRect, optimumRect;
int minRows, numberCards;
void handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint);
CardZone *origZone;
bool revealZone, writeableRevealZone;
bool sortByName, sortByType;
public:
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, bool _revealZone = false, bool _writeableRevealZone = false, QGraphicsItem *parent = 0);
~ZoneViewZone();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void initializeCards(const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
void removeCard(int position);
int getNumberCards() const { return numberCards; }
void setGeometry(const QRectF &rect);
QRectF getOptimumRect() const { return optimumRect; }
bool getRevealZone() const { return revealZone; }
bool getWriteableRevealZone() const { return writeableRevealZone; }
void setWriteableRevealZone(bool _writeableRevealZone);
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, bool _revealZone = false, bool _writeableRevealZone = false, QGraphicsItem *parent = 0);
~ZoneViewZone();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void initializeCards(const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
void removeCard(int position);
int getNumberCards() const { return numberCards; }
void setGeometry(const QRectF &rect);
QRectF getOptimumRect() const { return optimumRect; }
bool getRevealZone() const { return revealZone; }
bool getWriteableRevealZone() const { return writeableRevealZone; }
void setWriteableRevealZone(bool _writeableRevealZone);
public slots:
void setSortByName(int _sortByName);
void setSortByType(int _sortByType);
void setSortByName(int _sortByName);
void setSortByType(int _sortByType);
private slots:
void zoneDumpReceived(const Response &r);
void zoneDumpReceived(const Response &r);
signals:
void beingDeleted();
void optimumRectChanged();
void wheelEventReceived(QGraphicsSceneWheelEvent *event);
void beingDeleted();
void optimumRectChanged();
void wheelEventReceived(QGraphicsSceneWheelEvent *event);
protected:
void addCardImpl(CardItem *card, int x, int y);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
void wheelEvent(QGraphicsSceneWheelEvent *event);
void addCardImpl(CardItem *card, int x, int y);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
void wheelEvent(QGraphicsSceneWheelEvent *event);
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment