|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
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 |
|
8 * |
|
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. |
|
13 * |
|
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 |
|
17 */ |
|
18 |
|
19 #include <QGridLayout> |
|
20 #include <QPushButton> |
|
21 #include <QGroupBox> |
|
22 #include <QComboBox> |
|
23 #include <QCheckBox> |
|
24 #include <QLabel> |
|
25 #include <QLineEdit> |
|
26 #include <QSpinBox> |
|
27 #include <QTextBrowser> |
|
28 #include <QTableWidget> |
|
29 #include <QSlider> |
|
30 |
|
31 #include "pages.h" |
|
32 #include "hwconsts.h" |
|
33 #include "fpsedit.h" |
|
34 #include "igbox.h" |
|
35 |
|
36 PageOptions::PageOptions(QWidget* parent) : |
|
37 AbstractPage(parent) |
|
38 { |
|
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); |
|
48 |
|
49 |
|
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); |
|
56 |
|
57 QPixmap pmNew(":/res/new.png"); |
|
58 QPixmap pmEdit(":/res/edit.png"); |
|
59 QPixmap pmDelete(":/res/delete.png"); |
|
60 |
|
61 { |
|
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")); |
|
68 |
|
69 QGridLayout * GBTlayout = new QGridLayout(teamsBox); |
|
70 |
|
71 CBTeamName = new QComboBox(teamsBox); |
|
72 GBTlayout->addWidget(CBTeamName, 0, 0); |
|
73 |
|
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); |
|
80 |
|
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); |
|
87 |
|
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); |
|
94 |
|
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); |
|
100 |
|
101 gbTBLayout->addWidget(teamsBox, 0, 0); |
|
102 } |
|
103 |
|
104 { |
|
105 IconedGroupBox* groupWeapons = new IconedGroupBox(this); |
|
106 |
|
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); |
|
113 |
|
114 QLabel* SchemeLabel = new QLabel(groupWeapons); |
|
115 SchemeLabel->setText(QLabel::tr("Game scheme")); |
|
116 WeaponsLayout->addWidget(SchemeLabel, 1, 0); |
|
117 |
|
118 SchemesName = new QComboBox(groupWeapons); |
|
119 WeaponsLayout->addWidget(SchemesName, 1, 1); |
|
120 |
|
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); |
|
127 |
|
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); |
|
134 |
|
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); |
|
141 |
|
142 QLabel* WeaponLabel = new QLabel(groupWeapons); |
|
143 WeaponLabel->setText(QLabel::tr("Weapons")); |
|
144 WeaponsLayout->addWidget(WeaponLabel, 2, 0); |
|
145 |
|
146 WeaponsName = new QComboBox(groupWeapons); |
|
147 WeaponsLayout->addWidget(WeaponsName, 2, 1); |
|
148 |
|
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); |
|
155 |
|
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); |
|
162 |
|
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); |
|
169 |
|
170 WeaponTooltip = new QCheckBox(this); |
|
171 WeaponTooltip->setText(QCheckBox::tr("Show ammo menu tooltips")); |
|
172 WeaponsLayout->addWidget(WeaponTooltip, 3, 0, 1, 4); |
|
173 |
|
174 gbTBLayout->addWidget(groupWeapons, 1, 0); |
|
175 } |
|
176 |
|
177 { |
|
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); |
|
185 |
|
186 labelNN = new QLabel(groupMisc); |
|
187 labelNN->setText(QLabel::tr("Net nick")); |
|
188 MiscLayout->addWidget(labelNN, 0, 0); |
|
189 |
|
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); |
|
195 |
|
196 QLabel *labelLanguage = new QLabel(groupMisc); |
|
197 labelLanguage->setText(QLabel::tr("Locale") + " *"); |
|
198 MiscLayout->addWidget(labelLanguage, 1, 0); |
|
199 |
|
200 CBLanguage = new QComboBox(groupMisc); |
|
201 QDir tmpdir; |
|
202 tmpdir.cd(datadir->absolutePath()); |
|
203 tmpdir.cd("Locale"); |
|
204 tmpdir.setFilter(QDir::Files); |
|
205 QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm")); |
|
206 CBLanguage->addItem(QComboBox::tr("(System default)"), QString("")); |
|
207 for(int i = 0; i < locs.count(); i++) |
|
208 { |
|
209 QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); |
|
210 CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); |
|
211 } |
|
212 |
|
213 MiscLayout->addWidget(CBLanguage, 1, 1); |
|
214 |
|
215 CBAltDamage = new QCheckBox(groupMisc); |
|
216 CBAltDamage->setText(QCheckBox::tr("Alternative damage show")); |
|
217 MiscLayout->addWidget(CBAltDamage, 2, 0, 1, 2); |
|
218 |
|
219 CBNameWithDate = new QCheckBox(groupMisc); |
|
220 CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name")); |
|
221 MiscLayout->addWidget(CBNameWithDate, 3, 0, 1, 2); |
|
222 |
|
223 #ifdef SPARKLE_ENABLED |
|
224 CBAutoUpdate = new QCheckBox(groupMisc); |
|
225 CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup")); |
|
226 MiscLayout->addWidget(CBAutoUpdate, 4, 0, 1, 2); |
|
227 #endif |
|
228 #ifndef __APPLE__ |
|
229 BtnAssociateFiles = new QPushButton(groupMisc); |
|
230 BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions")); |
|
231 BtnAssociateFiles->setEnabled(!custom_data && !custom_config); |
|
232 MiscLayout->addWidget(BtnAssociateFiles, 4, 0, 1, 2); |
|
233 #endif |
|
234 gbTBLayout->addWidget(groupMisc, 2, 0); |
|
235 } |
|
236 |
|
237 { |
|
238 AGGroupBox = new IconedGroupBox(this); |
|
239 //AGGroupBox->setContentTopPadding(0); |
|
240 AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png")); |
|
241 //AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); |
|
242 AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options")); |
|
243 |
|
244 QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox); |
|
245 QHBoxLayout * GBAreslayout = new QHBoxLayout(0); |
|
246 QHBoxLayout * GBAstereolayout = new QHBoxLayout(0); |
|
247 QHBoxLayout * GBAqualayout = new QHBoxLayout(0); |
|
248 |
|
249 CBFrontendFullscreen = new QCheckBox(AGGroupBox); |
|
250 CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen")); |
|
251 GBAlayout->addWidget(CBFrontendFullscreen); |
|
252 |
|
253 CBFrontendEffects = new QCheckBox(AGGroupBox); |
|
254 CBFrontendEffects->setText(QCheckBox::tr("Frontend effects") + " *"); |
|
255 GBAlayout->addWidget(CBFrontendEffects); |
|
256 |
|
257 CBEnableFrontendSound = new QCheckBox(AGGroupBox); |
|
258 CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds")); |
|
259 GBAlayout->addWidget(CBEnableFrontendSound); |
|
260 |
|
261 CBEnableFrontendMusic = new QCheckBox(AGGroupBox); |
|
262 CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music")); |
|
263 GBAlayout->addWidget(CBEnableFrontendMusic); |
|
264 |
|
265 QFrame * hr = new QFrame(AGGroupBox); |
|
266 hr->setFrameStyle(QFrame::HLine); |
|
267 hr->setLineWidth(3); |
|
268 hr->setFixedHeight(10); |
|
269 GBAlayout->addWidget(hr); |
|
270 |
|
271 QLabel * resolution = new QLabel(AGGroupBox); |
|
272 resolution->setText(QLabel::tr("Resolution")); |
|
273 GBAreslayout->addWidget(resolution); |
|
274 |
|
275 CBResolution = new QComboBox(AGGroupBox); |
|
276 GBAreslayout->addWidget(CBResolution); |
|
277 GBAlayout->addLayout(GBAreslayout); |
|
278 |
|
279 CBFullscreen = new QCheckBox(AGGroupBox); |
|
280 CBFullscreen->setText(QCheckBox::tr("Fullscreen")); |
|
281 GBAlayout->addWidget(CBFullscreen); |
|
282 connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(void))); |
|
283 |
|
284 QLabel * quality = new QLabel(AGGroupBox); |
|
285 quality->setText(QLabel::tr("Quality")); |
|
286 quality->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
287 GBAqualayout->addWidget(quality); |
|
288 |
|
289 SLQuality = new QSlider(Qt::Horizontal, AGGroupBox); |
|
290 SLQuality->setTickPosition(QSlider::TicksBelow); |
|
291 SLQuality->setMaximum(5); |
|
292 SLQuality->setMinimum(0); |
|
293 SLQuality->setFixedWidth(150); |
|
294 GBAqualayout->addWidget(SLQuality); |
|
295 GBAlayout->addLayout(GBAqualayout); |
|
296 QLabel * stereo = new QLabel(AGGroupBox); |
|
297 stereo->setText(QLabel::tr("Stereo rendering")); |
|
298 GBAstereolayout->addWidget(stereo); |
|
299 |
|
300 CBStereoMode = new QComboBox(AGGroupBox); |
|
301 CBStereoMode->addItem(QComboBox::tr("Disabled")); |
|
302 CBStereoMode->addItem(QComboBox::tr("Red/Cyan")); |
|
303 CBStereoMode->addItem(QComboBox::tr("Cyan/Red")); |
|
304 CBStereoMode->addItem(QComboBox::tr("Red/Blue")); |
|
305 CBStereoMode->addItem(QComboBox::tr("Blue/Red")); |
|
306 CBStereoMode->addItem(QComboBox::tr("Red/Green")); |
|
307 CBStereoMode->addItem(QComboBox::tr("Green/Red")); |
|
308 CBStereoMode->addItem(QComboBox::tr("Side-by-side")); |
|
309 CBStereoMode->addItem(QComboBox::tr("Top-Bottom")); |
|
310 CBStereoMode->addItem(QComboBox::tr("Wiggle")); |
|
311 connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int))); |
|
312 |
|
313 GBAstereolayout->addWidget(CBStereoMode); |
|
314 GBAlayout->addLayout(GBAstereolayout); |
|
315 |
|
316 hr = new QFrame(AGGroupBox); |
|
317 hr->setFrameStyle(QFrame::HLine); |
|
318 hr->setLineWidth(3); |
|
319 hr->setFixedHeight(10); |
|
320 GBAlayout->addWidget(hr); |
|
321 |
|
322 QHBoxLayout * GBAvollayout = new QHBoxLayout(0); |
|
323 QLabel * vol = new QLabel(AGGroupBox); |
|
324 vol->setText(QLabel::tr("Initial sound volume")); |
|
325 GBAvollayout->addWidget(vol); |
|
326 GBAlayout->addLayout(GBAvollayout); |
|
327 volumeBox = new QSpinBox(AGGroupBox); |
|
328 volumeBox->setRange(0, 100); |
|
329 volumeBox->setSingleStep(5); |
|
330 GBAvollayout->addWidget(volumeBox); |
|
331 |
|
332 CBEnableSound = new QCheckBox(AGGroupBox); |
|
333 CBEnableSound->setText(QCheckBox::tr("Enable sound")); |
|
334 GBAlayout->addWidget(CBEnableSound); |
|
335 |
|
336 CBEnableMusic = new QCheckBox(AGGroupBox); |
|
337 CBEnableMusic->setText(QCheckBox::tr("Enable music")); |
|
338 GBAlayout->addWidget(CBEnableMusic); |
|
339 |
|
340 hr = new QFrame(AGGroupBox); |
|
341 hr->setFrameStyle(QFrame::HLine); |
|
342 hr->setLineWidth(3); |
|
343 hr->setFixedHeight(10); |
|
344 GBAlayout->addWidget(hr); |
|
345 |
|
346 QHBoxLayout * GBAfpslayout = new QHBoxLayout(0); |
|
347 QLabel * maxfps = new QLabel(AGGroupBox); |
|
348 maxfps->setText(QLabel::tr("FPS limit")); |
|
349 GBAfpslayout->addWidget(maxfps); |
|
350 GBAlayout->addLayout(GBAfpslayout); |
|
351 fpsedit = new FPSEdit(AGGroupBox); |
|
352 GBAfpslayout->addWidget(fpsedit); |
|
353 |
|
354 CBShowFPS = new QCheckBox(AGGroupBox); |
|
355 CBShowFPS->setText(QCheckBox::tr("Show FPS")); |
|
356 GBAlayout->addWidget(CBShowFPS); |
|
357 |
|
358 hr = new QFrame(AGGroupBox); |
|
359 hr->setFrameStyle(QFrame::HLine); |
|
360 hr->setLineWidth(3); |
|
361 hr->setFixedHeight(10); |
|
362 GBAlayout->addWidget(hr); |
|
363 |
|
364 QLabel *restartNote = new QLabel(this); |
|
365 restartNote->setText(QString("* ") + QLabel::tr("Restart game to apply")); |
|
366 restartNote->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); |
|
367 GBAlayout->addWidget(restartNote); |
|
368 |
|
369 gbTBLayout->addWidget(AGGroupBox, 0, 1, 3, 1); |
|
370 } |
|
371 |
|
372 BtnSaveOptions = addButton(":/res/Save.png", pageLayout, 2, 2, true); |
|
373 BtnSaveOptions->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); |
|
374 |
|
375 BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
|
376 BtnBack->setFixedHeight(BtnSaveOptions->height()); |
|
377 BtnBack->setFixedWidth(BtnBack->width()+2); |
|
378 BtnBack->setStyleSheet("QPushButton{margin: 22px 0 9px 2px;}"); |
|
379 } |
|
380 |
|
381 void PageOptions::forceFullscreen(int index) |
|
382 { |
|
383 if (index != 0) { |
|
384 previousFullscreenValue = this->CBFullscreen->isChecked(); |
|
385 this->CBFullscreen->setChecked(true); |
|
386 this->CBFullscreen->setEnabled(false); |
|
387 previousQuality = this->SLQuality->value(); |
|
388 this->SLQuality->setValue(this->SLQuality->maximum()); |
|
389 this->SLQuality->setEnabled(false); |
|
390 } else { |
|
391 this->CBFullscreen->setChecked(previousFullscreenValue); |
|
392 this->CBFullscreen->setEnabled(true); |
|
393 this->SLQuality->setValue(previousQuality); |
|
394 this->SLQuality->setEnabled(true); |
|
395 } |
|
396 } |
|
397 |
|
398 void PageOptions::setFullscreen(void) |
|
399 { |
|
400 int tmp = this->CBResolution->currentIndex(); |
|
401 if (this->CBFullscreen->isChecked()) |
|
402 this->CBResolution->setCurrentIndex(0); |
|
403 else |
|
404 this->CBResolution->setCurrentIndex(previousResolutionIndex); |
|
405 previousResolutionIndex = tmp; |
|
406 this->CBResolution->setEnabled(!this->CBFullscreen->isChecked()); |
|
407 } |
|
408 |
|
409 void PageOptions::trimNetNick() |
|
410 { |
|
411 editNetNick->setText(editNetNick->text().trimmed()); |
|
412 } |