nice ellipses :)

This commit is contained in:
Max-Wilhelm Bruker 2009-05-23 01:58:11 +02:00
parent 7e13352a95
commit 175512a2ad
13 changed files with 144 additions and 101 deletions

View file

@ -103,3 +103,26 @@ void CardZone::moveAllToZone(const QString &targetZone, int targetX)
for (int i = cards->size() - 1; i >= 0; i--) for (int i = cards->size() - 1; i >= 0; i--)
player->client->moveCard(cards->at(i)->getId(), getName(), targetZone, targetX); 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();
}

View file

@ -7,6 +7,7 @@
class Player; class Player;
class ZoneViewZone; class ZoneViewZone;
class QMenu; class QMenu;
class QPainter;
class CardZone : public QGraphicsItem { class CardZone : public QGraphicsItem {
protected: protected:
@ -20,6 +21,7 @@ protected:
bool isShufflable; bool isShufflable;
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void addCardImpl(CardItem *card, int x, int y) = 0; virtual void addCardImpl(CardItem *card, int x, int y) = 0;
void paintCardNumberEllipse(QPainter *painter);
public: public:
enum { Type = typeZone }; enum { Type = typeZone };
int type() const { return Type; } int type() const { return Type; }

View file

@ -3,6 +3,7 @@
#include <QTextStream> #include <QTextStream>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QProgressDialog>
#include "decklist.h" #include "decklist.h"
#include "carddatabase.h" #include "carddatabase.h"
@ -123,7 +124,7 @@ bool DeckList::saveToFile_Plain(QIODevice *device)
return true; return true;
} }
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt) bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt, QWidget *parent)
{ {
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) 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; case CockatriceFormat: result = loadFromFile_Native(&file); break;
} }
if (result) if (result)
cacheCardPictures(); cacheCardPictures(parent);
return result; return result;
} }
@ -161,7 +162,7 @@ bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
bool DeckList::loadDialog(QWidget *parent) bool DeckList::loadDialog(QWidget *parent)
{ {
QFileDialog dialog(parent); QFileDialog dialog(parent, tr("Load deck"));
dialog.setNameFilters(fileNameFilters); dialog.setNameFilters(fileNameFilters);
if (!dialog.exec()) if (!dialog.exec())
return false; return false;
@ -174,7 +175,7 @@ bool DeckList::loadDialog(QWidget *parent)
default: fmt = PlainTextFormat; break; default: fmt = PlainTextFormat; break;
} }
if (loadFromFile(fileName, fmt)) { if (loadFromFile(fileName, fmt, parent)) {
lastFileName = fileName; lastFileName = fileName;
lastFileFormat = fmt; lastFileFormat = fmt;
return true; return true;
@ -184,7 +185,7 @@ bool DeckList::loadDialog(QWidget *parent)
bool DeckList::saveDialog(QWidget *parent) bool DeckList::saveDialog(QWidget *parent)
{ {
QFileDialog dialog(parent); QFileDialog dialog(parent, tr("Save deck"));
dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setConfirmOverwrite(true); dialog.setConfirmOverwrite(true);
dialog.setDefaultSuffix("cod"); dialog.setDefaultSuffix("cod");
@ -208,10 +209,15 @@ bool DeckList::saveDialog(QWidget *parent)
return false; 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(); db->getCard(at(i)->getCard())->getPixmap();
progress.setValue(i + 1);
}
} }
void DeckList::cleanList() void DeckList::cleanList()

View file

@ -19,23 +19,24 @@ public:
bool isSideboard() const { return sideboard; } bool isSideboard() const { return sideboard; }
}; };
class DeckList : public QList<DecklistRow *> { class DeckList : public QObject, public QList<DecklistRow *> {
Q_OBJECT
public: public:
enum FileFormat { PlainTextFormat, CockatriceFormat }; enum FileFormat { PlainTextFormat, CockatriceFormat };
private: private:
static const QStringList fileNameFilters; static const QStringList fileNameFilters;
void cacheCardPictures(); void cacheCardPictures(QWidget *parent = 0);
CardDatabase *db; CardDatabase *db;
QString name, comments; QString name, comments;
QString lastFileName; QString lastFileName;
FileFormat lastFileFormat; FileFormat lastFileFormat;
public slots:
void setName(const QString &_name) { name = _name; }
void setComments(const QString &_comments) { comments = _comments; }
public: public:
DeckList(CardDatabase *_db); DeckList(CardDatabase *_db);
~DeckList(); ~DeckList();
void setName(const QString &_name) { name = _name; }
QString getName() const { return name; } QString getName() const { return name; }
void setComments(const QString &_comments) { comments = _comments; }
QString getComments() const { return comments; } QString getComments() const { return comments; }
QString getLastFileName() const { return lastFileName; } QString getLastFileName() const { return lastFileName; }
FileFormat getLastFileFormat() const { return lastFileFormat; } FileFormat getLastFileFormat() const { return lastFileFormat; }
@ -44,7 +45,7 @@ public:
bool saveToFile_Native(QIODevice *device); bool saveToFile_Native(QIODevice *device);
bool loadFromFile_Plain(QIODevice *device); bool loadFromFile_Plain(QIODevice *device);
bool saveToFile_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 saveToFile(const QString &fileName, FileFormat fmt);
bool loadDialog(QWidget *parent = 0); bool loadDialog(QWidget *parent = 0);
bool saveDialog(QWidget *parent = 0); bool saveDialog(QWidget *parent = 0);

View file

@ -9,6 +9,7 @@ GraveZone::GraveZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "grave", false, false, parent) : CardZone(_p, "grave", false, false, parent)
{ {
cards = new CardList(true); cards = new CardList(true);
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
} }
QRectF GraveZone::boundingRect() const QRectF GraveZone::boundingRect() const
@ -16,17 +17,15 @@ QRectF GraveZone::boundingRect() const
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); 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->save();
painter->fillRect(boundingRect(), QColor("yellow")); paintCardNumberEllipse(painter);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
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()));
painter->restore(); painter->restore();
} }
@ -78,8 +77,7 @@ void GraveZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }
void GraveZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void GraveZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
Q_UNUSED(event);
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }

View file

@ -10,8 +10,8 @@ LibraryZone::LibraryZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "deck", false, true, parent) : CardZone(_p, "deck", false, true, parent)
{ {
cards = new CardList(false); cards = new CardList(false);
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setCacheMode(DeviceCoordinateCache);
image = player->getDb()->getCard()->getPixmap(); image = player->getDb()->getCard()->getPixmap();
} }
@ -21,21 +21,15 @@ QRectF LibraryZone::boundingRect() const
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); 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(); painter->save();
QRectF foo = option->matrix.mapRect(boundingRect()); QRectF foo = option->matrix.mapRect(boundingRect());
QPixmap bar = image->scaled((int) foo.width(), (int) foo.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QPixmap bar = image->scaled((int) foo.width(), (int) foo.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(boundingRect(), bar, bar.rect()); painter->drawPixmap(boundingRect(), bar, bar.rect());
painter->setFont(QFont("Times", 32, QFont::Bold)); paintCardNumberEllipse(painter);
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()));
painter->restore(); painter->restore();
} }

View file

@ -162,12 +162,13 @@ void Player::gameEvent(ServerEventData *event)
CardZone *deck = zones.findZone("deck"); CardZone *deck = zones.findZone("deck");
for (; deck_cards; deck_cards--) for (; deck_cards; deck_cards--)
deck->addCard(new CardItem(db), false, -1); deck->addCard(new CardItem(db), false, -1);
deck->reorganizeCards();
CardZone *sb = zones.findZone("sb"); CardZone *sb = zones.findZone("sb");
for (; sb_cards; sb_cards--) for (; sb_cards; sb_cards--)
sb->addCard(new CardItem(db), false, -1); sb->addCard(new CardItem(db), false, -1);
sb->reorganizeCards();
for (int i = 0; i < zones.size(); i++)
zones.at(i)->reorganizeCards();
if (local) { if (local) {
client->addCounter("life", QColor("white"), 20); client->addCounter("life", QColor("white"), 20);

View file

@ -9,6 +9,7 @@ RfgZone::RfgZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "rfg", false, false, parent) : CardZone(_p, "rfg", false, false, parent)
{ {
cards = new CardList(true); cards = new CardList(true);
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
} }
QRectF RfgZone::boundingRect() const QRectF RfgZone::boundingRect() const
@ -18,17 +19,13 @@ QRectF RfgZone::boundingRect() const
void RfgZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void RfgZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
Q_UNUSED(option); if (!cards->isEmpty())
Q_UNUSED(widget); cards->at(0)->paint(painter, option, widget);
painter->save(); painter->save();
painter->fillRect(boundingRect(), QColor("yellow")); paintCardNumberEllipse(painter);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
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()));
painter->restore(); painter->restore();
} }
@ -80,8 +77,7 @@ void RfgZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }
void RfgZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void RfgZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
Q_UNUSED(event);
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }

View file

@ -14,10 +14,8 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
databaseView->setSortingEnabled(true); databaseView->setSortingEnabled(true);
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &))); connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
deckModel = new DeckListModel(db, this); QVBoxLayout *leftFrame = new QVBoxLayout;
deckView = new QTreeView(); leftFrame->addWidget(databaseView);
deckView->setModel(deckModel);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
cardInfo = new CardInfoWidget(db); cardInfo = new CardInfoWidget(db);
@ -25,10 +23,33 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
middleFrame->addWidget(cardInfo); middleFrame->addWidget(cardInfo);
middleFrame->addStretch(); 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; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(databaseView); mainLayout->addLayout(leftFrame);
mainLayout->addLayout(middleFrame); mainLayout->addLayout(middleFrame);
mainLayout->addWidget(deckView); mainLayout->addLayout(rightFrame);
QWidget *centralWidget = new QWidget; QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout); centralWidget->setLayout(mainLayout);
@ -47,7 +68,7 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
aSaveDeckAs = new QAction(tr("&Save deck as..."), this); aSaveDeckAs = new QAction(tr("&Save deck as..."), this);
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
deckMenu = menuBar()->addMenu(tr("Deck")); deckMenu = menuBar()->addMenu(tr("&Deck"));
deckMenu->addAction(aNewDeck); deckMenu->addAction(aNewDeck);
deckMenu->addAction(aLoadDeck); deckMenu->addAction(aLoadDeck);
deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeck);
@ -84,6 +105,8 @@ void WndDeckEditor::actLoadDeck()
lastFileName = l->getLastFileName(); lastFileName = l->getLastFileName();
lastFileFormat = l->getLastFileFormat(); lastFileFormat = l->getLastFileFormat();
deckView->reset(); deckView->reset();
nameEdit->setText(l->getName());
commentsEdit->setText(l->getComments());
} }
} }

View file

@ -10,6 +10,7 @@ class CardDatabaseModel;
class DeckListModel; class DeckListModel;
class QTreeView; class QTreeView;
class CardInfoWidget; class CardInfoWidget;
class QLineEdit;
class WndDeckEditor : public QMainWindow { class WndDeckEditor : public QMainWindow {
Q_OBJECT Q_OBJECT
@ -30,6 +31,7 @@ private:
DeckListModel *deckModel; DeckListModel *deckModel;
QTreeView *databaseView, *deckView; QTreeView *databaseView, *deckView;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
QLineEdit *nameEdit, *commentsEdit;
QMenu *deckMenu; QMenu *deckMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs; QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs;

View file

@ -22,7 +22,7 @@ void ZoneViewLayout::reorganize()
for (int i = 0; i < views.size(); i++) { for (int i = 0; i < views.size(); i++) {
QRectF viewSize = views.at(i)->windowFrameRect(); QRectF viewSize = views.at(i)->windowFrameRect();
qreal w = viewSize.right() - viewSize.left(); qreal w = viewSize.right() - viewSize.left();
qreal h = viewSize.bottom() - viewSize.top(); // qreal h = viewSize.bottom() - viewSize.top();
views.at(i)->setPos(totalWidth, y); views.at(i)->setPos(totalWidth, y);
totalWidth += w; totalWidth += w;
} }

View file

@ -21,11 +21,8 @@ QRectF ZoneViewZone::boundingRect() const
return QRectF(0, 0, CARD_WIDTH * 1.75, height); 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() bool ZoneViewZone::initializeCards()