Index: trunk/src/defaults.h
===================================================================
--- trunk/src/defaults.h	(revision 161)
+++ trunk/src/defaults.h	(revision 162)
@@ -53,5 +53,5 @@
  * \brief Default for "Use translucency effects"
  */
-#ifdef Q_WS_WIN
+#ifdef Q_WS_WIN32
 #   define DEF_USE_TRANSLUCENCY true
 #else
@@ -78,10 +78,14 @@
 //////// OUTPUT
 
-//! Default for "Show solution graph"
-#define DEF_SHOW_GRAPH true
+//! Default for "Generate solution graph"
+#define DEF_GENERATE_GRAPH true
 //! Default for "Save solution graph as"
 #define DEF_GRAPH_IMAGE_FORMAT "png"
 //! Default for "Draw solution graph in higher quality"
 #define DEF_HQ_GRAPH false
+//! Default for "Embed solution graph into HTML"
+#define DEF_EMBED_GRAPH_INTO_HTML false
+//! Default solution graph size in centimeters (HQ size is this size * HQ_FACTOR)
+#define DEF_GRAPH_WIDTH 4.5
 //! Default for "Show solution steps' matrices for every solution step"
 #define DEF_SHOW_MATRIX true
Index: trunk/src/globals.h
===================================================================
--- trunk/src/globals.h	(revision 161)
+++ trunk/src/globals.h	(revision 162)
@@ -102,4 +102,9 @@
 #define INFSTR "---"
 
+//! Number of centimeters in 1 inch
+#define CM_IN_INCH 2.54
+//! Factor for high quality graph generation
+#define HQ_FACTOR 2
+
 // FUNCTIONS
 /*!
Index: trunk/src/mainwindow.cpp
===================================================================
--- trunk/src/mainwindow.cpp	(revision 161)
+++ trunk/src/mainwindow.cpp	(revision 162)
@@ -180,4 +180,5 @@
     tabWidget->setCurrentIndex(0);
     solutionText->clear();
+    graph = QPicture();
     toggleSolutionActions(false);
     QApplication::restoreOverrideCursor();
@@ -274,9 +275,8 @@
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 #ifndef QT_NO_PRINTER
-    if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) {
-QPrinter printer(QPrinter::HighResolution);
-        printer.setOutputFormat(QPrinter::PdfFormat);
-        printer.setOutputFileName(selectedFile);
-        solutionText->document()->print(&printer);
+    if (selectedFile.endsWith(".pdf", Qt::CaseInsensitive)) {
+        printer->setOutputFileName(selectedFile);
+        solutionText->document()->print(printer);
+        printer->setOutputFileName(QString());
         QApplication::restoreOverrideCursor();
         return;
@@ -293,16 +293,72 @@
 QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString();
 #if !defined(NOSVG)
-    if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) {
+        if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) {
 #else // NOSVG
-    if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) {
+        if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) {
 #endif // NOSVG
-        format = DEF_GRAPH_IMAGE_FORMAT;
-        settings->remove("Output/GraphImageFormat");
-    }
-QString html = solutionText->document()->toHtml("UTF-8"),
-        img =  fi.completeBaseName() + "." + format;
+            format = DEF_GRAPH_IMAGE_FORMAT;
+            settings->remove("Output/GraphImageFormat");
+        }
+QString html = solutionText->document()->toHtml("UTF-8");
+
         html.replace(QRegExp("font-family:([^;]*);"), "font-family:\\1, 'DejaVu Sans Mono', 'Courier New', Courier, monospace;");
-        html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph")));
-
+
+        if (!graph.isNull()) {
+            QString img =  fi.completeBaseName() + "." + format;
+            bool embed = settings->value("Output/EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool();
+            QByteArray data;
+            QBuffer buf(&data);
+            if (!embed) {
+                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph")));
+            }
+
+            // Saving solution graph in SVG or supported raster format (depending on settings and SVG support)
+#if !defined(NOSVG)
+            if (format == "svg") {
+                QSvgGenerator svg;
+                svg.setSize(QSize(graph.width() + 2, graph.height() + 2));
+                svg.setResolution(graph.logicalDpiX());
+                svg.setFileName(fi.path() + "/" + img);
+                svg.setTitle(tr("Solution Graph"));
+                svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName()));
+                QPainter p;
+                p.begin(&svg);
+                p.drawPicture(1, 1, graph);
+                p.end();
+            } else {
+#endif // NOSVG
+                QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
+                i.fill(0x00FFFFFF);
+                QPainter p;
+                p.begin(&i);
+                p.drawPicture(1, 1, graph);
+                p.end();
+                QImageWriter pic;
+                if (embed) {
+                    pic.setDevice(&buf);
+                    pic.setFormat(format.toAscii());
+                } else {
+                    pic.setFileName(fi.path() + "/" + img);
+                }
+                if (pic.supportsOption(QImageIOHandler::Description)) {
+                    pic.setText("Title", "Solution Graph");
+                    pic.setText("Software", QCoreApplication::applicationName());
+                }
+                if (format == "png")
+                    pic.setQuality(5);
+                else if (format == "jpeg")
+                    pic.setQuality(80);
+                if (!pic.write(i)) {
+                    QApplication::restoreOverrideCursor();
+                    QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));
+                    return;
+                }
+#if !defined(NOSVG)
+            }
+#endif // NOSVG
+            if (embed) {
+                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"data:image/%1;base64,%2\" alt=\"%3\"").arg(format, data.toBase64(), tr("Solution Graph")));
+            }
+        }
         // Saving solution text as HTML
 QTextStream ts(&file);
@@ -310,43 +366,4 @@
         ts << html;
         file.close();
-
-        // Saving solution graph as SVG or PNG (depending on settings and SVG support)
-#if !defined(NOSVG)
-        if (format == "svg") {
-QSvgGenerator svg;
-            svg.setSize(QSize(graph.width() + 2, graph.height() + 2));
-            svg.setResolution(graph.logicalDpiX());
-            svg.setFileName(fi.path() + "/" + img);
-            svg.setTitle(tr("Solution Graph"));
-            svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName()));
-QPainter p;
-            p.begin(&svg);
-            p.drawPicture(1, 1, graph);
-            p.end();
-        } else {
-#endif // NOSVG
-QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
-            i.fill(0x00FFFFFF);
-QPainter p;
-            p.begin(&i);
-            p.drawPicture(1, 1, graph);
-            p.end();
-QImageWriter pic(fi.path() + "/" + img);
-            if (pic.supportsOption(QImageIOHandler::Description)) {
-                pic.setText("Title", "Solution Graph");
-                pic.setText("Software", QCoreApplication::applicationName());
-            }
-            if (format == "png")
-                pic.setQuality(5);
-            else if (format == "jpeg")
-                pic.setQuality(80);
-            if (!pic.write(i)) {
-                QApplication::restoreOverrideCursor();
-                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));
-                return;
-            }
-#if !defined(NOSVG)
-        }
-#endif // NOSVG
     } else {
 QTextDocumentWriter dw(selectedFile);
@@ -743,5 +760,4 @@
             tl = NULL;
         } else {
-//			tl->SetProgressState(winId(), TBPF_INDETERMINATE);
             tl->SetProgressValue(winId(), 0, n * 2);
         }
@@ -769,5 +785,4 @@
 #ifdef Q_WS_WIN32
             if (tl != NULL) {
-//				tl->SetProgressValue(winId(), n, n * 2);
                 tl->SetProgressState(winId(), TBPF_ERROR);
             }
@@ -818,13 +833,16 @@
 
 QPainter pic;
-    if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
+bool dograph = settings->value("Output/GenerateGraph", DEF_GENERATE_GRAPH).toBool();
+    if (dograph) {
         pic.begin(&graph);
         pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
 QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE)));
-        //! \todo FIXME: Get rid of the "magic number" in the code.
-        font.setPixelSize(logicalDpiX() / 7);
+        font.setStyleHint(QFont::Monospace);
+        // Font size in pixels = graph node radius / 2.75.
+        // See MainWindow::drawNode() for graph node radius calcualtion description.
+        font.setPixelSize(logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5 / 2.75);
         if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
             font.setWeight(QFont::DemiBold);
-            font.setPixelSize(font.pixelSize() * 2);
+            font.setPixelSize(font.pixelSize() * HQ_FACTOR);
         }
         pic.setFont(font);
@@ -832,8 +850,10 @@
         if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
 QPen pen = pic.pen();
-            pen.setWidth(2);
+            pen.setWidth(HQ_FACTOR);
             pic.setPen(pen);
         }
         pic.setBackgroundMode(Qt::OpaqueMode);
+    } else {
+        graph = QPicture();
     }
 
@@ -847,5 +867,5 @@
     cur.insertText(tr("Task:"), fmt_default);
     outputMatrix(cur, matrix);
-    if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
+    if (dograph) {
 #ifdef _T_T_L_
         _b_ _i_ _z_ _a_ _r_ _r_ _e_
@@ -904,5 +924,8 @@
             outputMatrix(cur, *step);
         }
-        cur.insertBlock(fmt_paragraph);
+        if (step->alts.empty())
+            cur.insertBlock(fmt_lastparagraph);
+        else
+            cur.insertBlock(fmt_paragraph);
         cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
         if (!step->alts.empty()) {
@@ -914,12 +937,10 @@
                 alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
             }
-            cur.insertBlock(fmt_paragraph);
+            cur.insertBlock(fmt_lastparagraph);
             cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist);
         }
-        cur.insertBlock(fmt_paragraph);
-        cur.insertText(" ", fmt_default);
         cur.endEditBlock();
 
-        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
+        if (dograph) {
             if (step->prNode != NULL)
                 drawNode(pic, n, false, step->prNode);
@@ -947,12 +968,15 @@
     cur.insertBlock(fmt_paragraph);
     if (solver.isOptimal())
-        cur.insertText(tr("Optimal path:"));
+        cur.insertText(tr("Optimal path:"), fmt_default);
     else
-        cur.insertText(tr("Resulting path:"));
+        cur.insertText(tr("Resulting path:"), fmt_default);
 
     cur.insertBlock(fmt_paragraph);
     cur.insertText("  " + solver.getSortedPath(tr("City %1")));
 
-    cur.insertBlock(fmt_paragraph);
+    if (solver.isOptimal())
+        cur.insertBlock(fmt_paragraph);
+    else
+        cur.insertBlock(fmt_lastparagraph);
     if (isInteger(step->price))
         cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>");
@@ -961,11 +985,9 @@
     if (!solver.isOptimal()) {
         cur.insertBlock(fmt_paragraph);
-        cur.insertText(" ");
-        cur.insertBlock(fmt_paragraph);
         cur.insertHtml("<p>" + tr("<b>WARNING!!!</b><br>This result is a record, but it may not be optimal.<br>Iterations need to be continued to check whether this result is optimal or get an optimal one.") + "</p>");
     }
     cur.endEditBlock();
 
-    if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
+    if (dograph) {
         pic.end();
 
@@ -980,6 +1002,6 @@
         img.setName("tspsg://graph.pic");
         if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
-            img.setWidth(i.width() / 2);
-            img.setHeight(i.height() / 2);
+            img.setWidth(i.width() / HQ_FACTOR);
+            img.setHeight(i.height() / HQ_FACTOR);
         } else {
             img.setWidth(i.width());
@@ -1167,10 +1189,12 @@
 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
 {
-qreal r;
-    //! \todo FIXME: Get rid of the "magic numbers" in the code.
+qreal r; // Radius of graph node
+    // We calculate r from the full graph width in centimeters:
+    //   r = width in pixels / 4.5.
+    //   width in pixels = DPI * width in inches.
+    //   width in inches = width in cm / cm in inch.
+    r = logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5;
     if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool())
-        r = logicalDpiX() / 1.27;
-    else
-        r = logicalDpiX() / 2.54;
+        r *= HQ_FACTOR;
 #ifdef Q_WS_S60
     /*! \hack HACK: Solution graph on Symbian is visually larger than on
@@ -1247,4 +1271,9 @@
     fmt_paragraph.setBottomMargin(0);
     fmt_paragraph.setLeftMargin(10);
+
+    fmt_lastparagraph.setTopMargin(5);
+    fmt_lastparagraph.setRightMargin(10);
+    fmt_lastparagraph.setBottomMargin(15);
+    fmt_lastparagraph.setLeftMargin(10);
 
     fmt_table.setTopMargin(5);
Index: trunk/src/mainwindow.h
===================================================================
--- trunk/src/mainwindow.h	(revision 161)
+++ trunk/src/mainwindow.h	(revision 162)
@@ -133,4 +133,5 @@
     QTextTableFormat fmt_table;
     QTextBlockFormat fmt_paragraph,
+        fmt_lastparagraph,
         fmt_cell;
     QTextCharFormat fmt_default,
Index: trunk/src/settingsdialog.cpp
===================================================================
--- trunk/src/settingsdialog.cpp	(revision 161)
+++ trunk/src/settingsdialog.cpp	(revision 162)
@@ -76,6 +76,6 @@
     hbox->addSpacing(10);
     hbox->addWidget(cbHQGraph);
-    box->insertLayout(box->indexOf(cbShowGraph) + 1, hbox);
-    connect(cbShowGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
+    box->insertLayout(box->indexOf(cbGenerateGraph) + 2, hbox);
+    connect(cbGenerateGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
 #endif
 
@@ -147,5 +147,5 @@
         cbUseTranslucency->setObjectName("cbUseTranslucency");
 #ifndef QT_NO_STATUSTIP
-        cbUseTranslucency->setStatusTip(tr("Use translucent effect on the Main Window under Windows Vista and 7"));
+        cbUseTranslucency->setStatusTip(tr("Make Main Window background translucent"));
 #endif // QT_NO_STATUSTIP
         cbUseTranslucency->setText(tr("Use translucency effects"));
@@ -174,7 +174,6 @@
     labelHint->setObjectName("labelHint");
     labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
-//	labelHint->setMinimumSize(QSize(190,28));
-    labelHint->setMinimumSize(QSize(0,28));
-    labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
+    labelHint->setMinimumSize(QSize(250, 28));
+    labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX, 28));
     labelHint->setTextFormat(Qt::PlainText);
 //	labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
@@ -260,9 +259,9 @@
 
     settings->beginGroup("Output");
-    cbShowGraph->setChecked(settings->value("ShowGraph", DEF_SHOW_GRAPH).toBool());
+    cbGenerateGraph->setChecked(settings->value("GenerateGraph", DEF_GENERATE_GRAPH).toBool());
 
 #ifndef QT_NO_PRINTER
-    cbHQGraph->setEnabled(cbShowGraph->isChecked());
-    cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH && cbShowGraph->isChecked()).toBool());
+    cbHQGraph->setEnabled(cbGenerateGraph->isChecked());
+    cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH).toBool());
 #endif
 
@@ -283,6 +282,8 @@
     if (comboGraphImageFormat->currentIndex() < 0)
         comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString));
-    labelGraphImageFormat->setEnabled(cbShowGraph->isChecked());
-    comboGraphImageFormat->setEnabled(cbShowGraph->isChecked());
+    labelGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
+    comboGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
+    cbEmbedGraphIntoHTML->setChecked(settings->value("EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool());
+    cbEmbedGraphIntoHTML->setEnabled(cbGenerateGraph->isChecked());
 
     cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
@@ -326,5 +327,5 @@
  * \brief Indicates whether and how the translucency setting was changed
  * \retval -1 the translucency was \em disabled.
- * \retval  0 the translucency was <em>not changed</em>.
+ * \retval  0 the translucency <em>didn't change</em>.
  * \retval  1 the translucency was \em enabled.
  */
@@ -381,13 +382,16 @@
 
     settings->beginGroup("Output");
-    settings->setValue("ShowGraph", cbShowGraph->isChecked());
+    settings->setValue("GenerateGraph", cbGenerateGraph->isChecked());
+    if (cbGenerateGraph->isChecked()) {
 #ifndef QT_NO_PRINTER
-    settings->setValue("HQGraph", cbShowGraph->isChecked() && cbHQGraph->isChecked());
+        settings->setValue("HQGraph", cbHQGraph->isChecked());
 #endif
-    if (cbShowGraph->isChecked()) {
-        if (comboGraphImageFormat->currentIndex() >= 0)
-            settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
-        else
-            settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
+        if (cbGenerateGraph->isChecked()) {
+            if (comboGraphImageFormat->currentIndex() >= 0)
+                settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
+            else
+                settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
+        }
+        settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked());
     }
     settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
