Merge branch 'master' of ssh://brukie@cockatrice.git.sourceforge.net/gitroot/cockatrice

This commit is contained in:
Max-Wilhelm Bruker 2009-06-26 23:26:55 +02:00
commit 3be0eb916d
16 changed files with 264 additions and 36 deletions

View file

@ -16,5 +16,5 @@ QT += network svg
#QTPLUGIN += qjpeg #QTPLUGIN += qjpeg
# Input # Input
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/dlg_editmessages.h
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/dlg_editmessages.cpp

View file

@ -62,11 +62,21 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1)); painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
} }
if (counters) { if (counters) {
painter->setFont(QFont("Times", 32, QFont::Bold)); QString numStr = QString::number(counters);
painter->setPen(QPen(Qt::black)); QFont font("Times", 32, QFont::Bold);
painter->setBackground(QBrush(QColor(255, 255, 255, 100))); QFontMetrics fm(font);
painter->setBackgroundMode(Qt::OpaqueMode); QRect br = fm.boundingRect(numStr);
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(counters)); double w = br.width() * 1.42;
double h = br.height() * 1.42;
if (w < h)
w = h;
painter->setPen(Qt::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(); painter->restore();
} }

View file

@ -53,6 +53,11 @@ AbstractDecklistNode *InnerDecklistNode::findChild(const QString &name)
return 0; return 0;
} }
int InnerDecklistNode::height() const
{
return at(0)->height() + 1;
}
int InnerDecklistNode::recursiveCount(bool countTotalCards) const int InnerDecklistNode::recursiveCount(bool countTotalCards) const
{ {
int result = 0; int result = 0;

View file

@ -19,6 +19,7 @@ public:
virtual QString getName() const = 0; virtual QString getName() const = 0;
InnerDecklistNode *getParent() const { return parent; } InnerDecklistNode *getParent() const { return parent; }
int depth() const; int depth() const;
virtual int height() const = 0;
virtual bool compare(AbstractDecklistNode *other) const = 0; virtual bool compare(AbstractDecklistNode *other) const = 0;
}; };
@ -34,6 +35,7 @@ public:
virtual QString getVisibleName() const; virtual QString getVisibleName() const;
void clearTree(); void clearTree();
AbstractDecklistNode *findChild(const QString &name); AbstractDecklistNode *findChild(const QString &name);
int height() const;
int recursiveCount(bool countTotalCards = false) const; int recursiveCount(bool countTotalCards = false) const;
bool compare(AbstractDecklistNode *other) const; bool compare(AbstractDecklistNode *other) const;
void sort(Qt::SortOrder order = Qt::AscendingOrder); void sort(Qt::SortOrder order = Qt::AscendingOrder);
@ -46,6 +48,7 @@ public:
virtual void setNumber(int _number) = 0; virtual void setNumber(int _number) = 0;
virtual QString getName() const = 0; virtual QString getName() const = 0;
virtual void setName(const QString &_name) = 0; virtual void setName(const QString &_name) = 0;
int height() const { return 0; }
bool compare(AbstractDecklistNode *other) const; bool compare(AbstractDecklistNode *other) const;
}; };

View file

@ -2,6 +2,10 @@
#include <QTextStream> #include <QTextStream>
#include <QFont> #include <QFont>
#include <QBrush> #include <QBrush>
#include <QTextCursor>
#include <QTextDocument>
#include <QPrinter>
#include <QTextTable>
#include "decklistmodel.h" #include "decklistmodel.h"
#include "carddatabase.h" #include "carddatabase.h"
@ -282,3 +286,43 @@ void DeckListModel::cleanList()
deckList->cleanList(); deckList->cleanList();
reset(); reset();
} }
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{
cursor->insertBlock();
cursor->insertText(node->getVisibleName());
if (node->height() == 1) {
QTextTableFormat tableFormat;
// XXX
QTextTable *table = cursor->insertTable(node->size(), 2, tableFormat);
for (int i = 0; i < node->size(); i++) {
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
QTextCursor cellCursor = table->cellAt(i, 0).firstCursorPosition();
cellCursor.insertText(QString::number(card->getNumber()));
cellCursor = table->cellAt(i, 1).firstCursorPosition();
cellCursor.insertText(card->getName());
}
} else {
for (int i = 0; i < node->size(); i++)
printDeckListNode(cursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
}
cursor->movePosition(QTextCursor::End);
}
void DeckListModel::printDeckList(QPrinter *printer)
{
QTextDocument doc;
QTextCursor cursor(&doc);
cursor.insertBlock();
cursor.insertText(deckList->getName());
cursor.insertBlock();
cursor.insertText(deckList->getComments());
for (int i = 0; i < root->size(); i++)
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
doc.print(printer);
}

View file

@ -6,6 +6,8 @@
#include "decklist.h" #include "decklist.h"
class CardDatabase; class CardDatabase;
class QPrinter;
class QTextCursor;
class DecklistModelCardNode : public AbstractDecklistCardNode { class DecklistModelCardNode : public AbstractDecklistCardNode {
private: private:
@ -23,6 +25,8 @@ class DeckListModel : public QAbstractItemModel {
Q_OBJECT Q_OBJECT
private slots: private slots:
void rebuildTree(); void rebuildTree();
public slots:
void printDeckList(QPrinter *printer);
public: public:
DeckListModel(CardDatabase *_db, QObject *parent = 0); DeckListModel(CardDatabase *_db, QObject *parent = 0);
~DeckListModel(); ~DeckListModel();
@ -48,6 +52,8 @@ private:
void emitRecursiveUpdates(const QModelIndex &index); void emitRecursiveUpdates(const QModelIndex &index);
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 printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
template<typename T> T getNode(const QModelIndex &index) const template<typename T> T getNode(const QModelIndex &index) const
{ {

View file

@ -0,0 +1,76 @@
#include <QtGui>
#include "dlg_editmessages.h"
DlgEditMessages::DlgEditMessages(QWidget *parent)
: QDialog(parent)
{
aAdd = new QAction(tr("Add"), this);
connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd()));
aRemove = new QAction(tr("Remove"), this);
connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove()));
messageList = new QListWidget;
QToolBar *messageToolBar = new QToolBar;
messageToolBar->setOrientation(Qt::Vertical);
messageToolBar->addAction(aAdd);
messageToolBar->addAction(aRemove);
QSettings settings;
settings.beginGroup("messages");
int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++)
messageList->addItem(settings.value(QString("msg%1").arg(i)).toString());
QHBoxLayout *listLayout = new QHBoxLayout;
listLayout->addWidget(messageList);
listLayout->addWidget(messageToolBar);
cancelButton = new QPushButton(tr("&Cancel"));
okButton = new QPushButton(tr("O&K"));
okButton->setAutoDefault(true);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(cancelButton);
buttonLayout->addWidget(okButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(listLayout);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Edit messages"));
setMinimumWidth(sizeHint().width());
resize(300, 300);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
}
void DlgEditMessages::storeSettings()
{
QSettings settings;
settings.beginGroup("messages");
settings.setValue("count", messageList->count());
for (int i = 0; i < messageList->count(); i++)
settings.setValue(QString("msg%1").arg(i), messageList->item(i)->text());
}
void DlgEditMessages::actAdd()
{
bool ok;
QString msg = QInputDialog::getText(this, tr("Add message"), QString("Message:"), QLineEdit::Normal, QString(), &ok);
if (ok) {
messageList->addItem(msg);
storeSettings();
}
}
void DlgEditMessages::actRemove()
{
if (messageList->currentItem()) {
delete messageList->takeItem(messageList->currentRow());
storeSettings();
}
}

View file

@ -0,0 +1,24 @@
#ifndef DLG_EDITMESSAGES_H
#define DLG_EDITMESSAGES_H
#include <QDialog>
class QListWidget;
class QPushButton;
class DlgEditMessages: public QDialog {
Q_OBJECT
public:
DlgEditMessages(QWidget *parent = 0);
private slots:
void actAdd();
void actRemove();
private:
QListWidget *messageList;
QAction *aAdd, *aRemove;
QPushButton *cancelButton, *okButton;
void storeSettings();
};
#endif

View file

@ -1,6 +1,7 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings>
#include "serverplayer.h" #include "serverplayer.h"
#include "game.h" #include "game.h"
#include "servereventdata.h" #include "servereventdata.h"
@ -9,6 +10,7 @@
#include "handzone.h" #include "handzone.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "dlg_startgame.h" #include "dlg_startgame.h"
#include "dlg_editmessages.h"
#include "playerarea.h" #include "playerarea.h"
#include "counter.h" #include "counter.h"
@ -51,6 +53,9 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
aCreateToken = new QAction(tr("&Create token..."), this); aCreateToken = new QAction(tr("&Create token..."), this);
aCreateToken->setShortcut(tr("Ctrl+T")); aCreateToken->setShortcut(tr("Ctrl+T"));
connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken()));
aEditMessages = new QAction(tr("&Edit messages..."), this);
connect(aEditMessages, SIGNAL(triggered()), this, SLOT(actEditMessages()));
actionsMenu->addAction(aUntapAll); actionsMenu->addAction(aUntapAll);
actionsMenu->addSeparator(); actionsMenu->addSeparator();
@ -64,6 +69,9 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
actionsMenu->addAction(aRollDice); actionsMenu->addAction(aRollDice);
actionsMenu->addSeparator(); actionsMenu->addSeparator();
actionsMenu->addAction(aCreateToken); actionsMenu->addAction(aCreateToken);
actionsMenu->addSeparator();
sayMenu = actionsMenu->addMenu(tr("S&ay"));
initSayMenu();
aTap = new QAction(tr("&Tap"), this); aTap = new QAction(tr("&Tap"), this);
connect(aTap, SIGNAL(triggered()), this, SLOT(actTap())); connect(aTap, SIGNAL(triggered()), this, SLOT(actTap()));
@ -108,6 +116,32 @@ Game::~Game()
} }
} }
void Game::initSayMenu()
{
sayMenu->clear();
sayMenu->addAction(aEditMessages);
sayMenu->addSeparator();
QSettings settings;
settings.beginGroup("messages");
int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++) {
QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this);
QString shortcut;
switch (i) {
case 0: shortcut = tr("F5"); break;
case 1: shortcut = tr("F6"); break;
case 2: shortcut = tr("F7"); break;
case 3: shortcut = tr("F8"); break;
case 4: shortcut = tr("F9"); break;
case 5: shortcut = tr("F10"); break;
}
newAction->setShortcut(shortcut);
connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage()));
sayMenu->addAction(newAction);
}
}
Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, bool local) Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, bool local)
{ {
Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene); Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene);
@ -295,6 +329,13 @@ void Game::actCreateToken()
client->createToken("table", cardname, QString(), 0, 0); client->createToken("table", cardname, QString(), 0, 0);
} }
void Game::actEditMessages()
{
DlgEditMessages dlg;
if (dlg.exec())
initSayMenu();
}
void Game::showCardMenu(QPoint p) void Game::showCardMenu(QPoint p)
{ {
cardMenu->exec(p); cardMenu->exec(p);
@ -396,3 +437,9 @@ void Game::actRearrange()
client->moveCard(temp->getId(), zoneName, zoneName, x, y); client->moveCard(temp->getId(), zoneName, zoneName, x, y);
} }
} }
void Game::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());
client->say(a->text());
}

View file

@ -14,9 +14,9 @@ class DlgStartGame;
class Game : public QObject { class Game : public QObject {
Q_OBJECT Q_OBJECT
private: private:
QMenu *actionsMenu, *cardMenu; QMenu *actionsMenu, *sayMenu, *cardMenu;
QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters, *aRearrange, QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters, *aRearrange,
*aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken; *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken, *aEditMessages;
DlgStartGame *dlgStartGame; DlgStartGame *dlgStartGame;
CardDatabase *db; CardDatabase *db;
@ -26,6 +26,7 @@ private:
Player *localPlayer; Player *localPlayer;
bool started; bool started;
Player *addPlayer(int playerId, const QString &playerName, QPointF base, bool local); Player *addPlayer(int playerId, const QString &playerName, QPointF base, bool local);
void initSayMenu();
private slots: private slots:
void actUntapAll(); void actUntapAll();
void actIncLife(); void actIncLife();
@ -36,6 +37,7 @@ private slots:
void actDrawCards(); void actDrawCards();
void actRollDice(); void actRollDice();
void actCreateToken(); void actCreateToken();
void actEditMessages();
void showCardMenu(QPoint p); void showCardMenu(QPoint p);
void actTap(); void actTap();
@ -46,6 +48,8 @@ private slots:
void actRemoveCounter(); void actRemoveCounter();
void actSetCounters(); void actSetCounters();
void actRearrange(); void actRearrange();
void actSayMessage();
void gameEvent(const ServerEventData &msg); void gameEvent(const ServerEventData &msg);
void playerListReceived(QList<ServerPlayer *> playerList); void playerListReceived(QList<ServerPlayer *> playerList);

View file

@ -9,7 +9,7 @@ GameSelector::GameSelector(Client *_client, QWidget *parent)
gameListModel = new GamesModel(this); gameListModel = new GamesModel(this);
gameListView->setModel(gameListModel); gameListView->setModel(gameListModel);
createButton = new QPushButton(tr("&Create")); createButton = new QPushButton(tr("C&reate"));
joinButton = new QPushButton(tr("&Join")); joinButton = new QPushButton(tr("&Join"));
QHBoxLayout *buttonLayout = new QHBoxLayout; QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(); buttonLayout->addStretch();

View file

@ -21,14 +21,14 @@ Player::Player(const QString &_name, int _id, QPointF _base, bool _local, CardDa
aViewLibrary = new QAction(tr("&View library"), this); aViewLibrary = new QAction(tr("&View library"), this);
if (local) if (local)
aViewLibrary->setShortcut(tr("F5")); aViewLibrary->setShortcut(tr("F3"));
connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary())); connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary()));
aViewTopCards = new QAction(tr("View &top cards of library..."), this); aViewTopCards = new QAction(tr("View &top cards of library..."), this);
connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards())); connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards()));
aViewGraveyard = new QAction(tr("&View graveyard"), this); aViewGraveyard = new QAction(tr("&View graveyard"), this);
if (local) if (local)
aViewGraveyard->setShortcut(tr("F6")); aViewGraveyard->setShortcut(tr("F4"));
connect(aViewGraveyard, SIGNAL(triggered()), this, SLOT(actViewGraveyard())); connect(aViewGraveyard, SIGNAL(triggered()), this, SLOT(actViewGraveyard()));
aViewRfg = new QAction(tr("&View removed cards"), this); aViewRfg = new QAction(tr("&View removed cards"), this);

View file

@ -94,6 +94,9 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
aSaveDeckAs = new QAction(tr("&Save deck as..."), this); aSaveDeckAs = new QAction(tr("&Save deck as..."), this);
// aSaveDeckAs->setShortcuts(QKeySequence::SaveAs); // aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
aPrintDeck = new QAction(tr("&Print deck..."), this);
aPrintDeck->setShortcuts(QKeySequence::Print);
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
aClose = new QAction(tr("&Close"), this); aClose = new QAction(tr("&Close"), this);
aClose->setShortcut(tr("Ctrl+Q")); aClose->setShortcut(tr("Ctrl+Q"));
connect(aClose, SIGNAL(triggered()), this, SLOT(close())); connect(aClose, SIGNAL(triggered()), this, SLOT(close()));
@ -107,6 +110,8 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeck);
deckMenu->addAction(aSaveDeckAs); deckMenu->addAction(aSaveDeckAs);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aPrintDeck);
deckMenu->addSeparator();
deckMenu->addAction(aClose); deckMenu->addAction(aClose);
setsMenu = menuBar()->addMenu(tr("&Sets")); setsMenu = menuBar()->addMenu(tr("&Sets"));
@ -234,6 +239,13 @@ bool WndDeckEditor::actSaveDeckAs()
return false; return false;
} }
void WndDeckEditor::actPrintDeck()
{
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *)));
dlg->exec();
}
void WndDeckEditor::actEditSets() void WndDeckEditor::actEditSets()
{ {
WndSets *w = new WndSets(db, this); WndSets *w = new WndSets(db, this);

View file

@ -24,6 +24,7 @@ private slots:
void actLoadDeck(); void actLoadDeck();
bool actSaveDeck(); bool actSaveDeck();
bool actSaveDeckAs(); bool actSaveDeckAs();
void actPrintDeck();
void actEditSets(); void actEditSets();
@ -49,7 +50,7 @@ private:
QLineEdit *searchEdit, *nameEdit, *commentsEdit; QLineEdit *searchEdit, *nameEdit, *commentsEdit;
QMenu *deckMenu, *setsMenu; QMenu *deckMenu, *setsMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aClose; QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;
QAction *aEditSets; QAction *aEditSets;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
public: public:

View file

@ -60,6 +60,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
break; break;
case StatusDisconnected: case StatusDisconnected:
if (game) { if (game) {
zoneLayout->clear();
delete game; delete game;
game = 0; game = 0;
} }
@ -72,6 +73,14 @@ void MainWindow::statusChanged(ProtocolStatus _status)
aDisconnect->setEnabled(true); aDisconnect->setEnabled(true);
break; break;
case StatusIdle: { case StatusIdle: {
if (game) {
zoneLayout->clear();
delete game;
game = 0;
}
aRestartGame->setEnabled(false);
aLeaveGame->setEnabled(false);
GameSelector *gameSelector = new GameSelector(client); GameSelector *gameSelector = new GameSelector(client);
viewLayout->insertWidget(0, gameSelector); viewLayout->insertWidget(0, gameSelector);
} }
@ -104,12 +113,7 @@ void MainWindow::actRestartGame()
void MainWindow::actLeaveGame() void MainWindow::actLeaveGame()
{ {
zoneLayout->clear();
client->leaveGame(); client->leaveGame();
delete game;
game = 0;
aRestartGame->setEnabled(false);
aLeaveGame->setEnabled(false);
} }
void MainWindow::actDeckEditor() void MainWindow::actDeckEditor()
@ -140,15 +144,11 @@ void MainWindow::updateSceneSize()
view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
} }
void MainWindow::textChanged(const QString &text) void MainWindow::actSay()
{
sayButton->setEnabled(!text.isEmpty());
}
// Knöpfe
void MainWindow::buttonSay()
{ {
if (sayEdit->text().isEmpty())
return;
client->say(sayEdit->text()); client->say(sayEdit->text());
sayEdit->clear(); sayEdit->clear();
} }
@ -190,7 +190,7 @@ void MainWindow::createActions()
aDeckEditor = new QAction(tr("&Deck editor"), this); aDeckEditor = new QAction(tr("&Deck editor"), this);
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor())); connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
aFullScreen = new QAction(tr("&Full screen"), this); aFullScreen = new QAction(tr("&Full screen"), this);
aFullScreen->setShortcut(tr("F4")); aFullScreen->setShortcut(tr("Ctrl+F"));
aFullScreen->setCheckable(true); aFullScreen->setCheckable(true);
connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool))); connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool)));
aExit = new QAction(tr("&Exit"), this); aExit = new QAction(tr("&Exit"), this);
@ -244,13 +244,13 @@ MainWindow::MainWindow(QWidget *parent)
cardInfo = new CardInfoWidget(db); cardInfo = new CardInfoWidget(db);
messageLog = new MessageLogWidget; messageLog = new MessageLogWidget;
QLabel *sayLabel = new QLabel(tr("&Say:"));
sayEdit = new QLineEdit; sayEdit = new QLineEdit;
sayButton = new QPushButton(tr("&Say")); sayLabel->setBuddy(sayEdit);
sayButton->setEnabled(false);
QHBoxLayout *hLayout = new QHBoxLayout; QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(sayLabel);
hLayout->addWidget(sayEdit); hLayout->addWidget(sayEdit);
hLayout->addWidget(sayButton);
QVBoxLayout *verticalLayout = new QVBoxLayout; QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo); verticalLayout->addWidget(cardInfo);
@ -268,9 +268,7 @@ MainWindow::MainWindow(QWidget *parent)
centralWidget->setLayout(mainLayout); centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget); setCentralWidget(centralWidget);
connect(sayEdit, SIGNAL(returnPressed()), sayButton, SLOT(click())); connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
connect(sayEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
connect(sayButton, SIGNAL(clicked()), this, SLOT(buttonSay()));
client = new Client(this); client = new Client(this);
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout())); connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));

View file

@ -48,8 +48,7 @@ private slots:
void playerIdReceived(int id, QString name); void playerIdReceived(int id, QString name);
void serverTimeout(); void serverTimeout();
void textChanged(const QString &text); void actSay();
void buttonSay();
void actConnect(); void actConnect();
void actDisconnect(); void actDisconnect();
@ -74,7 +73,6 @@ private:
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
MessageLogWidget *messageLog; MessageLogWidget *messageLog;
QLineEdit *sayEdit; QLineEdit *sayEdit;
QPushButton *sayButton;
Client *client; Client *client;
QGraphicsScene *scene; QGraphicsScene *scene;