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