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