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