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