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