Debian Codegraph @

src/newgamedialog.cpp

raw symbols SCIP
1 #include "newgamedialog.h"
2 #include "ui_newgamedialog.h"
3
4 #include <QSettings>
5 #include "mainwindow.h"
6 #include "boardwindow.h"
7
8 NewGameDialog::NewGameDialog(MainWindow *parent) :
9 QDialog(parent),
10 ui(new Ui::NewGameDialog)
11 {
12 mw = parent;
13 ui->setupUi(this);
14
15 QSettings settings;
16 QVariant var;
17 //SGF edition tab default values
18 if((var = settings.value("EDIT_SIZE")) == QVariant())
19 var = 19;
20 ui->newFile_Size->setValue(var.toInt());
21 handicap = settings.value("EDIT_HANDICAP").toInt();
22 ui->newFile_Handicap->setValue(handicap);
23 if((var = settings.value("EDIT_KOMI")) == QVariant())
24 var = 5.5;
25 ui->newFile_Komi->setValue(var.toDouble());
26
27 ui->computerPlaysWhite->setChecked(settings.value("COMPUTER_PLAYS_WHITE").toBool());
28 ui->computerPlaysBlack->setChecked(settings.value("COMPUTER_PLAYS_BLACK").toBool());
29
30 connect(ui->newFile_Handicap, QOverload<int>::of(&QSpinBox::valueChanged), this, &NewGameDialog::slot_newFile_HandicapChange);
31 }
32
33 NewGameDialog::~NewGameDialog()
34 {
35 QSettings settings;
36 //SGF edition tab default values
37 settings.setValue("EDIT_SIZE",ui->newFile_Size->value());
38 settings.setValue("EDIT_HANDICAP",ui->newFile_Handicap->value());
39 settings.setValue("EDIT_KOMI",ui->newFile_Komi->value());
40
41 settings.setValue("COMPUTER_PLAYS_WHITE", ui->computerPlaysWhite->isChecked());
42 settings.setValue("COMPUTER_PLAYS_BLACK", ui->computerPlaysBlack->isChecked());
43 delete ui;
44 }
45
46 void NewGameDialog::slot_newFile_HandicapChange(int a)
47 {
48 if(a == 1)
49 {
50 handicap = (handicap < 1 ? 2 : 0);
51 ui->newFile_Handicap->setValue(handicap);
52 } else
53 handicap = a;
54 }
55
56 void NewGameDialog::accept()
57 {
58 GameData *gd = new GameData();
59 gd->gameMode = modeLocal;
60
61 gd->board_size = ui->newFile_Size->value();
62 gd->handicap = ui->newFile_Handicap->value();
63 gd->black_name = ui->newFile_BlackPlayer->text();
64 gd->white_name = ui->newFile_WhitePlayer->text();
65 gd->komi = ui->newFile_Komi->value();
66
67 BoardWindow * bw = new BoardWindow(gd, !(ui->computerPlaysBlack->isChecked()),
68 !(ui->computerPlaysWhite->isChecked()));
69 if(bw)
70 mw->addBoardWindow(bw);
71
72 QDialog::accept();
73 }