author | unc0rr |
Thu, 09 Oct 2008 16:05:01 +0000 | |
changeset 1335 | c795cbc752c1 |
parent 1289 | 789db262d90d |
child 1377 | a9e768739345 |
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> |
|
23 |
#include <QFileInfo> |
|
24 |
#include <QDateTime> |
|
25 |
#include <QTextStream> |
|
1146 | 26 |
#include <QDesktopWidget> |
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 |
||
46 |
int main(int argc, char *argv[]) |
|
47 |
{ |
|
48 |
QApplication app(argc, argv); |
|
49 |
||
50 |
QDateTime now = QDateTime::currentDateTime(); |
|
51 |
QDateTime zero; |
|
52 |
srand(now.secsTo(zero)); |
|
1215 | 53 |
rand(); |
579 | 54 |
|
55 |
Q_INIT_RESOURCE(hedgewars); |
|
56 |
||
1146 | 57 |
qApp->setStyleSheet |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
58 |
(QString( |
1219
89babaafe99d
Make dialogs and messageboxes be customized like main form
unc0rr
parents:
1217
diff
changeset
|
59 |
"HWForm,QDialog{" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
60 |
"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
|
61 |
"background-position: bottom center;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
62 |
"background-repeat: repeat-x;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
63 |
"background-color: #870c8f;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
64 |
"}" |
1154 | 65 |
|
66 |
"QPushButton{" |
|
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
67 |
"border: solid;" |
1214 | 68 |
"border-width: 3px;" |
1157 | 69 |
"border-radius: 10px;" |
1214 | 70 |
"border-color: #ffcc00;" |
1168 | 71 |
"background-origin: margin;" |
72 |
"background-position: top left;" |
|
1167 | 73 |
"background-color: #00351d;" |
1214 | 74 |
"color: #ffcc00;" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
75 |
"}" |
1153 | 76 |
"QPushButton:hover{" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
77 |
"border-color: yellow;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
78 |
"}" |
1153 | 79 |
"QPushButton:pressed{" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
80 |
"border-color: white;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
81 |
"}" |
1154 | 82 |
|
1160 | 83 |
"QLineEdit{" |
84 |
"border: solid;" |
|
1214 | 85 |
"border-width: 3px;" |
1160 | 86 |
"border-radius: 12px;" |
1214 | 87 |
"border-color: #ffcc00;" |
1160 | 88 |
"background-color: #0d0544;" |
1214 | 89 |
"color: #ffcc00;" |
1160 | 90 |
"font: bold 14px;" |
91 |
"}" |
|
92 |
"QLineEdit:hover{" |
|
93 |
"border-color: yellow;" |
|
94 |
"}" |
|
95 |
||
1172 | 96 |
"QLabel{" |
1214 | 97 |
"color: #ffcc00;" |
1172 | 98 |
"font: bold 14px;" |
99 |
"}" |
|
100 |
||
1171 | 101 |
"QListWidget{" |
102 |
"border: solid;" |
|
1214 | 103 |
"border-width: 3px;" |
1171 | 104 |
"border-radius: 12px;" |
1214 | 105 |
"border-color: #ffcc00;" |
1171 | 106 |
"background-color: #0d0544;" |
1211 | 107 |
// "alternate-background-color: #2f213a;" //what's it? |
1214 | 108 |
"color: #ffcc00;" |
1171 | 109 |
"font: bold 14px;" |
110 |
"}" |
|
111 |
"QListWidget:hover{" |
|
112 |
"border-color: yellow;" |
|
113 |
"}" |
|
1211 | 114 |
// "QListWidget::item:alternate{" |
115 |
// "background: #2f213a;" |
|
116 |
// "}" |
|
1171 | 117 |
|
1161 | 118 |
"QSpinBox{" |
119 |
"border: solid;" |
|
1214 | 120 |
"border-width: 3px;" |
1161 | 121 |
"border-radius: 12px;" |
1214 | 122 |
"border-color: #ffcc00;" |
1161 | 123 |
"background-color: #0d0544;" |
1214 | 124 |
"color: #ffcc00;" |
1161 | 125 |
"font: bold 14px;" |
126 |
"}" |
|
127 |
"QSpinBox:hover{" |
|
128 |
"border-color: yellow;" |
|
129 |
"}" |
|
1289 | 130 |
"QSpinBox::up-button{" |
131 |
"background: transparent;" |
|
132 |
"width: 16px;" |
|
133 |
"height: 10px;" |
|
134 |
"}" |
|
135 |
"QSpinBox::up-arrow{" |
|
136 |
"image: url(\":/res/spin_up.png\");" |
|
137 |
//"width: 5px;" |
|
138 |
//"height: 5px;" |
|
139 |
"}" |
|
140 |
"QSpinBox::down-button{" |
|
141 |
"background: transparent;" |
|
142 |
"width: 16px;" |
|
143 |
"height: 10px;" |
|
144 |
"}" |
|
145 |
"QSpinBox::down-arrow{" |
|
146 |
"image: url(\":/res/spin_down.png\");" |
|
147 |
"}" |
|
1161 | 148 |
|
1172 | 149 |
"QToolBox{" |
150 |
"border: solid;" |
|
1214 | 151 |
"border-width: 3px;" |
1172 | 152 |
"border-radius: 12px;" |
1214 | 153 |
"border-color: #ffcc00;" |
1252 | 154 |
//"background-color: #0d0544;" |
1172 | 155 |
"}" |
156 |
"QToolBox::tab{" |
|
1214 | 157 |
"color: #ffcc00;" |
1172 | 158 |
"font: bold 14px;" |
159 |
"}" |
|
160 |
"QToolBox:hover{" |
|
161 |
"border-color: yellow;" |
|
162 |
"}" |
|
163 |
||
1154 | 164 |
"QComboBox{" |
165 |
"border: solid;" |
|
1214 | 166 |
"border-width: 3px;" |
1161 | 167 |
"border-radius: 15px;" |
1214 | 168 |
"border-color: #ffcc00;" |
1154 | 169 |
"background-color: #0d0544;" |
1214 | 170 |
"color: #ffcc00;" |
1154 | 171 |
"font: bold 14px;" |
172 |
"padding: 3px;" |
|
173 |
// "text-align: center;" |
|
174 |
"}" |
|
175 |
"QComboBox:hover{" |
|
176 |
"border-color: yellow;" |
|
177 |
"}" |
|
178 |
"QComboBox:pressed{" |
|
179 |
"border-color: white;" |
|
180 |
"}" |
|
181 |
"QComboBox::drop-down{" |
|
182 |
"border: transparent;" |
|
183 |
"width: 25px;" |
|
184 |
"}" |
|
185 |
"QComboBox::down-arrow {" |
|
1155 | 186 |
"image: url(\":/res/dropdown.png\");" |
1154 | 187 |
"}" |
188 |
"QComboBox QAbstractItemView{" |
|
189 |
"border: solid transparent;" |
|
1214 | 190 |
"border-width: 3px;" |
1157 | 191 |
//"border-radius: 12px;" -- bad corners look |
1214 | 192 |
"border-color: #ffcc00;" |
1154 | 193 |
"background-color: #0d0544;" |
1214 | 194 |
"color: #ffcc00;" |
1154 | 195 |
"font: bold 14px;" |
196 |
"}" |
|
1155 | 197 |
|
1198 | 198 |
|
199 |
"IconedGroupBox{" |
|
200 |
"border: solid;" |
|
1214 | 201 |
"border-width: 3px;" |
1198 | 202 |
"border-radius: 16px;" |
1214 | 203 |
"border-color: #ffcc00;" |
1198 | 204 |
"background-color: #130f2c;" |
1214 | 205 |
"color: #ffcc00;" |
1198 | 206 |
"font: bold 14px;" |
1228 | 207 |
"padding: 2px;" |
1198 | 208 |
"}" |
1217 | 209 |
".QGroupBox,GameCFGWidget,TeamSelWidget{" |
1197 | 210 |
"background-image: url(\":/res/panelbg.png\");" |
211 |
"background-position: bottom center;" |
|
212 |
"background-repeat: repeat-x;" |
|
1155 | 213 |
"border: solid;" |
1214 | 214 |
"border-width: 3px;" |
1155 | 215 |
"border-radius: 16px;" |
1214 | 216 |
"border-color: #ffcc00;" |
1198 | 217 |
"background-color: #040200;" |
1199 | 218 |
"padding: 6px;" |
1214 | 219 |
"color: #ffcc00;" |
1155 | 220 |
"font: bold 14px;" |
1209 | 221 |
//"margin-top: 24px;" |
1201 | 222 |
"}" |
223 |
".QGroupBox::title{" |
|
224 |
"subcontrol-origin: margin;" |
|
225 |
"subcontrol-position: top left;" |
|
226 |
//"padding-left: 82px;" |
|
227 |
//"padding-top: 26px;" |
|
228 |
"text-align: left;" |
|
1155 | 229 |
"}" |
230 |
||
231 |
"QCheckBox{" |
|
1214 | 232 |
"color: #ffcc00;" |
1155 | 233 |
"font: bold 14px;" |
234 |
"}" |
|
235 |
"QCheckBox::indicator:checked{" |
|
236 |
"image: url(\":/res/checked.png\");" |
|
237 |
"}" |
|
238 |
"QCheckBox::indicator:unchecked{" |
|
239 |
"image: url(\":/res/unchecked.png\");" |
|
240 |
"}" |
|
1172 | 241 |
|
242 |
"QRadioButton{" |
|
1214 | 243 |
"color: #ffcc00;" |
1172 | 244 |
"font: bold 14px;" |
245 |
"}" |
|
1252 | 246 |
|
247 |
".QWidget{" |
|
248 |
"background: transparent;" |
|
249 |
"}" |
|
250 |
".QTabWidget{" |
|
251 |
//"background: transparent;" |
|
252 |
"background-color: #130f2c;" |
|
253 |
"}" |
|
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
254 |
) |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
255 |
); |
1150 | 256 |
|
579 | 257 |
bindir->cd("bin"); // workaround over NSIS installer |
258 |
||
259 |
cfgdir->setPath(cfgdir->homePath()); |
|
260 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars")) |
|
261 |
{ |
|
262 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos"); |
|
263 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves"); |
|
264 |
} |
|
265 |
cfgdir->cd(".hedgewars"); |
|
266 |
||
267 |
datadir->cd(bindir->absolutePath()); |
|
268 |
datadir->cd(*cDataDir); |
|
269 |
if(!datadir->cd("hedgewars/Data")) { |
|
270 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
|
271 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
|
272 |
"Please check your installation"). |
|
273 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
|
274 |
return 1; |
|
275 |
} |
|
276 |
||
277 |
QTranslator Translator; |
|
278 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name()); |
|
279 |
app.installTranslator(&Translator); |
|
280 |
||
281 |
Themes = new QStringList(); |
|
282 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
283 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
284 |
QTextStream stream(&themesfile); |
|
285 |
QString str; |
|
286 |
while (!stream.atEnd()) |
|
287 |
{ |
|
288 |
Themes->append(stream.readLine()); |
|
289 |
} |
|
290 |
themesfile.close(); |
|
291 |
} else { |
|
292 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
293 |
} |
|
294 |
||
1210 | 295 |
QDir tmpdir; |
296 |
tmpdir.cd(datadir->absolutePath()); |
|
297 |
tmpdir.cd("Maps"); |
|
298 |
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
299 |
mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
|
300 |
||
579 | 301 |
HWForm *Form = new HWForm(); |
302 |
Form->show(); |
|
303 |
return app.exec(); |
|
304 |
} |