2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 2 of the License
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
#include <QGridLayout>
20
#include <QPushButton>
27
#include <QTextBrowser>
28
#include <QTableWidget>
31
#include "pageoptions.h"
36
PageOptions::PageOptions(QWidget* parent) :
39
QGridLayout * pageLayout = new QGridLayout(this);
40
pageLayout->setColumnStretch(0, 100);
41
pageLayout->setColumnStretch(1, 100);
42
pageLayout->setColumnStretch(2, 100);
43
pageLayout->setRowStretch(0, 0);
44
//pageLayout->setRowStretch(1, 100);
45
pageLayout->setRowStretch(2, 0);
46
pageLayout->setContentsMargins(7, 7, 7, 0);
47
pageLayout->setSpacing(0);
50
QGroupBox * gbTwoBoxes = new QGroupBox(this);
51
pageLayout->addWidget(gbTwoBoxes, 0, 0, 1, 3);
52
QGridLayout * gbTBLayout = new QGridLayout(gbTwoBoxes);
53
gbTBLayout->setMargin(0);
54
gbTBLayout->setSpacing(0);
55
gbTBLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
57
QPixmap pmNew(":/res/new.png");
58
QPixmap pmEdit(":/res/edit.png");
59
QPixmap pmDelete(":/res/delete.png");
62
teamsBox = new IconedGroupBox(this);
63
//teamsBox->setContentTopPadding(0);
64
//teamsBox->setAttribute(Qt::WA_PaintOnScreen, true);
65
teamsBox->setIcon(QIcon(":/res/teamicon.png"));
66
teamsBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
67
teamsBox->setTitle(QGroupBox::tr("Teams"));
69
QGridLayout * GBTlayout = new QGridLayout(teamsBox);
71
CBTeamName = new QComboBox(teamsBox);
72
GBTlayout->addWidget(CBTeamName, 0, 0);
74
BtnNewTeam = new QPushButton(teamsBox);
75
BtnNewTeam->setToolTip(tr("New team"));
76
BtnNewTeam->setIconSize(pmNew.size());
77
BtnNewTeam->setIcon(pmNew);
78
BtnNewTeam->setMaximumWidth(pmNew.width() + 6);
79
GBTlayout->addWidget(BtnNewTeam, 0, 1);
81
BtnEditTeam = new QPushButton(teamsBox);
82
BtnEditTeam->setToolTip(tr("Edit team"));
83
BtnEditTeam->setIconSize(pmEdit.size());
84
BtnEditTeam->setIcon(pmEdit);
85
BtnEditTeam->setMaximumWidth(pmEdit.width() + 6);
86
GBTlayout->addWidget(BtnEditTeam, 0, 2);
88
BtnDeleteTeam = new QPushButton(teamsBox);
89
BtnDeleteTeam->setToolTip(tr("Delete team"));
90
BtnDeleteTeam->setIconSize(pmDelete.size());
91
BtnDeleteTeam->setIcon(pmDelete);
92
BtnDeleteTeam->setMaximumWidth(pmDelete.width() + 6);
93
GBTlayout->addWidget(BtnDeleteTeam, 0, 3);
95
LblNoEditTeam = new QLabel(teamsBox);
96
LblNoEditTeam->setText(tr("You can't edit teams from team selection. Go back to main menu to add, edit or delete teams."));
97
LblNoEditTeam->setWordWrap(true);
98
LblNoEditTeam->setVisible(false);
99
GBTlayout->addWidget(LblNoEditTeam, 0, 0);
101
gbTBLayout->addWidget(teamsBox, 0, 0);
105
IconedGroupBox* groupWeapons = new IconedGroupBox(this);
107
//groupWeapons->setContentTopPadding(0);
108
//groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
109
groupWeapons->setIcon(QIcon(":/res/weaponsicon.png"));
110
groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
111
groupWeapons->setTitle(QGroupBox::tr("Schemes and Weapons"));
112
QGridLayout * WeaponsLayout = new QGridLayout(groupWeapons);
114
QLabel* SchemeLabel = new QLabel(groupWeapons);
115
SchemeLabel->setText(QLabel::tr("Game scheme"));
116
WeaponsLayout->addWidget(SchemeLabel, 1, 0);
118
SchemesName = new QComboBox(groupWeapons);
119
WeaponsLayout->addWidget(SchemesName, 1, 1);
121
SchemeNew = new QPushButton(groupWeapons);
122
SchemeNew->setToolTip(tr("New scheme"));
123
SchemeNew->setIconSize(pmNew.size());
124
SchemeNew->setIcon(pmNew);
125
SchemeNew->setMaximumWidth(pmNew.width() + 6);
126
WeaponsLayout->addWidget(SchemeNew, 1, 2);
128
SchemeEdit = new QPushButton(groupWeapons);
129
SchemeEdit->setToolTip(tr("Edit scheme"));
130
SchemeEdit->setIconSize(pmEdit.size());
131
SchemeEdit->setIcon(pmEdit);
132
SchemeEdit->setMaximumWidth(pmEdit.width() + 6);
133
WeaponsLayout->addWidget(SchemeEdit, 1, 3);
135
SchemeDelete = new QPushButton(groupWeapons);
136
SchemeDelete->setToolTip(tr("Delete scheme"));
137
SchemeDelete->setIconSize(pmDelete.size());
138
SchemeDelete->setIcon(pmDelete);
139
SchemeDelete->setMaximumWidth(pmDelete.width() + 6);
140
WeaponsLayout->addWidget(SchemeDelete, 1, 4);
142
QLabel* WeaponLabel = new QLabel(groupWeapons);
143
WeaponLabel->setText(QLabel::tr("Weapons"));
144
WeaponsLayout->addWidget(WeaponLabel, 2, 0);
146
WeaponsName = new QComboBox(groupWeapons);
147
WeaponsLayout->addWidget(WeaponsName, 2, 1);
149
WeaponNew = new QPushButton(groupWeapons);
150
WeaponNew->setToolTip(tr("New weapon set"));
151
WeaponNew->setIconSize(pmNew.size());
152
WeaponNew->setIcon(pmNew);
153
WeaponNew->setMaximumWidth(pmNew.width() + 6);
154
WeaponsLayout->addWidget(WeaponNew, 2, 2);
156
WeaponEdit = new QPushButton(groupWeapons);
157
WeaponEdit->setToolTip(tr("Edit weapon set"));
158
WeaponEdit->setIconSize(pmEdit.size());
159
WeaponEdit->setIcon(pmEdit);
160
WeaponEdit->setMaximumWidth(pmEdit.width() + 6);
161
WeaponsLayout->addWidget(WeaponEdit, 2, 3);
163
WeaponDelete = new QPushButton(groupWeapons);
164
WeaponDelete->setToolTip(tr("Delete weapon set"));
165
WeaponDelete->setIconSize(pmDelete.size());
166
WeaponDelete->setIcon(pmDelete);
167
WeaponDelete->setMaximumWidth(pmDelete.width() + 6);
168
WeaponsLayout->addWidget(WeaponDelete, 2, 4);
170
WeaponTooltip = new QCheckBox(this);
171
WeaponTooltip->setText(QCheckBox::tr("Show ammo menu tooltips"));
172
WeaponsLayout->addWidget(WeaponTooltip, 3, 0, 1, 4);
174
gbTBLayout->addWidget(groupWeapons, 1, 0);
178
IconedGroupBox* groupMisc = new IconedGroupBox(this);
179
//groupMisc->setContentTopPadding(0);
180
groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
181
groupMisc->setIcon(QIcon(":/res/miscicon.png"));
182
//groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
183
groupMisc->setTitle(QGroupBox::tr("Misc"));
184
QGridLayout * MiscLayout = new QGridLayout(groupMisc);
186
labelNN = new QLabel(groupMisc);
187
labelNN->setText(QLabel::tr("Net nick"));
188
MiscLayout->addWidget(labelNN, 0, 0);
190
editNetNick = new QLineEdit(groupMisc);
191
editNetNick->setMaxLength(20);
192
editNetNick->setText(QLineEdit::tr("unnamed"));
193
connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick()));
194
MiscLayout->addWidget(editNetNick, 0, 1);
196
labelNetPassword = new QLabel(groupMisc);
197
labelNetPassword->setText(QLabel::tr("Password"));
198
MiscLayout->addWidget(labelNetPassword, 1, 0);
200
editNetPassword = new QLineEdit(groupMisc);
201
editNetPassword->setEchoMode(QLineEdit::Password);
202
MiscLayout->addWidget(editNetPassword, 1, 1);
204
QLabel *labelLanguage = new QLabel(groupMisc);
205
labelLanguage->setText(QLabel::tr("Locale") + " *");
206
MiscLayout->addWidget(labelLanguage, 2, 0);
208
CBLanguage = new QComboBox(groupMisc);
210
tmpdir.cd(cfgdir->absolutePath());
211
tmpdir.cd("Data/Locale");
212
tmpdir.setFilter(QDir::Files);
213
QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm"));
214
CBLanguage->addItem(QComboBox::tr("(System default)"), QString(""));
215
for(int i = 0; i < locs.count(); i++)
217
QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
218
CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
221
tmpdir.cd(datadir->absolutePath());
223
tmpdir.setFilter(QDir::Files);
224
QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm"));
225
for(int i = 0; i < tmplist.count(); i++)
227
if (locs.contains(tmplist[i])) continue;
228
QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
229
CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
232
MiscLayout->addWidget(CBLanguage, 2, 1);
234
CBAltDamage = new QCheckBox(groupMisc);
235
CBAltDamage->setText(QCheckBox::tr("Alternative damage show"));
236
MiscLayout->addWidget(CBAltDamage, 3, 0, 1, 2);
238
CBNameWithDate = new QCheckBox(groupMisc);
239
CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name"));
240
MiscLayout->addWidget(CBNameWithDate, 4, 0, 1, 2);
242
BtnAssociateFiles = new QPushButton(groupMisc);
243
BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions"));
244
BtnAssociateFiles->setEnabled(!custom_data && !custom_config);
245
MiscLayout->addWidget(BtnAssociateFiles, 5, 0, 1, 2);
248
#ifdef SPARKLE_ENABLED
249
CBAutoUpdate = new QCheckBox(groupMisc);
250
CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
251
MiscLayout->addWidget(CBAutoUpdate, 6, 0, 1, 3);
254
gbTBLayout->addWidget(groupMisc, 2, 0);
258
AGGroupBox = new IconedGroupBox(this);
259
//AGGroupBox->setContentTopPadding(0);
260
AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png"));
261
//AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
262
AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options"));
264
QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox);
265
QHBoxLayout * GBAreslayout = new QHBoxLayout(0);
266
QHBoxLayout * GBAstereolayout = new QHBoxLayout(0);
267
QHBoxLayout * GBAqualayout = new QHBoxLayout(0);
269
CBFrontendFullscreen = new QCheckBox(AGGroupBox);
270
CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen"));
271
GBAlayout->addWidget(CBFrontendFullscreen);
273
CBFrontendEffects = new QCheckBox(AGGroupBox);
274
CBFrontendEffects->setText(QCheckBox::tr("Frontend effects") + " *");
275
GBAlayout->addWidget(CBFrontendEffects);
277
CBEnableFrontendSound = new QCheckBox(AGGroupBox);
278
CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds"));
279
GBAlayout->addWidget(CBEnableFrontendSound);
281
CBEnableFrontendMusic = new QCheckBox(AGGroupBox);
282
CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music"));
283
GBAlayout->addWidget(CBEnableFrontendMusic);
285
QFrame * hr = new QFrame(AGGroupBox);
286
hr->setFrameStyle(QFrame::HLine);
288
hr->setFixedHeight(10);
289
GBAlayout->addWidget(hr);
291
QLabel * resolution = new QLabel(AGGroupBox);
292
resolution->setText(QLabel::tr("Resolution"));
293
GBAreslayout->addWidget(resolution);
295
CBResolution = new QComboBox(AGGroupBox);
296
GBAreslayout->addWidget(CBResolution);
297
GBAlayout->addLayout(GBAreslayout);
298
connect(CBResolution, SIGNAL(currentIndexChanged(int)), this, SLOT(setResolution(int)));
300
CBFullscreen = new QCheckBox(AGGroupBox);
301
CBFullscreen->setText(QCheckBox::tr("Fullscreen"));
302
GBAlayout->addWidget(CBFullscreen);
303
connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(int)));
305
QLabel * quality = new QLabel(AGGroupBox);
306
quality->setText(QLabel::tr("Quality"));
307
quality->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
308
GBAqualayout->addWidget(quality);
310
SLQuality = new QSlider(Qt::Horizontal, AGGroupBox);
311
SLQuality->setTickPosition(QSlider::TicksBelow);
312
SLQuality->setMaximum(5);
313
SLQuality->setMinimum(0);
314
SLQuality->setFixedWidth(150);
315
GBAqualayout->addWidget(SLQuality);
316
GBAlayout->addLayout(GBAqualayout);
317
connect(SLQuality, SIGNAL(valueChanged(int)), this, SLOT(setQuality(int)));
319
QLabel * stereo = new QLabel(AGGroupBox);
320
stereo->setText(QLabel::tr("Stereo rendering"));
321
GBAstereolayout->addWidget(stereo);
323
CBStereoMode = new QComboBox(AGGroupBox);
324
CBStereoMode->addItem(QComboBox::tr("Disabled"));
325
CBStereoMode->addItem(QComboBox::tr("Red/Cyan"));
326
CBStereoMode->addItem(QComboBox::tr("Cyan/Red"));
327
CBStereoMode->addItem(QComboBox::tr("Red/Blue"));
328
CBStereoMode->addItem(QComboBox::tr("Blue/Red"));
329
CBStereoMode->addItem(QComboBox::tr("Red/Green"));
330
CBStereoMode->addItem(QComboBox::tr("Green/Red"));
331
CBStereoMode->addItem(QComboBox::tr("Side-by-side"));
332
CBStereoMode->addItem(QComboBox::tr("Top-Bottom"));
333
CBStereoMode->addItem(QComboBox::tr("Wiggle"));
334
CBStereoMode->addItem(QComboBox::tr("Red/Cyan grayscale"));
335
CBStereoMode->addItem(QComboBox::tr("Cyan/Red grayscale"));
336
CBStereoMode->addItem(QComboBox::tr("Red/Blue grayscale"));
337
CBStereoMode->addItem(QComboBox::tr("Blue/Red grayscale"));
338
CBStereoMode->addItem(QComboBox::tr("Red/Green grayscale"));
339
CBStereoMode->addItem(QComboBox::tr("Green/Red grayscale"));
340
connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int)));
342
GBAstereolayout->addWidget(CBStereoMode);
343
GBAlayout->addLayout(GBAstereolayout);
345
hr = new QFrame(AGGroupBox);
346
hr->setFrameStyle(QFrame::HLine);
348
hr->setFixedHeight(10);
349
GBAlayout->addWidget(hr);
351
QHBoxLayout * GBAvollayout = new QHBoxLayout(0);
352
QLabel * vol = new QLabel(AGGroupBox);
353
vol->setText(QLabel::tr("Initial sound volume"));
354
GBAvollayout->addWidget(vol);
355
GBAlayout->addLayout(GBAvollayout);
356
volumeBox = new QSpinBox(AGGroupBox);
357
volumeBox->setRange(0, 100);
358
volumeBox->setSingleStep(5);
359
GBAvollayout->addWidget(volumeBox);
361
CBEnableSound = new QCheckBox(AGGroupBox);
362
CBEnableSound->setText(QCheckBox::tr("Enable sound"));
363
GBAlayout->addWidget(CBEnableSound);
365
CBEnableMusic = new QCheckBox(AGGroupBox);
366
CBEnableMusic->setText(QCheckBox::tr("Enable music"));
367
GBAlayout->addWidget(CBEnableMusic);
369
hr = new QFrame(AGGroupBox);
370
hr->setFrameStyle(QFrame::HLine);
372
hr->setFixedHeight(10);
373
GBAlayout->addWidget(hr);
375
QHBoxLayout * GBAfpslayout = new QHBoxLayout(0);
376
QLabel * maxfps = new QLabel(AGGroupBox);
377
maxfps->setText(QLabel::tr("FPS limit"));
378
GBAfpslayout->addWidget(maxfps);
379
GBAlayout->addLayout(GBAfpslayout);
380
fpsedit = new FPSEdit(AGGroupBox);
381
GBAfpslayout->addWidget(fpsedit);
383
CBShowFPS = new QCheckBox(AGGroupBox);
384
CBShowFPS->setText(QCheckBox::tr("Show FPS"));
385
GBAlayout->addWidget(CBShowFPS);
387
hr = new QFrame(AGGroupBox);
388
hr->setFrameStyle(QFrame::HLine);
390
hr->setFixedHeight(10);
391
GBAlayout->addWidget(hr);
393
QLabel *restartNote = new QLabel(this);
394
restartNote->setText(QString("* ") + QLabel::tr("Restart game to apply"));
395
restartNote->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
396
GBAlayout->addWidget(restartNote);
398
gbTBLayout->addWidget(AGGroupBox, 0, 1, 3, 1);
401
BtnSaveOptions = addButton(":/res/Save.png", pageLayout, 2, 2, true);
402
BtnSaveOptions->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}");
404
BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
405
BtnBack->setFixedHeight(BtnSaveOptions->height());
406
BtnBack->setFixedWidth(BtnBack->width()+2);
407
BtnBack->setStyleSheet("QPushButton{margin: 22px 0 9px 2px;}");
409
previousQuality = this->SLQuality->value();
410
previousResolutionIndex = this->CBResolution->currentIndex();
411
previousFullscreenValue = this->CBFullscreen->isChecked();
414
void PageOptions::forceFullscreen(int index)
416
bool forced = (index == 7 || index == 8 || index == 9);
419
this->SLQuality->setValue(this->SLQuality->maximum());
420
this->SLQuality->setEnabled(false);
421
this->CBFullscreen->setEnabled(!forced);
422
this->CBFullscreen->setChecked(forced ? true : previousFullscreenValue);
423
this->CBResolution->setCurrentIndex(forced ? 0 : previousResolutionIndex);
425
this->SLQuality->setEnabled(true);
426
this->CBFullscreen->setEnabled(true);
427
this->SLQuality->setValue(previousQuality);
428
this->CBFullscreen->setChecked(previousFullscreenValue);
429
this->CBResolution->setCurrentIndex(previousResolutionIndex);
433
void PageOptions::setQuality(int value)
435
int index = this->CBStereoMode->currentIndex();
437
previousQuality = this->SLQuality->value();
440
void PageOptions::setFullscreen(int state)
442
int index = this->CBStereoMode->currentIndex();
443
if (index != 7 && index != 8 && index != 9)
444
previousFullscreenValue = this->CBFullscreen->isChecked();
447
void PageOptions::setResolution(int state)
449
int index = this->CBStereoMode->currentIndex();
450
if (index != 7 && index != 8 && index != 9)
451
previousResolutionIndex = this->CBResolution->currentIndex();
454
void PageOptions::trimNetNick()
456
editNetNick->setText(editNetNick->text().trimmed());