QTfrontend/main.cpp
author unc0rr
Tue, 05 Aug 2008 22:39:05 +0000
changeset 1155 ffd0a34171f1
parent 1154 03cc0ab9c013
child 1157 c2e02c52dcad
permissions -rw-r--r--
Customize checkboxes
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
	qApp->setStyleSheet
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    57
		(QString(
1154
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    58
			".HWForm{"
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    59
				"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
    60
				"background-position: bottom center;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    61
				"background-repeat: repeat-x;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    62
				"background-color: #870c8f;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    63
				"}"
1154
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    64
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    65
			"QPushButton{"
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    66
				"border: solid;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    67
				"border-width: 4px;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    68
				"border-radius: 8px;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    69
				"border-color: orange;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    70
				"background-origin: content;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    71
				"}"
1153
825931b81ad4 Iconed "Back" button everywhere
unc0rr
parents: 1152
diff changeset
    72
				"QPushButton:hover{"
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    73
				"border-color: yellow;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    74
				"}"
1153
825931b81ad4 Iconed "Back" button everywhere
unc0rr
parents: 1152
diff changeset
    75
				"QPushButton:pressed{"
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    76
				"border-color: white;"
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
    77
				"}"
1154
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    78
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    79
			"QComboBox{"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    80
				"border: solid;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    81
				"border-width: 4px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    82
				"border-radius: 16px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    83
				"border-color: orange;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    84
				"background-color: #0d0544;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    85
				"color: orange;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    86
				"font: bold 14px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    87
				"padding: 3px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    88
//				"text-align: center;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    89
				"}"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    90
			"QComboBox:hover{"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    91
				"border-color: yellow;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    92
				"}"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    93
			"QComboBox:pressed{"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    94
				"border-color: white;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    95
				"}"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    96
			"QComboBox::drop-down{"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    97
				"border: transparent;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    98
				"width: 25px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
    99
				"}"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   100
			"QComboBox::down-arrow {"
1155
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   101
				"image: url(\":/res/dropdown.png\");"
1154
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   102
				"}"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   103
			"QComboBox QAbstractItemView{"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   104
				"border: solid transparent;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   105
				"border-width: 4px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   106
				//"border-radius: 12px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   107
				"border-color: orange;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   108
				"background-color: #0d0544;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   109
				"color: orange;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   110
				"font: bold 14px;"
03cc0ab9c013 Customize comboboxes look
unc0rr
parents: 1153
diff changeset
   111
				"}"
1155
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   112
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   113
			"QGroupBox{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   114
				"border: solid;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   115
				"border-width: 4px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   116
				"border-radius: 16px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   117
				"border-color: orange;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   118
				"background-color: #0d0544;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   119
				"color: orange;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   120
				"font: bold 14px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   121
				"padding: 3px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   122
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   123
			"QGroupBox:hover{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   124
				"border-color: yellow;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   125
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   126
			"QGroupBox:pressed{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   127
				"border-color: white;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   128
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   129
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   130
			"QCheckBox{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   131
//				"background-color: #0d0544;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   132
				"color: orange;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   133
				"font: bold 14px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   134
//				"padding: 3px;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   135
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   136
			"QCheckBox::indicator{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   137
				"image-position: right;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   138
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   139
			"QCheckBox::indicator:checked{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   140
				"image: url(\":/res/checked.png\");"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   141
				"image-position: right;"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   142
				"}"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   143
			"QCheckBox::indicator:unchecked{"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   144
				"image: url(\":/res/unchecked.png\");"
ffd0a34171f1 Customize checkboxes
unc0rr
parents: 1154
diff changeset
   145
				"}"
1152
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
   146
			)
c72b939c00df Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents: 1150
diff changeset
   147
		);
1150
ae86e36dad2e - Make look better
unc0rr
parents: 1149
diff changeset
   148
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   149
	bindir->cd("bin"); // workaround over NSIS installer
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   150
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   151
	cfgdir->setPath(cfgdir->homePath());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   152
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   153
	{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   154
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   155
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   156
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   157
	cfgdir->cd(".hedgewars");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   158
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   159
	datadir->cd(bindir->absolutePath());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   160
	datadir->cd(*cDataDir);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   161
	if(!datadir->cd("hedgewars/Data")) {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   162
		QMessageBox::critical(0, QMessageBox::tr("Error"),
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   163
			QMessageBox::tr("Failed to open data directory:\n%1\n"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   164
					"Please check your installation").
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   165
					arg(datadir->absolutePath()+"/hedgewars/Data"));
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   166
		return 1;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   167
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   168
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   169
	QTranslator Translator;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   170
	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   171
	app.installTranslator(&Translator);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   172
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   173
	Themes = new QStringList();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   174
	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   175
	if (themesfile.open(QIODevice::ReadOnly)) {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   176
		QTextStream stream(&themesfile);
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   177
		QString str;
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   178
		while (!stream.atEnd())
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   179
		{
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   180
			Themes->append(stream.readLine());
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   181
		}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   182
		themesfile.close();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   183
	} else {
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   184
		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   185
	}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   186
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   187
	HWForm *Form = new HWForm();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   188
	Form->show();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   189
	return app.exec();
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   190
}