final (?) spectator code, small bugfix

This commit is contained in:
Max-Wilhelm Bruker 2009-09-24 20:12:44 +02:00
parent fa16d86283
commit a543c9b90c
22 changed files with 453 additions and 190 deletions

View file

@ -1,18 +1,23 @@
#include <QtGui>
#include "gameselector.h"
#include "dlg_creategame.h"
#include "gamesmodel.h"
GameSelector::GameSelector(Client *_client, QWidget *parent)
: QWidget(parent), client(_client)
{
gameListView = new QTreeView;
gameListModel = new GamesModel(this);
gameListView->setModel(gameListModel);
gameListProxyModel = new GamesProxyModel(this);
gameListProxyModel->setSourceModel(gameListModel);
gameListView->setModel(gameListProxyModel);
showFullGamesCheckBox = new QCheckBox;
createButton = new QPushButton;
joinButton = new QPushButton;
spectateButton = new QPushButton;
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(showFullGamesCheckBox);
buttonLayout->addStretch();
buttonLayout->addWidget(createButton);
buttonLayout->addWidget(joinButton);
@ -28,11 +33,17 @@ GameSelector::GameSelector(Client *_client, QWidget *parent)
setMinimumWidth(gameListView->columnWidth(0) * gameListModel->columnCount());
setMinimumHeight(400);
connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int)));
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin()));
}
void GameSelector::showFullGamesChanged(int state)
{
gameListProxyModel->setFullGamesVisible(state);
}
void GameSelector::actCreate()
{
DlgCreateGame dlg(client, this);
@ -66,16 +77,16 @@ void GameSelector::actJoin()
QModelIndex ind = gameListView->currentIndex();
if (!ind.isValid())
return;
ServerGame *game = gameListModel->getGame(ind.row());
const ServerGame &game = gameListModel->getGame(ind.row());
QString password;
if (game->getHasPassword()) {
if (game.getHasPassword()) {
bool ok;
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
if (!ok)
return;
}
PendingCommand *joinCommand = client->joinGame(game->getGameId(), password, spectator);
PendingCommand *joinCommand = client->joinGame(game.getGameId(), password, spectator);
connect(joinCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
createButton->setEnabled(false);
joinButton->setEnabled(false);
@ -87,7 +98,7 @@ void GameSelector::enableGameList()
if (isVisible())
return;
connect(client, SIGNAL(gameListEvent(ServerGame *)), gameListModel, SLOT(updateGameList(ServerGame *)));
connect(client, SIGNAL(gameListEvent(const ServerGame &)), gameListModel, SLOT(updateGameList(const ServerGame &)));
client->listGames();
show();
}
@ -104,6 +115,7 @@ void GameSelector::disableGameList()
void GameSelector::retranslateUi()
{
showFullGamesCheckBox->setText(tr("&Show full games"));
createButton->setText(tr("C&reate"));
joinButton->setText(tr("&Join"));
spectateButton->setText(tr("J&oin as spectator"));