nice ellipses :)
This commit is contained in:
parent
7e13352a95
commit
175512a2ad
13 changed files with 144 additions and 101 deletions
|
@ -103,3 +103,26 @@ void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
|||
for (int i = cards->size() - 1; i >= 0; i--)
|
||||
player->client->moveCard(cards->at(i)->getId(), getName(), targetZone, targetX);
|
||||
}
|
||||
|
||||
void CardZone::paintCardNumberEllipse(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QString numStr = QString::number(cards->size());
|
||||
QFont font("Times", 32, QFont::Bold);
|
||||
QFontMetrics fm(font);
|
||||
QRect br = fm.boundingRect(numStr);
|
||||
double w = br.width() * 1.42;
|
||||
double h = br.height() * 1.42;
|
||||
if (w < h)
|
||||
w = h;
|
||||
|
||||
painter->setPen(QPen(QColor("black")));
|
||||
painter->setBrush(QColor(255, 255, 255, 150));
|
||||
painter->drawEllipse(QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h));
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, numStr);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
class Player;
|
||||
class ZoneViewZone;
|
||||
class QMenu;
|
||||
class QPainter;
|
||||
|
||||
class CardZone : public QGraphicsItem {
|
||||
protected:
|
||||
|
@ -20,6 +21,7 @@ protected:
|
|||
bool isShufflable;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
||||
void paintCardNumberEllipse(QPainter *painter);
|
||||
public:
|
||||
enum { Type = typeZone };
|
||||
int type() const { return Type; }
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QTextStream>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QProgressDialog>
|
||||
#include "decklist.h"
|
||||
#include "carddatabase.h"
|
||||
|
||||
|
@ -123,7 +124,7 @@ bool DeckList::saveToFile_Plain(QIODevice *device)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt, QWidget *parent)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
|
@ -136,7 +137,7 @@ bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt)
|
|||
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
||||
}
|
||||
if (result)
|
||||
cacheCardPictures();
|
||||
cacheCardPictures(parent);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -161,7 +162,7 @@ bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
|
|||
|
||||
bool DeckList::loadDialog(QWidget *parent)
|
||||
{
|
||||
QFileDialog dialog(parent);
|
||||
QFileDialog dialog(parent, tr("Load deck"));
|
||||
dialog.setNameFilters(fileNameFilters);
|
||||
if (!dialog.exec())
|
||||
return false;
|
||||
|
@ -174,7 +175,7 @@ bool DeckList::loadDialog(QWidget *parent)
|
|||
default: fmt = PlainTextFormat; break;
|
||||
}
|
||||
|
||||
if (loadFromFile(fileName, fmt)) {
|
||||
if (loadFromFile(fileName, fmt, parent)) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
return true;
|
||||
|
@ -184,7 +185,7 @@ bool DeckList::loadDialog(QWidget *parent)
|
|||
|
||||
bool DeckList::saveDialog(QWidget *parent)
|
||||
{
|
||||
QFileDialog dialog(parent);
|
||||
QFileDialog dialog(parent, tr("Save deck"));
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setConfirmOverwrite(true);
|
||||
dialog.setDefaultSuffix("cod");
|
||||
|
@ -208,10 +209,15 @@ bool DeckList::saveDialog(QWidget *parent)
|
|||
return false;
|
||||
}
|
||||
|
||||
void DeckList::cacheCardPictures()
|
||||
void DeckList::cacheCardPictures(QWidget *parent)
|
||||
{
|
||||
for (int i = 0; i < size(); i++)
|
||||
QProgressDialog progress(tr("Caching card pictures..."), QString(), 0, size(), parent);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
||||
for (int i = 0; i < size(); i++) {
|
||||
db->getCard(at(i)->getCard())->getPixmap();
|
||||
progress.setValue(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DeckList::cleanList()
|
||||
|
|
|
@ -19,23 +19,24 @@ public:
|
|||
bool isSideboard() const { return sideboard; }
|
||||
};
|
||||
|
||||
class DeckList : public QList<DecklistRow *> {
|
||||
class DeckList : public QObject, public QList<DecklistRow *> {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
||||
private:
|
||||
static const QStringList fileNameFilters;
|
||||
void cacheCardPictures();
|
||||
void cacheCardPictures(QWidget *parent = 0);
|
||||
CardDatabase *db;
|
||||
QString name, comments;
|
||||
QString lastFileName;
|
||||
FileFormat lastFileFormat;
|
||||
public slots:
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
void setComments(const QString &_comments) { comments = _comments; }
|
||||
public:
|
||||
|
||||
DeckList(CardDatabase *_db);
|
||||
~DeckList();
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
QString getName() const { return name; }
|
||||
void setComments(const QString &_comments) { comments = _comments; }
|
||||
QString getComments() const { return comments; }
|
||||
QString getLastFileName() const { return lastFileName; }
|
||||
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
||||
|
@ -44,7 +45,7 @@ public:
|
|||
bool saveToFile_Native(QIODevice *device);
|
||||
bool loadFromFile_Plain(QIODevice *device);
|
||||
bool saveToFile_Plain(QIODevice *device);
|
||||
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||
bool loadFromFile(const QString &fileName, FileFormat fmt, QWidget *parent = 0);
|
||||
bool saveToFile(const QString &fileName, FileFormat fmt);
|
||||
bool loadDialog(QWidget *parent = 0);
|
||||
bool saveDialog(QWidget *parent = 0);
|
||||
|
|
|
@ -9,6 +9,7 @@ GraveZone::GraveZone(Player *_p, QGraphicsItem *parent)
|
|||
: CardZone(_p, "grave", false, false, parent)
|
||||
{
|
||||
cards = new CardList(true);
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
}
|
||||
|
||||
QRectF GraveZone::boundingRect() const
|
||||
|
@ -16,17 +17,15 @@ QRectF GraveZone::boundingRect() const
|
|||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||
void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if (!cards->isEmpty())
|
||||
cards->at(0)->paint(painter, option, widget);
|
||||
|
||||
painter->save();
|
||||
|
||||
painter->fillRect(boundingRect(), QColor("yellow"));
|
||||
|
||||
painter->setFont(QFont("Times", 32, QFont::Bold));
|
||||
painter->setPen(QPen(QColor("black")));
|
||||
painter->setBackground(QBrush(QColor(255, 255, 255, 100)));
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(cards->size()));
|
||||
paintCardNumberEllipse(painter);
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -78,8 +77,7 @@ void GraveZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
void GraveZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void GraveZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ LibraryZone::LibraryZone(Player *_p, QGraphicsItem *parent)
|
|||
: CardZone(_p, "deck", false, true, parent)
|
||||
{
|
||||
cards = new CardList(false);
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
image = player->getDb()->getCard()->getPixmap();
|
||||
}
|
||||
|
@ -21,21 +21,15 @@ QRectF LibraryZone::boundingRect() const
|
|||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
painter->save();
|
||||
|
||||
QRectF foo = option->matrix.mapRect(boundingRect());
|
||||
QPixmap bar = image->scaled((int) foo.width(), (int) foo.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
painter->drawPixmap(boundingRect(), bar, bar.rect());
|
||||
|
||||
painter->setFont(QFont("Times", 32, QFont::Bold));
|
||||
painter->setPen(QPen(QColor("black")));
|
||||
painter->setBackground(QBrush(QColor(255, 255, 255, 100)));
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(cards->size()));
|
||||
paintCardNumberEllipse(painter);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
|
|
@ -162,12 +162,13 @@ void Player::gameEvent(ServerEventData *event)
|
|||
CardZone *deck = zones.findZone("deck");
|
||||
for (; deck_cards; deck_cards--)
|
||||
deck->addCard(new CardItem(db), false, -1);
|
||||
deck->reorganizeCards();
|
||||
|
||||
CardZone *sb = zones.findZone("sb");
|
||||
for (; sb_cards; sb_cards--)
|
||||
sb->addCard(new CardItem(db), false, -1);
|
||||
sb->reorganizeCards();
|
||||
|
||||
for (int i = 0; i < zones.size(); i++)
|
||||
zones.at(i)->reorganizeCards();
|
||||
|
||||
if (local) {
|
||||
client->addCounter("life", QColor("white"), 20);
|
||||
|
|
|
@ -9,6 +9,7 @@ RfgZone::RfgZone(Player *_p, QGraphicsItem *parent)
|
|||
: CardZone(_p, "rfg", false, false, parent)
|
||||
{
|
||||
cards = new CardList(true);
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
}
|
||||
|
||||
QRectF RfgZone::boundingRect() const
|
||||
|
@ -18,17 +19,13 @@ QRectF RfgZone::boundingRect() const
|
|||
|
||||
void RfgZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
if (!cards->isEmpty())
|
||||
cards->at(0)->paint(painter, option, widget);
|
||||
|
||||
painter->save();
|
||||
|
||||
painter->fillRect(boundingRect(), QColor("yellow"));
|
||||
|
||||
painter->setFont(QFont("Times", 32, QFont::Bold));
|
||||
painter->setPen(QPen(QColor("black")));
|
||||
painter->setBackground(QBrush(QColor(255, 255, 255, 100)));
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(cards->size()));
|
||||
paintCardNumberEllipse(painter);
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -80,8 +77,7 @@ void RfgZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
void RfgZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void RfgZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
databaseView->setSortingEnabled(true);
|
||||
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
|
||||
|
||||
deckModel = new DeckListModel(db, this);
|
||||
deckView = new QTreeView();
|
||||
deckView->setModel(deckModel);
|
||||
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
|
||||
QVBoxLayout *leftFrame = new QVBoxLayout;
|
||||
leftFrame->addWidget(databaseView);
|
||||
|
||||
cardInfo = new CardInfoWidget(db);
|
||||
|
||||
|
@ -25,10 +23,33 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
middleFrame->addWidget(cardInfo);
|
||||
middleFrame->addStretch();
|
||||
|
||||
deckModel = new DeckListModel(db, this);
|
||||
deckView = new QTreeView();
|
||||
deckView->setModel(deckModel);
|
||||
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
|
||||
|
||||
QLabel *nameLabel = new QLabel(tr("Deck &name:"));
|
||||
nameEdit = new QLineEdit;
|
||||
nameLabel->setBuddy(nameEdit);
|
||||
connect(nameEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setName(const QString &)));
|
||||
QLabel *commentsLabel = new QLabel(tr("&Comments:"));
|
||||
commentsEdit = new QLineEdit;
|
||||
commentsLabel->setBuddy(commentsEdit);
|
||||
connect(commentsEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setComments(const QString &)));
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(nameEdit, 0, 1);
|
||||
grid->addWidget(commentsLabel, 1, 0);
|
||||
grid->addWidget(commentsEdit, 1, 1);
|
||||
|
||||
QVBoxLayout *rightFrame = new QVBoxLayout;
|
||||
rightFrame->addLayout(grid);
|
||||
rightFrame->addWidget(deckView);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(databaseView);
|
||||
mainLayout->addLayout(leftFrame);
|
||||
mainLayout->addLayout(middleFrame);
|
||||
mainLayout->addWidget(deckView);
|
||||
mainLayout->addLayout(rightFrame);
|
||||
|
||||
QWidget *centralWidget = new QWidget;
|
||||
centralWidget->setLayout(mainLayout);
|
||||
|
@ -47,7 +68,7 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
aSaveDeckAs = new QAction(tr("&Save deck as..."), this);
|
||||
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
|
||||
|
||||
deckMenu = menuBar()->addMenu(tr("Deck"));
|
||||
deckMenu = menuBar()->addMenu(tr("&Deck"));
|
||||
deckMenu->addAction(aNewDeck);
|
||||
deckMenu->addAction(aLoadDeck);
|
||||
deckMenu->addAction(aSaveDeck);
|
||||
|
@ -84,6 +105,8 @@ void WndDeckEditor::actLoadDeck()
|
|||
lastFileName = l->getLastFileName();
|
||||
lastFileFormat = l->getLastFileFormat();
|
||||
deckView->reset();
|
||||
nameEdit->setText(l->getName());
|
||||
commentsEdit->setText(l->getComments());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ class CardDatabaseModel;
|
|||
class DeckListModel;
|
||||
class QTreeView;
|
||||
class CardInfoWidget;
|
||||
class QLineEdit;
|
||||
|
||||
class WndDeckEditor : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
@ -30,6 +31,7 @@ private:
|
|||
DeckListModel *deckModel;
|
||||
QTreeView *databaseView, *deckView;
|
||||
CardInfoWidget *cardInfo;
|
||||
QLineEdit *nameEdit, *commentsEdit;
|
||||
|
||||
QMenu *deckMenu;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs;
|
||||
|
|
|
@ -22,7 +22,7 @@ void ZoneViewLayout::reorganize()
|
|||
for (int i = 0; i < views.size(); i++) {
|
||||
QRectF viewSize = views.at(i)->windowFrameRect();
|
||||
qreal w = viewSize.right() - viewSize.left();
|
||||
qreal h = viewSize.bottom() - viewSize.top();
|
||||
// qreal h = viewSize.bottom() - viewSize.top();
|
||||
views.at(i)->setPos(totalWidth, y);
|
||||
totalWidth += w;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,8 @@ QRectF ZoneViewZone::boundingRect() const
|
|||
return QRectF(0, 0, CARD_WIDTH * 1.75, height);
|
||||
}
|
||||
|
||||
void ZoneViewZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
}
|
||||
|
||||
bool ZoneViewZone::initializeCards()
|
||||
|
|
Loading…
Reference in a new issue