Commit 77f5ec29 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

some gui code

parent cb9a2bf2
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
#include "player.h" #include "player.h"
#include "game.h" #include "game.h"
#include "arrowitem.h" #include "arrowitem.h"
#include "main.h"
CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent) CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent)
: AbstractGraphicsItem(parent), db(_db), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL) : AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
{ {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable); setFlag(ItemIsSelectable);
......
...@@ -23,7 +23,6 @@ enum CardItemType { ...@@ -23,7 +23,6 @@ enum CardItemType {
class CardItem : public QObject, public AbstractGraphicsItem { class CardItem : public QObject, public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
CardDatabase *db;
CardInfo *info; CardInfo *info;
QString name; QString name;
int id; int id;
...@@ -40,7 +39,7 @@ private slots: ...@@ -40,7 +39,7 @@ private slots:
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } int type() const { return Type; }
CardItem(CardDatabase *_db, const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0); CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
~CardItem(); ~CardItem();
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
......
...@@ -84,7 +84,7 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y) ...@@ -84,7 +84,7 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
{ {
if (view) if (view)
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
view->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y); view->addCard(new CardItem(card->getName(), card->getId()), reorganize, x, y);
addCardImpl(card, x, y); addCardImpl(card, x, y);
......
...@@ -288,23 +288,24 @@ void Client::processProtocolItem(ProtocolItem *item) ...@@ -288,23 +288,24 @@ void Client::processProtocolItem(ProtocolItem *item)
case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break; case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break;
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break; case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break;
case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break; case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break;
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
} }
delete genericEvent; delete genericEvent;
return; return;
} }
/* GameEvent *gameEvent = qobject_cast<GameEvent *>(item); GameEvent *gameEvent = qobject_cast<GameEvent *>(item);
if (gameEvent) { if (gameEvent) {
emit gameEventReceived(gameEvent); emit gameEventReceived(gameEvent);
delete gameEvent; delete gameEvent;
return; return;
} }
*/
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item); ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
if (chatEvent) { if (chatEvent) {
qDebug() << "chatEventReceived()";
emit chatEventReceived(chatEvent); emit chatEventReceived(chatEvent);
delete chatEvent; delete chatEvent;
return;
} }
} }
......
...@@ -18,6 +18,7 @@ class GameEvent; ...@@ -18,6 +18,7 @@ class GameEvent;
class Event_ListGames; class Event_ListGames;
class Event_ServerMessage; class Event_ServerMessage;
class Event_ListChatChannels; class Event_ListChatChannels;
class Event_GameJoined;
enum ClientStatus { enum ClientStatus {
StatusDisconnected, StatusDisconnected,
...@@ -32,7 +33,6 @@ class Client : public QObject { ...@@ -32,7 +33,6 @@ class Client : public QObject {
signals: signals:
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
// void playerIdReceived(int id, QString name); // void playerIdReceived(int id, QString name);
// void gameEvent(const ServerEventData &msg);
void maxPingTime(int seconds, int maxSeconds); void maxPingTime(int seconds, int maxSeconds);
void serverTimeout(); void serverTimeout();
void logSocketError(const QString &errorString); void logSocketError(const QString &errorString);
...@@ -48,6 +48,7 @@ signals: ...@@ -48,6 +48,7 @@ signals:
void listGamesEventReceived(Event_ListGames *event); void listGamesEventReceived(Event_ListGames *event);
void serverMessageEventReceived(Event_ServerMessage *event); void serverMessageEventReceived(Event_ServerMessage *event);
void listChatChannelsEventReceived(Event_ListChatChannels *event); void listChatChannelsEventReceived(Event_ListChatChannels *event);
void gameJoinedEventReceived(Event_GameJoined *event);
private slots: private slots:
void slotConnected(); void slotConnected();
......
#include <QtGui> #include <QtGui>
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "protocol_items.h"
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent) DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
: QDialog(parent), client(_client) : QDialog(parent), client(_client)
...@@ -58,13 +59,15 @@ void DlgCreateGame::actOK() ...@@ -58,13 +59,15 @@ void DlgCreateGame::actOK()
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players.")); QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return; return;
} }
// PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked()); Command_CreateGame *createCommand = new Command_CreateGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked());
// connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse))); connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(createCommand);
okButton->setEnabled(false); okButton->setEnabled(false);
cancelButton->setEnabled(false); cancelButton->setEnabled(false);
} }
/*void DlgCreateGame::checkResponse(ServerResponse response) void DlgCreateGame::checkResponse(ResponseCode response)
{ {
okButton->setEnabled(true); okButton->setEnabled(true);
cancelButton->setEnabled(true); cancelButton->setEnabled(true);
...@@ -76,4 +79,3 @@ void DlgCreateGame::actOK() ...@@ -76,4 +79,3 @@ void DlgCreateGame::actOK()
return; return;
} }
} }
*/
\ No newline at end of file
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
DlgCreateGame(Client *_client, QWidget *parent = 0); DlgCreateGame(Client *_client, QWidget *parent = 0);
private slots: private slots:
void actOK(); void actOK();
// void checkResponse(ServerResponse response); void checkResponse(ResponseCode response);
private: private:
Client *client; Client *client;
...@@ -26,4 +26,3 @@ private: ...@@ -26,4 +26,3 @@ private:
}; };
#endif #endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "carddatabase.h" #include "carddatabase.h"
#include "dlg_settings.h" #include "dlg_settings.h"
#include "main.h"
GeneralSettingsPage::GeneralSettingsPage() GeneralSettingsPage::GeneralSettingsPage()
{ {
...@@ -397,8 +398,8 @@ void MessagesSettingsPage::retranslateUi() ...@@ -397,8 +398,8 @@ void MessagesSettingsPage::retranslateUi()
aRemove->setText(tr("&Remove")); aRemove->setText(tr("&Remove"));
} }
DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent) DlgSettings::DlgSettings(QWidget *parent)
: QDialog(parent), db(_db), translator(_translator) : QDialog(parent)
{ {
contentsWidget = new QListWidget; contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode); contentsWidget->setViewMode(QListView::IconMode);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include <QDialog> #include <QDialog>
class CardDatabase; class CardDatabase;
class QTranslator;
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
class QStackedWidget; class QStackedWidget;
...@@ -90,13 +89,11 @@ private: ...@@ -90,13 +89,11 @@ private:
class DlgSettings : public QDialog { class DlgSettings : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent = 0); DlgSettings(QWidget *parent = 0);
private slots: private slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous); void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void changeLanguage(const QString &qmFile); void changeLanguage(const QString &qmFile);
private: private:
CardDatabase *db;
QTranslator *translator;
QListWidget *contentsWidget; QListWidget *contentsWidget;
QStackedWidget *pagesWidget; QStackedWidget *pagesWidget;
QListWidgetItem *generalButton, *appearanceButton, *messagesButton; QListWidgetItem *generalButton, *appearanceButton, *messagesButton;
......
...@@ -135,7 +135,7 @@ void Game::retranslateUi() ...@@ -135,7 +135,7 @@ void Game::retranslateUi()
Player *Game::addPlayer(int playerId, const QString &playerName, bool local) Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
{ {
Player *newPlayer = new Player(playerName, playerId, local, db, client, this); Player *newPlayer = new Player(playerName, playerId, local, client, this);
scene->addPlayer(newPlayer); scene->addPlayer(newPlayer);
connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint))); connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint)));
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QtPlugin> #include <QtPlugin>
...@@ -29,10 +28,15 @@ ...@@ -29,10 +28,15 @@
#include <QIcon> #include <QIcon>
#include <stdio.h> #include <stdio.h>
#include "main.h"
#include "window_main.h" #include "window_main.h"
#include "carddatabase.h"
//Q_IMPORT_PLUGIN(qjpeg) //Q_IMPORT_PLUGIN(qjpeg)
CardDatabase *db;
QTranslator *translator;
void myMessageOutput(QtMsgType type, const char *msg) void myMessageOutput(QtMsgType type, const char *msg)
{ {
static FILE *f = NULL; static FILE *f = NULL;
...@@ -52,25 +56,27 @@ int main(int argc, char *argv[]) ...@@ -52,25 +56,27 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("Cockatrice"); QCoreApplication::setOrganizationName("Cockatrice");
QCoreApplication::setOrganizationDomain("cockatrice.de"); QCoreApplication::setOrganizationDomain("cockatrice.de");
QCoreApplication::setApplicationName("Cockatrice"); QCoreApplication::setApplicationName("Cockatrice");
db = new CardDatabase;
QString localeName;// = QLocale::system().name(); QString localeName;// = QLocale::system().name();
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
QTranslator translator; translator = new QTranslator;
QSettings settings; QSettings settings;
settings.beginGroup("personal"); settings.beginGroup("personal");
QString lang = settings.value("lang").toString(); QString lang = settings.value("lang").toString();
if (lang.isEmpty()) if (lang.isEmpty())
translator.load("cockatrice_" + localeName, ":/translations", QString(), ".qm"); translator->load("cockatrice_" + localeName, ":/translations", QString(), ".qm");
else else
translator.load(lang); translator->load(lang);
app.installTranslator(&translator); app.installTranslator(translator);
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
MainWindow ui(&translator); MainWindow ui;
qDebug("main(): MainWindow constructor finished"); qDebug("main(): MainWindow constructor finished");
QIcon icon(":/resources/icon.svg"); QIcon icon(":/resources/icon.svg");
...@@ -81,4 +87,3 @@ int main(int argc, char *argv[]) ...@@ -81,4 +87,3 @@ int main(int argc, char *argv[])
return app.exec(); return app.exec();
} }
#ifndef MAIN_H
#define MAIN_H
class CardDatabase;
class QTranslator;
extern CardDatabase *db;
extern QTranslator *translator;
#endif
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <QPainter> #include <QPainter>
#include <QMenu> #include <QMenu>
Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Client *_client, Game *_parent) Player::Player(const QString &_name, int _id, bool _local, Client *_client, Game *_parent)
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), db(_db), client(_client) : QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), client(_client)
{ {
QSettings settings; QSettings settings;
QString bgPath = settings.value("zonebg/playerarea").toString(); QString bgPath = settings.value("zonebg/playerarea").toString();
......
...@@ -75,7 +75,6 @@ private: ...@@ -75,7 +75,6 @@ private:
TableZone *table; TableZone *table;
HandZone *hand; HandZone *hand;
CardDatabase *db;
void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards); void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards);
QPixmap bgPixmap; QPixmap bgPixmap;
...@@ -104,7 +103,7 @@ public: ...@@ -104,7 +103,7 @@ public:
Client *client; Client *client;
void addZone(CardZone *z); void addZone(CardZone *z);
Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Client *_client, Game *_parent); Player(const QString &_name, int _id, bool _local, Client *_client, Game *_parent);
~Player(); ~Player();
void retranslateUi(); void retranslateUi();
QMenu *getPlayerMenu() const { return playerMenu; } QMenu *getPlayerMenu() const { return playerMenu; }
...@@ -115,7 +114,6 @@ public: ...@@ -115,7 +114,6 @@ public:
const QMap<int, ArrowItem *> &getArrows() const { return arrows; } const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
TableZone *getTable() const { return table; } TableZone *getTable() const { return table; }
// void gameEvent(const ServerEventData &event); // void gameEvent(const ServerEventData &event);
CardDatabase *getDb() const { return db; }
void showCardMenu(const QPoint &p); void showCardMenu(const QPoint &p);
bool getActive() const { return active; } bool getActive() const { return active; }
void setActive(bool _active); void setActive(bool _active);
......
#include <QtGui>
#include "tab_game.h"
#include "cardinfowidget.h"
#include "messagelogwidget.h"
#include "phasestoolbar.h"
#include "gameview.h"
#include "gamescene.h"
#include "player.h"
#include "game.h"
#include "zoneviewzone.h"
#include "zoneviewwidget.h"
#include "zoneviewlayout.h"
#include "main.h"
TabGame::TabGame(Client *_client, int _gameId)
: client(_client), gameId(_gameId)
{
zoneLayout = new ZoneViewLayout;
scene = new GameScene(zoneLayout, this);
view = new GameView(scene);
cardInfo = new CardInfoWidget(db);
messageLog = new MessageLogWidget;
sayLabel = new QLabel;
sayEdit = new QLineEdit;
sayLabel->setBuddy(sayEdit);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(sayLabel);
hLayout->addWidget(sayEdit);
phasesToolbar = new PhasesToolbar;
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo);
verticalLayout->addWidget(messageLog);
verticalLayout->addLayout(hLayout);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(phasesToolbar);
mainLayout->addWidget(view, 10);
mainLayout->addLayout(verticalLayout);
setLayout(mainLayout);
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));
}
void TabGame::processGameEvent(GameEvent *event)
{
}
#ifndef TAB_GAME_H
#define TAB_GAME_H
#include <QWidget>
class Client;
class CardDatabase;
class GameEvent;
class GameView;
class GameScene;
class Game;
class CardInfoWidget;
class MessageLogWidget;
class QLabel;
class QLineEdit;
class QPushButton;
class ZoneViewLayout;
class ZoneViewWidget;
class PhasesToolbar;
class TabGame : public QWidget {
Q_OBJECT
private:
Client *client;
int gameId;
CardInfoWidget *cardInfo;
MessageLogWidget *messageLog;
QLabel *sayLabel;
QLineEdit *sayEdit;
PhasesToolbar *phasesToolbar;
GameScene *scene;
GameView *view;
Game *game;
ZoneViewLayout *zoneLayout;
private slots:
public:
TabGame(Client *_client, int _gameId);
void processGameEvent(GameEvent *event);
};
#endif
...@@ -63,7 +63,6 @@ void GameSelector::checkResponse(ResponseCode response) ...@@ -63,7 +63,6 @@ void GameSelector::checkResponse(ResponseCode response)
spectateButton->setEnabled(true); spectateButton->setEnabled(true);
switch (response) { switch (response) {
case RespOk: /* HIER CODE FÜR NEUEN GAME_TAB EINFÜGEN */ break;
case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break; case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break;
case RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break; case RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break;
case RespContextError: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; case RespContextError: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break;
...@@ -172,88 +171,6 @@ void ChatChannelSelector::processListChatChannelsEvent(Event_ListChatChannels *e ...@@ -172,88 +171,6 @@ void ChatChannelSelector::processListChatChannelsEvent(Event_ListChatChannels *e
} }
} }
/*
void ChatWidget::chatEvent(const ChatEventData &data)
{
const QStringList &msg = data.getEventData();
switch (data.getEventType()) {
case eventListChatChannels: {
if (msg.size() != 4)
break;
for (int i = 0; i < channelList->topLevelItemCount(); ++i) {
QTreeWidgetItem *twi = channelList->topLevelItem(i);
if (twi->text(0) == msg[0]) {
twi->setToolTip(0, msg[1]);
twi->setText(1, msg[2]);
return;
}
}
QTreeWidgetItem *twi = new QTreeWidgetItem(QStringList() << msg[0] << msg[2]);
twi->setTextAlignment(1, Qt::AlignRight);
twi->setToolTip(0, msg[1]);
channelList->addTopLevelItem(twi);
channelList->resizeColumnToContents(0);
channelList->resizeColumnToContents(1);
if (msg[3] == "1")
joinChannel(msg[0]);
break;
}
case eventChatJoinChannel: {
if (msg.size() != 2)
break;
ChannelWidget *w = getChannel(msg[0]);
if (!w)
break;
w->joinEvent(msg[1]);
break;
}
case eventChatListPlayers: {
if (msg.size() != 2)
break;
ChannelWidget *w = getChannel(msg[0]);
if (!w)
break;
w->listPlayersEvent(msg[1]);
break;
}
case eventChatLeaveChannel: {
if (msg.size() != 2)
break;
ChannelWidget *w = getChannel(msg[0]);
if (!w)
break;
w->leaveEvent(msg[1]);
break;
}
case eventChatSay: {
if (msg.size() != 3)
break;
ChannelWidget *w = getChannel(msg[0]);
if (!w)
break;
w->sayEvent(msg[1], msg[2]);
break;
}
case eventChatServerMessage: {
if (msg.size() != 2)
break;
ChannelWidget *w;
if (msg[0].isEmpty()) {
w = getChannel("Server");
if (!w) {
w = new ChannelWidget(client, "Server", true, true);
tab->addTab(w, "Server");
}
} else
w = getChannel(msg[0]);
w->serverMessageEvent(msg[1]);
break;
}
default: {
}
}
}
*/
void ChatChannelSelector::joinChannel(const QString &channelName) void ChatChannelSelector::joinChannel(const QString &channelName)
{ {
Command_ChatJoinChannel *command = new Command_ChatJoinChannel(channelName); Command_ChatJoinChannel *command = new Command_ChatJoinChannel(channelName);
......
...@@ -22,6 +22,7 @@ void TabSupervisor::start(Client *_client) ...@@ -22,6 +22,7 @@ void TabSupervisor::start(Client *_client)
client = _client; client = _client;
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *))); connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *))); connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *)));
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
tabServer = new TabServer(client); tabServer = new TabServer(client);
connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int))); connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int)));
...@@ -34,12 +35,32 @@ void TabSupervisor::start(Client *_client) ...@@ -34,12 +35,32 @@ void TabSupervisor::start(Client *_client)
void TabSupervisor::stop() void TabSupervisor::stop()
{ {
if (!client)
return;
disconnect(client, 0, this, 0);
clear();
delete tabServer;
tabServer = 0;
QMapIterator<QString, TabChatChannel *> chatChannelIterator(chatChannelTabs);
while (chatChannelIterator.hasNext())
delete chatChannelIterator.next().value();
chatChannelTabs.clear();
QMapIterator<int, TabGame *> gameIterator(gameTabs);
while (gameIterator.hasNext())
delete gameIterator.next().value();
gameTabs.clear();
} }
void TabSupervisor::addGameTab(int gameId) void TabSupervisor::gameJoined(Event_GameJoined *event)
{ {
TabGame *tab = new TabGame(client, event->getGameId());
addTab(tab, tr("Game %1").arg(event->getGameId()));
gameTabs.insert(event->getGameId(), tab);
} }
void TabSupervisor::addChatChannelTab(const QString &channelName) void TabSupervisor::addChatChannelTab(const QString &channelName)
...@@ -58,5 +79,7 @@ void TabSupervisor::processChatEvent(ChatEvent *event) ...@@ -58,5 +79,7 @@ void TabSupervisor::processChatEvent(ChatEvent *event)
void TabSupervisor::processGameEvent(GameEvent *event) void TabSupervisor::processGameEvent(GameEvent *event)
{ {
TabGame *tab = gameTabs.value(event->getGameId());
if (tab)
tab->processGameEvent(event);
} }
...@@ -10,6 +10,7 @@ class TabChatChannel; ...@@ -10,6 +10,7 @@ class TabChatChannel;
class TabGame; class TabGame;
class ChatEvent; class ChatEvent;
class GameEvent; class GameEvent;
class Event_GameJoined;
class TabSupervisor : public QTabWidget { class TabSupervisor : public QTabWidget {
Q_OBJECT Q_OBJECT
...@@ -24,7 +25,7 @@ public: ...@@ -24,7 +25,7 @@ public:
void start(Client *_client); void start(Client *_client);
void stop(); void stop();
private slots: private slots:
void addGameTab(int gameId); void gameJoined(Event_GameJoined *event);
void addChatChannelTab(const QString &channelName); void addChatChannelTab(const QString &channelName);
void processChatEvent(ChatEvent *event); void processChatEvent(ChatEvent *event);
void processGameEvent(GameEvent *event); void processGameEvent(GameEvent *event);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "carddatabasemodel.h" #include "carddatabasemodel.h"
#include "decklistmodel.h" #include "decklistmodel.h"
#include "cardinfowidget.h" #include "cardinfowidget.h"
#include "main.h"
void SearchLineEdit::keyPressEvent(QKeyEvent *event) void SearchLineEdit::keyPressEvent(QKeyEvent *event)
{ {
...@@ -13,8 +14,8 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event) ...@@ -13,8 +14,8 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
QLineEdit::keyPressEvent(event); QLineEdit::keyPressEvent(event);
} }
WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent) WndDeckEditor::WndDeckEditor(QWidget *parent)
: QMainWindow(parent), db(_db) : QMainWindow(parent)
{ {
QLabel *searchLabel = new QLabel(tr("&Search for:")); QLabel *searchLabel = new QLabel(tr("&Search for:"));
searchEdit = new SearchLineEdit; searchEdit = new SearchLineEdit;
...@@ -281,7 +282,7 @@ void WndDeckEditor::actPrintDeck() ...@@ -281,7 +282,7 @@ void WndDeckEditor::actPrintDeck()
void WndDeckEditor::actEditSets() void WndDeckEditor::actEditSets()
{ {
WndSets *w = new WndSets(db, this); WndSets *w = new WndSets(this);
w->setWindowModality(Qt::WindowModal); w->setWindowModality(Qt::WindowModal);
w->show(); w->show();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment