-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParamsDlg.cpp
80 lines (64 loc) · 2.04 KB
/
ParamsDlg.cpp
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
#include "ParamsDlg.h"
#include "palette.h"
ParamsDlg::ParamsDlg(QWidget* parent, QList<GameParam*>& params, GameAllInfo& info,
QStringList& maps, QPair<int,int> minmax)
: QDialog(parent), m_params(params), m_info(info)
{
setupUi(this);
for(int i=0;i<params.size();i++)
{
QWidget *left=0, *right=0;
if(params[i])
{
params[i]->createWidget(info.vecParamValues[i], &left, &right);
if(left != 0)
m_layout.addWidget(left, i, 0, 1, 1);
m_layout.addWidget(right, i, 1, 1, 1);
}
m_widgets.append(QPair<QWidget*,QWidget*>(left,right));
}
tabExtended->setLayout(&m_layout);
okButton->setEnabled(info.bAdmin);
lineName->setText(info.strName);
linePassword->setText(info.strRoomPassword);
comboMap->addItems(maps);
comboMap->setCurrentIndex(maps.indexOf(info.strGameMap));
checkAllowStarted->setCheckState((info.bCanJoinAfterStart) ? Qt::Checked : Qt::Unchecked);
spinPlayers->setRange(minmax.first, minmax.second);
spinPlayers->setValue(info.nMaxPlayers);
QString temp = info.strDescr;
temp.replace("\\r\\n", "\n");
textDescr->setPlainText(temp);
connect(this, SIGNAL(accepted()), this, SLOT(save()));
applyPalette(this, PaletteMain);
applyPalette(lineName, PaletteEdit);
applyPalette(linePassword, PaletteEdit);
applyPalette(textDescr, PaletteEdit);
applyPalette(spinPlayers, PaletteEdit);
applyPalette(comboMap, PaletteEdit);
applyPalette(checkAllowStarted, PaletteCheck);
}
ParamsDlg::~ParamsDlg()
{
for(int i=0;i<m_widgets.size();i++)
{
delete m_widgets[i].first;
delete m_widgets[i].second;
}
}
void ParamsDlg::save()
{
for(int i=0;i<m_params.size();i++)
{
if(m_params[i])
m_info.vecParamValues[i] = m_params[i]->getWidgetValue(m_widgets[i].second);
}
m_info.strName = lineName->text();
m_info.strRoomPassword = linePassword->text();
m_info.strGameMap = comboMap->currentText();
m_info.bCanJoinAfterStart = checkAllowStarted->checkState() == Qt::Checked;
m_info.nMaxPlayers = spinPlayers->value();
QString temp = textDescr->toPlainText();
temp.replace("\n", "\\r\\n");
m_info.strDescr = temp;
}