93 QDateTime now = QDateTime::currentDateTime(); |
95 QDateTime now = QDateTime::currentDateTime(); |
94 srand(now.toTime_t()); |
96 srand(now.toTime_t()); |
95 rand(); |
97 rand(); |
96 |
98 |
97 Q_INIT_RESOURCE(hedgewars); |
99 Q_INIT_RESOURCE(hedgewars); |
98 |
|
99 QString styleSheetFromHell = |
|
100 QString( |
|
101 "HWForm,QDialog{" |
|
102 "background-image: url(\":/res/Background.png\");" |
|
103 "background-position: bottom center;" |
|
104 "background-repeat: repeat-x;" |
|
105 "background-color: #141250;" |
|
106 "}" |
|
107 |
|
108 "* {" |
|
109 "color: #ffcc00;" |
|
110 "selection-background-color: #ffcc00;" |
|
111 "selection-color: #00351d;" |
|
112 "}" |
|
113 |
|
114 "QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, " |
|
115 "QComboBox QAbstractItemView, QMenu::item {" |
|
116 "background-color: rgba(13, 5, 68, 70%);" |
|
117 "}" |
|
118 |
|
119 "QComboBox::separator {" |
|
120 "border: solid; border-width: 3px; border-color: #ffcc00;" |
|
121 "}" |
|
122 |
|
123 "QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, " |
|
124 "QTextBrowser, QSpinBox, QToolBox, QComboBox, " |
|
125 "QComboBox QAbstractItemView, IconedGroupBox, " |
|
126 ".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, " |
|
127 "QTabWidget::pane, QTabBar::tab {" |
|
128 "border: solid;" |
|
129 "border-width: 3px;" |
|
130 "border-color: #ffcc00;" |
|
131 "}" |
|
132 |
|
133 "QPushButton:hover, QLineEdit:hover, QListWidget:hover, " |
|
134 "QSpinBox:hover, QToolBox:hover, QComboBox:hover {" |
|
135 "border-color: yellow;" |
|
136 "}" |
|
137 |
|
138 "QLineEdit, QListWidget,QTableView, QTextBrowser, " |
|
139 "QSpinBox, QToolBox { " |
|
140 "border-radius: 10px;" |
|
141 "}" |
|
142 |
|
143 "QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, " |
|
144 "QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, " |
|
145 "IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, " |
|
146 "SelWeaponWidget, QCheckBox, QRadioButton, QPushButton {" |
|
147 "font: bold 13px;" |
|
148 "}" |
|
149 "SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {" |
|
150 "background-position: bottom center;" |
|
151 "background-repeat: repeat-x;" |
|
152 "background-color: #000000;" |
|
153 "}" |
|
154 ".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {" |
|
155 "background-position: bottom center;" |
|
156 "background-repeat: repeat-x;" |
|
157 "border-radius: 16px;" |
|
158 "background-color: rgba(13, 5, 68, 70%);" |
|
159 "padding: 6px;" |
|
160 "}" |
|
161 /* Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well |
|
162 "IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, " |
|
163 "IconedGroupBox QSpinBox {" |
|
164 "border-radius: 0;" |
|
165 "}" |
|
166 "IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */ |
|
167 "IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" |
|
168 "background-color: #130f2c;" |
|
169 "}" |
|
170 |
|
171 |
|
172 "QPushButton {" |
|
173 "border-radius: 8px;" |
|
174 "background-origin: margin;" |
|
175 "background-position: top left;" |
|
176 "background-color: rgba(18, 42, 5, 70%);" |
|
177 "}" |
|
178 |
|
179 "QPushButton:pressed{" |
|
180 "border-color: white;" |
|
181 "}" |
|
182 |
|
183 "QHeaderView {" |
|
184 "border-radius: 0;" |
|
185 "border-width: 0;" |
|
186 "border-bottom-width: 3px;" |
|
187 "background-color: #00351d;" |
|
188 "}" |
|
189 "QTableView {" |
|
190 "alternate-background-color: #2f213a;" |
|
191 "gridline-color: transparent;" |
|
192 "}" |
|
193 |
|
194 "QTabBar::tab {" |
|
195 "border-bottom-width: 0;" |
|
196 "border-radius: 0;" |
|
197 "border-top-left-radius: 6px;" |
|
198 "border-top-right-radius: 6px;" |
|
199 "padding: 3px;" |
|
200 "}" |
|
201 "QTabBar::tab:!selected {" |
|
202 "color: #0d0544;" |
|
203 "background-color: #ffcc00;" |
|
204 "}" |
|
205 "QSpinBox::up-button{" |
|
206 "background: transparent;" |
|
207 "width: 16px;" |
|
208 "height: 10px;" |
|
209 "}" |
|
210 |
|
211 "QSpinBox::up-arrow {" |
|
212 "image: url(\":/res/spin_up.png\");" |
|
213 "}" |
|
214 |
|
215 "QSpinBox::down-arrow {" |
|
216 "image: url(\":/res/spin_down.png\");" |
|
217 "}" |
|
218 |
|
219 "QSpinBox::down-button {" |
|
220 "background: transparent;" |
|
221 "width: 16px;" |
|
222 "height: 10px;" |
|
223 "}" |
|
224 |
|
225 "QComboBox {" |
|
226 "border-radius: 10px;" |
|
227 "padding: 3px;" |
|
228 "}" |
|
229 "QComboBox:pressed{" |
|
230 "border-color: white;" |
|
231 "}" |
|
232 "QComboBox::drop-down{" |
|
233 "border: transparent;" |
|
234 "width: 25px;" |
|
235 "}" |
|
236 "QComboBox::down-arrow {" |
|
237 "image: url(\":/res/dropdown.png\");" |
|
238 "}" |
|
239 |
|
240 "VertScrArea {" |
|
241 "background-position: bottom center;" |
|
242 "background-repeat: repeat-x;" |
|
243 "}" |
|
244 |
|
245 "IconedGroupBox {" |
|
246 "border-radius: 16px;" |
|
247 "padding: 2px;" |
|
248 "}" |
|
249 |
|
250 "QGroupBox::title{" |
|
251 "subcontrol-origin: margin;" |
|
252 "subcontrol-position: top left;" |
|
253 "text-align: left;" |
|
254 "left: 15px;" |
|
255 "top: -4px;" |
|
256 "}" |
|
257 |
|
258 "QCheckBox::indicator:checked{" |
|
259 "image: url(\":/res/checked.png\");" |
|
260 "}" |
|
261 "QCheckBox::indicator:unchecked{" |
|
262 "image: url(\":/res/unchecked.png\");" |
|
263 "}" |
|
264 |
|
265 ".QWidget{" |
|
266 "background: transparent;" |
|
267 "}" |
|
268 |
|
269 "QTabWidget::pane {" |
|
270 "border-top-width: 2px;" |
|
271 "}" |
|
272 |
|
273 "QMenu{" |
|
274 "background-color: #ffcc00;" |
|
275 "margin: 3px;" |
|
276 "}" |
|
277 "QMenu::item {" |
|
278 "background-color: #0d0544;" |
|
279 "border: 1px solid transparent;" |
|
280 "font: bold;" |
|
281 "padding: 2px 25px 2px 20px;" |
|
282 "}" |
|
283 "QMenu::item:selected {" |
|
284 "background-color: #2d2564;" |
|
285 "}" |
|
286 "QMenu::indicator {" |
|
287 "width: 16px;" |
|
288 "height: 16px;" |
|
289 "}" |
|
290 "QMenu::indicator:non-exclusive:checked{" |
|
291 "image: url(\":/res/checked.png\");" |
|
292 "}" |
|
293 "QMenu::indicator:non-exclusive:unchecked{" |
|
294 "image: url(\":/res/unchecked.png\");" |
|
295 "}" |
|
296 |
|
297 "QToolTip{" |
|
298 "background-color: #0d0544;" |
|
299 "border: 1px solid #ffcc00;" |
|
300 "}" |
|
301 |
|
302 ":disabled{" |
|
303 "color: #a0a0a0;" |
|
304 "}" |
|
305 "SquareLabel, ItemNum {" |
|
306 "background-color: #000000;" |
|
307 "}" |
|
308 "QSlider::groove::horizontal {" |
|
309 "height: 2px;" |
|
310 "margin: 2px 0px;" |
|
311 "background-color: #ffcc00;" |
|
312 "}" |
|
313 "QSlider::handle::horizontal {" |
|
314 "border: 0px;" |
|
315 "margin: -2px 0px;" |
|
316 "border-radius: 3px;" |
|
317 "background-color: #ffcc00;" |
|
318 "width: 8px;" |
|
319 "}" |
|
320 ); |
|
321 |
100 |
322 bindir->cd("bin"); // workaround over NSIS installer |
101 bindir->cd("bin"); // workaround over NSIS installer |
323 |
102 |
324 if(cConfigDir->length() == 0) |
103 if(cConfigDir->length() == 0) |
325 cfgdir->setPath(cfgdir->homePath()); |
104 cfgdir->setPath(cfgdir->homePath()); |
384 "Please check your installation"). |
163 "Please check your installation"). |
385 arg(datadir->absolutePath()+"/hedgewars/Data")); |
164 arg(datadir->absolutePath()+"/hedgewars/Data")); |
386 return 1; |
165 return 1; |
387 } |
166 } |
388 |
167 |
389 { |
168 HWDataManager & dataMgr = HWDataManager::instance(); |
390 QDir dir; |
169 |
391 dir.setPath(cfgdir->absolutePath() + "/Data/Themes"); |
170 { |
392 |
|
393 QStringList themes; |
171 QStringList themes; |
394 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
172 |
395 |
173 themes.append(dataMgr.entryList( |
396 dir.setPath(datadir->absolutePath() + "/Themes"); |
174 "Themes", |
397 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
175 QDir::AllDirs | QDir::NoDotAndDotDot) |
|
176 ); |
398 |
177 |
399 QList<QPair<QIcon, QIcon> > icons; |
178 QList<QPair<QIcon, QIcon> > icons; |
400 |
179 |
401 themes.sort(); |
180 themes.sort(); |
402 for(int i = themes.size() - 1; i >= 0; --i) |
181 for(int i = themes.size() - 1; i >= 0; --i) |
403 { |
182 { |
404 QFile tmpfile; |
183 QString file = dataMgr.findFileForRead( |
405 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
184 QString("Themes/%1/icon.png").arg(themes.at(i)) |
406 if (!tmpfile.exists()) |
185 ); |
407 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
186 |
408 |
187 if(QFile::exists(file)) |
409 if(tmpfile.exists()) |
|
410 { // load icon |
188 { // load icon |
411 QPair<QIcon, QIcon> ic; |
189 QPair<QIcon, QIcon> ic; |
412 ic.first = QIcon(QFileInfo(tmpfile).absoluteFilePath()); |
190 ic.first = QIcon(file); |
413 |
191 |
414 QFile previewIconFile; |
192 // load preview icon |
415 previewIconFile.setFileName(QString("%1/Data/Themes/%2/icon@2x.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
193 ic.second = QIcon( |
416 if (previewIconFile.exists()) ic.second = QIcon(QFileInfo(previewIconFile).absoluteFilePath()); |
194 dataMgr.findFileForRead( |
417 else ic.second = QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
195 QString("Themes/%1/icon@2x.png").arg(themes.at(i)) |
|
196 ) |
|
197 ); |
418 |
198 |
419 icons.prepend(ic); |
199 icons.prepend(ic); |
420 } |
200 } |
421 else |
201 else |
422 { |
202 { |
431 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
211 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
432 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
212 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
433 } |
213 } |
434 } |
214 } |
435 |
215 |
436 QDir tmpdir; |
216 mapList = new QStringList(dataMgr.entryList( |
437 tmpdir.cd(cfgdir->absolutePath()); |
217 QString("Maps"), |
438 tmpdir.cd("Data/Maps"); |
218 QDir::Dirs | QDir::NoDotAndDotDot |
439 tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
219 ) |
440 mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
220 ); |
441 |
|
442 tmpdir.cd(datadir->absolutePath()); |
|
443 tmpdir.cd("Maps"); |
|
444 tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
445 QStringList tmplist = QStringList(tmpdir.entryList(QStringList("*"))); |
|
446 for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) |
|
447 if (!mapList->contains(*it,Qt::CaseInsensitive)) mapList->append(*it); |
|
448 |
221 |
449 tmpdir.cd(cfgdir->absolutePath()); |
222 scriptList = new QStringList(dataMgr.entryList( |
450 tmpdir.cd("Data/Scripts/Multiplayer"); |
223 QString("Scripts/Multiplayer"), |
451 tmpdir.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
224 QDir::Files, |
452 scriptList = new QStringList(tmpdir.entryList(QStringList("*.lua"))); |
225 QStringList("*.lua") |
453 |
226 ) |
454 tmpdir.cd(datadir->absolutePath()); |
227 ); |
455 tmpdir.cd("Scripts/Multiplayer"); |
|
456 tmpdir.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
|
457 tmplist = QStringList(tmpdir.entryList(QStringList("*.lua"))); |
|
458 for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) |
|
459 if (!scriptList->contains(*it,Qt::CaseInsensitive)) scriptList->append(*it); |
|
460 |
228 |
461 QTranslator Translator; |
229 QTranslator Translator; |
462 { |
230 { |
463 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
231 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
464 QString cc = settings.value("misc/locale", QString()).toString(); |
232 QString cc = settings.value("misc/locale", QString()).toString(); |
465 if(cc.isEmpty()) |
233 if(cc.isEmpty()) |
466 cc = QLocale::system().name(); |
234 cc = QLocale::system().name(); |
467 QFile tmpfile; |
235 |
468 tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Locale/hedgewars_" + cc); |
236 // load locale file into translator |
469 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "/Locale/hedgewars_" + cc); |
237 Translator.load( |
470 Translator.load(QFileInfo(tmpfile).absoluteFilePath()); |
238 dataMgr.findFileForRead( |
|
239 QString("Locale/hedgewars_" + cc) |
|
240 ) |
|
241 ); |
471 app.installTranslator(&Translator); |
242 app.installTranslator(&Translator); |
472 } |
243 } |
473 |
244 |
474 #ifdef _WIN32 |
245 #ifdef _WIN32 |
475 // Win32 registry setup (used for xfire detection etc. - don't set it if we're running in "portable" mode with a custom config dir) |
246 // Win32 registry setup (used for xfire detection etc. - don't set it if we're running in "portable" mode with a custom config dir) |