Skip to content

Commit

Permalink
Clang-format (#3028)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ctrlaltca committed Jan 27, 2018
1 parent 8dbdd24 commit b29bd9e
Show file tree
Hide file tree
Showing 272 changed files with 13,437 additions and 9,594 deletions.
25 changes: 25 additions & 0 deletions .ci/travis-compile.sh
Expand Up @@ -21,7 +21,32 @@ if [[ $BUILDTYPE == "Debug" ]]; then
cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE $prefix -DTEST=1
make -j2
make test

if [[ $TRAVIS_OS_NAME == "linux" ]]; then
cd ..
clang-format -i \
common/*.h \
common/*.cpp \
cockatrice/src/*.h \
cockatrice/src/*.cpp \
oracle/src/*.h \
oracle/src/*.cpp \
servatrice/src/*.h \
servatrice/src/*.cpp

git clean -f
git diff --quiet || (
echo "*****************************************************";
echo "*** This PR is not clean against our code style ***";
echo "*** Run clang-format and fix up any differences ***";
echo "*** Check our CONTRIBUTING.md file for details! ***";
echo "*** Thank you ♥ ***";
echo "*****************************************************";
)
git diff --exit-code
fi
fi

if [[ $BUILDTYPE == "Release" ]]; then
cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE $prefix
make package -j2
Expand Down
2 changes: 1 addition & 1 deletion .ci/travis-dependencies.sh
Expand Up @@ -3,7 +3,7 @@
if [[ $TRAVIS_OS_NAME == "osx" ]] ; then
brew install ccache # enable caching on mac (PATH only set in travis-compile.sh)
brew install --force qt@5.7
brew install protobuf
brew install protobuf clang-format
fi
if [[ $TRAVIS_OS_NAME == "linux" ]] ; then
echo Skipping... packages are installed with the Travis apt addon for sudo disabled container builds
Expand Down
25 changes: 25 additions & 0 deletions .clang-format
@@ -0,0 +1,25 @@
IndentWidth: 4
AccessModifierOffset: -4
ColumnLimit: 120
---
Language: Cpp
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
AllowShortFunctionsOnASingleLine: None
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
IndentCaseLabels: true
PointerAlignment: Right
7 changes: 5 additions & 2 deletions .travis.yml
Expand Up @@ -26,9 +26,13 @@ matrix:
#install dependencies for container-based "linux" builds
addons:
apt:
sources:
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main'
key_url: 'http://llvm.org/apt/llvm-snapshot.gpg.key'
packages:
- bc
- cmake
- clang-format-5.0
- cmake
- libprotobuf-dev
- protobuf-compiler
- qt5-default
Expand All @@ -39,7 +43,6 @@ addons:
- libqt5svg5-dev
- libqt5sql5-mysql


before_install: bash ./.ci/travis-dependencies.sh

script: bash ./.ci/travis-compile.sh
Expand Down
11 changes: 8 additions & 3 deletions cockatrice/src/abstractcarddragitem.cpp
@@ -1,15 +1,17 @@
#include "abstractcarddragitem.h"
#include "carddatabase.h"
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>

static const float CARD_WIDTH_HALF = CARD_WIDTH / 2;
static const float CARD_HEIGHT_HALF = CARD_HEIGHT / 2;
const QColor GHOST_MASK = QColor(255, 255, 255, 50);

AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item,
const QPointF &_hotSpot,
AbstractCardDragItem *parentDrag)
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
{
if (parentDrag) {
Expand All @@ -27,7 +29,10 @@ AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPoint
setZValue(2000000007);
}
if (item->getTapped())
setTransform(QTransform().translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF).rotate(90).translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));
setTransform(QTransform()
.translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF)
.rotate(90)
.translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));

setCacheMode(DeviceCoordinateCache);
}
Expand Down
30 changes: 24 additions & 6 deletions cockatrice/src/abstractcarddragitem.h
Expand Up @@ -7,24 +7,42 @@ class QGraphicsScene;
class CardZone;
class CardInfo;

class AbstractCardDragItem : public QObject, public QGraphicsItem {
class AbstractCardDragItem : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
protected:
AbstractCardItem *item;
QPointF hotSpot;
QList<AbstractCardDragItem *> childDrags;

public:
enum { Type = typeCardDrag };
int type() const { return Type; }
enum
{
Type = typeCardDrag
};
int type() const
{
return Type;
}
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
~AbstractCardDragItem();
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
QRectF boundingRect() const
{
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
AbstractCardItem *getItem() const { return item; }
QPointF getHotSpot() const { return hotSpot; }
AbstractCardItem *getItem() const
{
return item;
}
QPointF getHotSpot() const
{
return hotSpot;
}
void addChildDrag(AbstractCardDragItem *child);
virtual void updatePosition(const QPointF &cursorScenePos) = 0;

protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
};
Expand Down
78 changes: 38 additions & 40 deletions cockatrice/src/abstractcarditem.cpp
@@ -1,26 +1,27 @@
#include <QPainter>
#include <QGraphicsScene>
#include <QCursor>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <cmath>
#include <QPainter>
#include <algorithm>
#include <cmath>
#ifdef _WIN32
#include "round.h"
#endif /* _WIN32 */
#include "carddatabase.h"
#include "abstractcarditem.h"
#include "carddatabase.h"
#include "gamescene.h"
#include "main.h"
#include "pictureloader.h"
#include "settingscache.h"
#include "main.h"
#include "gamescene.h"

AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
: ArrowTarget(_owner, parent), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), bgColor(Qt::transparent), isHovered(false), realZValue(0)
: ArrowTarget(_owner, parent), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0),
bgColor(Qt::transparent), isHovered(false), realZValue(0)
{
setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable);
setCacheMode(DeviceCoordinateCache);

connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
cardInfoUpdated();
}
Expand All @@ -44,7 +45,7 @@ void AbstractCardItem::pixmapUpdated()
void AbstractCardItem::cardInfoUpdated()
{
info = db->getCard(name);
if(info)
if (info)
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));

cacheBgColor();
Expand All @@ -59,10 +60,8 @@ void AbstractCardItem::setRealZValue(qreal _zValue)

QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
{
return QSizeF(
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
);
return QSizeF(painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length());
}

void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
Expand All @@ -71,9 +70,9 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
const int fontSize = std::max(9, MAX_FONT_SIZE);

QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());

painter->resetTransform();

QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(angle);
Expand All @@ -92,24 +91,22 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
QPixmap translatedPixmap;
bool paintImage = true;

if(facedown || name.isEmpty())
{
if (facedown || name.isEmpty()) {
// never reveal card color, always paint the card back
PictureLoader::getCardBackPixmap(translatedPixmap, translatedSize.toSize());
} else {
// don't even spend time trying to load the picture if our size is too small
if(translatedSize.width() > 10)
{
if (translatedSize.width() > 10) {
PictureLoader::getPixmap(translatedPixmap, info, translatedSize.toSize());
if(translatedPixmap.isNull())
if (translatedPixmap.isNull())
paintImage = false;
} else {
paintImage = false;
}
}

painter->save();

if (paintImage) {
painter->save();
transformPainter(painter, translatedSize, angle);
Expand All @@ -129,7 +126,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
painter->drawRect(QRectF(0, 0, CARD_WIDTH - 1, CARD_HEIGHT - penWidth));
else
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 1.5));

if (translatedPixmap.isNull() || settingsCache->getDisplayCardNames() || facedown) {
painter->save();
transformPainter(painter, translatedSize, angle);
Expand All @@ -141,10 +138,12 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
nameStr = "# " + QString::number(id);
else
nameStr = name;
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr);
painter->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();
}

Expand All @@ -154,7 +153,7 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *

QSizeF translatedSize = getTranslatedSize(painter);
paintPicture(painter, translatedSize, tapAngle);

painter->save();
painter->setRenderHint(QPainter::Antialiasing, false);
transformPainter(painter, translatedSize, tapAngle);
Expand All @@ -180,9 +179,9 @@ void AbstractCardItem::setName(const QString &_name)
{
if (name == _name)
return;

emit deleteCardInfoPopup(name);
if(info)
if (info)
disconnect(info, nullptr, this, nullptr);
name = _name;

Expand All @@ -193,7 +192,7 @@ void AbstractCardItem::setHovered(bool _hovered)
{
if (isHovered == _hovered)
return;

if (_hovered)
processHoverEvent();
isHovered = _hovered;
Expand All @@ -213,16 +212,14 @@ void AbstractCardItem::setColor(const QString &_color)
void AbstractCardItem::cacheBgColor()
{
QChar colorChar;
if (color.isEmpty())
{
if(info)
if (color.isEmpty()) {
if (info)
colorChar = info->getColorChar();
} else {
colorChar = color.at(0);
}

switch(colorChar.toLower().toLatin1())
{

switch (colorChar.toLower().toLatin1()) {
case 'b':
bgColor = QColor(0, 0, 0);
break;
Expand Down Expand Up @@ -251,13 +248,16 @@ void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
{
if (tapped == _tapped)
return;

tapped = _tapped;
if (settingsCache->getTapAnimation() && canAnimate)
static_cast<GameScene *>(scene())->registerAnimationItem(this);
else {
tapAngle = tapped ? 90 : 0;
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
setTransform(QTransform()
.translate((float)CARD_WIDTH / 2, (float)CARD_HEIGHT / 2)
.rotate(tapAngle)
.translate((float)-CARD_WIDTH / 2, (float)-CARD_HEIGHT / 2));
update();
}
}
Expand All @@ -273,8 +273,7 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->modifiers() & Qt::ControlModifier)) {
setSelected(!isSelected());
}
else if (!isSelected()) {
} else if (!isSelected()) {
scene()->clearSelection();
setSelected(true);
}
Expand All @@ -289,7 +288,7 @@ void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::MidButton)
emit deleteCardInfoPopup(name);

// This function ensures the parent function doesn't mess around with our selection.
event->accept();
}
Expand All @@ -307,4 +306,3 @@ QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change,
} else
return QGraphicsItem::itemChange(change, value);
}

0 comments on commit b29bd9e

Please sign in to comment.