author | nemo |
Thu, 15 Oct 2009 21:47:05 +0000 | |
changeset 2468 | 0b62498c201a |
parent 2428 | 6800f8aa0184 |
child 2517 | 6ed1fba6da18 |
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 |
"}" |
|
135 |
||
136 |
".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {" |
|
137 |
"background-image: url(\":/res/panelbg.png\");" |
|
138 |
"background-position: bottom center;" |
|
139 |
"background-repeat: repeat-x;" |
|
140 |
"border-radius: 16px;" |
|
141 |
"background-color: #040200;" |
|
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;" |
|
1167 | 159 |
"background-color: #00351d;" |
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-image: url(\":/res/panelbg.png\");" |
224 |
"background-position: bottom center;" |
|
225 |
"background-repeat: repeat-x;" |
|
1893 | 226 |
"}" |
2377 | 227 |
|
1893 | 228 |
"IconedGroupBox {" |
1198 | 229 |
"border-radius: 16px;" |
1228 | 230 |
"padding: 2px;" |
1893 | 231 |
"}" |
232 |
||
1201 | 233 |
".QGroupBox::title{" |
234 |
"subcontrol-origin: margin;" |
|
235 |
"subcontrol-position: top left;" |
|
236 |
//"padding-left: 82px;" |
|
237 |
//"padding-top: 26px;" |
|
238 |
"text-align: left;" |
|
1155 | 239 |
"}" |
240 |
||
241 |
"QCheckBox::indicator:checked{" |
|
242 |
"image: url(\":/res/checked.png\");" |
|
243 |
"}" |
|
244 |
"QCheckBox::indicator:unchecked{" |
|
245 |
"image: url(\":/res/unchecked.png\");" |
|
246 |
"}" |
|
2377 | 247 |
|
1252 | 248 |
".QWidget{" |
249 |
"background: transparent;" |
|
250 |
"}" |
|
1893 | 251 |
|
252 |
"QTabWidget::pane {" |
|
253 |
"border-top-width: 2px;" |
|
254 |
"}" |
|
1413 | 255 |
|
256 |
"QMenu{" |
|
257 |
"background-color: #ffcc00;" |
|
258 |
"margin: 3px;" |
|
1893 | 259 |
"}" |
260 |
"QMenu::item {" |
|
1413 | 261 |
"background-color: #0d0544;" |
262 |
"border: 1px solid transparent;" |
|
263 |
"font: bold;" |
|
264 |
"padding: 2px 25px 2px 20px;" |
|
1893 | 265 |
"}" |
266 |
"QMenu::item:selected {" |
|
1413 | 267 |
"background-color: #2d2564;" |
1893 | 268 |
"}" |
269 |
"QMenu::indicator {" |
|
1413 | 270 |
"width: 16px;" |
271 |
"height: 16px;" |
|
1893 | 272 |
"}" |
1413 | 273 |
"QMenu::indicator:non-exclusive:checked{" |
274 |
"image: url(\":/res/checked.png\");" |
|
1893 | 275 |
"}" |
1413 | 276 |
"QMenu::indicator:non-exclusive:unchecked{" |
277 |
"image: url(\":/res/unchecked.png\");" |
|
1893 | 278 |
"}" |
1450 | 279 |
|
280 |
"QToolTip{" |
|
281 |
"background-color: #0d0544;" |
|
1893 | 282 |
"}" |
2377 | 283 |
|
1438 | 284 |
":disabled{" |
285 |
"color: #a0a0a0;" |
|
1893 | 286 |
"}" |
2072
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
287 |
"SquareLabel, ItemNum {" |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
288 |
"background-color: #000000;" |
6e0fcbcc3f60
Custom controls implementing paintEvent play poorly with stars, especially SquareLabel
nemo
parents:
2035
diff
changeset
|
289 |
"}" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
290 |
) |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
291 |
); |
1150 | 292 |
|
579 | 293 |
bindir->cd("bin"); // workaround over NSIS installer |
294 |
||
2428 | 295 |
if(cConfigDir->length() == 0) |
296 |
cfgdir->setPath(cfgdir->homePath()); |
|
297 |
else |
|
298 |
cfgdir->setPath(*cConfigDir); |
|
299 |
||
300 |
if(cConfigDir->length() == 0) |
|
301 |
{ |
|
1965 | 302 |
#ifdef __APPLE__ |
2428 | 303 |
if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars")) |
304 |
{ |
|
305 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos"); |
|
306 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves"); |
|
307 |
} |
|
308 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
|
309 |
#else |
|
310 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars")) |
|
311 |
{ |
|
312 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos"); |
|
313 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves"); |
|
314 |
} |
|
315 |
cfgdir->cd(".hedgewars"); |
|
316 |
#endif |
|
1965 | 317 |
} |
2428 | 318 |
else |
579 | 319 |
{ |
2428 | 320 |
if (checkForDir(cfgdir->absolutePath())) |
321 |
{ |
|
322 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
323 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
324 |
} |
|
579 | 325 |
} |
326 |
||
327 |
datadir->cd(bindir->absolutePath()); |
|
328 |
datadir->cd(*cDataDir); |
|
329 |
if(!datadir->cd("hedgewars/Data")) { |
|
330 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
|
331 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
|
332 |
"Please check your installation"). |
|
333 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
|
334 |
return 1; |
|
335 |
} |
|
336 |
||
337 |
QTranslator Translator; |
|
338 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name()); |
|
339 |
app.installTranslator(&Translator); |
|
340 |
||
341 |
Themes = new QStringList(); |
|
342 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
343 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
344 |
QTextStream stream(&themesfile); |
|
345 |
QString str; |
|
346 |
while (!stream.atEnd()) |
|
347 |
{ |
|
348 |
Themes->append(stream.readLine()); |
|
349 |
} |
|
350 |
themesfile.close(); |
|
351 |
} else { |
|
352 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
353 |
} |
|
354 |
||
1210 | 355 |
QDir tmpdir; |
356 |
tmpdir.cd(datadir->absolutePath()); |
|
357 |
tmpdir.cd("Maps"); |
|
358 |
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
359 |
mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
|
360 |
||
579 | 361 |
HWForm *Form = new HWForm(); |
2377 | 362 |
|
2261 | 363 |
|
579 | 364 |
Form->show(); |
365 |
return app.exec(); |
|
366 |
} |