-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywithcomputerdialog.cpp
More file actions
157 lines (135 loc) · 4.76 KB
/
Copy pathplaywithcomputerdialog.cpp
File metadata and controls
157 lines (135 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
mugo, sgf editor.
Copyright (C) 2009-2010 nsase.
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QSettings>
#include "appdef.h"
#include "playwithcomputerdialog.h"
#include "enginelistdialog.h"
#include "enginelist.h"
#include "ui_playwithcomputerdialog.h"
/**
* constructor
*/
PlayWithComputerDialog::PlayWithComputerDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::PlayWithComputerDialog)
{
m_ui->setupUi(this);
m_ui->colorComboBox->addItem( tr("Black") );
m_ui->colorComboBox->addItem( tr("White") );
m_ui->boardSizeComboBox->addItem( "19 x 19" );
m_ui->boardSizeComboBox->addItem( "13 x 13" );
m_ui->boardSizeComboBox->addItem( "9 x 9" );
// set default value from initial file
QSettings settings;
m_ui->colorComboBox->setCurrentIndex( settings.value("playWithComputer/color").toInt() );
m_ui->boardSizeComboBox->setCurrentIndex( settings.value("playWithComputer/size").toInt() );
m_ui->komiSpinBox->setValue( settings.value("playWithComputer/komi", 6.5).toDouble() );
m_ui->handicapSpinBox->setValue( settings.value("playWithComputer/handicap").toInt() );
m_ui->levelSpinBox->setValue( settings.value("playWithComputer/level", 10).toInt() );
updateEngineList();
}
/**
* destructor
*/
PlayWithComputerDialog::~PlayWithComputerDialog()
{
delete m_ui;
}
void PlayWithComputerDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
/**
* event handler
* ok button was pushed.
*/
void PlayWithComputerDialog::accept(){
QDialog::accept();
// game settings
isBlack = m_ui->colorComboBox->currentIndex() == 0;
int boardSize = m_ui->boardSizeComboBox->currentIndex();
size = boardSize == 0 ? 19 : (boardSize == 1 ? 13 : 9);
komi = m_ui->komiSpinBox->value();
handicap = m_ui->handicapSpinBox->value();
level = m_ui->levelSpinBox->value();
// engine settings
int engine = m_ui->engineComboBox->currentIndex();
EngineList engineList;
engineList.load();
if (engine >= 0 && engine < engineList.engines.size()){
name = engineList.engines[engine].name;
path = engineList.engines[engine].path;
parameters = engineList.engines[engine].parameters;
}
// start position
startPosition = m_ui->newGame->isChecked() ? eNewGame : eContinueGame;
// save dialog settings for ini file(or registry)
QSettings settings;
settings.setValue("playWithComputer/color", m_ui->colorComboBox->currentIndex());
settings.setValue("playWithComputer/size", m_ui->boardSizeComboBox->currentIndex());
settings.setValue("playWithComputer/komi", komi);
settings.setValue("playWithComputer/handicap", handicap);
settings.setValue("playWithComputer/level", level);
settings.setValue("playWithComputer/defaultEngine", engine);
}
/**
* edit engines button is clicked.
* show manage engine dialog.
*/
void PlayWithComputerDialog::on_editEngineButton_clicked(){
EngineListDialog dlg(this);
if (dlg.exec() != QDialog::Accepted)
return;
updateEngineList();
}
/**
* new game radio button is toggled.
*/
void PlayWithComputerDialog::on_newGame_toggled(bool checked){
m_ui->boardSizeComboBox->setEnabled(checked);
m_ui->komiSpinBox->setEnabled(checked);
m_ui->handicapSpinBox->setEnabled(checked);
}
/**
* resume radio button is toggled.
*/
void PlayWithComputerDialog::on_resume_toggled(bool checked){
m_ui->boardSizeComboBox->setEnabled(checked == false);
m_ui->komiSpinBox->setEnabled(checked == false);
m_ui->handicapSpinBox->setEnabled(checked == false);
}
/**
*/
void PlayWithComputerDialog::updateEngineList(){
m_ui->engineComboBox->clear();
EngineList engineList;
engineList.load();
foreach(const Engine& e, engineList.engines){
m_ui->engineComboBox->addItem( e.name );
}
int index = QSettings().value("playWithComputer/defaultEngine", 0).toInt();
if (index < 0 || index >= m_ui->engineComboBox->count())
index = 0;
if (m_ui->engineComboBox->count() > 0)
m_ui->engineComboBox->setCurrentIndex(index);
}