QTfrontend/main.cpp
author displacer
Mon, 04 Aug 2008 19:28:01 +0000
changeset 1149 c2d3b4f71836
parent 1147 ce37ebba0806
child 1150 ae86e36dad2e
permissions -rw-r--r--
transparent background for buttons at main page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 579
diff changeset
     2
 * Hedgewars, a free turn based strategy game
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     4
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     8
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    13
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    17
 */
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    18
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    19
#include <QApplication>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    20
#include <QTranslator>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    21
#include <QLocale>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    22
#include <QMessageBox>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    23
#include <QFileInfo>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    24
#include <QDateTime>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    25
#include <QTextStream>
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    26
#include <QDesktopWidget>
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    27
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    28
#include "hwform.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    29
#include "hwconsts.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    30
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    31
bool checkForDir(const QString & dir)
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    32
{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    33
	QDir tmpdir;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    34
	if (!tmpdir.exists(dir))
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    35
		if (!tmpdir.mkdir(dir))
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    36
		{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    37
			QMessageBox::critical(0,
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    38
					QObject::tr("Error"),
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    39
					QObject::tr("Cannot create directory %1").arg(dir),
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    40
					QObject::tr("OK"));
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    41
			return false;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    42
		}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    43
	return true;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    44
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    45
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    46
int main(int argc, char *argv[])
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    47
{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    48
	QApplication app(argc, argv);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    49
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    50
	QDateTime now = QDateTime::currentDateTime();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    51
	QDateTime zero;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    52
	srand(now.secsTo(zero));
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    53
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    54
	Q_INIT_RESOURCE(hedgewars);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    55
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    56
	QString imgAddr=":/res/Background.png";
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    57
	QImage bgrndIm(imgAddr);
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    58
	QRect deskSz=qApp->desktop()->screenGeometry();
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    59
	bgrndIm=bgrndIm.scaled(deskSz.width()-deskSz.left(), deskSz.height()-deskSz.top(), 
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    60
			       Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    61
	if (bgrndIm.save(QDir::tempPath()+"/hedgewarsScaledBgrnd.png")) {
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    62
	  imgAddr=QDir::tempPath()+"/hedgewarsScaledBgrnd.png";
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    63
	}
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    64
	
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    65
	qApp->setStyleSheet
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    66
	  (QString(
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    67
		   ".HWForm{"
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    68
		   "background-image: url(\"%1\");"
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    69
		   "background-position: bottom center;"
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    70
		   //" background-origin: content;"
1147
ce37ebba0806 no-repeat background with bgcolor instead
displacer
parents: 1146
diff changeset
    71
		   "background-repeat: no-repeat;"
ce37ebba0806 no-repeat background with bgcolor instead
displacer
parents: 1146
diff changeset
    72
		   "background-color: #3f095f;"
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    73
		   "}"
1149
c2d3b4f71836 transparent background for buttons at main page
displacer
parents: 1147
diff changeset
    74
		   "PageMain > QPushButton{"
c2d3b4f71836 transparent background for buttons at main page
displacer
parents: 1147
diff changeset
    75
		   "border: solid transparent;"
c2d3b4f71836 transparent background for buttons at main page
displacer
parents: 1147
diff changeset
    76
		   "}"
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    77
		   ).arg(imgAddr)
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    78
	   );
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    79
	
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    80
	bindir->cd("bin"); // workaround over NSIS installer
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    81
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    82
	cfgdir->setPath(cfgdir->homePath());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    83
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    84
	{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    85
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    86
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    87
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    88
	cfgdir->cd(".hedgewars");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    89
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    90
	datadir->cd(bindir->absolutePath());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    91
	datadir->cd(*cDataDir);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    92
	if(!datadir->cd("hedgewars/Data")) {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    93
		QMessageBox::critical(0, QMessageBox::tr("Error"),
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    94
			QMessageBox::tr("Failed to open data directory:\n%1\n"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    95
					"Please check your installation").
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    96
					arg(datadir->absolutePath()+"/hedgewars/Data"));
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    97
		return 1;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    98
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    99
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   100
	QTranslator Translator;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   101
	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   102
	app.installTranslator(&Translator);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   103
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   104
	Themes = new QStringList();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   105
	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   106
	if (themesfile.open(QIODevice::ReadOnly)) {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   107
		QTextStream stream(&themesfile);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   108
		QString str;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   109
		while (!stream.atEnd())
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   110
		{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   111
			Themes->append(stream.readLine());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   112
		}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   113
		themesfile.close();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   114
	} else {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   115
		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   116
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   117
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   118
	HWForm *Form = new HWForm();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   119
	Form->show();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   120
	return app.exec();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   121
}