Index: src/defines.h
===================================================================
--- src/defines.h	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
+++ src/defines.h	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -0,0 +1,38 @@
+/*
+ *  TSPSG - TSP Solver and Generator
+ *  Copyright (C) 2007-2009 L¸ppa <contacts[at]oleksii[dot]name>
+ *
+ *  $Id$
+ *  $URL$
+ *
+ *  This file is part of TSPSG.
+ *
+ *  TSPSG is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  TSPSG is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEFAULTS_H
+#define DEFAULTS_H
+
+// Ini file name
+#define INI_FILE "tspsg.ini"
+
+// Default values
+#define DEF_RAND_MIN 1
+#define DEF_RAND_MAX 10
+#define DEF_OFFSET 100
+#define DEF_FONT_FAMILY "Courier New"
+#define DEF_FONT_SIZE 12
+#define DEF_FONT_COLOR Qt::black
+
+#endif // DEFAULTS_H
Index: src/main.cpp
===================================================================
--- src/main.cpp	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/main.cpp	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -30,4 +30,7 @@
 {
 QApplication app(argc, argv);
+	app.setOrganizationName("..::Lёppsville::..");
+	app.setOrganizationDomain("www.leppsville.com");
+	app.setApplicationName("TSPSG");
 /*/ i18n
 // TODO: Make English as program's "native" language
Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/mainwindow.cpp	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -26,13 +26,15 @@
 	#include <QPrintDialog>
 #endif // Q_OS_WINCE
+#include "defines.h"
 #include "mainwindow.h"
 
-// TODO: Saving window state on close
-
 MainWindow::MainWindow(QWidget *parent)
-	: QMainWindow(parent), randMin(1), randMax(10)
+	: QMainWindow(parent)
 {
 	setupUi(this);
+QSettings settings(INI_FILE,QSettings::IniFormat);
+	spinCities->setValue(settings.value("NumCities",5).toInt());
 	connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
+	connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
 #ifndef Q_OS_WINCE
 	connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
@@ -48,20 +50,41 @@
 	tabWidget->resize(rect.width(),rect.height() - toolBar->size().height());
 #else
-	// Centering MainWindow
-	// TODO: Loading of saved window state
-	rect.moveCenter(QApplication::desktop()->availableGeometry().center());
+	if (settings.value("SavePos",false).toBool()) {
+		// Loading of saved window state
+		settings.beginGroup("MainWindow");
+		resize(settings.value("Size",size()).toSize());
+		move(settings.value("Position",pos()).toPoint());
+		if (settings.value("Maximized",false).toBool())
+			setWindowState(windowState() | Qt::WindowMaximized);
+		settings.endGroup();
+	} else {
+		// Centering main window
+		rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
+		setGeometry(rect);
+	}
 #endif // Q_OS_WINCE
-	setGeometry(rect);
 	qsrand(QDateTime().currentDateTime().toTime_t());
 	tspmodel = new CTSPModel();
-	tspmodel->randMin = randMin;
-	tspmodel->randMax = randMax;
 	tspmodel->setNumCities(spinCities->value());
 	taskView->setModel(tspmodel);
+#ifdef Q_OS_WINCE
+	taskView->resizeColumnsToContents();
+	taskView->resizeRowsToContents();
+#endif // Q_OS_WINCE
 }
 
 void MainWindow::CitiesNumberChanged(int n)
 {
+#ifdef Q_OS_WINCE
+int count = tspmodel->numCities();
+#endif // Q_OS_WINCE
 	tspmodel->setNumCities(n);
+#ifdef Q_OS_WINCE
+	if (n > count)
+		for (int k = count; k < n; k++) {
+			taskView->resizeColumnToContents(k);
+			taskView->resizeRowToContents(k);
+		}
+#endif // Q_OS_WINCE
 }
 
@@ -69,10 +92,5 @@
 {
 SettingsDialog sd(this);
-	sd.spinRandMin->setValue(randMin);
-	sd.spinRandMax->setValue(randMax);
-	if (sd.exec() == QDialog::Accepted) {
-		randMin = sd.spinRandMin->value();
-		randMax = sd.spinRandMax->value();
-	}
+	sd.exec();
 }
 
@@ -88,4 +106,8 @@
 {
 	tspmodel->randomize();
+#ifdef Q_OS_WINCE
+	taskView->resizeColumnsToContents();
+	taskView->resizeRowsToContents();
+#endif // Q_OS_WINCE
 }
 
@@ -114,2 +136,34 @@
 	// tabWidget->setCurrentIndex(1);
 }
+
+void MainWindow::showAbout()
+{
+	// TODO: Normal about window :-)
+QString about = QString::fromUtf8("TSPSG - TSP Solver and Generator\n\
+    Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n\
+Qt library versions:\n\
+    Compile time: %2\n\
+    Runtime: %3\n\
+\n\
+TSPSG is licensed under the terms of the GNU General Public License. You should have received a copy of the GNU General Public License along with TSPSG.").arg(QDate().toString("%Y"),QT_VERSION_STR,qVersion());
+	QMessageBox(QMessageBox::Information,"About",about).exec();
+}
+
+#ifndef Q_OS_WINCE
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+	// Saving windows state
+QSettings settings(INI_FILE,QSettings::IniFormat);
+	settings.setValue("NumCities",spinCities->value());
+	if (settings.value("SavePos",false).toBool()) {
+		settings.beginGroup("MainWindow");
+		settings.setValue("Maximized",isMaximized());
+		if (!isMaximized()) {
+			settings.setValue("Size",size());
+			settings.setValue("Position",pos());
+		}
+		settings.endGroup();
+	}
+	QMainWindow::closeEvent(event);
+}
+#endif // Q_OS_WINCE
Index: src/mainwindow.h
===================================================================
--- src/mainwindow.h	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/mainwindow.h	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -40,6 +40,10 @@
 public:
 	MainWindow(QWidget *parent = 0);
+#ifndef Q_OS_WINCE
+	void closeEvent(QCloseEvent *event);
+#endif // Q_OS_WINCE
 private slots:
 	void ChangeSettings();
+	void showAbout();
 #ifndef Q_OS_WINCE
 	void PrintSetup();
@@ -50,6 +54,4 @@
 private:
 	CTSPModel *tspmodel;
-	int randMin;
-	int randMax;
 };
 
Index: src/settingsdialog.cpp
===================================================================
--- src/settingsdialog.cpp	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/settingsdialog.cpp	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -25,4 +25,6 @@
 #include <QStatusTipEvent>
 #include <QFontDialog>
+#include <QColorDialog>
+#include "defines.h"
 #include "settingsdialog.h"
 
@@ -35,4 +37,5 @@
 	connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
 	connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
+	connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
 //	setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
 	setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
@@ -47,4 +50,17 @@
 	labelHint->setMinimumHeight(labelHint->height());
 #endif // Q_OS_WINCE
+	settings = new QSettings(INI_FILE,QSettings::IniFormat);
+	spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
+	spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
+#ifndef Q_OS_WINCE
+	cbSaveState->setChecked(settings->value("SavePos",false).toBool());
+#endif // Q_OS_WINCE
+	settings->beginGroup("Print");
+	font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
+	color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
+#ifndef Q_OS_WINCE
+	spinLeftMargin->setValue(settings->value("Offset",DEF_OFFSET).toInt());
+#endif // Q_OS_WINCE
+	settings->endGroup();
 }
 
@@ -69,6 +85,31 @@
 void SettingsDialog::buttonFontClicked()
 {
-	// TODO: Pass current font to dialog and save selected.
-QFontDialog fd;
-	fd.exec();
+bool ok;
+QFont font = QFontDialog::getFont(&ok,this->font,this);
+	if (ok)
+		this->font = font;
 }
+
+void SettingsDialog::buttonColorClicked()
+{
+QColorDialog cd(color,this);
+	if (cd.exec() == QDialog::Accepted)
+		color = cd.selectedColor();
+}
+
+void SettingsDialog::accept()
+{
+#ifndef Q_OS_WINCE
+	settings->setValue("SavePos",cbSaveState->isChecked());
+#endif // Q_OS_WINCE
+	settings->setValue("MinCost",spinRandMin->value());
+	settings->setValue("MaxCost",spinRandMax->value());
+	settings->beginGroup("Print");
+	settings->setValue("Font",font);
+	settings->setValue("Color",color);
+#ifndef Q_OS_WINCE
+	settings->setValue("Offset",spinLeftMargin->value());
+#endif // Q_OS_WINCE
+	settings->endGroup();
+	QDialog::accept();
+}
Index: src/settingsdialog.h
===================================================================
--- src/settingsdialog.h	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/settingsdialog.h	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -26,4 +26,5 @@
 
 #include <QDialog>
+#include <QSettings>
 #ifdef Q_OS_WINCE
 	#include "ui_settingsdialog.ce.h"
@@ -39,11 +40,16 @@
 
 private:
-#ifndef WINCE
+	QSettings *settings;
+	QFont font;
+	QColor color;
+#ifndef Q_OS_WINCE
 	bool event(QEvent *);
 #endif
 
 private slots:
+	void accept();
 	void spinRandMinValueChanged(int val) { spinRandMax->setMinimum(val + 1); }
 	void buttonFontClicked();
+	void buttonColorClicked();
 };
 
Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/tspmodel.cpp	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -23,9 +23,11 @@
 
 #include <QtGui>
+#include "defines.h"
 #include "tspmodel.h"
 
 CTSPModel::CTSPModel(QObject *parent)
-	: QAbstractTableModel(parent), randMin(1), randMax(10), nCities(0)
+	: QAbstractTableModel(parent), nCities(0)
 {
+	settings = new QSettings(INI_FILE,QSettings::IniFormat);
 }
 
@@ -115,4 +117,6 @@
 void CTSPModel::setNumCities(int n)
 {
+int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();
+int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();
 	if (n == nCities)
 		return;
@@ -140,4 +144,6 @@
 void CTSPModel::randomize()
 {
+int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();
+int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();
 	for (int r = 0; r < nCities; r++)
 		for (int c = 0; c < nCities; c++)
Index: src/tspmodel.h
===================================================================
--- src/tspmodel.h	(revision 8966f73b3f946dbb24f9de1869319bb266f5d2db)
+++ src/tspmodel.h	(revision aecdf994f963c2e4408ba015bccd3ca4b114a7ab)
@@ -31,9 +31,12 @@
 #define MAX_CITIES 100
 // This value means infinity :-)
-#define INFINITY 1.7E+308
+#ifndef INFINITY
+	#define INFINITY 1.7E+308
+#endif
 // This is string, which represents infinite value in table
 #define INFSTR "---"
 
 #include <QAbstractTableModel>
+#include <QSettings>
 
 class CTSPModel: public QAbstractTableModel
@@ -51,7 +54,6 @@
 	void setNumCities(int);
 	void randomize();
-	int randMin;
-	int randMax;
 private:
+	QSettings *settings;
 	double table[MAX_CITIES][MAX_CITIES];
 	int nCities;
