prepared deck list code to be moved out to common
This commit is contained in:
parent
77f5ec29eb
commit
34d2649f65
12 changed files with 112 additions and 134 deletions
|
@ -3,9 +3,7 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
#include <QProgressDialog>
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QSettings>
|
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
|
||||||
|
@ -130,8 +128,8 @@ QVector<QPair<int, int> > InnerDecklistNode::sort(Qt::SortOrder order)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckList::DeckList(CardDatabase *_db, QObject *parent)
|
DeckList::DeckList(QObject *parent)
|
||||||
: QObject(parent), db(_db)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +271,7 @@ bool DeckList::saveToFile_Plain(QIODevice *device)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt, QWidget *parent)
|
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -285,18 +283,11 @@ bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt, QWidget *pa
|
||||||
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
||||||
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result)
|
||||||
emit deckLoaded();
|
emit deckLoaded();
|
||||||
cacheCardPictures(parent);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList DeckList::fileNameFilters = QStringList()
|
|
||||||
<< QObject::tr("Cockatrice decks (*.cod)")
|
|
||||||
<< QObject::tr("Plain text decks (*.dec *.mwDeck)")
|
|
||||||
<< QObject::tr("All files (*.*)");
|
|
||||||
|
|
||||||
bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
|
bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
|
@ -311,82 +302,6 @@ bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckList::loadDialog(QWidget *parent)
|
|
||||||
{
|
|
||||||
QFileDialog dialog(parent, tr("Load deck"));
|
|
||||||
QSettings settings;
|
|
||||||
dialog.setDirectory(settings.value("paths/decks").toString());
|
|
||||||
dialog.setNameFilters(fileNameFilters);
|
|
||||||
if (!dialog.exec())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
|
||||||
FileFormat fmt;
|
|
||||||
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
|
||||||
case 0: fmt = CockatriceFormat; break;
|
|
||||||
case 1: fmt = PlainTextFormat; break;
|
|
||||||
default: fmt = PlainTextFormat; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadFromFile(fileName, fmt, parent)) {
|
|
||||||
lastFileName = fileName;
|
|
||||||
lastFileFormat = fmt;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeckList::saveDialog(QWidget *parent)
|
|
||||||
{
|
|
||||||
QFileDialog dialog(parent, tr("Save deck"));
|
|
||||||
QSettings settings;
|
|
||||||
dialog.setDirectory(settings.value("paths/decks").toString());
|
|
||||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
||||||
dialog.setConfirmOverwrite(true);
|
|
||||||
dialog.setDefaultSuffix("cod");
|
|
||||||
dialog.setNameFilters(fileNameFilters);
|
|
||||||
if (!dialog.exec())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
|
||||||
DeckList::FileFormat fmt;
|
|
||||||
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
|
||||||
case 0: fmt = DeckList::CockatriceFormat; break;
|
|
||||||
case 1: fmt = DeckList::PlainTextFormat; break;
|
|
||||||
default: fmt = DeckList::PlainTextFormat; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveToFile(fileName, fmt)) {
|
|
||||||
lastFileName = fileName;
|
|
||||||
lastFileFormat = fmt;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckList::cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < item->size(); i++) {
|
|
||||||
DecklistCardNode *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
|
||||||
if (node) {
|
|
||||||
db->getCard(node->getName())->loadPixmap();
|
|
||||||
progress->setValue(progress->value() + 1);
|
|
||||||
} else
|
|
||||||
cacheCardPicturesHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckList::cacheCardPictures(QWidget *parent)
|
|
||||||
{
|
|
||||||
int totalCards = root->recursiveCount();
|
|
||||||
|
|
||||||
QProgressDialog progress(tr("Caching card pictures..."), QString(), 0, totalCards, parent);
|
|
||||||
progress.setMinimumDuration(1000);
|
|
||||||
progress.setWindowModality(Qt::WindowModal);
|
|
||||||
|
|
||||||
cacheCardPicturesHelper(root, &progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckList::cleanList()
|
void DeckList::cleanList()
|
||||||
{
|
{
|
||||||
root->clearTree();
|
root->clearTree();
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
class QProgressDialog;
|
|
||||||
|
|
||||||
class InnerDecklistNode;
|
class InnerDecklistNode;
|
||||||
|
|
||||||
|
@ -71,21 +70,17 @@ class DeckList : public QObject {
|
||||||
public:
|
public:
|
||||||
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
||||||
private:
|
private:
|
||||||
static const QStringList fileNameFilters;
|
|
||||||
void cacheCardPictures(QWidget *parent = 0);
|
|
||||||
CardDatabase *db;
|
|
||||||
QString name, comments;
|
QString name, comments;
|
||||||
QString lastFileName;
|
QString lastFileName;
|
||||||
FileFormat lastFileFormat;
|
FileFormat lastFileFormat;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
void cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress);
|
|
||||||
signals:
|
signals:
|
||||||
void deckLoaded();
|
void deckLoaded();
|
||||||
public slots:
|
public slots:
|
||||||
void setName(const QString &_name = QString()) { name = _name; }
|
void setName(const QString &_name = QString()) { name = _name; }
|
||||||
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
||||||
public:
|
public:
|
||||||
DeckList(CardDatabase *_db, QObject *parent = 0);
|
DeckList(QObject *parent = 0);
|
||||||
~DeckList();
|
~DeckList();
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
QString getComments() const { return comments; }
|
QString getComments() const { return comments; }
|
||||||
|
@ -96,7 +91,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, QWidget *parent = 0);
|
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||||
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);
|
||||||
|
|
|
@ -6,13 +6,15 @@
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QTextTable>
|
#include <QTextTable>
|
||||||
|
#include <QProgressDialog>
|
||||||
|
#include "main.h"
|
||||||
#include "decklistmodel.h"
|
#include "decklistmodel.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
|
||||||
DeckListModel::DeckListModel(CardDatabase *_db, QObject *parent)
|
DeckListModel::DeckListModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), db(_db)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
deckList = new DeckList(db, this);
|
deckList = new DeckList(this);
|
||||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
@ -313,6 +315,29 @@ void DeckListModel::cleanList()
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckListModel::cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < item->size(); i++) {
|
||||||
|
DecklistCardNode *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
||||||
|
if (node) {
|
||||||
|
db->getCard(node->getName())->loadPixmap();
|
||||||
|
progress->setValue(progress->value() + 1);
|
||||||
|
} else
|
||||||
|
cacheCardPicturesHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckListModel::cacheCardPictures(QWidget *parent)
|
||||||
|
{
|
||||||
|
int totalCards = deckList->getRoot()->recursiveCount();
|
||||||
|
|
||||||
|
QProgressDialog progress(tr("Caching card pictures..."), QString(), 0, totalCards, parent);
|
||||||
|
progress.setMinimumDuration(1000);
|
||||||
|
progress.setWindowModality(Qt::WindowModal);
|
||||||
|
|
||||||
|
cacheCardPicturesHelper(deckList->getRoot(), &progress);
|
||||||
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
static const int totalColumns = 3;
|
static const int totalColumns = 3;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
|
class QProgressDialog;
|
||||||
class QPrinter;
|
class QPrinter;
|
||||||
class QTextCursor;
|
class QTextCursor;
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ private slots:
|
||||||
public slots:
|
public slots:
|
||||||
void printDeckList(QPrinter *printer);
|
void printDeckList(QPrinter *printer);
|
||||||
public:
|
public:
|
||||||
DeckListModel(CardDatabase *_db, QObject *parent = 0);
|
DeckListModel(QObject *parent = 0);
|
||||||
~DeckListModel();
|
~DeckListModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 2; }
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 2; }
|
||||||
|
@ -43,8 +44,8 @@ public:
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
void cleanList();
|
void cleanList();
|
||||||
DeckList *getDeckList() const { return deckList; }
|
DeckList *getDeckList() const { return deckList; }
|
||||||
|
void cacheCardPictures(QWidget *parent = 0);
|
||||||
private:
|
private:
|
||||||
CardDatabase *db;
|
|
||||||
DeckList *deckList;
|
DeckList *deckList;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
||||||
|
@ -53,7 +54,8 @@ private:
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
||||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
||||||
|
|
||||||
|
void cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress);
|
||||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||||
|
|
||||||
template<typename T> T getNode(const QModelIndex &index) const
|
template<typename T> T getNode(const QModelIndex &index) const
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
#include "dlg_startgame.h"
|
#include "dlg_startgame.h"
|
||||||
#include "decklistmodel.h"
|
#include "decklistmodel.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
DlgStartGame::DlgStartGame(CardDatabase *_db, QWidget *parent)
|
DlgStartGame::DlgStartGame(QWidget *parent)
|
||||||
: QDialog(parent), db(_db)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
deckView = new QTreeView;
|
deckView = new QTreeView;
|
||||||
deckModel = new DeckListModel(db, this);
|
deckModel = new DeckListModel(this);
|
||||||
deckView->setModel(deckModel);
|
deckView->setModel(deckModel);
|
||||||
deckView->setUniformRowHeights(true);
|
deckView->setUniformRowHeights(true);
|
||||||
|
|
||||||
|
@ -37,8 +38,8 @@ DlgStartGame::DlgStartGame(CardDatabase *_db, QWidget *parent)
|
||||||
|
|
||||||
void DlgStartGame::actLoad()
|
void DlgStartGame::actLoad()
|
||||||
{
|
{
|
||||||
if (!deckModel->getDeckList()->loadDialog(this))
|
// if (!deckModel->getDeckList()->loadDialog(this))
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
deckView->reset();
|
deckView->reset();
|
||||||
deckModel->sort(1);
|
deckModel->sort(1);
|
||||||
|
|
|
@ -11,14 +11,13 @@ class DeckListModel;
|
||||||
class DlgStartGame: public QDialog {
|
class DlgStartGame: public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgStartGame(CardDatabase *_db, QWidget *parent = 0);
|
DlgStartGame(QWidget *parent = 0);
|
||||||
QStringList getDeckList() const;
|
QStringList getDeckList() const;
|
||||||
signals:
|
signals:
|
||||||
void newDeckLoaded(const QStringList &cards);
|
void newDeckLoaded(const QStringList &cards);
|
||||||
private slots:
|
private slots:
|
||||||
void actLoad();
|
void actLoad();
|
||||||
private:
|
private:
|
||||||
CardDatabase *db;
|
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
DeckListModel *deckModel;
|
DeckListModel *deckModel;
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include "arrowitem.h"
|
#include "arrowitem.h"
|
||||||
#include "protocol_datastructures.h"
|
#include "protocol_datastructures.h"
|
||||||
|
|
||||||
Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent)
|
Game::Game(Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent)
|
||||||
: QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
|
: QObject(parent), client(_client), scene(_scene), started(false), currentPhase(-1)
|
||||||
{
|
{
|
||||||
connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &)));
|
connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &)));
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menu
|
||||||
connect(i.key(), SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
connect(i.key(), SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dlgStartGame = new DlgStartGame(db);
|
dlgStartGame = new DlgStartGame;
|
||||||
connect(dlgStartGame, SIGNAL(newDeckLoaded(const QStringList &)), client, SLOT(submitDeck(const QStringList &)));
|
connect(dlgStartGame, SIGNAL(newDeckLoaded(const QStringList &)), client, SLOT(submitDeck(const QStringList &)));
|
||||||
connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart()));
|
connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart()));
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ private:
|
||||||
*aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
*aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
||||||
DlgStartGame *dlgStartGame;
|
DlgStartGame *dlgStartGame;
|
||||||
|
|
||||||
CardDatabase *db;
|
|
||||||
Client *client;
|
Client *client;
|
||||||
GameScene *scene;
|
GameScene *scene;
|
||||||
QStringList spectatorList;
|
QStringList spectatorList;
|
||||||
|
@ -102,7 +101,7 @@ signals:
|
||||||
void logSetActivePlayer(Player *player);
|
void logSetActivePlayer(Player *player);
|
||||||
void setActivePhase(int phase);
|
void setActivePhase(int phase);
|
||||||
public:
|
public:
|
||||||
Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent = 0);
|
Game(Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent = 0);
|
||||||
~Game();
|
~Game();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void restartGameDialog();
|
void restartGameDialog();
|
||||||
|
|
|
@ -50,8 +50,19 @@ TabGame::TabGame(Client *_client, int _gameId)
|
||||||
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
|
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
|
||||||
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));
|
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));
|
||||||
|
|
||||||
}
|
/* game = new Game(client, scene, menuBar(), this);
|
||||||
|
connect(game, SIGNAL(hoverCard(QString)), cardInfo, SLOT(setCard(const QString &)));
|
||||||
|
connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *)));
|
||||||
|
connect(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *)));
|
||||||
|
connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int)));
|
||||||
|
connect(phasesToolbar, SIGNAL(signalDrawCard()), game, SLOT(activePlayerDrawCard()));
|
||||||
|
connect(phasesToolbar, SIGNAL(signalUntapAll()), game, SLOT(activePlayerUntapAll()));
|
||||||
|
messageLog->connectToGame(game);
|
||||||
|
|
||||||
|
game->queryGameState();
|
||||||
|
*/}
|
||||||
|
|
||||||
void TabGame::processGameEvent(GameEvent *event)
|
void TabGame::processGameEvent(GameEvent *event)
|
||||||
{
|
{
|
||||||
|
// game->processGameEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,11 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||||
QLineEdit::keyPressEvent(event);
|
QLineEdit::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QStringList WndDeckEditor::fileNameFilters = QStringList()
|
||||||
|
<< QObject::tr("Cockatrice decks (*.cod)")
|
||||||
|
<< QObject::tr("Plain text decks (*.dec *.mwDeck)")
|
||||||
|
<< QObject::tr("All files (*.*)");
|
||||||
|
|
||||||
WndDeckEditor::WndDeckEditor(QWidget *parent)
|
WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +68,7 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||||
middleFrame->addLayout(verticalToolBarLayout);
|
middleFrame->addLayout(verticalToolBarLayout);
|
||||||
middleFrame->addStretch();
|
middleFrame->addStretch();
|
||||||
|
|
||||||
deckModel = new DeckListModel(db, this);
|
deckModel = new DeckListModel(this);
|
||||||
deckView = new QTreeView();
|
deckView = new QTreeView();
|
||||||
deckView->setModel(deckModel);
|
deckView->setModel(deckModel);
|
||||||
deckView->setUniformRowHeights(true);
|
deckView->setUniformRowHeights(true);
|
||||||
|
@ -237,16 +242,33 @@ void WndDeckEditor::actLoadDeck()
|
||||||
if (!confirmClose())
|
if (!confirmClose())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
QFileDialog dialog(this, tr("Load deck"));
|
||||||
|
QSettings settings;
|
||||||
|
dialog.setDirectory(settings.value("paths/decks").toString());
|
||||||
|
dialog.setNameFilters(fileNameFilters);
|
||||||
|
if (!dialog.exec())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
|
DeckList::FileFormat fmt;
|
||||||
|
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
||||||
|
case 0: fmt = DeckList::CockatriceFormat; break;
|
||||||
|
case 1: fmt = DeckList::PlainTextFormat; break;
|
||||||
|
default: fmt = DeckList::PlainTextFormat; break;
|
||||||
|
}
|
||||||
|
|
||||||
DeckList *l = deckModel->getDeckList();
|
DeckList *l = deckModel->getDeckList();
|
||||||
if (l->loadDialog(this)) {
|
if (l->loadFromFile(fileName, fmt)) {
|
||||||
lastFileName = l->getLastFileName();
|
lastFileName = fileName;
|
||||||
lastFileFormat = l->getLastFileFormat();
|
lastFileFormat = fmt;
|
||||||
nameEdit->setText(l->getName());
|
nameEdit->setText(l->getName());
|
||||||
commentsEdit->setText(l->getComments());
|
commentsEdit->setText(l->getComments());
|
||||||
deckModel->sort(1);
|
deckModel->sort(1);
|
||||||
deckView->expandAll();
|
deckView->expandAll();
|
||||||
deckView->resizeColumnToContents(0);
|
deckView->resizeColumnToContents(0);
|
||||||
setWindowModified(false);
|
setWindowModified(false);
|
||||||
|
|
||||||
|
deckModel->cacheCardPictures(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,14 +285,31 @@ bool WndDeckEditor::actSaveDeck()
|
||||||
|
|
||||||
bool WndDeckEditor::actSaveDeckAs()
|
bool WndDeckEditor::actSaveDeckAs()
|
||||||
{
|
{
|
||||||
DeckList *l = deckModel->getDeckList();
|
QFileDialog dialog(this, tr("Save deck"));
|
||||||
if (l->saveDialog(this)) {
|
QSettings settings;
|
||||||
lastFileName = l->getLastFileName();
|
dialog.setDirectory(settings.value("paths/decks").toString());
|
||||||
lastFileFormat = l->getLastFileFormat();
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
dialog.setConfirmOverwrite(true);
|
||||||
|
dialog.setDefaultSuffix("cod");
|
||||||
|
dialog.setNameFilters(fileNameFilters);
|
||||||
|
if (!dialog.exec())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
|
DeckList::FileFormat fmt;
|
||||||
|
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
||||||
|
case 0: fmt = DeckList::CockatriceFormat; break;
|
||||||
|
case 1: fmt = DeckList::PlainTextFormat; break;
|
||||||
|
default: fmt = DeckList::PlainTextFormat; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deckModel->getDeckList()->saveToFile(fileName, fmt)) {
|
||||||
|
lastFileName = fileName;
|
||||||
|
lastFileFormat = fmt;
|
||||||
setWindowModified(false);
|
setWindowModified(false);
|
||||||
return true;
|
return true;
|
||||||
} else
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WndDeckEditor::actPrintDeck()
|
void WndDeckEditor::actPrintDeck()
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
bool confirmClose();
|
bool confirmClose();
|
||||||
|
|
||||||
|
static const QStringList fileNameFilters;
|
||||||
QString lastFileName;
|
QString lastFileName;
|
||||||
DeckList::FileFormat lastFileFormat;
|
DeckList::FileFormat lastFileFormat;
|
||||||
|
|
||||||
|
|
|
@ -110,18 +110,9 @@ void MainWindow::statusChanged(ClientStatus _status)
|
||||||
// case StatusPlaying: {
|
// case StatusPlaying: {
|
||||||
/* chatWidget->disableChat();
|
/* chatWidget->disableChat();
|
||||||
|
|
||||||
game = new Game(db, client, scene, menuBar(), this);
|
|
||||||
connect(game, SIGNAL(hoverCard(QString)), cardInfo, SLOT(setCard(const QString &)));
|
|
||||||
connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *)));
|
|
||||||
connect(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *)));
|
|
||||||
connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int)));
|
|
||||||
connect(phasesToolbar, SIGNAL(signalDrawCard()), game, SLOT(activePlayerDrawCard()));
|
|
||||||
connect(phasesToolbar, SIGNAL(signalUntapAll()), game, SLOT(activePlayerUntapAll()));
|
|
||||||
messageLog->connectToGame(game);
|
|
||||||
aRestartGame->setEnabled(true);
|
aRestartGame->setEnabled(true);
|
||||||
aLeaveGame->setEnabled(true);
|
aLeaveGame->setEnabled(true);
|
||||||
|
|
||||||
game->queryGameState();
|
|
||||||
|
|
||||||
phasesToolbar->show();
|
phasesToolbar->show();
|
||||||
view->show();
|
view->show();
|
||||||
|
|
Loading…
Reference in a new issue