/* VierGewinnt - A simple 4-in-a-row network game * * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de * http://www.seba-geek.de * * This file is part of VierGewinnt. * * VierGewinnt is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * VierGewinnt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VierGewinnt. If not, see . */ #include "newgame.h" NewGameDialog::NewGameDialog(QTcpSocket *sock, QWidget *parent) : QDialog(parent) { mysock = sock; gameend = new QLabel(""); newgame = new QLabel(tr("Ein neues Spiel?")); netplayer = new QLabel(""); ok = new QPushButton(tr("Ok")); connect(ok, SIGNAL(clicked()), this, SLOT(localAck())); cancel = new QPushButton(tr("Abbrechen")); connect(cancel, SIGNAL(clicked()), this, SLOT(closeGame())); connect(this, SIGNAL(rejected()), this, SLOT(closeGame())); setWindowTitle(tr("Neues Spiel?")); reset(true); buttonrow = new QHBoxLayout; buttonrow->addStretch(); buttonrow->addWidget(ok); buttonrow->addStretch(); buttonrow->addWidget(cancel); buttonrow->addStretch(); layout = new QVBoxLayout; layout->addWidget(gameend); layout->addSpacing(32); layout->addWidget(newgame); layout->addWidget(netplayer); layout->addLayout(buttonrow); //center layout->setAlignment(gameend, Qt::AlignHCenter); layout->setAlignment(newgame, Qt::AlignHCenter); layout->setAlignment(netplayer, Qt::AlignHCenter); setLayout(layout); setModal(Qt::WindowModal); } void NewGameDialog::reset(bool won) { netplayer->setText(tr("Dein Mispieler hat bisher noch nicht zugestimmt.")); ok->setDisabled(false); if(won) { gameend->setText(tr("Whee, du hast gewonnen! :)")); } else { gameend->setText(tr("Du hast verloren -.-")); } } void NewGameDialog::netPlayerAck() { netplayer->setText(tr("Dein Mispieler hat zugestimmt.")); } void NewGameDialog::localAck() { ok->setDisabled(true); QTextStream sockstream(mysock); sockstream << "ACK NEW GAME\n"; } void NewGameDialog::closeGame() { mysock->close(); done(1); }