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