QTfrontend/main.cpp
changeset 2948 3f21a9dc93d0
parent 2913 865ae941d59e
child 3019 d6e19f35d98d
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    28 #include "hwform.h"
    28 #include "hwform.h"
    29 #include "hwconsts.h"
    29 #include "hwconsts.h"
    30 
    30 
    31 bool checkForDir(const QString & dir)
    31 bool checkForDir(const QString & dir)
    32 {
    32 {
    33 	QDir tmpdir;
    33     QDir tmpdir;
    34 	if (!tmpdir.exists(dir))
    34     if (!tmpdir.exists(dir))
    35 		if (!tmpdir.mkdir(dir))
    35         if (!tmpdir.mkdir(dir))
    36 		{
    36         {
    37 			QMessageBox::critical(0,
    37             QMessageBox::critical(0,
    38 					QObject::tr("Error"),
    38                     QObject::tr("Error"),
    39 					QObject::tr("Cannot create directory %1").arg(dir),
    39                     QObject::tr("Cannot create directory %1").arg(dir),
    40 					QObject::tr("OK"));
    40                     QObject::tr("OK"));
    41 			return false;
    41             return false;
    42 		}
    42         }
    43 	return true;
    43     return true;
    44 }
    44 }
    45 
    45 
    46 int main(int argc, char *argv[]) {        
    46 int main(int argc, char *argv[]) {        
    47     QApplication app(argc, argv);
    47     QApplication app(argc, argv);
    48 
    48 
    74     if(parsedArgs.contains("config-dir")) {
    74     if(parsedArgs.contains("config-dir")) {
    75         QFileInfo f(parsedArgs["config-dir"]);
    75         QFileInfo f(parsedArgs["config-dir"]);
    76         *cConfigDir = f.absoluteFilePath();
    76         *cConfigDir = f.absoluteFilePath();
    77     }
    77     }
    78 
    78 
    79 	app.setStyle(new QPlastiqueStyle);
    79     app.setStyle(new QPlastiqueStyle);
    80 
    80 
    81 	QDateTime now = QDateTime::currentDateTime();
    81     QDateTime now = QDateTime::currentDateTime();
    82 	srand(now.toTime_t());
    82     srand(now.toTime_t());
    83 	rand();
    83     rand();
    84 
    84 
    85 	Q_INIT_RESOURCE(hedgewars);
    85     Q_INIT_RESOURCE(hedgewars);
    86 
    86 
    87 	qApp->setStyleSheet
    87     qApp->setStyleSheet
    88 		(QString(
    88         (QString(
    89 			"HWForm,QDialog{"
    89             "HWForm,QDialog{"
    90 				"background-image: url(\":/res/Background.png\");"
    90                 "background-image: url(\":/res/Background.png\");"
    91 				"background-position: bottom center;"
    91                 "background-position: bottom center;"
    92 				"background-repeat: repeat-x;"
    92                 "background-repeat: repeat-x;"
    93 				"background-color: #141250;"
    93                 "background-color: #141250;"
    94 				"}"
    94                 "}"
    95 
    95 
    96 			"* {"
    96             "* {"
    97 				"color: #ffcc00;"
    97                 "color: #ffcc00;"
    98 				"selection-background-color: #ffcc00;"
    98                 "selection-background-color: #ffcc00;"
    99 				"selection-color: #00351d;"
    99                 "selection-color: #00351d;"
   100 			"}"
   100             "}"
   101 
   101 
   102 			"QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, "
   102             "QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, "
   103             "QComboBox QAbstractItemView, QMenu::item {"
   103             "QComboBox QAbstractItemView, QMenu::item {"
   104 				"background-color: rgba(13, 5, 68, 70%);"
   104                 "background-color: rgba(13, 5, 68, 70%);"
   105 			"}"
   105             "}"
   106 
   106 
   107 			"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, "
   107             "QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, "
   108 			"QTextBrowser, QSpinBox, QToolBox, QComboBox, "
   108             "QTextBrowser, QSpinBox, QToolBox, QComboBox, "
   109             "QComboBox QAbstractItemView, IconedGroupBox, "
   109             "QComboBox QAbstractItemView, IconedGroupBox, "
   110 			".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
   110             ".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
   111             "QTabWidget::pane, QTabBar::tab {"
   111             "QTabWidget::pane, QTabBar::tab {"
   112 				"border: solid;"
   112                 "border: solid;"
   113 				"border-width: 3px;"
   113                 "border-width: 3px;"
   114 				"border-color: #ffcc00;"
   114                 "border-color: #ffcc00;"
   115 			"}"
   115             "}"
   116 
   116 
   117 			"QPushButton:hover, QLineEdit:hover, QListWidget:hover, "
   117             "QPushButton:hover, QLineEdit:hover, QListWidget:hover, "
   118 			"QSpinBox:hover, QToolBox:hover, QComboBox:hover {"
   118             "QSpinBox:hover, QToolBox:hover, QComboBox:hover {"
   119 			    "border-color: yellow;"
   119                 "border-color: yellow;"
   120 			"}"
   120             "}"
   121 
   121 
   122 			"QLineEdit, QListWidget,QTableView, QTextBrowser, "
   122             "QLineEdit, QListWidget,QTableView, QTextBrowser, "
   123 			"QSpinBox, QToolBox { "
   123             "QSpinBox, QToolBox { "
   124 				"border-radius: 12px;"
   124                 "border-radius: 12px;"
   125 			"}"
   125             "}"
   126 
   126 
   127 			"QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, "
   127             "QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, "
   128 			"QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, "
   128             "QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, "
   129 			"IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, "
   129             "IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, "
   130             "SelWeaponWidget, QCheckBox, QRadioButton {"
   130             "SelWeaponWidget, QCheckBox, QRadioButton {"
   131 				"font: bold 14px;"
   131                 "font: bold 14px;"
   132 			"}"
   132             "}"
   133             "SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {"
   133             "SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {"
   134 				"background-position: bottom center;"
   134                 "background-position: bottom center;"
   135 				"background-repeat: repeat-x;"
   135                 "background-repeat: repeat-x;"
   136 				"background-color: #000000;"
   136                 "background-color: #000000;"
   137 			"}"
   137             "}"
   138 			".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {"
   138             ".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {"
   139 				"background-position: bottom center;"
   139                 "background-position: bottom center;"
   140 				"background-repeat: repeat-x;"
   140                 "background-repeat: repeat-x;"
   141 				"border-radius: 16px;"
   141                 "border-radius: 16px;"
   142 				"background-color: rgba(13, 5, 68, 70%);"
   142                 "background-color: rgba(13, 5, 68, 70%);"
   143 				"padding: 6px;"
   143                 "padding: 6px;"
   144 			"}"
   144             "}"
   145 /*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
   145 /*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
   146 			"IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, "
   146             "IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, "
   147             "IconedGroupBox QSpinBox {"
   147             "IconedGroupBox QSpinBox {"
   148 				"border-radius: 0;"
   148                 "border-radius: 0;"
   149 			"}"
   149             "}"
   150 			"IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
   150             "IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
   151 			"IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{"
   151             "IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{"
   152 				"background-color: #130f2c;"
   152                 "background-color: #130f2c;"
   153 			"}"
   153             "}"
   154 
   154 
   155 
   155 
   156 			"QPushButton {"
   156             "QPushButton {"
   157 				"border-radius: 10px;"
   157                 "border-radius: 10px;"
   158 				"background-origin: margin;"
   158                 "background-origin: margin;"
   159 				"background-position: top left;"
   159                 "background-position: top left;"
   160 				"background-color: rgba(18, 42, 5, 70%);"
   160                 "background-color: rgba(18, 42, 5, 70%);"
   161 			"}"
   161             "}"
   162 
   162 
   163 			"QPushButton:pressed{"
   163             "QPushButton:pressed{"
   164 			    "border-color: white;"
   164                 "border-color: white;"
   165 			"}"
   165             "}"
   166 
   166 
   167 			"QHeaderView {"
   167             "QHeaderView {"
   168 				"border-radius: 0;"
   168                 "border-radius: 0;"
   169 				"border-width: 0;"
   169                 "border-width: 0;"
   170 				"border-bottom-width: 3px;"
   170                 "border-bottom-width: 3px;"
   171 				"background-color: #00351d;"
   171                 "background-color: #00351d;"
   172 			"}"
   172             "}"
   173 			"QTableView {"
   173             "QTableView {"
   174 				"alternate-background-color: #2f213a;"
   174                 "alternate-background-color: #2f213a;"
   175 			"}"
   175             "}"
   176 
   176 
   177             "QTabBar::tab {"
   177             "QTabBar::tab {"
   178                  "border-bottom-width: 0;"
   178                  "border-bottom-width: 0;"
   179                  "border-radius: 0;"
   179                  "border-radius: 0;"
   180                  "border-top-left-radius: 6px;"
   180                  "border-top-left-radius: 6px;"
   183             "}"
   183             "}"
   184             "QTabBar::tab:!selected {"
   184             "QTabBar::tab:!selected {"
   185                  "color: #0d0544;"
   185                  "color: #0d0544;"
   186                  "background-color: #ffcc00;"
   186                  "background-color: #ffcc00;"
   187             "}"
   187             "}"
   188 			"QSpinBox::up-button{"
   188             "QSpinBox::up-button{"
   189 				"background: transparent;"
   189                 "background: transparent;"
   190 				"width: 16px;"
   190                 "width: 16px;"
   191 				"height: 10px;"
   191                 "height: 10px;"
   192 			"}"
   192             "}"
   193 
   193 
   194 			"QSpinBox::up-arrow {"
   194             "QSpinBox::up-arrow {"
   195 				"image: url(\":/res/spin_up.png\");"
   195                 "image: url(\":/res/spin_up.png\");"
   196 			"}"
   196             "}"
   197 
   197 
   198 			"QSpinBox::down-arrow {"
   198             "QSpinBox::down-arrow {"
   199 				"image: url(\":/res/spin_down.png\");"
   199                 "image: url(\":/res/spin_down.png\");"
   200 			"}"
   200             "}"
   201 
   201 
   202 			"QSpinBox::down-button {"
   202             "QSpinBox::down-button {"
   203 				"background: transparent;"
   203                 "background: transparent;"
   204 				"width: 16px;"
   204                 "width: 16px;"
   205 				"height: 10px;"
   205                 "height: 10px;"
   206 			"}"
   206             "}"
   207 
   207 
   208 			"QComboBox {"
   208             "QComboBox {"
   209 				"border-radius: 15px;"
   209                 "border-radius: 15px;"
   210 				"padding: 3px;"
   210                 "padding: 3px;"
   211 			"}"
   211             "}"
   212 			"QComboBox:pressed{"
   212             "QComboBox:pressed{"
   213 				"border-color: white;"
   213                 "border-color: white;"
   214 			"}"
   214             "}"
   215 			"QComboBox::drop-down{"
   215             "QComboBox::drop-down{"
   216 				"border: transparent;"
   216                 "border: transparent;"
   217 				"width: 25px;"
   217                 "width: 25px;"
   218 			"}"
   218             "}"
   219 			"QComboBox::down-arrow {"
   219             "QComboBox::down-arrow {"
   220 				"image: url(\":/res/dropdown.png\");"
   220                 "image: url(\":/res/dropdown.png\");"
   221 			"}"
   221             "}"
   222 
   222 
   223 			"VertScrArea {"
   223             "VertScrArea {"
   224 				"background-position: bottom center;"
   224                 "background-position: bottom center;"
   225 				"background-repeat: repeat-x;"
   225                 "background-repeat: repeat-x;"
   226 			"}"
   226             "}"
   227 
   227 
   228 			"IconedGroupBox {"
   228             "IconedGroupBox {"
   229 				"border-radius: 16px;"
   229                 "border-radius: 16px;"
   230 				"padding: 2px;"
   230                 "padding: 2px;"
   231 			"}"
   231             "}"
   232 
   232 
   233 			"QGroupBox::title{"
   233             "QGroupBox::title{"
   234 				"subcontrol-origin: margin;"
   234                 "subcontrol-origin: margin;"
   235 				"subcontrol-position: top left;"
   235                 "subcontrol-position: top left;"
   236 				"text-align: left;"
   236                 "text-align: left;"
   237 				"}"
   237                 "}"
   238 
   238 
   239 			"QCheckBox::indicator:checked{"
   239             "QCheckBox::indicator:checked{"
   240 				"image: url(\":/res/checked.png\");"
   240                 "image: url(\":/res/checked.png\");"
   241 				"}"
   241                 "}"
   242 			"QCheckBox::indicator:unchecked{"
   242             "QCheckBox::indicator:unchecked{"
   243 				"image: url(\":/res/unchecked.png\");"
   243                 "image: url(\":/res/unchecked.png\");"
   244 				"}"
   244                 "}"
   245 
   245 
   246 			".QWidget{"
   246             ".QWidget{"
   247 				"background: transparent;"
   247                 "background: transparent;"
   248 				"}"
   248                 "}"
   249 
   249 
   250 			"QTabWidget::pane {"
   250             "QTabWidget::pane {"
   251                 "border-top-width: 2px;"
   251                 "border-top-width: 2px;"
   252 			"}"
   252             "}"
   253 
   253 
   254 			"QMenu{"
   254             "QMenu{"
   255 				"background-color: #ffcc00;"
   255                 "background-color: #ffcc00;"
   256 				"margin: 3px;"
   256                 "margin: 3px;"
   257 			"}"
   257             "}"
   258 			"QMenu::item {"
   258             "QMenu::item {"
   259 				"background-color: #0d0544;"
   259                 "background-color: #0d0544;"
   260 				"border: 1px solid transparent;"
   260                 "border: 1px solid transparent;"
   261 				"font: bold;"
   261                 "font: bold;"
   262 				"padding: 2px 25px 2px 20px;"
   262                 "padding: 2px 25px 2px 20px;"
   263 			"}"
   263             "}"
   264 			"QMenu::item:selected {"
   264             "QMenu::item:selected {"
   265 				"background-color: #2d2564;"
   265                 "background-color: #2d2564;"
   266 			"}"
   266             "}"
   267 			"QMenu::indicator {"
   267             "QMenu::indicator {"
   268 				"width: 16px;"
   268                 "width: 16px;"
   269 				"height: 16px;"
   269                 "height: 16px;"
   270 			"}"
   270             "}"
   271 			"QMenu::indicator:non-exclusive:checked{"
   271             "QMenu::indicator:non-exclusive:checked{"
   272 				"image: url(\":/res/checked.png\");"
   272                 "image: url(\":/res/checked.png\");"
   273 			"}"
   273             "}"
   274 			"QMenu::indicator:non-exclusive:unchecked{"
   274             "QMenu::indicator:non-exclusive:unchecked{"
   275 				"image: url(\":/res/unchecked.png\");"
   275                 "image: url(\":/res/unchecked.png\");"
   276 			"}"
   276             "}"
   277 
   277 
   278 			"QToolTip{"
   278             "QToolTip{"
   279 				"background-color: #0d0544;"
   279                 "background-color: #0d0544;"
   280 			"}"
   280             "}"
   281 
   281 
   282 			":disabled{"
   282             ":disabled{"
   283 				"color: #a0a0a0;"
   283                 "color: #a0a0a0;"
   284 			"}"
   284             "}"
   285             "SquareLabel, ItemNum {"
   285             "SquareLabel, ItemNum {"
   286 				"background-color: #000000;"
   286                 "background-color: #000000;"
   287 			"}"
   287             "}"
   288 			)
   288             )
   289 		);
   289         );
   290 
   290 
   291 	bindir->cd("bin"); // workaround over NSIS installer
   291     bindir->cd("bin"); // workaround over NSIS installer
   292 
   292 
   293 	if(cConfigDir->length() == 0)
   293     if(cConfigDir->length() == 0)
   294 		cfgdir->setPath(cfgdir->homePath());
   294         cfgdir->setPath(cfgdir->homePath());
   295 	else
   295     else
   296 		cfgdir->setPath(*cConfigDir);
   296         cfgdir->setPath(*cConfigDir);
   297 
   297 
   298 	if(cConfigDir->length() == 0)
   298     if(cConfigDir->length() == 0)
   299 	{
   299     {
   300 #ifdef __APPLE__
   300 #ifdef __APPLE__
   301 		if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"))
   301         if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"))
   302 		{
   302         {
   303 			checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
   303             checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
   304 			checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves");
   304             checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves");
   305 		}
   305         }
   306 		cfgdir->cd("Library/Application Support/Hedgewars");
   306         cfgdir->cd("Library/Application Support/Hedgewars");
   307 #else
   307 #else
   308 		if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
   308         if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
   309 		{
   309         {
   310 			checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
   310             checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
   311 			checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
   311             checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
   312 		}
   312         }
   313 		cfgdir->cd(".hedgewars");
   313         cfgdir->cd(".hedgewars");
   314 #endif
   314 #endif
   315 	}
   315     }
   316 	else
   316     else
   317 	{
   317     {
   318 		if (checkForDir(cfgdir->absolutePath()))
   318         if (checkForDir(cfgdir->absolutePath()))
   319 		{
   319         {
   320 			checkForDir(cfgdir->absolutePath() + "/Demos");
   320             checkForDir(cfgdir->absolutePath() + "/Demos");
   321 			checkForDir(cfgdir->absolutePath() + "/Saves");
   321             checkForDir(cfgdir->absolutePath() + "/Saves");
   322 		}
   322         }
   323 	}
   323     }
   324 
   324 
   325 
   325 
   326 	datadir->cd(bindir->absolutePath());
   326     datadir->cd(bindir->absolutePath());
   327 	datadir->cd(*cDataDir);
   327     datadir->cd(*cDataDir);
   328 	if(!datadir->cd("hedgewars/Data")) {
   328     if(!datadir->cd("hedgewars/Data")) {
   329 		QMessageBox::critical(0, QMessageBox::tr("Error"),
   329         QMessageBox::critical(0, QMessageBox::tr("Error"),
   330 			QMessageBox::tr("Failed to open data directory:\n%1\n"
   330             QMessageBox::tr("Failed to open data directory:\n%1\n"
   331 					"Please check your installation").
   331                     "Please check your installation").
   332 					arg(datadir->absolutePath()+"/hedgewars/Data"));
   332                     arg(datadir->absolutePath()+"/hedgewars/Data"));
   333 		return 1;
   333         return 1;
   334 	}
   334     }
   335 
   335 
   336 	Themes = new QStringList();
   336     Themes = new QStringList();
   337 	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
   337     QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
   338 	if (themesfile.open(QIODevice::ReadOnly)) {
   338     if (themesfile.open(QIODevice::ReadOnly)) {
   339 		QTextStream stream(&themesfile);
   339         QTextStream stream(&themesfile);
   340 		QString str;
   340         QString str;
   341 		while (!stream.atEnd())
   341         while (!stream.atEnd())
   342 		{
   342         {
   343 			Themes->append(stream.readLine());
   343             Themes->append(stream.readLine());
   344 		}
   344         }
   345 		themesfile.close();
   345         themesfile.close();
   346 	} else {
   346     } else {
   347 		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
   347         QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
   348 	}
   348     }
   349 
   349 
   350 	QDir tmpdir;
   350     QDir tmpdir;
   351 	tmpdir.cd(datadir->absolutePath());
   351     tmpdir.cd(datadir->absolutePath());
   352 	tmpdir.cd("Maps");
   352     tmpdir.cd("Maps");
   353 	tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
   353     tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
   354 	mapList = new QStringList(tmpdir.entryList(QStringList("*")));
   354     mapList = new QStringList(tmpdir.entryList(QStringList("*")));
   355 
   355 
   356 
   356 
   357 	QTranslator Translator;
   357     QTranslator Translator;
   358 	{
   358     {
   359 		QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
   359         QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
   360 		QString cc = settings.value("misc/locale", "").toString();
   360         QString cc = settings.value("misc/locale", "").toString();
   361 		if(!cc.compare(""))
   361         if(!cc.compare(""))
   362 			cc = QLocale::system().name();
   362             cc = QLocale::system().name();
   363 		Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + cc);
   363         Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + cc);
   364 		app.installTranslator(&Translator);
   364         app.installTranslator(&Translator);
   365 	}
   365     }
   366 
   366 
   367 
   367 
   368 	HWForm *Form = new HWForm();
   368     HWForm *Form = new HWForm();
   369 
   369 
   370 
   370 
   371 	Form->show();
   371     Form->show();
   372 	return app.exec();
   372     return app.exec();
   373 }
   373 }