Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 003e4193be7b61fbc0e0f0060b58c118e31e33be)
+++ src/mainwindow.cpp	(revision bb994a7ff87ee8b817ac29d72cd45400e75c18ca)
@@ -1,23 +1,23 @@
 /*
- *	TSPSG - TSP Solver and Generator
- *	Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
+ *  TSPSG - TSP Solver and Generator
+ *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
  *
- *	$Id$
- *	$URL$
+ *  $Id$
+ *  $URL$
  *
- *	This file is part of TSPSG.
+ *  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 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.
+ *  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/>.
+ *  You should have received a copy of the GNU General Public License
+ *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
  */
 
@@ -28,8 +28,10 @@
 
 MainWindow::MainWindow(QWidget *parent)
-	: QMainWindow(parent)
+	: QMainWindow(parent), randMin(1), randMax(10)
 {
 	setupUi(this);
 	connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
+	connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
+	connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
 	connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
 	// Centering MainWindow
@@ -38,11 +40,28 @@
     rect.moveCenter(QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()).center());
 	setGeometry(rect);
-	for (int k = 0; k < tableTask->rowCount(); k++) {
-		QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(k + 1).toString());
-		tableTask->setVerticalHeaderItem(k,item);
-	}
-	for (int k = 0; k < tableTask->columnCount(); k++) {
-		QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(k + 1).toString());
-		tableTask->setHorizontalHeaderItem(k,item);
+	PrepareTable();
+}
+
+void MainWindow::PrepareTable()
+{
+QTableWidgetItem *item;
+	for (int y = 0; y < spinCities->value(); y++) {
+		item = new QTableWidgetItem(trUtf8("Город ") + QVariant(y + 1).toString());
+		tableTask->setVerticalHeaderItem(y,item);
+		item = new QTableWidgetItem(trUtf8("Город ") + QVariant(y + 1).toString());
+		tableTask->setHorizontalHeaderItem(y,item);
+		for (int x = 0; x < spinCities->value(); x++) {
+			if (y == x) {
+				item = new QTableWidgetItem("...");
+				item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+			} else {
+				item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
+QFont font = item->font();
+				font.setBold(true);
+				item->setFont(font);
+			}
+			item->setTextAlignment(Qt::AlignCenter);
+			tableTask->setItem(x,y,item);
+		}
 	}
 	tableTask->resizeRowsToContents();
@@ -52,19 +71,34 @@
 void MainWindow::CitiesNumberChanged(int n)
 {
-	// Adding row, setting header and adjusting its size
 bool increased = tableTask->rowCount() < n ? true : false;
 	tableTask->setRowCount(n);
-QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(n).toString());
-	tableTask->setVerticalHeaderItem(n - 1,item);
-	if (increased)
+	tableTask->setColumnCount(n);
+	for (int k = 0; k < n; k++)
+//		tableTask->setColumnWidth(k,tableTask->viewport()->width() / n);
+	// If number of cities increased we need to reset headers and set
+	// appropriate sizes for new column and row.
+	if (increased) {
+QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ") + QVariant(n).toString());
+		tableTask->setVerticalHeaderItem(n - 1,item);
+		item = new QTableWidgetItem(trUtf8("Город ") + QVariant(n).toString());
+		tableTask->setHorizontalHeaderItem(n - 1,item);
 		tableTask->resizeRowToContents(n - 1);
-	// Adding column, setting header and adjusting its size
-	increased = tableTask->columnCount() < n ? true : false;
-	tableTask->setColumnCount(n);
-	item = new QTableWidgetItem(trUtf8("Город ")+QVariant(n).toString());
-	tableTask->setHorizontalHeaderItem(n - 1,item);
-	if (increased)
-	tableTask->resizeColumnToContents(n - 1);
-	tableTask->setMinimumSize(tableTask->sizeHint());
+		tableTask->resizeColumnToContents(n - 1);
+		item = new QTableWidgetItem("...");
+		item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+		tableTask->setItem(spinCities->value() - 1,spinCities->value() - 1,item);
+		for (int k = 0; k < spinCities->value() - 1; k++) {
+			item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
+QFont font = item->font();
+			font.setBold(true);
+			item->setFont(font);
+			tableTask->setItem(k,spinCities->value() - 1,item);
+			item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
+			font = item->font();
+			font.setBold(true);
+			item->setFont(font);
+			tableTask->setItem(spinCities->value() - 1,k,item);
+		}
+	}
 }
 
@@ -72,4 +106,24 @@
 {
 SettingsDialog sd(this);
-	sd.exec();
+	sd.spinRandMin->setValue(randMin);
+	sd.spinRandMax->setValue(randMax);
+	if (sd.exec() == QDialog::Accepted) {
+		randMin = sd.spinRandMin->value();
+		randMax = sd.spinRandMax->value();
+	}
 }
+
+void MainWindow::Random()
+{
+	for (int y = 0; y < spinCities->value(); y++)
+		for (int x = 0; x < spinCities->value(); x++)
+			if (x != y)
+				tableTask->item(x,y)->setText(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
+}
+
+void MainWindow::Solve()
+{
+	tabWidget->setCurrentIndex(1);
+	// TODO: Task solving goes here :-)
+}
+
