Debian Codegraph @

src/game_interfaces/resultdialog.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #include <QtWidgets>
24 #include "../network/messages.h"
25 #include "resultdialog.h"
26 #include "../network/boarddispatch.h"
27
28 ResultDialog::ResultDialog(QWidget * parent, BoardDispatch * dis, unsigned int game_id, GameResult * gr) : QDialog(parent), dispatch(dis)
29 {
30 if(!dispatch)
31 {
32 qDebug("ResultDialog called without board dispatch");
33 deleteLater();
34 return;
35 }
36 if(!gr)
37 {
38 // This was created by the board dispatch in response
39 // to a rematch request
40
41 mainlabel = new QLabel(dispatch->getOpponentName() + tr(" requests rematch"));
42 seconds = 20;
43 okayButton = new QPushButton(tr("&Accept?"));
44 accepting = true;
45 }
46 else
47 {
48 accepting = false;
49 if(dispatch->supportsRematch())
50 {
51 seconds = 20;
52 /* We make them stare at message for 20 seconds */
53 okayButton = new QPushButton(tr("&Rematch?"));
54 dispatch->setRematchDialog(this);
55 }
56 else
57 {
58 seconds = 0;
59 okayButton = new QPushButton(tr("&Okay"));
60 okayButton->setDefault(true);
61 }
62 mainlabel = new QLabel(gr->longMessage());
63 }
64 connect(okayButton, &QPushButton::clicked, this, &ResultDialog::slot_okay);
65
66 QGridLayout * mainLayout = new QGridLayout;
67 /*mainLayout->setSizeConstraint(QLayout::SetFixedSize);*/
68 mainLayout->addWidget(mainlabel, 0, 0);
69 mainLayout->addWidget(okayButton, 1, 0);
70 setLayout(mainLayout);
71
72
73 setWindowTitle(tr("Game ") + QString::number(game_id));
74 //setSizePolicy(QSizePolicy::Minimum);
75 // FIXME size?
76 resize(200, 100);
77 //setMinimumSize(QSize(300, 150));
78 if(dispatch->supportsRematch())
79 startTimer(1000);
80 }
81
82 void ResultDialog::recvRematchRequest(void)
83 {
84 mainlabel->setText(dispatch->getOpponentName() + tr(" requests rematch"));
85 seconds = 20;
86 okayButton->setText(tr("&Accept?"));
87 accepting = true;
88 }
89
90 void ResultDialog::timerEvent(QTimerEvent*)
91 {
92 // in case we need this?
93 if(seconds == 1)
94 {
95 //what about sending a declineRematch?? if(accepting)??
96 hide();
97 deleteLater();
98 }
99 else
100 seconds--;
101 }
102
103 void ResultDialog::closeEvent(QCloseEvent *)
104 {
105 /*if(dispatch)
106 dispatch->setRematchDialog(0);*/
107 }
108
109 ResultDialog::~ResultDialog()
110 {
111 if(dispatch) //here also in case no "closeEvent"
112 dispatch->setRematchDialog(0);
113 qDebug("deleting result dialog");
114 delete okayButton;
115 delete mainlabel;
116 }
117
118 /* I'm assuming here that a close by time returns 0 */
119 void ResultDialog::slot_okay(void)
120 {
121 if(dispatch->supportsRematch())
122 {
123 if(accepting)
124 dispatch->sendRematchAccept();
125 else
126 dispatch->sendRematchRequest();
127 dispatch->setRematchDialog(0);
128 qDebug("rematch slot okay");
129 dispatch = 0;
130 }
131 hide();
132 deleteLater();
133 // or should this be just done()
134 }