Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/mainwindow.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -23,4 +23,60 @@
 
 #include "mainwindow.h"
+#include "settingsdialog.h"
+#include "tspmodel.h"
+
+#include <QBuffer>
+#include <QCloseEvent>
+#include <QDate>
+#include <QDesktopServices>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QImageWriter>
+#include <QLibraryInfo>
+#include <QMessageBox>
+#include <QPageSetupDialog>
+#include <QPainter>
+#include <QProgressBar>
+#include <QProgressDialog>
+#include <QSettings>
+#include <QStatusBar>
+#include <QStyleFactory>
+#include <QTextCodec>
+#include <QTextDocumentWriter>
+#include <QTextBrowser>
+#include <QTextStream>
+#include <QTextTable>
+#include <QTranslator>
+
+#ifdef Q_OS_WINCE_WM
+#   include <QScrollArea>
+#endif
+
+#ifndef QT_NO_PRINTER
+#   include <QPrinter>
+#   include <QPrintDialog>
+#   include <QPrintPreviewDialog>
+#endif
+
+#if !defined(NOSVG)
+#   include <QSvgGenerator>
+#endif // NOSVG
+
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+#   include <QtConcurrent>
+#endif
+
+#include "os.h"
+
+#ifndef HANDHELD
+#   include "qttoolbardialog.h"
+    // Eyecandy
+#   include "qtwin.h"
+#endif // HANDHELD
+
+#ifndef QT_NO_PRINTER
+    Q_DECLARE_METATYPE(QPrinter::PageSize)
+    Q_DECLARE_METATYPE(QPrinter::Orientation)
+#endif
 
 #ifdef Q_OS_WIN32
@@ -32,4 +88,33 @@
 _C_ _R_ _Y_ _P_ _T_
 #endif
+
+// BEGIN HELPER FUNCTIONS
+/*!
+ * \brief Checks whether \a x contains an integer value.
+ * \param x A value to check.
+ * \return \c true if \a x countains an integer, oherwise \c false.
+ */
+inline bool isInteger(double x)
+{
+double i;
+    return (modf(x, &i) == 0.0);
+}
+
+/*!
+ * \brief Converts \a in into Base64 format with lines wrapped at 64 characters.
+ * \param in A byte array to be converted.
+ * \return Converted byte array.
+ */
+inline QByteArray toWrappedBase64(const QByteArray &in)
+{
+    QByteArray out, base64(in.toBase64());
+    for (int i = 0; i <= base64.size() - 64; i += 64) {
+        out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n');
+    }
+    if (int rest = base64.size() % 64)
+        out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest));
+    return out;
+}
+// END HELPER FUNCTIONS
 
 /*!
@@ -571,5 +656,5 @@
 #endif
     about += tr("Build <b>%1</b>, built on <b>%2</b> at <b>%3</b>%5 with <b>%4</b> compiler.").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__).arg(COMPILER).arg(tag) + "<br>";
-    about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId());
+    about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), TSPSolver::CTSPSolver::getVersionId());
     about += "<br>";
     about += tr("This program is free software: you can redistribute it and/or modify<br>\n"
@@ -738,8 +823,8 @@
 void MainWindow::buttonSolveClicked()
 {
-TMatrix matrix;
-QList<double> row;
-int n = spinCities->value();
-bool ok;
+    TSPSolver::TMatrix matrix;
+    QList<double> row;
+    int n = spinCities->value();
+    bool ok;
     for (int r = 0; r < n; r++) {
         row.clear();
@@ -784,5 +869,5 @@
 #endif
 
-CTSPSolver solver;
+    TSPSolver::CTSPSolver solver;
     solver.setCleanupOnCancel(false);
     connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
@@ -792,5 +877,5 @@
         connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int)));
 #endif
-SStep *root = solver.solve(n, matrix);
+    TSPSolver::SStep *root = solver.solve(n, matrix);
 #ifdef Q_OS_WIN32
     if (tl != NULL)
@@ -821,5 +906,5 @@
 
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+        QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
         while (!f.isFinished()) {
             QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -899,12 +984,12 @@
     cur.insertHtml("<hr>");
     cur.insertBlock(fmt_paragraph);
-int imgpos = cur.position();
+    int imgpos = cur.position();
     cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
     cur.endEditBlock();
 
-SStep *step = root;
-int c = n = 1;
+    TSPSolver::SStep *step = root;
+    int c = n = 1;
     pb->setFormat(tr("Generating step %v"));
-    while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) {
+    while ((step->next != TSPSolver::SStep::NoNextStep) && (c < spinCities->value())) {
         if (pd.wasCanceled()) {
             pd.setLabelText(tr("Memory cleanup..."));
@@ -918,5 +1003,5 @@
 #endif
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+            QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
             while (!f.isFinished()) {
                 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -952,7 +1037,7 @@
         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);
+        cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == TSPSolver::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()) {
-            SStep::SCandidate cand;
+            TSPSolver::SStep::SCandidate cand;
             QString alts;
             foreach(cand, step->alts) {
@@ -974,8 +1059,8 @@
         n++;
 
-        if (step->next == SStep::RightBranch) {
+        if (step->next == TSPSolver::SStep::RightBranch) {
             c++;
             step = step->prNode;
-        } else if (step->next == SStep::LeftBranch) {
+        } else if (step->next == TSPSolver::SStep::LeftBranch) {
             step = step->plNode;
         } else
@@ -1052,5 +1137,5 @@
 #endif
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+    QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
     while (!f.isFinished()) {
         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -1211,5 +1296,5 @@
 }
 
-void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
+void MainWindow::drawNode(QPainter &pic, int nstep, bool left, TSPSolver::SStep *step)
 {
 qreal r; // Radius of graph node
@@ -1268,5 +1353,5 @@
         pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
     } else if (nstep > 1) {
-        pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
+        pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == TSPSolver::SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
     }
 
@@ -1563,5 +1648,5 @@
 }
 
-void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix)
+void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix)
 {
 int n = spinCities->value();
@@ -1583,5 +1668,5 @@
 }
 
-void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step)
+void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step)
 {
 int n = spinCities->value();
@@ -1597,5 +1682,5 @@
                 cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_selected);
             else {
-SStep::SCandidate cand;
+    TSPSolver::SStep::SCandidate cand;
                 cand.nRow = r;
                 cand.nCol = c;
