mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54: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,15 +1,17 @@
|
|||
#include "deckview.h"
|
||||
#include "carddatabase.h"
|
||||
#include "decklist.h"
|
||||
#include "main.h"
|
||||
#include "settingscache.h"
|
||||
#include "thememanager.h"
|
||||
#include <QApplication>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <math.h>
|
||||
#include "deckview.h"
|
||||
#include "decklist.h"
|
||||
#include "carddatabase.h"
|
||||
#include "settingscache.h"
|
||||
#include "thememanager.h"
|
||||
#include "main.h"
|
||||
|
||||
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
||||
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item,
|
||||
const QPointF &_hotSpot,
|
||||
AbstractCardDragItem *parentDrag)
|
||||
: AbstractCardDragItem(_item, _hotSpot, parentDrag), currentZone(0)
|
||||
{
|
||||
}
|
||||
|
|
@ -25,7 +27,7 @@ void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|||
if (!cursorZone)
|
||||
return;
|
||||
currentZone = cursorZone;
|
||||
|
||||
|
||||
QPointF newPos = cursorScenePos;
|
||||
if (newPos != pos()) {
|
||||
for (int i = 0; i < childDrags.size(); i++)
|
||||
|
|
@ -56,10 +58,10 @@ void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
c->handleDrop(currentZone);
|
||||
sc->removeItem(c);
|
||||
}
|
||||
|
||||
|
||||
sc->updateContents();
|
||||
}
|
||||
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +79,7 @@ DeckViewCard::~DeckViewCard()
|
|||
void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
AbstractCardItem::paint(painter, option, widget);
|
||||
|
||||
|
||||
painter->save();
|
||||
QPen pen;
|
||||
pen.setWidth(3);
|
||||
|
|
@ -90,18 +92,19 @@ void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||
|
||||
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
|
||||
2 * QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
|
||||
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
||||
return;
|
||||
|
||||
|
||||
delete dragItem;
|
||||
dragItem = new DeckViewCardDragItem(this, event->pos());
|
||||
scene()->addItem(dragItem);
|
||||
dragItem->updatePosition(event->scenePos());
|
||||
dragItem->grabMouse();
|
||||
|
||||
|
||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||
int j = 0;
|
||||
for (int i = 0; i < sel.size(); i++) {
|
||||
|
|
@ -122,8 +125,7 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
||||
return;
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
QList<MoveCard_ToZone> result;
|
||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||
|
||||
|
|
@ -156,8 +158,7 @@ void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||
processHoverEvent();
|
||||
}
|
||||
|
||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
||||
: QGraphicsItem(), name(_name), width(0), height(0)
|
||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name) : QGraphicsItem(), name(_name), width(0), height(0)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
}
|
||||
|
|
@ -170,19 +171,20 @@ QRectF DeckViewCardContainer::boundingRect() const
|
|||
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
qreal totalTextWidth = getCardTypeTextWidth();
|
||||
|
||||
|
||||
painter->fillRect(boundingRect(), themeManager->getTableBgBrush());
|
||||
painter->setPen(QColor(255, 255, 255, 100));
|
||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||
|
||||
|
||||
painter->setPen(QColor(Qt::white));
|
||||
QFont f("Serif");
|
||||
f.setStyleHint(QFont::Serif);
|
||||
f.setPixelSize(24);
|
||||
f.setWeight(QFont::Bold);
|
||||
painter->setFont(f);
|
||||
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size()));
|
||||
|
||||
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
|
||||
InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size()));
|
||||
|
||||
f.setPixelSize(16);
|
||||
painter->setFont(f);
|
||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||
|
|
@ -212,12 +214,12 @@ void DeckViewCardContainer::addCard(DeckViewCard *card)
|
|||
void DeckViewCardContainer::removeCard(DeckViewCard *card)
|
||||
{
|
||||
cards.removeAt(cards.indexOf(card));
|
||||
cardsByType.remove(card->getInfo() ? card->getInfo()->getMainCardType(): "", card);
|
||||
cardsByType.remove(card->getInfo() ? card->getInfo()->getMainCardType() : "", card);
|
||||
}
|
||||
|
||||
QList<QPair<int, int> > DeckViewCardContainer::getRowsAndCols() const
|
||||
QList<QPair<int, int>> DeckViewCardContainer::getRowsAndCols() const
|
||||
{
|
||||
QList<QPair<int, int> > result;
|
||||
QList<QPair<int, int>> result;
|
||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||
for (int i = 0; i < cardTypeList.size(); ++i)
|
||||
result.append(QPair<int, int>(1, cardsByType.count(cardTypeList[i])));
|
||||
|
|
@ -231,7 +233,7 @@ int DeckViewCardContainer::getCardTypeTextWidth() const
|
|||
f.setPixelSize(16);
|
||||
f.setWeight(QFont::Bold);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
|
||||
int maxCardTypeWidth = 0;
|
||||
QMapIterator<QString, DeckViewCard *> i(cardsByType);
|
||||
while (i.hasNext()) {
|
||||
|
|
@ -239,56 +241,56 @@ int DeckViewCardContainer::getCardTypeTextWidth() const
|
|||
if (cardTypeWidth > maxCardTypeWidth)
|
||||
maxCardTypeWidth = cardTypeWidth;
|
||||
}
|
||||
|
||||
|
||||
return maxCardTypeWidth + 15;
|
||||
}
|
||||
|
||||
QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int> > &rowsAndCols) const
|
||||
QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int>> &rowsAndCols) const
|
||||
{
|
||||
qreal totalHeight = 0;
|
||||
qreal totalWidth = 0;
|
||||
|
||||
|
||||
// Calculate space needed for cards
|
||||
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
||||
totalHeight += CARD_HEIGHT * rowsAndCols[i].first + paddingY;
|
||||
if (CARD_WIDTH * rowsAndCols[i].second > totalWidth)
|
||||
totalWidth = CARD_WIDTH * rowsAndCols[i].second;
|
||||
}
|
||||
|
||||
|
||||
return QSizeF(getCardTypeTextWidth() + totalWidth, totalHeight + separatorY + paddingY);
|
||||
}
|
||||
|
||||
bool DeckViewCardContainer::sortCardsByName(DeckViewCard * c1, DeckViewCard * c2)
|
||||
bool DeckViewCardContainer::sortCardsByName(DeckViewCard *c1, DeckViewCard *c2)
|
||||
{
|
||||
if (c1 && c2)
|
||||
return c1->getName() < c2->getName();
|
||||
return c1->getName() < c2->getName();
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeckViewCardContainer::rearrangeItems(const QList<QPair<int, int> > &rowsAndCols)
|
||||
void DeckViewCardContainer::rearrangeItems(const QList<QPair<int, int>> &rowsAndCols)
|
||||
{
|
||||
currentRowsAndCols = rowsAndCols;
|
||||
|
||||
|
||||
int totalCols = 0, totalRows = 0;
|
||||
qreal yUntilNow = separatorY + paddingY;
|
||||
qreal x = (qreal) getCardTypeTextWidth();
|
||||
qreal x = (qreal)getCardTypeTextWidth();
|
||||
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
||||
const int tempRows = rowsAndCols[i].first;
|
||||
const int tempCols = rowsAndCols[i].second;
|
||||
totalRows += tempRows;
|
||||
if (tempCols > totalCols)
|
||||
totalCols = tempCols;
|
||||
|
||||
|
||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||
QList<DeckViewCard *> row = cardsByType.values(cardTypeList[i]);
|
||||
qSort( row.begin(), row.end(), DeckViewCardContainer::sortCardsByName);
|
||||
qSort(row.begin(), row.end(), DeckViewCardContainer::sortCardsByName);
|
||||
for (int j = 0; j < row.size(); ++j) {
|
||||
DeckViewCard *card = row[j];
|
||||
card->setPos(x + (j % tempCols) * CARD_WIDTH, yUntilNow + (j / tempCols) * CARD_HEIGHT);
|
||||
}
|
||||
yUntilNow += tempRows * CARD_HEIGHT + paddingY;
|
||||
}
|
||||
|
||||
|
||||
prepareGeometryChange();
|
||||
QSizeF bRect = calculateBoundingRect(rowsAndCols);
|
||||
width = bRect.width();
|
||||
|
|
@ -302,8 +304,7 @@ void DeckViewCardContainer::setWidth(qreal _width)
|
|||
update();
|
||||
}
|
||||
|
||||
DeckViewScene::DeckViewScene(QObject *parent)
|
||||
: QGraphicsScene(parent), locked(true), deck(0), optimalAspectRatio(1.0)
|
||||
DeckViewScene::DeckViewScene(QObject *parent) : QGraphicsScene(parent), locked(true), deck(0), optimalAspectRatio(1.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -325,7 +326,7 @@ void DeckViewScene::setDeck(const DeckList &_deck)
|
|||
{
|
||||
if (deck)
|
||||
delete deck;
|
||||
|
||||
|
||||
deck = new DeckList(_deck);
|
||||
rebuildTree();
|
||||
applySideboardPlan(deck->getCurrentSideboardPlan());
|
||||
|
|
@ -335,21 +336,21 @@ void DeckViewScene::setDeck(const DeckList &_deck)
|
|||
void DeckViewScene::rebuildTree()
|
||||
{
|
||||
clearContents();
|
||||
|
||||
|
||||
if (!deck)
|
||||
return;
|
||||
|
||||
|
||||
InnerDecklistNode *listRoot = deck->getRoot();
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
|
||||
|
||||
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
||||
if (!container) {
|
||||
container = new DeckViewCardContainer(currentZone->getName());
|
||||
cardContainers.insert(currentZone->getName(), container);
|
||||
addItem(container);
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard)
|
||||
|
|
@ -372,7 +373,7 @@ void DeckViewScene::applySideboardPlan(const QList<MoveCard_ToZone> &plan)
|
|||
DeckViewCardContainer *target = cardContainers.value(QString::fromStdString(m.target_zone()));
|
||||
if (!start || !target)
|
||||
continue;
|
||||
|
||||
|
||||
DeckViewCard *card = 0;
|
||||
const QList<DeckViewCard *> &cardList = start->getCards();
|
||||
for (int j = 0; j < cardList.size(); ++j)
|
||||
|
|
@ -382,7 +383,7 @@ void DeckViewScene::applySideboardPlan(const QList<MoveCard_ToZone> &plan)
|
|||
}
|
||||
if (!card)
|
||||
continue;
|
||||
|
||||
|
||||
start->removeCard(card);
|
||||
target->addCard(card);
|
||||
card->setParentItem(target);
|
||||
|
|
@ -393,19 +394,19 @@ void DeckViewScene::rearrangeItems()
|
|||
{
|
||||
const int spacing = CARD_HEIGHT / 3;
|
||||
QList<DeckViewCardContainer *> contList = cardContainers.values();
|
||||
|
||||
|
||||
// Initialize space requirements
|
||||
QList<QList<QPair<int, int> > > rowsAndColsList;
|
||||
QList<QList<int> > cardCountList;
|
||||
QList<QList<QPair<int, int>>> rowsAndColsList;
|
||||
QList<QList<int>> cardCountList;
|
||||
for (int i = 0; i < contList.size(); ++i) {
|
||||
QList<QPair<int, int> > rowsAndCols = contList[i]->getRowsAndCols();
|
||||
QList<QPair<int, int>> rowsAndCols = contList[i]->getRowsAndCols();
|
||||
rowsAndColsList.append(rowsAndCols);
|
||||
|
||||
|
||||
cardCountList.append(QList<int>());
|
||||
for (int j = 0; j < rowsAndCols.size(); ++j)
|
||||
cardCountList[i].append(rowsAndCols[j].second);
|
||||
}
|
||||
|
||||
|
||||
qreal totalHeight, totalWidth;
|
||||
for (;;) {
|
||||
// Calculate total size before this iteration
|
||||
|
|
@ -417,11 +418,11 @@ void DeckViewScene::rearrangeItems()
|
|||
if (contSize.width() > totalWidth)
|
||||
totalWidth = contSize.width();
|
||||
}
|
||||
|
||||
|
||||
// We're done when the aspect ratio shifts from too high to too low.
|
||||
if (totalWidth / totalHeight <= optimalAspectRatio)
|
||||
break;
|
||||
|
||||
|
||||
// Find category with highest column count
|
||||
int maxIndex1 = -1, maxIndex2 = -1, maxCols = 0;
|
||||
for (int i = 0; i < rowsAndColsList.size(); ++i)
|
||||
|
|
@ -431,13 +432,14 @@ void DeckViewScene::rearrangeItems()
|
|||
maxIndex2 = j;
|
||||
maxCols = rowsAndColsList[i][j].second;
|
||||
}
|
||||
|
||||
|
||||
// Add row to category
|
||||
const int maxRows = rowsAndColsList[maxIndex1][maxIndex2].first;
|
||||
const int maxCardCount = cardCountList[maxIndex1][maxIndex2];
|
||||
rowsAndColsList[maxIndex1][maxIndex2] = QPair<int, int>(maxRows + 1, (int) ceil((qreal) maxCardCount / (qreal) (maxRows + 1)));
|
||||
rowsAndColsList[maxIndex1][maxIndex2] =
|
||||
QPair<int, int>(maxRows + 1, (int)ceil((qreal)maxCardCount / (qreal)(maxRows + 1)));
|
||||
}
|
||||
|
||||
|
||||
totalHeight = -spacing;
|
||||
for (int i = 0; i < contList.size(); ++i) {
|
||||
DeckViewCardContainer *c = contList[i];
|
||||
|
|
@ -445,11 +447,11 @@ void DeckViewScene::rearrangeItems()
|
|||
c->setPos(0, totalHeight + spacing);
|
||||
totalHeight += c->boundingRect().height() + spacing;
|
||||
}
|
||||
|
||||
|
||||
totalWidth = totalHeight * optimalAspectRatio;
|
||||
for (int i = 0; i < contList.size(); ++i)
|
||||
contList[i]->setWidth(totalWidth);
|
||||
|
||||
|
||||
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||
}
|
||||
|
||||
|
|
@ -484,14 +486,13 @@ void DeckViewScene::resetSideboardPlan()
|
|||
rearrangeItems();
|
||||
}
|
||||
|
||||
DeckView::DeckView(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
DeckView::DeckView(QWidget *parent) : QGraphicsView(parent)
|
||||
{
|
||||
deckViewScene = new DeckViewScene(this);
|
||||
|
||||
|
||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||
setDragMode(RubberBandDrag);
|
||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing /* | QPainter::SmoothPixmapTransform*/);
|
||||
setScene(deckViewScene);
|
||||
|
||||
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||
|
|
@ -502,7 +503,7 @@ DeckView::DeckView(QWidget *parent)
|
|||
void DeckView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
deckViewScene->setOptimalAspectRatio((qreal) width() / (qreal) height());
|
||||
deckViewScene->setOptimalAspectRatio((qreal)width() / (qreal)height());
|
||||
deckViewScene->rearrangeItems();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue