author | unc0rr |
Sat, 20 Sep 2008 04:51:06 +0000 | |
changeset 1283 | a1e99d1e4fd3 |
parent 1252 | 2e2719c0a397 |
child 1289 | 789db262d90d |
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 |
"}" |
|
130 |
||
1172 | 131 |
"QToolBox{" |
132 |
"border: solid;" |
|
1214 | 133 |
"border-width: 3px;" |
1172 | 134 |
"border-radius: 12px;" |
1214 | 135 |
"border-color: #ffcc00;" |
1252 | 136 |
//"background-color: #0d0544;" |
1172 | 137 |
"}" |
138 |
"QToolBox::tab{" |
|
1214 | 139 |
"color: #ffcc00;" |
1172 | 140 |
"font: bold 14px;" |
141 |
"}" |
|
142 |
"QToolBox:hover{" |
|
143 |
"border-color: yellow;" |
|
144 |
"}" |
|
145 |
||
1154 | 146 |
"QComboBox{" |
147 |
"border: solid;" |
|
1214 | 148 |
"border-width: 3px;" |
1161 | 149 |
"border-radius: 15px;" |
1214 | 150 |
"border-color: #ffcc00;" |
1154 | 151 |
"background-color: #0d0544;" |
1214 | 152 |
"color: #ffcc00;" |
1154 | 153 |
"font: bold 14px;" |
154 |
"padding: 3px;" |
|
155 |
// "text-align: center;" |
|
156 |
"}" |
|
157 |
"QComboBox:hover{" |
|
158 |
"border-color: yellow;" |
|
159 |
"}" |
|
160 |
"QComboBox:pressed{" |
|
161 |
"border-color: white;" |
|
162 |
"}" |
|
163 |
"QComboBox::drop-down{" |
|
164 |
"border: transparent;" |
|
165 |
"width: 25px;" |
|
166 |
"}" |
|
167 |
"QComboBox::down-arrow {" |
|
1155 | 168 |
"image: url(\":/res/dropdown.png\");" |
1154 | 169 |
"}" |
170 |
"QComboBox QAbstractItemView{" |
|
171 |
"border: solid transparent;" |
|
1214 | 172 |
"border-width: 3px;" |
1157 | 173 |
//"border-radius: 12px;" -- bad corners look |
1214 | 174 |
"border-color: #ffcc00;" |
1154 | 175 |
"background-color: #0d0544;" |
1214 | 176 |
"color: #ffcc00;" |
1154 | 177 |
"font: bold 14px;" |
178 |
"}" |
|
1155 | 179 |
|
1198 | 180 |
|
181 |
"IconedGroupBox{" |
|
182 |
"border: solid;" |
|
1214 | 183 |
"border-width: 3px;" |
1198 | 184 |
"border-radius: 16px;" |
1214 | 185 |
"border-color: #ffcc00;" |
1198 | 186 |
"background-color: #130f2c;" |
1214 | 187 |
"color: #ffcc00;" |
1198 | 188 |
"font: bold 14px;" |
1228 | 189 |
"padding: 2px;" |
1198 | 190 |
"}" |
1217 | 191 |
".QGroupBox,GameCFGWidget,TeamSelWidget{" |
1197 | 192 |
"background-image: url(\":/res/panelbg.png\");" |
193 |
"background-position: bottom center;" |
|
194 |
"background-repeat: repeat-x;" |
|
1155 | 195 |
"border: solid;" |
1214 | 196 |
"border-width: 3px;" |
1155 | 197 |
"border-radius: 16px;" |
1214 | 198 |
"border-color: #ffcc00;" |
1198 | 199 |
"background-color: #040200;" |
1199 | 200 |
"padding: 6px;" |
1214 | 201 |
"color: #ffcc00;" |
1155 | 202 |
"font: bold 14px;" |
1209 | 203 |
//"margin-top: 24px;" |
1201 | 204 |
"}" |
205 |
".QGroupBox::title{" |
|
206 |
"subcontrol-origin: margin;" |
|
207 |
"subcontrol-position: top left;" |
|
208 |
//"padding-left: 82px;" |
|
209 |
//"padding-top: 26px;" |
|
210 |
"text-align: left;" |
|
1155 | 211 |
"}" |
212 |
||
213 |
"QCheckBox{" |
|
1214 | 214 |
"color: #ffcc00;" |
1155 | 215 |
"font: bold 14px;" |
216 |
"}" |
|
217 |
"QCheckBox::indicator:checked{" |
|
218 |
"image: url(\":/res/checked.png\");" |
|
219 |
"}" |
|
220 |
"QCheckBox::indicator:unchecked{" |
|
221 |
"image: url(\":/res/unchecked.png\");" |
|
222 |
"}" |
|
1172 | 223 |
|
224 |
"QRadioButton{" |
|
1214 | 225 |
"color: #ffcc00;" |
1172 | 226 |
"font: bold 14px;" |
227 |
"}" |
|
1252 | 228 |
|
229 |
".QWidget{" |
|
230 |
"background: transparent;" |
|
231 |
"}" |
|
232 |
".QTabWidget{" |
|
233 |
//"background: transparent;" |
|
234 |
"background-color: #130f2c;" |
|
235 |
"}" |
|
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
236 |
) |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
237 |
); |
1150 | 238 |
|
579 | 239 |
bindir->cd("bin"); // workaround over NSIS installer |
240 |
||
241 |
cfgdir->setPath(cfgdir->homePath()); |
|
242 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars")) |
|
243 |
{ |
|
244 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos"); |
|
245 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves"); |
|
246 |
} |
|
247 |
cfgdir->cd(".hedgewars"); |
|
248 |
||
249 |
datadir->cd(bindir->absolutePath()); |
|
250 |
datadir->cd(*cDataDir); |
|
251 |
if(!datadir->cd("hedgewars/Data")) { |
|
252 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
|
253 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
|
254 |
"Please check your installation"). |
|
255 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
|
256 |
return 1; |
|
257 |
} |
|
258 |
||
259 |
QTranslator Translator; |
|
260 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name()); |
|
261 |
app.installTranslator(&Translator); |
|
262 |
||
263 |
Themes = new QStringList(); |
|
264 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
265 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
266 |
QTextStream stream(&themesfile); |
|
267 |
QString str; |
|
268 |
while (!stream.atEnd()) |
|
269 |
{ |
|
270 |
Themes->append(stream.readLine()); |
|
271 |
} |
|
272 |
themesfile.close(); |
|
273 |
} else { |
|
274 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
275 |
} |
|
276 |
||
1210 | 277 |
QDir tmpdir; |
278 |
tmpdir.cd(datadir->absolutePath()); |
|
279 |
tmpdir.cd("Maps"); |
|
280 |
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
281 |
mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
|
282 |
||
579 | 283 |
HWForm *Form = new HWForm(); |
284 |
Form->show(); |
|
285 |
return app.exec(); |
|
286 |
} |