Index: trunk/src/mainwindow.cpp
===================================================================
--- trunk/src/mainwindow.cpp	(revision 105)
+++ trunk/src/mainwindow.cpp	(revision 106)
@@ -513,14 +513,10 @@
 	pd.setValue(0);
 
-#ifdef DEBUG
-QTime t;
-	t.start();
-#endif
 	solutionText->clear();
-#ifdef DEBUG
-	qDebug() << "Clear:" << t.elapsed();
-	t.restart();
-#endif
 	solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value()));
+
+QPainter pic;
+	pic.begin(&graph);
+	pic.setRenderHint(QPainter::Antialiasing);
 
 QTextDocument *doc = solutionText->document();
@@ -529,11 +525,13 @@
 	cur.beginEditBlock();
 	cur.setBlockFormat(fmt_paragraph);
-	cur.insertText(tr("Variant #%1").arg(spinVariant->value()), fmt_default);
+	cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default);
 	cur.insertBlock(fmt_paragraph);
 	cur.insertText(tr("Task:"));
 	outputMatrix(cur, matrix);
+	drawNode(pic, 0);
 	cur.insertHtml("<hr>");
 	cur.insertBlock(fmt_paragraph);
-	cur.insertText(tr("Solution of Variant #%1 Task").arg(spinVariant->value()), fmt_default);
+int imgpos = cur.position();
+	cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
 	cur.endEditBlock();
 
@@ -581,9 +579,15 @@
 			}
 		}
-		if (step->prNode->prNode != NULL)
+		if (n < spinCities->value()) {
+			if (step->prNode != NULL)
+				drawNode(pic, n - 1, false, step->prNode);
+			if (step->plNode != NULL)
+				drawNode(pic, n - 1, true, step->plNode);
+		}
+		if (step->prNode->prNode != NULL) {
 			step = step->prNode;
-		else if (step->plNode->prNode != NULL)
+		} else if (step->plNode->prNode != NULL) {
 			step = step->plNode;
-		else
+		} else
 			break;
 	}
@@ -613,7 +617,18 @@
 	}
 	cur.endEditBlock();
-#ifdef DEBUG
-	qDebug() << "Generate:" << t.elapsed();
-#endif
+	pic.end();
+
+QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
+	i.fill(0);
+	pic.begin(&i);
+	pic.drawPicture(1, 1, graph);
+	pic.end();
+	doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i);
+
+QTextImageFormat img;
+	img.setName("tspsg://graph.pic");
+
+	cur.setPosition(imgpos);
+	cur.insertImage(img, QTextFrameFormat::FloatRight);
 
 	if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
@@ -744,4 +759,42 @@
 }
 
+void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
+{
+const int r = 35;
+qreal x, y;
+	if (step != NULL)
+		x = left ? r : r * 3.5;
+	else
+		x = r * 2.25;
+	y = r * (3 * nstep + 1);
+
+	pic.drawEllipse(QPointF(x, y), r, r);
+
+	if (step != NULL) {
+QFont font;
+		if (left) {
+			font = pic.font();
+			font.setStrikeOut(true);
+			pic.setFont(font);
+		}
+		pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("(%1;%2)").arg(step->pNode->candidate.nRow + 1).arg(step->pNode->candidate.nCol + 1) + "\n");
+		if (left) {
+			font.setStrikeOut(false);
+			pic.setFont(font);
+		}
+		pic.setBackgroundMode(Qt::OpaqueMode);
+		pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, isInteger(step->price) ?  QString("\n%1").arg(step->price) : QString("\n%1").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()));
+		pic.setBackgroundMode(Qt::TransparentMode);
+	} else {
+		pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root"));
+	}
+
+	if (nstep == 1)
+		pic.drawLine(QPointF(r * 2.25, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r));
+	else
+		pic.drawLine(QPointF(r * 3.5, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r));
+
+}
+
 void MainWindow::dropEvent(QDropEvent *ev)
 {
@@ -783,5 +836,5 @@
 	fmt_table.setCellSpacing(5);
 
-	fmt_center.setAlignment(Qt::AlignHCenter);
+	fmt_cell.setAlignment(Qt::AlignHCenter);
 
 QColor color = settings->value("Output/Colors/Text", DEF_TEXT_COLOR).value<QColor>();
@@ -913,5 +966,5 @@
 		for (int c = 0; c < n; c++) {
 			cur = table->cellAt(r, c).firstCursorPosition();
-			cur.setBlockFormat(fmt_center);
+			cur.setBlockFormat(fmt_cell);
 			cur.setBlockCharFormat(fmt_default);
 			if (matrix.at(r).at(c) == INFINITY)
@@ -933,5 +986,5 @@
 		for (int c = 0; c < n; c++) {
 			cur = table->cellAt(r, c).firstCursorPosition();
-			cur.setBlockFormat(fmt_center);
+			cur.setBlockFormat(fmt_cell);
 			if (step.matrix.at(r).at(c) == INFINITY)
 				cur.insertText(INFSTR, fmt_default);
Index: trunk/src/mainwindow.h
===================================================================
--- trunk/src/mainwindow.h	(revision 105)
+++ trunk/src/mainwindow.h	(revision 106)
@@ -101,8 +101,11 @@
 #endif // Q_OS_WINCE_WM
 
+	// The solution graph SVG
+	QPicture graph;
+
 	// Formats
 	QTextTableFormat fmt_table;
 	QTextBlockFormat fmt_paragraph,
-		fmt_center;
+		fmt_cell;
 	QTextCharFormat fmt_default,
 		fmt_selected,
@@ -112,4 +115,5 @@
 	void closeEvent(QCloseEvent *ev);
 	void dragEnterEvent(QDragEnterEvent *ev);
+	void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL);
 	void dropEvent(QDropEvent *ev);
 	bool hasUpdater() const;
