QTfrontend/main.cpp
changeset 2948 3f21a9dc93d0
parent 2913 865ae941d59e
child 3019 d6e19f35d98d
--- a/QTfrontend/main.cpp	Sat Mar 06 10:54:24 2010 +0000
+++ b/QTfrontend/main.cpp	Sat Mar 06 10:59:20 2010 +0000
@@ -30,17 +30,17 @@
 
 bool checkForDir(const QString & dir)
 {
-	QDir tmpdir;
-	if (!tmpdir.exists(dir))
-		if (!tmpdir.mkdir(dir))
-		{
-			QMessageBox::critical(0,
-					QObject::tr("Error"),
-					QObject::tr("Cannot create directory %1").arg(dir),
-					QObject::tr("OK"));
-			return false;
-		}
-	return true;
+    QDir tmpdir;
+    if (!tmpdir.exists(dir))
+        if (!tmpdir.mkdir(dir))
+        {
+            QMessageBox::critical(0,
+                    QObject::tr("Error"),
+                    QObject::tr("Cannot create directory %1").arg(dir),
+                    QObject::tr("OK"));
+            return false;
+        }
+    return true;
 }
 
 int main(int argc, char *argv[]) {        
@@ -76,103 +76,103 @@
         *cConfigDir = f.absoluteFilePath();
     }
 
-	app.setStyle(new QPlastiqueStyle);
+    app.setStyle(new QPlastiqueStyle);
 
-	QDateTime now = QDateTime::currentDateTime();
-	srand(now.toTime_t());
-	rand();
+    QDateTime now = QDateTime::currentDateTime();
+    srand(now.toTime_t());
+    rand();
 
-	Q_INIT_RESOURCE(hedgewars);
+    Q_INIT_RESOURCE(hedgewars);
 
-	qApp->setStyleSheet
-		(QString(
-			"HWForm,QDialog{"
-				"background-image: url(\":/res/Background.png\");"
-				"background-position: bottom center;"
-				"background-repeat: repeat-x;"
-				"background-color: #141250;"
-				"}"
+    qApp->setStyleSheet
+        (QString(
+            "HWForm,QDialog{"
+                "background-image: url(\":/res/Background.png\");"
+                "background-position: bottom center;"
+                "background-repeat: repeat-x;"
+                "background-color: #141250;"
+                "}"
 
-			"* {"
-				"color: #ffcc00;"
-				"selection-background-color: #ffcc00;"
-				"selection-color: #00351d;"
-			"}"
+            "* {"
+                "color: #ffcc00;"
+                "selection-background-color: #ffcc00;"
+                "selection-color: #00351d;"
+            "}"
 
-			"QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, "
+            "QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, "
             "QComboBox QAbstractItemView, QMenu::item {"
-				"background-color: rgba(13, 5, 68, 70%);"
-			"}"
+                "background-color: rgba(13, 5, 68, 70%);"
+            "}"
 
-			"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, "
-			"QTextBrowser, QSpinBox, QToolBox, QComboBox, "
+            "QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, "
+            "QTextBrowser, QSpinBox, QToolBox, QComboBox, "
             "QComboBox QAbstractItemView, IconedGroupBox, "
-			".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
+            ".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
             "QTabWidget::pane, QTabBar::tab {"
-				"border: solid;"
-				"border-width: 3px;"
-				"border-color: #ffcc00;"
-			"}"
+                "border: solid;"
+                "border-width: 3px;"
+                "border-color: #ffcc00;"
+            "}"
 
-			"QPushButton:hover, QLineEdit:hover, QListWidget:hover, "
-			"QSpinBox:hover, QToolBox:hover, QComboBox:hover {"
-			    "border-color: yellow;"
-			"}"
+            "QPushButton:hover, QLineEdit:hover, QListWidget:hover, "
+            "QSpinBox:hover, QToolBox:hover, QComboBox:hover {"
+                "border-color: yellow;"
+            "}"
 
-			"QLineEdit, QListWidget,QTableView, QTextBrowser, "
-			"QSpinBox, QToolBox { "
-				"border-radius: 12px;"
-			"}"
+            "QLineEdit, QListWidget,QTableView, QTextBrowser, "
+            "QSpinBox, QToolBox { "
+                "border-radius: 12px;"
+            "}"
 
-			"QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, "
-			"QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, "
-			"IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, "
+            "QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, "
+            "QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, "
+            "IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, "
             "SelWeaponWidget, QCheckBox, QRadioButton {"
-				"font: bold 14px;"
-			"}"
+                "font: bold 14px;"
+            "}"
             "SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {"
-				"background-position: bottom center;"
-				"background-repeat: repeat-x;"
-				"background-color: #000000;"
-			"}"
-			".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {"
-				"background-position: bottom center;"
-				"background-repeat: repeat-x;"
-				"border-radius: 16px;"
-				"background-color: rgba(13, 5, 68, 70%);"
-				"padding: 6px;"
-			"}"
+                "background-position: bottom center;"
+                "background-repeat: repeat-x;"
+                "background-color: #000000;"
+            "}"
+            ".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {"
+                "background-position: bottom center;"
+                "background-repeat: repeat-x;"
+                "border-radius: 16px;"
+                "background-color: rgba(13, 5, 68, 70%);"
+                "padding: 6px;"
+            "}"
 /*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
-			"IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, "
+            "IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit, "
             "IconedGroupBox QSpinBox {"
-				"border-radius: 0;"
-			"}"
-			"IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
-			"IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{"
-				"background-color: #130f2c;"
-			"}"
+                "border-radius: 0;"
+            "}"
+            "IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
+            "IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{"
+                "background-color: #130f2c;"
+            "}"
 
 
-			"QPushButton {"
-				"border-radius: 10px;"
-				"background-origin: margin;"
-				"background-position: top left;"
-				"background-color: rgba(18, 42, 5, 70%);"
-			"}"
+            "QPushButton {"
+                "border-radius: 10px;"
+                "background-origin: margin;"
+                "background-position: top left;"
+                "background-color: rgba(18, 42, 5, 70%);"
+            "}"
 
-			"QPushButton:pressed{"
-			    "border-color: white;"
-			"}"
+            "QPushButton:pressed{"
+                "border-color: white;"
+            "}"
 
-			"QHeaderView {"
-				"border-radius: 0;"
-				"border-width: 0;"
-				"border-bottom-width: 3px;"
-				"background-color: #00351d;"
-			"}"
-			"QTableView {"
-				"alternate-background-color: #2f213a;"
-			"}"
+            "QHeaderView {"
+                "border-radius: 0;"
+                "border-width: 0;"
+                "border-bottom-width: 3px;"
+                "background-color: #00351d;"
+            "}"
+            "QTableView {"
+                "alternate-background-color: #2f213a;"
+            "}"
 
             "QTabBar::tab {"
                  "border-bottom-width: 0;"
@@ -185,189 +185,189 @@
                  "color: #0d0544;"
                  "background-color: #ffcc00;"
             "}"
-			"QSpinBox::up-button{"
-				"background: transparent;"
-				"width: 16px;"
-				"height: 10px;"
-			"}"
+            "QSpinBox::up-button{"
+                "background: transparent;"
+                "width: 16px;"
+                "height: 10px;"
+            "}"
 
-			"QSpinBox::up-arrow {"
-				"image: url(\":/res/spin_up.png\");"
-			"}"
+            "QSpinBox::up-arrow {"
+                "image: url(\":/res/spin_up.png\");"
+            "}"
 
-			"QSpinBox::down-arrow {"
-				"image: url(\":/res/spin_down.png\");"
-			"}"
+            "QSpinBox::down-arrow {"
+                "image: url(\":/res/spin_down.png\");"
+            "}"
 
-			"QSpinBox::down-button {"
-				"background: transparent;"
-				"width: 16px;"
-				"height: 10px;"
-			"}"
+            "QSpinBox::down-button {"
+                "background: transparent;"
+                "width: 16px;"
+                "height: 10px;"
+            "}"
 
-			"QComboBox {"
-				"border-radius: 15px;"
-				"padding: 3px;"
-			"}"
-			"QComboBox:pressed{"
-				"border-color: white;"
-			"}"
-			"QComboBox::drop-down{"
-				"border: transparent;"
-				"width: 25px;"
-			"}"
-			"QComboBox::down-arrow {"
-				"image: url(\":/res/dropdown.png\");"
-			"}"
+            "QComboBox {"
+                "border-radius: 15px;"
+                "padding: 3px;"
+            "}"
+            "QComboBox:pressed{"
+                "border-color: white;"
+            "}"
+            "QComboBox::drop-down{"
+                "border: transparent;"
+                "width: 25px;"
+            "}"
+            "QComboBox::down-arrow {"
+                "image: url(\":/res/dropdown.png\");"
+            "}"
 
-			"VertScrArea {"
-				"background-position: bottom center;"
-				"background-repeat: repeat-x;"
-			"}"
+            "VertScrArea {"
+                "background-position: bottom center;"
+                "background-repeat: repeat-x;"
+            "}"
 
-			"IconedGroupBox {"
-				"border-radius: 16px;"
-				"padding: 2px;"
-			"}"
+            "IconedGroupBox {"
+                "border-radius: 16px;"
+                "padding: 2px;"
+            "}"
 
-			"QGroupBox::title{"
-				"subcontrol-origin: margin;"
-				"subcontrol-position: top left;"
-				"text-align: left;"
-				"}"
+            "QGroupBox::title{"
+                "subcontrol-origin: margin;"
+                "subcontrol-position: top left;"
+                "text-align: left;"
+                "}"
 
-			"QCheckBox::indicator:checked{"
-				"image: url(\":/res/checked.png\");"
-				"}"
-			"QCheckBox::indicator:unchecked{"
-				"image: url(\":/res/unchecked.png\");"
-				"}"
+            "QCheckBox::indicator:checked{"
+                "image: url(\":/res/checked.png\");"
+                "}"
+            "QCheckBox::indicator:unchecked{"
+                "image: url(\":/res/unchecked.png\");"
+                "}"
 
-			".QWidget{"
-				"background: transparent;"
-				"}"
+            ".QWidget{"
+                "background: transparent;"
+                "}"
 
-			"QTabWidget::pane {"
+            "QTabWidget::pane {"
                 "border-top-width: 2px;"
-			"}"
+            "}"
 
-			"QMenu{"
-				"background-color: #ffcc00;"
-				"margin: 3px;"
-			"}"
-			"QMenu::item {"
-				"background-color: #0d0544;"
-				"border: 1px solid transparent;"
-				"font: bold;"
-				"padding: 2px 25px 2px 20px;"
-			"}"
-			"QMenu::item:selected {"
-				"background-color: #2d2564;"
-			"}"
-			"QMenu::indicator {"
-				"width: 16px;"
-				"height: 16px;"
-			"}"
-			"QMenu::indicator:non-exclusive:checked{"
-				"image: url(\":/res/checked.png\");"
-			"}"
-			"QMenu::indicator:non-exclusive:unchecked{"
-				"image: url(\":/res/unchecked.png\");"
-			"}"
+            "QMenu{"
+                "background-color: #ffcc00;"
+                "margin: 3px;"
+            "}"
+            "QMenu::item {"
+                "background-color: #0d0544;"
+                "border: 1px solid transparent;"
+                "font: bold;"
+                "padding: 2px 25px 2px 20px;"
+            "}"
+            "QMenu::item:selected {"
+                "background-color: #2d2564;"
+            "}"
+            "QMenu::indicator {"
+                "width: 16px;"
+                "height: 16px;"
+            "}"
+            "QMenu::indicator:non-exclusive:checked{"
+                "image: url(\":/res/checked.png\");"
+            "}"
+            "QMenu::indicator:non-exclusive:unchecked{"
+                "image: url(\":/res/unchecked.png\");"
+            "}"
 
-			"QToolTip{"
-				"background-color: #0d0544;"
-			"}"
+            "QToolTip{"
+                "background-color: #0d0544;"
+            "}"
 
-			":disabled{"
-				"color: #a0a0a0;"
-			"}"
+            ":disabled{"
+                "color: #a0a0a0;"
+            "}"
             "SquareLabel, ItemNum {"
-				"background-color: #000000;"
-			"}"
-			)
-		);
+                "background-color: #000000;"
+            "}"
+            )
+        );
 
-	bindir->cd("bin"); // workaround over NSIS installer
+    bindir->cd("bin"); // workaround over NSIS installer
 
-	if(cConfigDir->length() == 0)
-		cfgdir->setPath(cfgdir->homePath());
-	else
-		cfgdir->setPath(*cConfigDir);
+    if(cConfigDir->length() == 0)
+        cfgdir->setPath(cfgdir->homePath());
+    else
+        cfgdir->setPath(*cConfigDir);
 
-	if(cConfigDir->length() == 0)
-	{
+    if(cConfigDir->length() == 0)
+    {
 #ifdef __APPLE__
-		if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"))
-		{
-			checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
-			checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves");
-		}
-		cfgdir->cd("Library/Application Support/Hedgewars");
+        if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"))
+        {
+            checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
+            checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves");
+        }
+        cfgdir->cd("Library/Application Support/Hedgewars");
 #else
-		if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
-		{
-			checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
-			checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
-		}
-		cfgdir->cd(".hedgewars");
+        if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
+        {
+            checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
+            checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
+        }
+        cfgdir->cd(".hedgewars");
 #endif
-	}
-	else
-	{
-		if (checkForDir(cfgdir->absolutePath()))
-		{
-			checkForDir(cfgdir->absolutePath() + "/Demos");
-			checkForDir(cfgdir->absolutePath() + "/Saves");
-		}
-	}
+    }
+    else
+    {
+        if (checkForDir(cfgdir->absolutePath()))
+        {
+            checkForDir(cfgdir->absolutePath() + "/Demos");
+            checkForDir(cfgdir->absolutePath() + "/Saves");
+        }
+    }
 
 
-	datadir->cd(bindir->absolutePath());
-	datadir->cd(*cDataDir);
-	if(!datadir->cd("hedgewars/Data")) {
-		QMessageBox::critical(0, QMessageBox::tr("Error"),
-			QMessageBox::tr("Failed to open data directory:\n%1\n"
-					"Please check your installation").
-					arg(datadir->absolutePath()+"/hedgewars/Data"));
-		return 1;
-	}
+    datadir->cd(bindir->absolutePath());
+    datadir->cd(*cDataDir);
+    if(!datadir->cd("hedgewars/Data")) {
+        QMessageBox::critical(0, QMessageBox::tr("Error"),
+            QMessageBox::tr("Failed to open data directory:\n%1\n"
+                    "Please check your installation").
+                    arg(datadir->absolutePath()+"/hedgewars/Data"));
+        return 1;
+    }
 
-	Themes = new QStringList();
-	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
-	if (themesfile.open(QIODevice::ReadOnly)) {
-		QTextStream stream(&themesfile);
-		QString str;
-		while (!stream.atEnd())
-		{
-			Themes->append(stream.readLine());
-		}
-		themesfile.close();
-	} else {
-		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
-	}
+    Themes = new QStringList();
+    QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
+    if (themesfile.open(QIODevice::ReadOnly)) {
+        QTextStream stream(&themesfile);
+        QString str;
+        while (!stream.atEnd())
+        {
+            Themes->append(stream.readLine());
+        }
+        themesfile.close();
+    } else {
+        QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
+    }
 
-	QDir tmpdir;
-	tmpdir.cd(datadir->absolutePath());
-	tmpdir.cd("Maps");
-	tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
-	mapList = new QStringList(tmpdir.entryList(QStringList("*")));
+    QDir tmpdir;
+    tmpdir.cd(datadir->absolutePath());
+    tmpdir.cd("Maps");
+    tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
+    mapList = new QStringList(tmpdir.entryList(QStringList("*")));
 
 
-	QTranslator Translator;
-	{
-		QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
-		QString cc = settings.value("misc/locale", "").toString();
-		if(!cc.compare(""))
-			cc = QLocale::system().name();
-		Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + cc);
-		app.installTranslator(&Translator);
-	}
+    QTranslator Translator;
+    {
+        QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
+        QString cc = settings.value("misc/locale", "").toString();
+        if(!cc.compare(""))
+            cc = QLocale::system().name();
+        Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + cc);
+        app.installTranslator(&Translator);
+    }
 
 
-	HWForm *Form = new HWForm();
+    HWForm *Form = new HWForm();
 
 
-	Form->show();
-	return app.exec();
+    Form->show();
+    return app.exec();
 }