Debian Codegraph @

src/board/gameinfo.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 "gameinfo.h"
24 #include "boardwindow.h"
25 #include <QPushButton>
26
27 GameInfo::GameInfo(BoardWindow * bw) : GameinfoDialog(), boardwindow(bw)
28 {
29 ui.setupUi(this);
30
31 ui.whiteName->setText( boardwindow->getGameData()->white_name );
32 ui.blackName->setText( boardwindow->getGameData()->black_name );
33 ui.whiteRank->setText( boardwindow->getGameData()->white_rank );
34 ui.blackRank->setText( boardwindow->getGameData()->black_rank );
35 ui.komi->setText( QString::number(boardwindow->getGameData()->komi ));
36 ui.handicap->setText( QString::number(boardwindow->getGameData()->handicap ));
37 ui.result->setText( boardwindow->getGameData()->result );
38 ui.gameName->setText( boardwindow->getGameData()->gameName );
39 ui.date->setText( boardwindow->getGameData()->date );
40 ui.playedAt->setText( boardwindow->getGameData()->place );
41 ui.copyright->setText( boardwindow->getGameData()->copyright );
42
43 if(boardwindow->getGameData()->gameMode != modeEdit)
44 {
45 ui.whiteName->setReadOnly( 1 );
46 ui.blackName->setReadOnly( 1 );
47 ui.whiteRank->setReadOnly( 1 );
48 ui.blackRank->setReadOnly( 1 );
49 ui.komi->setReadOnly(1);
50 ui.handicap->setReadOnly(1);
51 ui.result->setReadOnly(1);
52 ui.gameName->setReadOnly(1);
53 ui.date->setReadOnly(1);
54 ui.playedAt->setReadOnly(1);
55 ui.copyright->setReadOnly(1);
56 }
57 else
58 {
59 connect(ui.whiteName, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
60 connect(ui.blackName, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
61 connect(ui.whiteRank, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
62 connect(ui.blackRank, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
63 connect(ui.komi, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
64 connect(ui.handicap, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
65 connect(ui.result, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
66 connect(ui.gameName, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
67 connect(ui.date, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
68 connect(ui.playedAt, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
69 connect(ui.copyright, &QLineEdit::textEdited, this, &GameInfo::slotGameInfoTextEdited);
70 }
71
72 connect(ui.buttonBox, &QDialogButtonBox::clicked, this, &GameInfo::slotGameInfoButton);
73 show();
74 }
75
76 GameInfo::~GameInfo()
77 {
78 }
79
80 void GameInfo::slotGameInfoButton(QAbstractButton * button)
81 {
82 if(button->text() == "Save")
83 {
84 boardwindow->getGameData()->white_name = ui.whiteName->text();
85 boardwindow->getGameData()->black_name = ui.blackName->text();
86 boardwindow->getGameData()->white_rank = ui.whiteRank->text();
87 boardwindow->getGameData()->black_rank = ui.blackRank->text();
88 sscanf(ui.komi->text().toLatin1().constData(), "%f", &(boardwindow->getGameData()->komi));
89 sscanf(ui.handicap->text().toLatin1().constData(), "%d", &(boardwindow->getGameData()->handicap));
90 boardwindow->getGameData()->result = ui.result->text();
91 boardwindow->getGameData()->gameName = ui.gameName->text();
92 boardwindow->getGameData()->date = ui.date->text();
93 boardwindow->getGameData()->place = ui.playedAt->text();
94 boardwindow->getGameData()->copyright = ui.copyright->text();
95 boardwindow->gameDataChanged();
96 }
97 this->deleteLater();
98 }
99
100 void GameInfo::slotGameInfoTextEdited(const QString &)
101 {
102 bool changed = false;
103
104 if(ui.whiteName->text() != boardwindow->getGameData()->white_name)
105 changed = true;
106 else if(ui.blackName->text() != boardwindow->getGameData()->black_name)
107 changed = true;
108 else if(ui.whiteRank->text() != boardwindow->getGameData()->white_rank)
109 changed = true;
110 else if(ui.blackRank->text() != boardwindow->getGameData()->black_rank)
111 changed = true;
112 else if(QString::number(boardwindow->getGameData()->komi) != ui.result->text())
113 changed = true;
114 else if(QString::number(boardwindow->getGameData()->handicap) != ui.result->text())
115 changed = true;
116 else if(boardwindow->getGameData()->result != ui.result->text())
117 changed = true;
118 else if(boardwindow->getGameData()->gameName != ui.gameName->text())
119 changed = true;
120 else if(boardwindow->getGameData()->date != ui.date->text())
121 changed = true;
122 else if(boardwindow->getGameData()->place != ui.playedAt->text())
123 changed = true;
124 else if(boardwindow->getGameData()->copyright != ui.copyright->text())
125 changed = true;
126
127 QPushButton * button = 0;
128 if(changed)
129 {
130 button = ui.buttonBox->button(QDialogButtonBox::Ok);
131 if(button)
132 {
133 ui.buttonBox->removeButton(button);
134 ui.buttonBox->addButton(QDialogButtonBox::Save);
135 }
136 }
137 else
138 {
139 button = ui.buttonBox->button(QDialogButtonBox::Save);
140 if(button)
141 {
142 ui.buttonBox->removeButton(button);
143 ui.buttonBox->addButton(QDialogButtonBox::Ok);
144 }
145 }
146 }