author | koda |
Sun, 14 Feb 2010 23:50:51 +0000 | |
changeset 2809 | b8956af350c1 |
parent 2798 | d48bbe4518e6 |
child 2845 | 19db164dd20d |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
579 | 3 |
* Copyright (c) 2005-2007 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 <QApplication> |
|
20 |
#include <QTranslator> |
|
21 |
#include <QLocale> |
|
22 |
#include <QMessageBox> |
|
1416
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
23 |
#include <QPlastiqueStyle> |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
24 |
#include <QRegExp> |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
25 |
#include <QMap> |
1146 | 26 |
|
579 | 27 |
#include "hwform.h" |
28 |
#include "hwconsts.h" |
|
29 |
||
30 |
bool checkForDir(const QString & dir) |
|
31 |
{ |
|
32 |
QDir tmpdir; |
|
33 |
if (!tmpdir.exists(dir)) |
|
34 |
if (!tmpdir.mkdir(dir)) |
|
35 |
{ |
|
36 |
QMessageBox::critical(0, |
|
37 |
QObject::tr("Error"), |
|
38 |
QObject::tr("Cannot create directory %1").arg(dir), |
|
39 |
QObject::tr("OK")); |
|
40 |
return false; |
|
41 |
} |
|
42 |
return true; |
|
43 |
} |
|
44 |
||
2523 | 45 |
int main(int argc, char *argv[]) { |
2261 | 46 |
QApplication app(argc, argv); |
579 | 47 |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
48 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
49 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
50 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
51 |
QList<QString>::iterator i = arguments.begin(); |
2035 | 52 |
while(i != arguments.end()) { |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
53 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
54 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
55 |
QRegExp opt("--(\\S+)=(.+)"); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
56 |
if(opt.exactMatch(arg)) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
57 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 58 |
i = arguments.erase(i); |
59 |
} else { |
|
60 |
++i; |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
61 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
62 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
63 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
64 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
65 |
if(parsedArgs.contains("data-dir")) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
66 |
QFileInfo f(parsedArgs["data-dir"]); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
67 |
if(!f.exists()) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
68 |
qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
69 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
70 |
*cDataDir = f.absoluteFilePath(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
71 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
72 |
|
2428 | 73 |
if(parsedArgs.contains("config-dir")) { |
74 |
QFileInfo f(parsedArgs["config-dir"]); |
|
75 |
*cConfigDir = f.absoluteFilePath(); |
|
76 |
} |
|
77 |
||
1416
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
78 |
app.setStyle(new QPlastiqueStyle); |
2377 | 79 |
|
579 | 80 |
QDateTime now = QDateTime::currentDateTime(); |
2428 | 81 |
srand(now.toTime_t()); |
1215 | 82 |
rand(); |
579 | 83 |
|
84 |
Q_INIT_RESOURCE(hedgewars); |
|
85 |
||
1146 | 86 |
qApp->setStyleSheet |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
87 |
(QString( |
1219
89babaafe99d
Make dialogs and messageboxes be customized like main form
unc0rr
parents:
1217
diff
changeset
|
88 |
"HWForm,QDialog{" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
89 |
"background-image: url(\":/res/Background.png\");" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
90 |
"background-position: bottom center;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
91 |
"background-repeat: repeat-x;" |
2750 | 92 |
"background-color: #141250;" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
93 |
"}" |
1154 | 94 |
|
1897 | 95 |
"* {" |
1893 | 96 |
"color: #ffcc00;" |
2798 | 97 |
"selection-background-color: #ffcc00;" |
98 |
"selection-color: #00351d;" |
|
1893 | 99 |
"}" |
100 |
||
101 |
"QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, " |
|
102 |
"QComboBox QAbstractItemView, QMenu::item {" |
|
2798 | 103 |
"background-color: rgba(13, 5, 68, 70%);" |
1893 | 104 |
"}" |
105 |
||
106 |
"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, " |
|
107 |
"QTextBrowser, QSpinBox, QToolBox, QComboBox, " |
|
108 |
"QComboBox QAbstractItemView, IconedGroupBox, " |
|
1897 | 109 |
".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, " |
110 |
"QTabWidget::pane, QTabBar::tab {" |
|
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
111 |
"border: solid;" |
1214 | 112 |
"border-width: 3px;" |
1893 | 113 |
"border-color: #ffcc00;" |
114 |
"}" |
|
115 |
||
116 |
"QPushButton:hover, QLineEdit:hover, QListWidget:hover, " |
|
117 |
"QSpinBox:hover, QToolBox:hover, QComboBox:hover {" |
|
118 |
"border-color: yellow;" |
|
119 |
"}" |
|
120 |
||
121 |
"QLineEdit, QListWidget,QTableView, QTextBrowser, " |
|
122 |
"QSpinBox, QToolBox { " |
|
123 |
"border-radius: 12px;" |
|
124 |
"}" |
|
125 |
||
126 |
"QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, " |
|
127 |
"QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, " |
|
128 |
"IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, " |
|
129 |
"SelWeaponWidget, QCheckBox, QRadioButton {" |
|
130 |
"font: bold 14px;" |
|
131 |
"}" |
|
2517 | 132 |
"SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {" |
133 |
"background-position: bottom center;" |
|
134 |
"background-repeat: repeat-x;" |
|
2798 | 135 |
"background-color: #000000;" |
2517 | 136 |
"}" |
1893 | 137 |
".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {" |
138 |
"background-position: bottom center;" |
|
139 |
"background-repeat: repeat-x;" |
|
140 |
"border-radius: 16px;" |
|
2798 | 141 |
"background-color: rgba(13, 5, 68, 70%);" |
1893 | 142 |
"padding: 6px;" |
143 |
"}" |
|
2072
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
144 |
/* Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
145 |
"IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, " |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
146 |
"IconedGroupBox QSpinBox {" |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
147 |
"border-radius: 0;" |
2077
7320931f12a0
Remove setting of background-color on iconed group box children just in case that was causing Tiy's problem. Is useless until PaintOnScreen + border-radius is resolved anyway.
nemo
parents:
2072
diff
changeset
|
148 |
"}" |
7320931f12a0
Remove setting of background-color on iconed group box children just in case that was causing Tiy's problem. Is useless until PaintOnScreen + border-radius is resolved anyway.
nemo
parents:
2072
diff
changeset
|
149 |
"IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */ |
7320931f12a0
Remove setting of background-color on iconed group box children just in case that was causing Tiy's problem. Is useless until PaintOnScreen + border-radius is resolved anyway.
nemo
parents:
2072
diff
changeset
|
150 |
"IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" |
1893 | 151 |
"background-color: #130f2c;" |
152 |
"}" |
|
153 |
||
154 |
||
155 |
"QPushButton {" |
|
1157 | 156 |
"border-radius: 10px;" |
1168 | 157 |
"background-origin: margin;" |
158 |
"background-position: top left;" |
|
2798 | 159 |
"background-color: rgba(18, 42, 5, 70%);" |
1893 | 160 |
"}" |
161 |
||
162 |
"QPushButton:pressed{" |
|
163 |
"border-color: white;" |
|
164 |
"}" |
|
1154 | 165 |
|
1893 | 166 |
"QHeaderView {" |
167 |
"border-radius: 0;" |
|
168 |
"border-width: 0;" |
|
169 |
"border-bottom-width: 3px;" |
|
170 |
"background-color: #00351d;" |
|
171 |
"}" |
|
1894 | 172 |
"QTableView {" |
173 |
"alternate-background-color: #2f213a;" |
|
174 |
"}" |
|
1172 | 175 |
|
1893 | 176 |
"QTabBar::tab {" |
1897 | 177 |
"border-bottom-width: 0;" |
1893 | 178 |
"border-radius: 0;" |
179 |
"border-top-left-radius: 6px;" |
|
180 |
"border-top-right-radius: 6px;" |
|
181 |
"padding: 3px;" |
|
182 |
"}" |
|
183 |
"QTabBar::tab:!selected {" |
|
184 |
"color: #0d0544;" |
|
185 |
"background-color: #ffcc00;" |
|
186 |
"}" |
|
1289 | 187 |
"QSpinBox::up-button{" |
188 |
"background: transparent;" |
|
189 |
"width: 16px;" |
|
190 |
"height: 10px;" |
|
1893 | 191 |
"}" |
192 |
||
193 |
"QSpinBox::up-arrow {" |
|
1289 | 194 |
"image: url(\":/res/spin_up.png\");" |
1893 | 195 |
"}" |
196 |
||
197 |
"QSpinBox::down-arrow {" |
|
198 |
"image: url(\":/res/spin_down.png\");" |
|
199 |
"}" |
|
200 |
||
201 |
"QSpinBox::down-button {" |
|
1289 | 202 |
"background: transparent;" |
203 |
"width: 16px;" |
|
204 |
"height: 10px;" |
|
1172 | 205 |
"}" |
206 |
||
1893 | 207 |
"QComboBox {" |
1161 | 208 |
"border-radius: 15px;" |
1154 | 209 |
"padding: 3px;" |
1893 | 210 |
"}" |
1154 | 211 |
"QComboBox:pressed{" |
212 |
"border-color: white;" |
|
1893 | 213 |
"}" |
1154 | 214 |
"QComboBox::drop-down{" |
215 |
"border: transparent;" |
|
216 |
"width: 25px;" |
|
1893 | 217 |
"}" |
1154 | 218 |
"QComboBox::down-arrow {" |
1155 | 219 |
"image: url(\":/res/dropdown.png\");" |
1893 | 220 |
"}" |
2377 | 221 |
|
1893 | 222 |
"VertScrArea {" |
1425 | 223 |
"background-position: bottom center;" |
224 |
"background-repeat: repeat-x;" |
|
1893 | 225 |
"}" |
2377 | 226 |
|
1893 | 227 |
"IconedGroupBox {" |
1198 | 228 |
"border-radius: 16px;" |
1228 | 229 |
"padding: 2px;" |
1893 | 230 |
"}" |
231 |
||
1201 | 232 |
".QGroupBox::title{" |
233 |
"subcontrol-origin: margin;" |
|
234 |
"subcontrol-position: top left;" |
|
235 |
//"padding-left: 82px;" |
|
236 |
//"padding-top: 26px;" |
|
237 |
"text-align: left;" |
|
1155 | 238 |
"}" |
239 |
||
240 |
"QCheckBox::indicator:checked{" |
|
241 |
"image: url(\":/res/checked.png\");" |
|
242 |
"}" |
|
243 |
"QCheckBox::indicator:unchecked{" |
|
244 |
"image: url(\":/res/unchecked.png\");" |
|
245 |
"}" |
|
2377 | 246 |
|
1252 | 247 |
".QWidget{" |
248 |
"background: transparent;" |
|
249 |
"}" |
|
1893 | 250 |
|
251 |
"QTabWidget::pane {" |
|
252 |
"border-top-width: 2px;" |
|
253 |
"}" |
|
1413 | 254 |
|
255 |
"QMenu{" |
|
256 |
"background-color: #ffcc00;" |
|
257 |
"margin: 3px;" |
|
1893 | 258 |
"}" |
259 |
"QMenu::item {" |
|
1413 | 260 |
"background-color: #0d0544;" |
261 |
"border: 1px solid transparent;" |
|
262 |
"font: bold;" |
|
263 |
"padding: 2px 25px 2px 20px;" |
|
1893 | 264 |
"}" |
265 |
"QMenu::item:selected {" |
|
1413 | 266 |
"background-color: #2d2564;" |
1893 | 267 |
"}" |
268 |
"QMenu::indicator {" |
|
1413 | 269 |
"width: 16px;" |
270 |
"height: 16px;" |
|
1893 | 271 |
"}" |
1413 | 272 |
"QMenu::indicator:non-exclusive:checked{" |
273 |
"image: url(\":/res/checked.png\");" |
|
1893 | 274 |
"}" |
1413 | 275 |
"QMenu::indicator:non-exclusive:unchecked{" |
276 |
"image: url(\":/res/unchecked.png\");" |
|
1893 | 277 |
"}" |
1450 | 278 |
|
279 |
"QToolTip{" |
|
280 |
"background-color: #0d0544;" |
|
1893 | 281 |
"}" |
2377 | 282 |
|
1438 | 283 |
":disabled{" |
284 |
"color: #a0a0a0;" |
|
1893 | 285 |
"}" |
2072
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
286 |
"SquareLabel, ItemNum {" |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
287 |
"background-color: #000000;" |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
288 |
"}" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
289 |
) |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
290 |
); |
1150 | 291 |
|
579 | 292 |
bindir->cd("bin"); // workaround over NSIS installer |
293 |
||
2428 | 294 |
if(cConfigDir->length() == 0) |
295 |
cfgdir->setPath(cfgdir->homePath()); |
|
296 |
else |
|
297 |
cfgdir->setPath(*cConfigDir); |
|
298 |
||
299 |
if(cConfigDir->length() == 0) |
|
300 |
{ |
|
1965 | 301 |
#ifdef __APPLE__ |
2428 | 302 |
if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars")) |
303 |
{ |
|
304 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos"); |
|
305 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves"); |
|
306 |
} |
|
307 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
|
308 |
#else |
|
309 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars")) |
|
310 |
{ |
|
311 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos"); |
|
312 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves"); |
|
313 |
} |
|
314 |
cfgdir->cd(".hedgewars"); |
|
315 |
#endif |
|
1965 | 316 |
} |
2428 | 317 |
else |
579 | 318 |
{ |
2428 | 319 |
if (checkForDir(cfgdir->absolutePath())) |
320 |
{ |
|
321 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
322 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
323 |
} |
|
579 | 324 |
} |
325 |
||
326 |
datadir->cd(bindir->absolutePath()); |
|
327 |
datadir->cd(*cDataDir); |
|
328 |
if(!datadir->cd("hedgewars/Data")) { |
|
329 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
|
330 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
|
331 |
"Please check your installation"). |
|
332 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
|
333 |
return 1; |
|
334 |
} |
|
335 |
||
336 |
QTranslator Translator; |
|
337 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name()); |
|
338 |
app.installTranslator(&Translator); |
|
339 |
||
340 |
Themes = new QStringList(); |
|
341 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
342 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
343 |
QTextStream stream(&themesfile); |
|
344 |
QString str; |
|
345 |
while (!stream.atEnd()) |
|
346 |
{ |
|
347 |
Themes->append(stream.readLine()); |
|
348 |
} |
|
349 |
themesfile.close(); |
|
350 |
} else { |
|
351 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
352 |
} |
|
353 |
||
1210 | 354 |
QDir tmpdir; |
355 |
tmpdir.cd(datadir->absolutePath()); |
|
356 |
tmpdir.cd("Maps"); |
|
357 |
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
358 |
mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
|
359 |
||
579 | 360 |
HWForm *Form = new HWForm(); |
2377 | 361 |
|
2261 | 362 |
|
579 | 363 |
Form->show(); |
364 |
return app.exec(); |
|
2798 | 365 |
} |