mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -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,31 +1,31 @@
|
|||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QMenu>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "gamescene.h"
|
||||
#include "carditem.h"
|
||||
#include "carddragitem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "cardzone.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include "tablezone.h"
|
||||
#include "player.h"
|
||||
#include "arrowitem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "carddragitem.h"
|
||||
#include "cardzone.h"
|
||||
#include "gamescene.h"
|
||||
#include "main.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
#include "player.h"
|
||||
#include "settingscache.h"
|
||||
#include "tab_game.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
|
||||
#include "tablezone.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include <QApplication>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
cardMenu = new QMenu;
|
||||
ptMenu = new QMenu;
|
||||
moveMenu = new QMenu;
|
||||
|
||||
|
||||
retranslateUi();
|
||||
emit updateCardMenu(this);
|
||||
}
|
||||
|
|
@ -33,14 +33,14 @@ CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _reve
|
|||
CardItem::~CardItem()
|
||||
{
|
||||
prepareDelete();
|
||||
|
||||
|
||||
if (scene())
|
||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||
|
||||
|
||||
delete cardMenu;
|
||||
delete ptMenu;
|
||||
delete moveMenu;
|
||||
|
||||
|
||||
deleteDragItem();
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ void CardItem::prepareDelete()
|
|||
}
|
||||
owner = 0;
|
||||
}
|
||||
|
||||
|
||||
while (!attachedCards.isEmpty()) {
|
||||
attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards()
|
||||
attachedCards.first()->setAttachedTo(0);
|
||||
}
|
||||
|
||||
|
||||
if (attachedTo) {
|
||||
attachedTo->removeAttachedCard(this);
|
||||
attachedTo = 0;
|
||||
|
|
@ -87,69 +87,65 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
{
|
||||
painter->save();
|
||||
AbstractCardItem::paint(painter, option, widget);
|
||||
|
||||
|
||||
int i = 0;
|
||||
QMapIterator<int, int> counterIterator(counters);
|
||||
while (counterIterator.hasNext())
|
||||
{
|
||||
while (counterIterator.hasNext()) {
|
||||
counterIterator.next();
|
||||
QColor color;
|
||||
color.setHsv(counterIterator.key() * 60, 150, 255);
|
||||
|
||||
|
||||
paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter);
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
QSizeF translatedSize = getTranslatedSize(painter);
|
||||
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
||||
|
||||
if (!pt.isEmpty())
|
||||
{
|
||||
|
||||
if (!pt.isEmpty()) {
|
||||
painter->save();
|
||||
transformPainter(painter, translatedSize, tapAngle);
|
||||
|
||||
if(info)
|
||||
{
|
||||
if (info) {
|
||||
QStringList ptSplit = pt.split("/");
|
||||
QStringList ptDbSplit = info->getPowTough().split("/");
|
||||
|
||||
|
||||
if (getFaceDown() || ptDbSplit.at(0) != ptSplit.at(0) || ptDbSplit.at(1) != ptSplit.at(1))
|
||||
painter->setPen(QColor(255, 150, 0));
|
||||
else
|
||||
painter->setPen(Qt::white);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
painter->setPen(Qt::white);
|
||||
}
|
||||
painter->setBackground(Qt::black);
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
|
||||
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 10 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignRight | Qt::AlignBottom, pt);
|
||||
|
||||
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 10 * scaleFactor,
|
||||
translatedSize.height() - 8 * scaleFactor),
|
||||
Qt::AlignRight | Qt::AlignBottom, pt);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
if (!annotation.isEmpty())
|
||||
{
|
||||
if (!annotation.isEmpty()) {
|
||||
painter->save();
|
||||
|
||||
transformPainter(painter, translatedSize, tapAngle);
|
||||
painter->setBackground(Qt::black);
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
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();
|
||||
}
|
||||
|
||||
if (getBeingPointedAt())
|
||||
{
|
||||
if (getBeingPointedAt()) {
|
||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
if (doesntUntap)
|
||||
{
|
||||
if (doesntUntap) {
|
||||
painter->save();
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
|
@ -203,7 +199,7 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
|
|||
{
|
||||
if (attachedTo)
|
||||
attachedTo->removeAttachedCard(this);
|
||||
|
||||
|
||||
gridPoint.setX(-1);
|
||||
attachedTo = _attachedTo;
|
||||
if (attachedTo) {
|
||||
|
|
@ -216,7 +212,7 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
|
|||
|
||||
if (zone)
|
||||
zone->reorganizeCards();
|
||||
|
||||
|
||||
emit updateCardMenu(this);
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +240,7 @@ void CardItem::processCardInfo(const ServerInfo_Card &info)
|
|||
const ServerInfo_CardCounter &counterInfo = info.counter_list(i);
|
||||
counters.insert(counterInfo.id(), counterInfo.value());
|
||||
}
|
||||
|
||||
|
||||
setId(info.id());
|
||||
setName(QString::fromStdString(info.name()));
|
||||
setAttacking(info.attacking());
|
||||
|
|
@ -271,7 +267,7 @@ CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPoin
|
|||
|
||||
void CardItem::deleteDragItem()
|
||||
{
|
||||
if(dragItem)
|
||||
if (dragItem)
|
||||
dragItem->deleteLater();
|
||||
dragItem = NULL;
|
||||
}
|
||||
|
|
@ -280,12 +276,12 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
|||
{
|
||||
if (static_cast<TabGame *>(owner->parent())->getSpectator())
|
||||
return;
|
||||
|
||||
|
||||
Player *arrowOwner = static_cast<TabGame *>(owner->parent())->getActiveLocalPlayer();
|
||||
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
|
||||
scene()->addItem(arrow);
|
||||
arrow->grabMouse();
|
||||
|
||||
|
||||
QListIterator<QGraphicsItem *> itemIterator(scene()->selectedItems());
|
||||
while (itemIterator.hasNext()) {
|
||||
CardItem *c = qgraphicsitem_cast<CardItem *>(itemIterator.next());
|
||||
|
|
@ -293,7 +289,7 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
|||
continue;
|
||||
if (c->getZone() != zone)
|
||||
continue;
|
||||
|
||||
|
||||
ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, c, arrowColor);
|
||||
scene()->addItem(childArrow);
|
||||
arrow->addChildArrow(childArrow);
|
||||
|
|
@ -303,9 +299,10 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
|||
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
QColor arrowColor = Qt::red;
|
||||
if (event->modifiers().testFlag(Qt::ControlModifier))
|
||||
arrowColor = Qt::yellow;
|
||||
|
|
@ -313,10 +310,11 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
arrowColor = Qt::blue;
|
||||
else if (event->modifiers().testFlag(Qt::ShiftModifier))
|
||||
arrowColor = Qt::green;
|
||||
|
||||
|
||||
drawArrow(arrowColor);
|
||||
} 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;
|
||||
if (zone->getIsView()) {
|
||||
const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
|
||||
|
|
@ -324,12 +322,12 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
return;
|
||||
} else if (!owner->getLocal())
|
||||
return;
|
||||
|
||||
|
||||
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
|
||||
|
||||
createDragItem(id, event->pos(), event->scenePos(), facedown || forceFaceDown);
|
||||
dragItem->grabMouse();
|
||||
|
||||
|
||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||
int j = 0;
|
||||
for (int i = 0; i < sel.size(); i++) {
|
||||
|
|
@ -399,7 +397,6 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
|
||||
bool CardItem::animationEvent()
|
||||
{
|
||||
int rotation = ROTATION_DEGREES_PER_FRAME;
|
||||
|
|
@ -408,7 +405,10 @@ bool CardItem::animationEvent()
|
|||
|
||||
tapAngle += rotation;
|
||||
|
||||
setTransform(QTransform().translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF).rotate(tapAngle).translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));
|
||||
setTransform(QTransform()
|
||||
.translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF)
|
||||
.rotate(tapAngle)
|
||||
.translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue