Debian Codegraph @

src/network/matchinvitedialog.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 "matchinvitedialog.h"
25
26 MatchInviteDialog::MatchInviteDialog(QString name, QString rank, bool canRefuseFuture)
27 {
28 int horiz_pos = 0;
29 seconds = 20; //does it?
30
31 /* FIXME, we need to center this text, make the font larger, or
32 * bold, etc.. */
33 namelabel = new QLabel(tr("%1 %2").arg(name).arg(rank));
34 dialoglabel = new QLabel(tr("wants to play a match..."));
35 timelabel = new QLabel(tr("%1 seconds").arg(seconds));
36
37 acceptButton = new QPushButton(tr("&Accept"));
38 acceptButton->setDefault(true);
39
40 declineButton = new QPushButton(tr("&Decline"));
41 if(canRefuseFuture)
42 refuseFutureCB = new QCheckBox(tr("Refuse Invites from %1").arg(name));
43 else
44 refuseFutureCB = 0;
45 buttonBox = new QDialogButtonBox(Qt::Horizontal);
46 buttonBox->addButton(acceptButton, QDialogButtonBox::ActionRole);
47 buttonBox->addButton(declineButton, QDialogButtonBox::ActionRole);
48
49 connect(acceptButton, &QPushButton::clicked, this, &MatchInviteDialog::slot_accept);
50 connect(declineButton, &QPushButton::clicked, this, &MatchInviteDialog::slot_decline);
51 if(refuseFutureCB)
52 connect(refuseFutureCB, &QCheckBox::clicked, this, &MatchInviteDialog::slot_refuseFutureCB);
53
54 QGridLayout * mainLayout = new QGridLayout;
55 mainLayout->setSizeConstraint(QLayout::SetFixedSize);
56 mainLayout->addWidget(namelabel, horiz_pos++, 0);
57 mainLayout->addWidget(dialoglabel, horiz_pos++, 0);
58 mainLayout->addWidget(timelabel, horiz_pos++, 0);
59 if(refuseFutureCB)
60 mainLayout->addWidget(refuseFutureCB, horiz_pos++, 0);
61 mainLayout->addWidget(buttonBox, horiz_pos++, 0);
62 setLayout(mainLayout);
63
64 setWindowTitle(tr("Match Invite!"));
65
66 startTimer(1000);
67 }
68
69 void MatchInviteDialog::timerEvent(QTimerEvent*)
70 {
71 seconds--;
72 if(seconds == -1)
73 done(-1); //does this return 0?
74 timelabel->setText(tr("%1 seconds").arg(seconds));
75 }
76
77 MatchInviteDialog::~MatchInviteDialog()
78 {
79 delete acceptButton;
80 delete declineButton;
81 delete refuseFutureCB;
82 delete buttonBox;
83 }
84
85 /* I'm assuming here that a close by time returns 0 */
86 void MatchInviteDialog::slot_accept(void)
87 {
88 done(1);
89 }
90
91 void MatchInviteDialog::slot_decline(void)
92 {
93 if(refuseFutureCB && refuseFutureCB->isChecked())
94 done(-2);
95 else
96 done(-1);
97 }
98
99 void MatchInviteDialog::slot_refuseFutureCB(bool b)
100 {
101 if(b)
102 {
103 acceptButton->setEnabled(false);
104 }
105 else
106 acceptButton->setEnabled(true);
107 }