author | koda |
Thu, 07 Jan 2010 19:50:40 +0000 | |
changeset 2682 | d4c395f25db2 |
parent 2523 | 7fc37a16f405 |
child 2750 | 0585262f76f6 |
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;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
92 |
"background-color: #870c8f;" |
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;" |
97 |
"}" |
|
98 |
||
99 |
"QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, " |
|
100 |
"QComboBox QAbstractItemView, QMenu::item {" |
|
101 |
"background-color: #0d0544;" |
|
102 |
"}" |
|
103 |
||
104 |
"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, " |
|
105 |
"QTextBrowser, QSpinBox, QToolBox, QComboBox, " |
|
106 |
"QComboBox QAbstractItemView, IconedGroupBox, " |
|
1897 | 107 |
".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, " |
108 |
"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
|
109 |
"border: solid;" |
1214 | 110 |
"border-width: 3px;" |
1893 | 111 |
"border-color: #ffcc00;" |
112 |
"}" |
|
113 |
||
114 |
"QPushButton:hover, QLineEdit:hover, QListWidget:hover, " |
|
115 |
"QSpinBox:hover, QToolBox:hover, QComboBox:hover {" |
|
116 |
"border-color: yellow;" |
|
117 |
"}" |
|
118 |
||
119 |
"QLineEdit, QListWidget,QTableView, QTextBrowser, " |
|
120 |
"QSpinBox, QToolBox { " |
|
121 |
"border-radius: 12px;" |
|
122 |
"}" |
|
123 |
||
124 |
"QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, " |
|
125 |
"QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, " |
|
126 |
"IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, " |
|
127 |
"SelWeaponWidget, QCheckBox, QRadioButton {" |
|
128 |
"font: bold 14px;" |
|
129 |
"}" |
|
2517 | 130 |
"SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {" |
131 |
"background-image: url(\":/res/panelbg.png\");" |
|
132 |
"background-position: bottom center;" |
|
133 |
"background-repeat: repeat-x;" |
|
134 |
"background-color: #040200;" |
|
135 |
"}" |
|
1893 | 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 |
} |