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:
ctrlaltca 2018-01-27 10:41:32 +01:00 committed by GitHub
parent 8dbdd24c8e
commit b29bd9e070
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
272 changed files with 13378 additions and 9535 deletions

View file

@ -1,26 +1,26 @@
#include <QGraphicsScene>
#include <QPainter>
#include <QSet>
#include <QGraphicsScene>
#include <cmath>
#ifdef _WIN32
#include "round.h"
#endif /* _WIN32 */
#include "tablezone.h"
#include "arrowitem.h"
#include "carddatabase.h"
#include "carddragitem.h"
#include "carditem.h"
#include "player.h"
#include "settingscache.h"
#include "tablezone.h"
#include "thememanager.h"
#include "arrowitem.h"
#include "carddragitem.h"
#include "carddatabase.h"
#include "carditem.h"
#include "pb/command_move_card.pb.h"
#include "pb/command_set_card_attr.pb.h"
const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100);
const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80);
const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150);
const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0);
const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100);
const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80);
const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150);
const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0);
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
: SelectZone(_p, "table", true, false, true, parent), active(false)
@ -30,7 +30,7 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
updateBg();
height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT + (TABLEROWS-1) * PADDING_Y;
height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT + (TABLEROWS - 1) * PADDING_Y;
width = MIN_WIDTH;
currentMinimumWidth = width;
@ -38,25 +38,22 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
setAcceptHoverEvents(true);
}
void TableZone::updateBg()
{
update();
}
QRectF TableZone::boundingRect() const
{
return QRectF(0, 0, width, height);
}
bool TableZone::isInverted() const
{
return ((player->getMirrored() && !settingsCache->getInvertVerticalCoordinate()) || (!player->getMirrored() && settingsCache->getInvertVerticalCoordinate()));
return ((player->getMirrored() && !settingsCache->getInvertVerticalCoordinate()) ||
(!player->getMirrored() && settingsCache->getInvertVerticalCoordinate()));
}
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
painter->fillRect(boundingRect(), themeManager->getTableBgBrush());
@ -72,13 +69,13 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
paintLandDivider(painter);
}
/**
Render a soft outline around the edge of the TableZone.
@param painter QPainter object
*/
void TableZone::paintZoneOutline(QPainter *painter) {
void TableZone::paintZoneOutline(QPainter *painter)
{
QLinearGradient grad1(0, 0, 0, 1);
grad1.setCoordinateMode(QGradient::ObjectBoundingMode);
grad1.setColorAt(0, GRADIENT_COLOR);
@ -96,13 +93,13 @@ void TableZone::paintZoneOutline(QPainter *painter) {
painter->fillRect(QRectF(width - BOX_LINE_WIDTH, 0, BOX_LINE_WIDTH, height), QBrush(grad1));
}
/**
Render a division line for land placement
@painter QPainter object
*/
void TableZone::paintLandDivider(QPainter *painter){
void TableZone::paintLandDivider(QPainter *painter)
{
// Place the line 2 grid heights down then back it off just enough to allow
// some space between a 3-card stack and the land area.
qreal separatorY = MARGIN_TOP + 2 * (CARD_HEIGHT + PADDING_Y) - STACKED_CARD_OFFSET_Y / 2;
@ -112,7 +109,6 @@ void TableZone::paintLandDivider(QPainter *painter){
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
}
void TableZone::addCardImpl(CardItem *card, int _x, int _y)
{
cards.append(card);
@ -123,14 +119,14 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
card->update();
}
void TableZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint)
{
handleDropEventByGrid(dragItems, startZone, mapToGrid(dropPoint));
}
void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &gridPoint)
void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems,
CardZone *startZone,
const QPoint &gridPoint)
{
Command_MoveCard cmd;
cmd.set_start_player_id(startZone->getPlayer()->getId());
@ -139,25 +135,24 @@ void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems, Ca
cmd.set_target_zone(getName().toStdString());
cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y());
for (int i = 0; i < dragItems.size(); ++i) {
CardToMove *ctm = cmd.mutable_cards_to_move()->add_card();
ctm->set_card_id(dragItems[i]->getId());
ctm->set_face_down(dragItems[i]->getFaceDown());
if(startZone->getName() != name && dragItems[i]->getItem()->getInfo())
if (startZone->getName() != name && dragItems[i]->getItem()->getInfo())
ctm->set_pt(dragItems[i]->getItem()->getInfo()->getPowTough().toStdString());
else
ctm->set_pt(std::string());
}
startZone->getPlayer()->sendGameCommand(cmd);
}
void TableZone::reorganizeCards()
{
QList<ArrowItem *> arrowsToUpdate;
// Calculate card stack widths so mapping functions work properly
computeCardStackWidths();
@ -165,20 +160,20 @@ void TableZone::reorganizeCards()
QPoint gridPoint = cards[i]->getGridPos();
if (gridPoint.x() == -1)
continue;
QPointF mapPoint = mapFromGrid(gridPoint);
qreal x = mapPoint.x();
qreal y = mapPoint.y();
int numberAttachedCards = cards[i]->getAttachedCards().size();
qreal actualX = x + numberAttachedCards * STACKED_CARD_OFFSET_X;
qreal actualY = y;
if (numberAttachedCards)
actualY += 15;
cards[i]->setPos(actualX, actualY);
cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100);
QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards());
int j = 0;
while (attachedCardIterator.hasNext()) {
@ -192,7 +187,7 @@ void TableZone::reorganizeCards()
arrowsToUpdate.append(attachedCard->getArrowsFrom());
arrowsToUpdate.append(attachedCard->getArrowsTo());
}
arrowsToUpdate.append(cards[i]->getArrowsFrom());
arrowsToUpdate.append(cards[i]->getArrowsTo());
}
@ -200,12 +195,11 @@ void TableZone::reorganizeCards()
QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate));
while (arrowIterator.hasNext())
arrowIterator.next()->updatePath();
resizeToContents();
update();
}
void TableZone::toggleTapped()
{
QList<QGraphicsItem *> selectedItems = scene()->selectedItems();
@ -215,7 +209,7 @@ void TableZone::toggleTapped()
tapAll = true;
break;
}
QList< const ::google::protobuf::Message * > cmdList;
QList<const ::google::protobuf::Message *> cmdList;
for (int i = 0; i < selectedItems.size(); i++) {
CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
if (temp->getTapped() != tapAll) {
@ -230,7 +224,6 @@ void TableZone::toggleTapped()
player->sendGameCommand(player->prepareGameCommand(cmdList));
}
CardItem *TableZone::takeCard(int position, int cardId, bool canResize)
{
CardItem *result = CardZone::takeCard(position, cardId);
@ -239,7 +232,6 @@ CardItem *TableZone::takeCard(int position, int cardId, bool canResize)
return result;
}
void TableZone::resizeToContents()
{
int xMax = 0;
@ -247,7 +239,7 @@ void TableZone::resizeToContents()
// Find rightmost card position, which includes the left margin amount.
for (int i = 0; i < cards.size(); ++i)
if (cards[i]->pos().x() > xMax)
xMax = (int) cards[i]->pos().x();
xMax = (int)cards[i]->pos().x();
// Minimum width is the rightmost card position plus enough room for
// another card with padding, then margin.
@ -263,7 +255,6 @@ void TableZone::resizeToContents()
}
}
CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
{
for (int i = 0; i < cards.size(); i++)
@ -272,14 +263,12 @@ CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
return 0;
}
CardItem *TableZone::getCardFromCoords(const QPointF &point) const
{
QPoint gridPoint = mapToGrid(point);
return getCardFromGrid(gridPoint);
}
void TableZone::computeCardStackWidths()
{
// Each card stack is three grid points worth of card locations.
@ -289,7 +278,7 @@ void TableZone::computeCardStackWidths()
const QPoint &gridPoint = cards[i]->getGridPos();
if (gridPoint.x() == -1)
continue;
const int key = getCardStackMapKey(gridPoint.x() / 3, gridPoint.y());
cardStackCount.insert(key, cardStackCount.value(key, 0) + 1);
}
@ -300,7 +289,7 @@ void TableZone::computeCardStackWidths()
const QPoint &gridPoint = cards[i]->getGridPos();
if (gridPoint.x() == -1)
continue;
const int key = getCardStackMapKey(gridPoint.x() / 3, gridPoint.y());
const int stackCount = cardStackCount.value(key, 0);
if (stackCount == 1)
@ -310,7 +299,6 @@ void TableZone::computeCardStackWidths()
}
}
QPointF TableZone::mapFromGrid(QPoint gridPoint) const
{
qreal x, y;
@ -319,15 +307,14 @@ QPointF TableZone::mapFromGrid(QPoint gridPoint) const
x = MARGIN_LEFT + (gridPoint.x() % 3) * STACKED_CARD_OFFSET_X;
// Add in width of card stack plus padding for each column
for (int i = 0; i < gridPoint.x() / 3; ++i)
{
for (int i = 0; i < gridPoint.x() / 3; ++i) {
const int key = getCardStackMapKey(i, gridPoint.y());
x += cardStackWidth.value(key, CARD_WIDTH) + PADDING_X;
}
if (isInverted())
gridPoint.setY(TABLEROWS - 1 - gridPoint.y());
// Start with margin plus stacked card offset
y = MARGIN_TOP + (gridPoint.x() % 3) * STACKED_CARD_OFFSET_Y;
@ -338,7 +325,6 @@ QPointF TableZone::mapFromGrid(QPoint gridPoint) const
return QPointF(x, y);
}
QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
{
// Begin by calculating the y-coordinate of the grid space, which will be
@ -369,7 +355,7 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
int xStack = 0;
int xNextStack = 0;
int nextStackCol = 0;
while ((xNextStack <= x) && (xNextStack <= xMax)) {
while ((xNextStack <= x) && (xNextStack <= xMax)) {
xStack = xNextStack;
const int key = getCardStackMapKey(nextStackCol, gridPointY);
xNextStack += cardStackWidth.value(key, CARD_WIDTH) + PADDING_X;
@ -386,7 +372,6 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
return QPoint(gridPointX, gridPointY);
}
QPointF TableZone::closestGridPoint(const QPointF &point)
{
QPoint gridPoint = mapToGrid(point + QPoint(1, 1));
@ -400,9 +385,9 @@ QPointF TableZone::closestGridPoint(const QPointF &point)
int TableZone::clampValidTableRow(const int row)
{
if(row < 0)
if (row < 0)
return 0;
if(row >= TABLEROWS)
if (row >= TABLEROWS)
return TABLEROWS - 1;
return row;
}