mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -1,21 +1,28 @@
|
|||
#include <math.h>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QBrush>
|
||||
#include <QPainter>
|
||||
#include "zoneviewzone.h"
|
||||
#include "player.h"
|
||||
#include "carddatabase.h"
|
||||
#include "carddragitem.h"
|
||||
#include "carditem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "pb/command_dump_zone.pb.h"
|
||||
#include "pb/command_move_card.pb.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
#include "pb/response_dump_zone.pb.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
#include "pending_command.h"
|
||||
#include "player.h"
|
||||
#include <QBrush>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QPainter>
|
||||
#include <math.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)
|
||||
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)
|
||||
{
|
||||
if (!(revealZone && !writeableRevealZone))
|
||||
origZone->setView(this);
|
||||
|
|
@ -34,9 +41,9 @@ QRectF ZoneViewZone::boundingRect() const
|
|||
return bRect;
|
||||
}
|
||||
|
||||
void ZoneViewZone::paint(QPainter * painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
void ZoneViewZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
QBrush windowBrush(QColor(240,240,240));
|
||||
QBrush windowBrush(QColor(240, 240, 240));
|
||||
windowBrush.setColor(windowBrush.color().darker(150));
|
||||
painter->fillRect(boundingRect(), windowBrush);
|
||||
}
|
||||
|
|
@ -45,16 +52,19 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
|||
{
|
||||
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);
|
||||
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 &)));
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(zoneDumpReceived(const Response &)));
|
||||
player->sendGameCommand(pend);
|
||||
} else {
|
||||
const CardList &c = origZone->getCards();
|
||||
|
|
@ -76,7 +86,7 @@ void ZoneViewZone::zoneDumpReceived(const Response &r)
|
|||
CardItem *card = new CardItem(player, QString::fromStdString(cardInfo.name()), cardInfo.id(), revealZone, this);
|
||||
addCard(card, false, i);
|
||||
}
|
||||
|
||||
|
||||
reorganizeCards();
|
||||
}
|
||||
|
||||
|
|
@ -88,21 +98,21 @@ void ZoneViewZone::reorganizeCards()
|
|||
for (int i = 0; i < cardCount; ++i)
|
||||
cards[i]->setId(i);
|
||||
|
||||
int cols = floor(sqrt((double) cardCount / 2));
|
||||
int cols = floor(sqrt((double)cardCount / 2));
|
||||
if (cols > 7)
|
||||
cols = 7;
|
||||
int rows = ceil((double) cardCount / cols);
|
||||
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);
|
||||
cols = ceil((double)cardCount / minRows);
|
||||
}
|
||||
if (cols < 2)
|
||||
cols = 2;
|
||||
|
||||
|
||||
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
|
||||
|
||||
CardList cardsToDisplay(cards);
|
||||
|
|
@ -118,10 +128,10 @@ void ZoneViewZone::reorganizeCards()
|
|||
CardItem *c = cardsToDisplay.at(i);
|
||||
QString cardType = c->getInfo() ? c->getInfo()->getMainCardType() : "";
|
||||
|
||||
if (i){ // if not the first card
|
||||
if (i) { // if not the first card
|
||||
if (cardType == lastCardType)
|
||||
typeRow++; // add below current card
|
||||
else { // if no match then move card to next column
|
||||
else { // if no match then move card to next column
|
||||
typeColumn++;
|
||||
typeRow = 0;
|
||||
}
|
||||
|
|
@ -143,11 +153,13 @@ void ZoneViewZone::reorganizeCards()
|
|||
c->setRealZValue(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qreal aleft = 0;
|
||||
qreal atop = 0;
|
||||
qreal awidth = (pileView && sortByType) ? qMax(typeColumn + 1, 3) * CARD_WIDTH + (CARD_WIDTH/2) : qMax(cols, 1) * CARD_WIDTH + (CARD_WIDTH/2);
|
||||
qreal aheight = (pileView && sortByType) ? (longestRow * CARD_HEIGHT) / 3 + CARD_HEIGHT * 1.3 : (rows * CARD_HEIGHT) / 3 + CARD_HEIGHT * 1.3;
|
||||
qreal awidth = (pileView && sortByType) ? qMax(typeColumn + 1, 3) * CARD_WIDTH + (CARD_WIDTH / 2)
|
||||
: qMax(cols, 1) * CARD_WIDTH + (CARD_WIDTH / 2);
|
||||
qreal aheight = (pileView && sortByType) ? (longestRow * CARD_HEIGHT) / 3 + CARD_HEIGHT * 1.3
|
||||
: (rows * CARD_HEIGHT) / 3 + CARD_HEIGHT * 1.3;
|
||||
optimumRect = QRectF(aleft, atop, awidth, aheight);
|
||||
|
||||
updateGeometry();
|
||||
|
|
@ -168,7 +180,8 @@ void ZoneViewZone::setSortByType(int _sortByType)
|
|||
reorganizeCards();
|
||||
}
|
||||
|
||||
void ZoneViewZone::setPileView(int _pileView) {
|
||||
void ZoneViewZone::setPileView(int _pileView)
|
||||
{
|
||||
pileView = _pileView;
|
||||
reorganizeCards();
|
||||
}
|
||||
|
|
@ -180,7 +193,9 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
card->update();
|
||||
}
|
||||
|
||||
void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
|
||||
void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||
CardZone *startZone,
|
||||
const QPoint & /*dropPoint*/)
|
||||
{
|
||||
Command_MoveCard cmd;
|
||||
cmd.set_start_player_id(startZone->getPlayer()->getId());
|
||||
|
|
@ -189,7 +204,7 @@ void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZ
|
|||
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());
|
||||
|
||||
|
|
@ -224,9 +239,8 @@ void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
|
|||
origZone->setView(this);
|
||||
else if (!writeableRevealZone && _writeableRevealZone)
|
||||
origZone->setView(NULL);
|
||||
|
||||
|
||||
writeableRevealZone = _writeableRevealZone;
|
||||
|
||||
}
|
||||
|
||||
void ZoneViewZone::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue