source: tspsg/src/mainwindow.cpp @ 7373d6357f

Last change on this file since 7373d6357f was 468fa8e7e5, checked in by Oleksii Serdiuk, 9 years ago

Fix compilation errors when C++11 is enabled

  • Property mode set to 100644
File size: 82.1 KB
RevLine 
[1babbd6ba3]1/*
2 *  TSPSG: TSP Solver and Generator
[b9167cec6d]3 *  Copyright (C) 2007-2016 Oleksii Serdiuk <contacts[at]oleksii[dot]name>
[1babbd6ba3]4 *
[7ba743d983]5 *  $Id: $Format:%h %ai %an$ $
6 *  $URL: http://tspsg.info/ $
[1babbd6ba3]7 *
8 *  This file is part of TSPSG.
9 *
10 *  TSPSG is free software: you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
[2940c14782]12 *  the Free Software Foundation, either version 2 of the License, or
[1babbd6ba3]13 *  (at your option) any later version.
14 *
15 *  TSPSG is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License
21 *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "mainwindow.h"
[07e43cf61a]25#include "settingsdialog.h"
26#include "tspmodel.h"
27
28#include <QBuffer>
29#include <QCloseEvent>
30#include <QDate>
31#include <QDesktopServices>
32#include <QDesktopWidget>
33#include <QFileDialog>
34#include <QImageWriter>
35#include <QLibraryInfo>
36#include <QMessageBox>
37#include <QPageSetupDialog>
38#include <QPainter>
39#include <QProgressBar>
40#include <QProgressDialog>
41#include <QSettings>
42#include <QStatusBar>
43#include <QStyleFactory>
44#include <QTextCodec>
45#include <QTextDocumentWriter>
46#include <QTextBrowser>
47#include <QTextStream>
48#include <QTextTable>
49#include <QTranslator>
50
51#ifdef Q_OS_WINCE_WM
52#   include <QScrollArea>
53#endif
54
55#ifndef QT_NO_PRINTER
56#   include <QPrinter>
57#   include <QPrintDialog>
58#   include <QPrintPreviewDialog>
59#endif
60
61#if !defined(NOSVG)
62#   include <QSvgGenerator>
63#endif // NOSVG
64
[1241232377]65#include <QtConcurrentRun>
[07e43cf61a]66
67#include "os.h"
68
69#ifndef HANDHELD
70#   include "qttoolbardialog.h"
71    // Eyecandy
72#   include "qtwin.h"
73#endif // HANDHELD
74
75#ifndef QT_NO_PRINTER
76    Q_DECLARE_METATYPE(QPrinter::PageSize)
77    Q_DECLARE_METATYPE(QPrinter::Orientation)
78#endif
[1babbd6ba3]79
[89e5214692]80#ifdef Q_OS_WIN32
[a7998257bc]81#   include <initguid.h>
[b8a2a118c4]82#   include "shobjidl.h"
[43c29c04ba]83#endif
84
[2a5e50e0a9]85#ifdef Q_OS_BLACKBERRY
86#   include <bb/ApplicationSupport>
87#   include <bb/cascades/pickers/FilePicker>
88using namespace bb::cascades::pickers;
89#endif
90
[3cadf24d00]91#ifdef _T_T_L_
92#include "_.h"
[e9db3e216b]93_C_ _R_ _Y_ _P_ _T_
[3cadf24d00]94#endif
95
[07e43cf61a]96// BEGIN HELPER FUNCTIONS
97/*!
98 * \brief Checks whether \a x contains an integer value.
99 * \param x A value to check.
100 * \return \c true if \a x countains an integer, oherwise \c false.
101 */
102inline bool isInteger(double x)
103{
104double i;
[1241232377]105#ifdef Q_OS_BLACKBERRY
106    return (std::modf(x, &i) == 0.0);
107#else
[07e43cf61a]108    return (modf(x, &i) == 0.0);
[1241232377]109#endif
[07e43cf61a]110}
111
112/*!
113 * \brief Converts \a in into Base64 format with lines wrapped at 64 characters.
114 * \param in A byte array to be converted.
115 * \return Converted byte array.
116 */
117inline QByteArray toWrappedBase64(const QByteArray &in)
118{
119    QByteArray out, base64(in.toBase64());
120    for (int i = 0; i <= base64.size() - 64; i += 64) {
121        out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n');
122    }
123    if (int rest = base64.size() % 64)
124        out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest));
125    return out;
126}
127// END HELPER FUNCTIONS
128
[1babbd6ba3]129/*!
130 * \brief Class constructor.
131 * \param parent Main Window parent widget.
132 *
133 *  Initializes Main Window and creates its layout based on target OS.
134 *  Loads TSPSG settings and opens a task file if it was specified as a commandline parameter.
135 */
136MainWindow::MainWindow(QWidget *parent)
[9eb63a1598]137    : QMainWindow(parent)
[1babbd6ba3]138{
[31694c8b58]139    settings = initSettings(this);
[1babbd6ba3]140
[47c811cc09]141    // Sanity check
142    int m = settings->value("Tweaks/MaxNumCities", MAX_NUM_CITIES).toInt();
143    if (m < 3)
144        settings->setValue("Tweaks/MaxNumCities", 3);
145
[9eb63a1598]146    if (settings->contains("Style")) {
[e3533af1cf]147QStyle *s = QStyleFactory::create(settings->value("Style").toString());
[9eb63a1598]148        if (s != NULL)
149            QApplication::setStyle(s);
150        else
151            settings->remove("Style");
152    }
[e3533af1cf]153
[9eb63a1598]154    loadLanguage();
155    setupUi();
156    setAcceptDrops(true);
[1babbd6ba3]157
[7ed8b57eea]158#ifdef Q_OS_BLACKBERRY
159    taskView->setEditTriggers(QAbstractItemView::AllEditTriggers);
160#endif
161
[9eb63a1598]162    initDocStyleSheet();
[1babbd6ba3]163
164#ifndef QT_NO_PRINTER
[9eb63a1598]165    printer = new QPrinter(QPrinter::HighResolution);
[a885c3d9d2]166    settings->beginGroup("Printer");
[20e8115cee]167QPrinter::PaperSize size = qvariant_cast<QPrinter::PaperSize>(settings->value("PaperSize", DEF_PAGE_SIZE));
168    if (size != QPrinter::Custom) {
169        printer->setPaperSize(size);
170    } else {
171        printer->setPaperSize(QSizeF(settings->value("PaperWidth").toReal(), settings->value("PaperHeight").toReal()),
172                              QPrinter::Millimeter);
173    }
174
[a885c3d9d2]175    printer->setOrientation(qvariant_cast<QPrinter::Orientation>(settings->value("PageOrientation", DEF_PAGE_ORIENTATION)));
176    printer->setPageMargins(
[20e8115cee]177        settings->value("MarginLeft", DEF_MARGIN_LEFT).toReal(),
178        settings->value("MarginTop", DEF_MARGIN_TOP).toReal(),
179        settings->value("MarginRight", DEF_MARGIN_RIGHT).toReal(),
180        settings->value("MarginBottom", DEF_MARGIN_BOTTOM).toReal(),
[a885c3d9d2]181        QPrinter::Millimeter);
182    settings->endGroup();
[1babbd6ba3]183#endif // QT_NO_PRINTER
184
[89e5214692]185#ifdef Q_OS_WINCE_WM
[9eb63a1598]186    currentGeometry = QApplication::desktop()->availableGeometry(0);
187    // We need to react to SIP show/hide and resize the window appropriately
188    connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
[89e5214692]189#endif // Q_OS_WINCE_WM
[9eb63a1598]190    connect(actionFileNew, SIGNAL(triggered()), SLOT(actionFileNewTriggered()));
191    connect(actionFileOpen, SIGNAL(triggered()), SLOT(actionFileOpenTriggered()));
192    connect(actionFileSave, SIGNAL(triggered()), SLOT(actionFileSaveTriggered()));
193    connect(actionFileSaveAsTask, SIGNAL(triggered()), SLOT(actionFileSaveAsTaskTriggered()));
194    connect(actionFileSaveAsSolution, SIGNAL(triggered()), SLOT(actionFileSaveAsSolutionTriggered()));
[7ed8b57eea]195#ifndef QT_NO_PRINTDIALOG
[9eb63a1598]196    connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered()));
[20e8115cee]197    connect(actionFilePageSetup, SIGNAL(triggered()), SLOT(actionFilePageSetupTriggered()));
[9eb63a1598]198    connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered()));
[1babbd6ba3]199#endif // QT_NO_PRINTER
[7bb19df196]200#ifndef HANDHELD
[9eb63a1598]201    connect(actionSettingsToolbarsConfigure, SIGNAL(triggered()), SLOT(actionSettingsToolbarsConfigureTriggered()));
[7bb19df196]202#endif // HANDHELD
[9eb63a1598]203    connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered()));
204    if (actionHelpCheck4Updates != NULL)
205        connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered()));
206    connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
207    connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *)));
208    connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool)));
209    connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*)));
210    connect(actionHelpOnlineSupport, SIGNAL(triggered()), SLOT(actionHelpOnlineSupportTriggered()));
211    connect(actionHelpReportBug, SIGNAL(triggered()), SLOT(actionHelpReportBugTriggered()));
212    connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
213    connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered()));
214
215    connect(buttonSolve, SIGNAL(clicked()), SLOT(buttonSolveClicked()));
216    connect(buttonRandom, SIGNAL(clicked()), SLOT(buttonRandomClicked()));
217    connect(buttonBackToTask, SIGNAL(clicked()), SLOT(buttonBackToTaskClicked()));
218    connect(spinCities, SIGNAL(valueChanged(int)), SLOT(spinCitiesValueChanged(int)));
[1babbd6ba3]219
220#ifndef HANDHELD
[9eb63a1598]221    // Centering main window
[1babbd6ba3]222QRect rect = geometry();
[9eb63a1598]223    rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
224    setGeometry(rect);
225    if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
226        // Loading of saved window state
227        settings->beginGroup("MainWindow");
228        restoreGeometry(settings->value("Geometry").toByteArray());
229        restoreState(settings->value("State").toByteArray());
230        settings->endGroup();
231    }
[1babbd6ba3]232#endif // HANDHELD
233
[9eb63a1598]234    tspmodel = new CTSPModel(this);
235    taskView->setModel(tspmodel);
236    connect(tspmodel, SIGNAL(numCitiesChanged(int)), SLOT(numCitiesChanged(int)));
237    connect(tspmodel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
238    connect(tspmodel, SIGNAL(layoutChanged()), SLOT(dataChanged()));
239    if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
240        setFileName(QCoreApplication::arguments().at(1));
241    else {
242        setFileName();
243        spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
244        spinCitiesValueChanged(spinCities->value());
245    }
246    setWindowModified(false);
247
248    if (actionHelpCheck4Updates != NULL) {
249        if (!settings->contains("Check4Updates/Enabled")) {
250            QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
251            settings->setValue("Check4Updates/Enabled",
252                QMessageBox::question(this, QCoreApplication::applicationName(),
253                    tr("Would you like %1 to automatically check for updates every %n day(s)?", "", settings->value("Check4Updates/Interval", DEF_UPDATE_CHECK_INTERVAL).toInt()).arg(QCoreApplication::applicationName()),
254                    QMessageBox::Yes | QMessageBox::No
255                ) == QMessageBox::Yes
256            );
257            QApplication::restoreOverrideCursor();
258        }
259        if ((settings->value("Check4Updates/Enabled", DEF_CHECK_FOR_UPDATES).toBool())
260            && (QDate(qvariant_cast<QDate>(settings->value("Check4Updates/LastAttempt"))).daysTo(QDate::currentDate()) >= settings->value("Check4Updates/Interval", DEF_UPDATE_CHECK_INTERVAL).toInt())) {
261            check4Updates(true);
262        }
263    }
[1babbd6ba3]264}
265
266MainWindow::~MainWindow()
267{
268#ifndef QT_NO_PRINTER
[9eb63a1598]269    delete printer;
[1babbd6ba3]270#endif
271}
272
[2a5e50e0a9]273#ifdef Q_OS_BLACKBERRY
274void MainWindow::setWindowModified(bool modified)
275{
276    QMainWindow::setWindowModified(modified);
277    bb::ApplicationSupport app;
278    if (modified)
279        app.setClosePrompt(tr("Unsaved Changes"), tr("The task has unsaved changes. Would you really like to close the application?"));
280    else
281        app.clearClosePrompt();
282}
283#endif
284
[1babbd6ba3]285/* Privates **********************************************************/
286
287void MainWindow::actionFileNewTriggered()
288{
[9eb63a1598]289    if (!maybeSave())
290        return;
291    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
292    tspmodel->clear();
293    setFileName();
294    setWindowModified(false);
295    tabWidget->setCurrentIndex(0);
296    solutionText->clear();
[8f2427aaf0]297    graph = QPicture();
[9eb63a1598]298    toggleSolutionActions(false);
299    QApplication::restoreOverrideCursor();
[1babbd6ba3]300}
301
302void MainWindow::actionFileOpenTriggered()
303{
[9eb63a1598]304    if (!maybeSave())
305        return;
[1babbd6ba3]306
[2a5e50e0a9]307    QStringList filters;
308#ifdef Q_OS_BLACKBERRY
309    filters << "*.tspt" << "*.zkt";
310#else
311    filters.append(tr("All Supported Formats") + " (*.tspt *.zkt)");
[9eb63a1598]312    filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)");
313    filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
314    filters.append(tr("All Files") + " (*)");
[2a5e50e0a9]315#endif
[1babbd6ba3]316
[ac76a6a753]317QString file;
[9eb63a1598]318    if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
[2a5e50e0a9]319#ifdef Q_OS_BLACKBERRY
320        file = settings->value(OS"/LastUsed/TaskLoadPath", "/accounts/1000/shared/documents").toString();
321#else
[9eb63a1598]322        file = settings->value(OS"/LastUsed/TaskLoadPath").toString();
[2a5e50e0a9]323#endif
[9eb63a1598]324    else
325        file = QFileInfo(fileName).path();
[2a5e50e0a9]326#ifdef Q_OS_BLACKBERRY
327    FilePicker fd;
328    fd.setType(FileType::Document | FileType::Other);
329    fd.setDefaultType(FileType::Document);
330    fd.setTitle(tr("Task Load"));
331    fd.setFilter(filters);
332    fd.setDirectories(QStringList(file));
333    fd.open();
334
335    QEventLoop loop;
336    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
337    loop.exec();
338
339    if (fd.selectedFiles().count() < 1)
340        return;
341    file = fd.selectedFiles().at(0);
342    if (!QFileInfo(file).isFile())
343        return;
344#else
345    QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
[9eb63a1598]346    file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts);
347    if (file.isEmpty() || !QFileInfo(file).isFile())
348        return;
[2a5e50e0a9]349#endif
[9eb63a1598]350    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
351        settings->setValue(OS"/LastUsed/TaskLoadPath", QFileInfo(file).path());
352
353    if (!tspmodel->loadTask(file))
354        return;
355    setFileName(file);
356    tabWidget->setCurrentIndex(0);
357    setWindowModified(false);
358    solutionText->clear();
359    toggleSolutionActions(false);
[1babbd6ba3]360}
361
362bool MainWindow::actionFileSaveTriggered()
363{
[9eb63a1598]364    if ((fileName == tr("Untitled") + ".tspt") || !fileName.endsWith(".tspt", Qt::CaseInsensitive))
365        return saveTask();
366    else
367        if (tspmodel->saveTask(fileName)) {
368            setWindowModified(false);
369            return true;
370        } else
371            return false;
[1babbd6ba3]372}
373
374void MainWindow::actionFileSaveAsTaskTriggered()
375{
[9eb63a1598]376    saveTask();
[1babbd6ba3]377}
378
379void MainWindow::actionFileSaveAsSolutionTriggered()
380{
381static QString selectedFile;
[9eb63a1598]382    if (selectedFile.isEmpty()) {
383        if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) {
[2a5e50e0a9]384#ifdef Q_OS_BLACKBERRY
385            selectedFile = settings->value(OS"/LastUsed/SolutionSavePath", "/accounts/1000/shared/documents").toString();
386#else
[9eb63a1598]387            selectedFile = settings->value(OS"/LastUsed/SolutionSavePath").toString();
[2a5e50e0a9]388#endif
[9eb63a1598]389        }
390    } else
391        selectedFile = QFileInfo(selectedFile).path();
392    if (!selectedFile.isEmpty())
393        selectedFile.append("/");
394    if (fileName == tr("Untitled") + ".tspt") {
[1babbd6ba3]395#ifndef QT_NO_PRINTER
[9eb63a1598]396        selectedFile += "solution.pdf";
[1babbd6ba3]397#else
[9eb63a1598]398        selectedFile += "solution.html";
[1babbd6ba3]399#endif // QT_NO_PRINTER
[9eb63a1598]400    } else {
[1babbd6ba3]401#ifndef QT_NO_PRINTER
[9eb63a1598]402        selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf";
[1babbd6ba3]403#else
[9eb63a1598]404        selectedFile += QFileInfo(fileName).completeBaseName() + ".html";
[1babbd6ba3]405#endif // QT_NO_PRINTER
[9eb63a1598]406    }
[1babbd6ba3]407
408QStringList filters;
[2a5e50e0a9]409#ifdef Q_OS_BLACKBERRY
410    filters << "*.pdf" << "*.html" << "*.htm" << "*.odf";
411#else
[1babbd6ba3]412#ifndef QT_NO_PRINTER
[9eb63a1598]413    filters.append(tr("PDF Files") + " (*.pdf)");
[1babbd6ba3]414#endif
[9eb63a1598]415    filters.append(tr("HTML Files") + " (*.html *.htm)");
[f48433245d]416    filters.append(tr("Web Archive Files") + " (*.mht *.mhtml)");
[9eb63a1598]417    filters.append(tr("OpenDocument Files") + " (*.odt)");
418    filters.append(tr("All Files") + " (*)");
[2a5e50e0a9]419#endif
[1babbd6ba3]420
[2a5e50e0a9]421#ifdef Q_OS_BLACKBERRY
422    FilePicker fd;
423    fd.setMode(FilePickerMode::Saver);
424    fd.setType(FileType::Document | FileType::Other);
425    fd.setDefaultType(FileType::Document);
426    fd.setAllowOverwrite(true);
427    fd.setTitle(tr("Solution Save"));
428//    fd.setDirectories(QStringList(QFileInfo(selectedFile).path()));
429    fd.setDefaultSaveFileNames(QStringList(selectedFile));
430    fd.setFilter(filters);
431    fd.open();
432
433    QEventLoop loop;
434    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
435    loop.exec();
436
437    if (fd.selectedFiles().count() < 1)
438        return;
439    selectedFile = fd.selectedFiles().at(0);
440#else
441    QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog);
442    QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts);
[9eb63a1598]443    if (file.isEmpty())
444        return;
445    selectedFile = file;
[2a5e50e0a9]446#endif
[9eb63a1598]447    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
448        settings->setValue(OS"/LastUsed/SolutionSavePath", QFileInfo(selectedFile).path());
449    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[1babbd6ba3]450#ifndef QT_NO_PRINTER
[8f2427aaf0]451    if (selectedFile.endsWith(".pdf", Qt::CaseInsensitive)) {
452        printer->setOutputFileName(selectedFile);
453        solutionText->document()->print(printer);
454        printer->setOutputFileName(QString());
[9eb63a1598]455        QApplication::restoreOverrideCursor();
456        return;
457    }
[1babbd6ba3]458#endif
[b26dc16dcf]459    QByteArray imgdata;
[f48433245d]460    bool mhtml = selectedFile.contains(QRegExp("\\.mht(ml)?$", Qt::CaseInsensitive));
461    bool embed = !mhtml && settings->value("Output/EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool();
462    if (selectedFile.contains(QRegExp("\\.(html?|mht(ml)?)$", Qt::CaseInsensitive))) {
[b26dc16dcf]463        QFile file(selectedFile);
464        if (!file.open(QFile::WriteOnly | QFile::Text)) {
[9eb63a1598]465            QApplication::restoreOverrideCursor();
466            QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString()));
467            return;
468        }
[b26dc16dcf]469
470        QString html = solutionText->document()->toHtml("UTF-8");
471        html.replace(QRegExp("font-family:([^;]*);"),
472                     "font-family:\\1, 'DejaVu Sans Mono', 'Courier New', Courier, monospace;");
473        html.replace(QRegExp("<style ([^>]*)>"), QString("<style \\1>\n"
474                                                         "body { color: %1 }\n"
475                                                         "td { border-style: solid; border-width: 1px; border-color: %2; }")
476                     .arg(settings->value("Output/Colors/Font", DEF_TEXT_COLOR).toString(),
477                          settings->value("Output/Colors/TableBorder", DEF_TABLE_COLOR).toString()));
478
479        QFileInfo fi(selectedFile);
480        QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString();
[2a436ea693]481#if !defined(NOSVG)
[7a39458d16]482        if (!QImageWriter::supportedImageFormats().contains(format.toLatin1()) && (format != "svg")) {
[2a436ea693]483#else // NOSVG
[7a39458d16]484        if (!QImageWriter::supportedImageFormats().contains(format.toLatin1())) {
[2a436ea693]485#endif // NOSVG
[8f2427aaf0]486            format = DEF_GRAPH_IMAGE_FORMAT;
487            settings->remove("Output/GraphImageFormat");
488        }
[20015b41e7]489
[8f2427aaf0]490        if (!graph.isNull()) {
[b26dc16dcf]491            imgdata = generateImage(format);
492            if (imgdata.isEmpty()) {
[b96b44b6b7]493                QApplication::restoreOverrideCursor();
[b26dc16dcf]494                return;
[9eb63a1598]495            }
[8f2427aaf0]496            if (embed) {
[b26dc16dcf]497                QString fmt = format;
498                if (format == "svg")
499                    fmt.append("+xml");
500                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""),
501                             QString("<img src=\"data:image/%1;base64,%2\" alt=\"%3\"")
502                             .arg(fmt, toWrappedBase64(imgdata), tr("Solution Graph")));
503            } else {
504                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""),
505                             QString("<img src=\"%1\" alt=\"%2\"")
506                             .arg(fi.completeBaseName() + "." + format, tr("Solution Graph")));
[9eb63a1598]507            }
508        }
[b26dc16dcf]509
[8f2427aaf0]510        // Saving solution text as HTML
511QTextStream ts(&file);
512        ts.setCodec(QTextCodec::codecForName("UTF-8"));
[f48433245d]513        QString boundary = QString("------=multipart_boundary.%1").arg(qHash(selectedFile));
514        if (mhtml) {
515            ts << "Content-Type: multipart/related; start=<[email protected]>; boundary=\""
516               << boundary << "\"; type=\"text/html\"" << endl;
517            boundary.prepend("--");
518            ts << "MIME-Version: 1.0" << endl;
519            ts << endl;
520            ts << boundary << endl;
521            ts << "Content-Disposition: inline; filename=" << fi.completeBaseName() << ".html" << endl;
522            ts << "Content-Type: text/html; name=" << fi.completeBaseName() << ".html" << endl;
523            ts << "Content-ID: <[email protected]>" << endl;
524            ts << "Content-Location: " << fi.completeBaseName() << ".html" << endl;
525            ts << "Content-Transfer-Encoding: 8bit" << endl;
526            ts << endl;
527        }
[b26dc16dcf]528        ts << html << endl;
[f48433245d]529        if (mhtml) {
530            ts << endl << boundary << endl;
531            ts << "Content-Disposition: inline; filename=" << fi.completeBaseName() << "." << format << endl;
532            ts << "Content-Type: image/" << format;
533            if (format == "svg")
534                ts << "+xml";
535            ts << "; name=" << fi.completeBaseName() << "." << format  << endl;
536            ts << "Content-Location: " << fi.completeBaseName() << "." << format << endl;
537            ts << "Content-Transfer-Encoding: Base64" << endl;
538            ts << endl;
539            ts << toWrappedBase64(imgdata) << endl;
540            ts << endl << boundary << "--" << endl;
541        }
[8f2427aaf0]542        file.close();
[f48433245d]543        if (!embed && !mhtml) {
[b26dc16dcf]544            QFile img(fi.path() + "/" + fi.completeBaseName() + "." + format);
545            if (!img.open(QFile::WriteOnly)) {
546                QApplication::restoreOverrideCursor();
547                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(img.errorString()));
548                return;
549            }
550            if (img.write(imgdata) != imgdata.size()) {
551                QApplication::restoreOverrideCursor();
552                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(img.errorString()));
553            }
554            img.close();
555        }
[9eb63a1598]556    } else {
[ca3d2a30fa]557QTextDocumentWriter dw(selectedFile);
[9eb63a1598]558        if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive))
559            dw.setFormat("plaintext");
560        if (!dw.write(solutionText->document()))
561            QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString()));
562    }
563    QApplication::restoreOverrideCursor();
[1babbd6ba3]564}
565
[7ed8b57eea]566#ifndef QT_NO_PRINTDIALOG
[1babbd6ba3]567void MainWindow::actionFilePrintPreviewTriggered()
568{
569QPrintPreviewDialog ppd(printer, this);
[9eb63a1598]570    connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
571    ppd.exec();
[144fbe6b96]572
573qreal l, t, r, b;
574    printer->getPageMargins(&l, &t, &r, &b, QPrinter::Millimeter);
575
[a885c3d9d2]576    settings->beginGroup("Printer");
[144fbe6b96]577    settings->setValue("PaperSize", printer->paperSize());
[20e8115cee]578    if (printer->paperSize() == QPrinter::Custom) {
579QSizeF size(printer->paperSize(QPrinter::Millimeter));
580        settings->setValue("PaperWidth", size.width());
581        settings->setValue("PaperHeight", size.height());
582    }
583    settings->setValue("PageOrientation", printer->orientation());
584    settings->setValue("MarginLeft", l);
585    settings->setValue("MarginTop", t);
586    settings->setValue("MarginRight", r);
587    settings->setValue("MarginBottom", b);
588    settings->endGroup();
589}
590
591void MainWindow::actionFilePageSetupTriggered()
592{
593QPageSetupDialog psd(printer, this);
594    if (psd.exec() != QDialog::Accepted)
595        return;
596
597qreal l, t, r ,b;
598    printer->getPageMargins(&l, &t, &r, &b, QPrinter::Millimeter);
599
600    settings->beginGroup("Printer");
601    settings->setValue("PaperSize", printer->paperSize());
602    if (printer->paperSize() == QPrinter::Custom) {
603QSizeF size(printer->paperSize(QPrinter::Millimeter));
604        settings->setValue("PaperWidth", size.width());
605        settings->setValue("PaperHeight", size.height());
606    }
[a885c3d9d2]607    settings->setValue("PageOrientation", printer->orientation());
[144fbe6b96]608    settings->setValue("MarginLeft", l);
609    settings->setValue("MarginTop", t);
610    settings->setValue("MarginRight", r);
611    settings->setValue("MarginBottom", b);
[a885c3d9d2]612    settings->endGroup();
[1babbd6ba3]613}
614
615void MainWindow::actionFilePrintTriggered()
616{
617QPrintDialog pd(printer,this);
[9eb63a1598]618    if (pd.exec() != QDialog::Accepted)
619        return;
620    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
621    solutionText->print(printer);
622    QApplication::restoreOverrideCursor();
[1babbd6ba3]623}
[7ed8b57eea]624#endif // QT_NO_PRINTDIALOG
[1babbd6ba3]625
626void MainWindow::actionSettingsPreferencesTriggered()
627{
628SettingsDialog sd(this);
[89e5214692]629#ifdef Q_OS_SYMBIAN
[1b40fef578]630    sd.setWindowState(Qt::WindowMaximized);
631#endif
[9eb63a1598]632    if (sd.exec() != QDialog::Accepted)
633        return;
634    if (sd.colorChanged() || sd.fontChanged()) {
635        if (!solutionText->document()->isEmpty() && sd.colorChanged())
636            QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output."));
637        initDocStyleSheet();
638    }
639    if (sd.translucencyChanged() != 0)
640        toggleTranclucency(sd.translucencyChanged() == 1);
[1babbd6ba3]641}
642
643void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked)
644{
[9eb63a1598]645    if (checked) {
646        settings->remove("Language");
647        QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QCoreApplication::applicationName()));
648    } else
649        settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());
[1babbd6ba3]650}
651
652void MainWindow::groupSettingsLanguageListTriggered(QAction *action)
653{
[97e90f9be6]654#ifndef Q_WS_MAEMO_5
[9eb63a1598]655    if (actionSettingsLanguageAutodetect->isChecked())
656        actionSettingsLanguageAutodetect->trigger();
[97e90f9be6]657#endif
[1babbd6ba3]658bool untitled = (fileName == tr("Untitled") + ".tspt");
[9eb63a1598]659    if (loadLanguage(action->data().toString())) {
660        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
661        settings->setValue("Language",action->data().toString());
662        retranslateUi();
663        if (untitled)
664            setFileName();
[b8a2a118c4]665#ifndef HANDHELD
[9eb63a1598]666        if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
667            toggleStyle(labelVariant, true);
668            toggleStyle(labelCities, true);
669        }
[1babbd6ba3]670#endif
[9eb63a1598]671        QApplication::restoreOverrideCursor();
672        if (!solutionText->document()->isEmpty())
673            QMessageBox::information(this, tr("Settings Changed"), tr("You have changed the application language.\nTo get current solution output in the new language\nyou need to re-run the solution process."));
674    }
[1babbd6ba3]675}
676
[e3533af1cf]677void MainWindow::actionSettingsStyleSystemTriggered(bool checked)
678{
[9eb63a1598]679    if (checked) {
680        settings->remove("Style");
681        QMessageBox::information(this, tr("Style Change"), tr("To apply the default style you need to restart %1.").arg(QCoreApplication::applicationName()));
682    } else {
683        settings->setValue("Style", groupSettingsStyleList->checkedAction()->text());
684    }
[e3533af1cf]685}
686
687void MainWindow::groupSettingsStyleListTriggered(QAction *action)
688{
689QStyle *s = QStyleFactory::create(action->text());
[9eb63a1598]690    if (s != NULL) {
691        QApplication::setStyle(s);
692        settings->setValue("Style", action->text());
693        actionSettingsStyleSystem->setChecked(false);
694    }
[e3533af1cf]695}
696
[7bb19df196]697#ifndef HANDHELD
698void MainWindow::actionSettingsToolbarsConfigureTriggered()
699{
700QtToolBarDialog dlg(this);
[9eb63a1598]701    dlg.setToolBarManager(toolBarManager);
702    dlg.exec();
[7bb19df196]703QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave));
[9eb63a1598]704    if (tb != NULL) {
705        tb->setMenu(menuFileSaveAs);
706        tb->setPopupMode(QToolButton::MenuButtonPopup);
707        tb->resize(tb->sizeHint());
708    }
[7bb19df196]709
[9eb63a1598]710    loadToolbarList();
[7bb19df196]711}
712#endif // HANDHELD
713
[1babbd6ba3]714void MainWindow::actionHelpCheck4UpdatesTriggered()
715{
[9eb63a1598]716    if (!hasUpdater()) {
[019894f5ef]717        QMessageBox::warning(this, tr("Unsupported Feature"), tr("Sorry, but this feature is not supported on your\nplatform or support for it was not installed."));
[9eb63a1598]718        return;
719    }
[1babbd6ba3]720
[9eb63a1598]721    check4Updates();
[1babbd6ba3]722}
723
724void MainWindow::actionHelpAboutTriggered()
725{
[9eb63a1598]726    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[43c29c04ba]727
[1babbd6ba3]728QString title;
[9eb63a1598]729    title += QString("<b>%1</b><br>").arg(QCoreApplication::applicationName());
730    title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QCoreApplication::applicationVersion());
[1babbd6ba3]731#ifndef HANDHELD
[9eb63a1598]732    title += QString("<b>&copy; 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QCoreApplication::organizationDomain(), QCoreApplication::organizationName());
[7bb19df196]733#endif // HANDHELD
[9eb63a1598]734    title += QString("<b><a href=\"http://tspsg.info/\">http://tspsg.info/</a></b>");
[1babbd6ba3]735
736QString about;
[9eb63a1598]737    about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), PLATFROM);
[fddcfa4b55]738    about += QString("%1:<br>").arg(tr("Qt library"));
[9eb63a1598]739    about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR);
740    about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Runtime"), qVersion());
[03df0acb95]741    about.append(QString("%1: <b>%2x%3</b><br>").arg(tr("Logical screen DPI")).arg(logicalDpiX()).arg(logicalDpiY()));
[1299ea5b49]742QString tag;
743#ifdef REVISION_STR
[87b8a22768]744    tag = tr(" from git commit <b>%1</b>").arg(QString(REVISION_STR).left(10));
[1299ea5b49]745#endif
[87b8a22768]746    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>";
[07e43cf61a]747    about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), TSPSolver::CTSPSolver::getVersionId());
[9eb63a1598]748    about += "<br>";
[202ca90d03]749    about += QString("<a href=\"https://www.transifex.com/projects/p/tspsg/\">%1</a><br>")
750            .arg(tr("Tanslate %1 into your language").arg(QCoreApplication::applicationName()));
751    about += "<br>";
[9eb63a1598]752    about += tr("This program is free software: you can redistribute it and/or modify<br>\n"
753        "it under the terms of the GNU General Public License as published by<br>\n"
[2940c14782]754        "the Free Software Foundation, either version 2 of the License, or<br>\n"
[9eb63a1598]755        "(at your option) any later version.<br>\n"
756        "<br>\n"
757        "This program is distributed in the hope that it will be useful,<br>\n"
758        "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>\n"
759        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>\n"
760        "GNU General Public License for more details.<br>\n"
761        "<br>\n"
762        "You should have received a copy of the GNU General Public License<br>\n"
763        "along with TSPSG.  If not, see <a href=\"http://www.gnu.org/licenses/\">www.gnu.org/licenses/</a>.");
[43c29c04ba]764
765QString credits;
[fecf053b50]766    credits += tr("%1 was created using <b>Qt</b> framework licensed "
767        "under the terms of <i>GNU Lesser General Public License</i>,<br>\n"
768        "see <a href=\"http://qt-project.org/\">qt-project.org</a><br>\n"
[9eb63a1598]769        "<br>\n"
770        "Most icons used in %1 are part of <b>Oxygen&nbsp;Icons</b> project "
[fecf053b50]771        "licensed according to the <i>GNU Lesser General Public License</i>,<br>\n"
[9eb63a1598]772        "see <a href=\"http://www.oxygen-icons.org/\">www.oxygen-icons.org</a><br>\n"
773        "<br>\n"
[30eb4f72f9]774        "Country flag icons used in %1 are part of <b>Flag Icons</b> by "
[fecf053b50]775        "<b>GoSquared</b> licensed under the terms of <i>MIT License</i>,<br>\n"
[30eb4f72f9]776        "see <a href=\"https://www.gosquared.com/\">www.gosquared.com</a><br>\n"
[9eb63a1598]777        "<br>\n"
778        "%1 comes with the default \"embedded\" font <b>DejaVu&nbsp;LGC&nbsp;Sans&nbsp;"
[fecf053b50]779        "Mono</b> from the <b>DejaVu fonts</b> licensed under <i>Free license</i></a>,<br>\n"
[9eb63a1598]780        "see <a href=\"http://dejavu-fonts.org/\">dejavu-fonts.org</a>")
781            .arg("TSPSG");
[43c29c04ba]782
783QFile f(":/files/COPYING");
[9eb63a1598]784    f.open(QIODevice::ReadOnly);
[43c29c04ba]785
[88a59e4d65]786QString translation = QCoreApplication::translate("--------", "AUTHORS %1", "Please, provide translator credits here. %1 will be replaced with VERSION");
[9eb63a1598]787    if ((translation != "AUTHORS %1") && (translation.contains("%1"))) {
[88a59e4d65]788QString about = QCoreApplication::translate("--------", "VERSION", "Please, provide your translation version here.");
[9eb63a1598]789        if (about != "VERSION")
790            translation = translation.arg(about);
791    }
[1babbd6ba3]792
793QDialog *dlg = new QDialog(this);
794QLabel *lblIcon = new QLabel(dlg),
[9eb63a1598]795    *lblTitle = new QLabel(dlg);
[1babbd6ba3]796#ifdef HANDHELD
[88a59e4d65]797QLabel *lblSubTitle = new QLabel(QString("<b>&copy; 2007-%1 <a href=\"http://%2/\">%3</a></b>").arg(QDate::currentDate().toString("yyyy"), QCoreApplication::organizationDomain(), QCoreApplication::organizationName()), dlg);
[1babbd6ba3]798#endif // HANDHELD
[43c29c04ba]799QTabWidget *tabs = new QTabWidget(dlg);
[1babbd6ba3]800QTextBrowser *txtAbout = new QTextBrowser(dlg);
[43c29c04ba]801QTextBrowser *txtLicense = new QTextBrowser(dlg);
802QTextBrowser *txtCredits = new QTextBrowser(dlg);
[1babbd6ba3]803QVBoxLayout *vb = new QVBoxLayout();
804QHBoxLayout *hb1 = new QHBoxLayout(),
[9eb63a1598]805    *hb2 = new QHBoxLayout();
[1babbd6ba3]806QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg);
807
[9eb63a1598]808    lblTitle->setOpenExternalLinks(true);
809    lblTitle->setText(title);
810    lblTitle->setAlignment(Qt::AlignTop);
811    lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
[1babbd6ba3]812#ifndef HANDHELD
[9eb63a1598]813    lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name()));
[1babbd6ba3]814#endif // HANDHELD
815
[9eb63a1598]816    lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToHeight(lblTitle->sizeHint().height(), Qt::SmoothTransformation));
817    lblIcon->setAlignment(Qt::AlignVCenter);
[1babbd6ba3]818#ifndef HANDHELD
[9eb63a1598]819    lblIcon->setStyleSheet(QString("QLabel {background-color: white; border-color: %1; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().windowText().color().name()));
[1babbd6ba3]820#endif // HANDHELD
821
[9eb63a1598]822    hb1->addWidget(lblIcon);
823    hb1->addWidget(lblTitle);
[1babbd6ba3]824
[9eb63a1598]825    txtAbout->setWordWrapMode(QTextOption::NoWrap);
826    txtAbout->setOpenExternalLinks(true);
827    txtAbout->setHtml(about);
828    txtAbout->moveCursor(QTextCursor::Start);
829    txtAbout->setFrameShape(QFrame::NoFrame);
[7ed8b57eea]830#ifdef Q_OS_BLACKBERRY
831    txtAbout->setAttribute(Qt::WA_InputMethodEnabled, false);
832#endif
[1babbd6ba3]833
[43c29c04ba]834//      txtCredits->setWordWrapMode(QTextOption::NoWrap);
[9eb63a1598]835    txtCredits->setOpenExternalLinks(true);
836    txtCredits->setHtml(credits);
837    txtCredits->moveCursor(QTextCursor::Start);
838    txtCredits->setFrameShape(QFrame::NoFrame);
[7ed8b57eea]839#ifdef Q_OS_BLACKBERRY
840    txtCredits->setAttribute(Qt::WA_InputMethodEnabled, false);
841#endif
[1babbd6ba3]842
[9eb63a1598]843    txtLicense->setWordWrapMode(QTextOption::NoWrap);
844    txtLicense->setOpenExternalLinks(true);
845    txtLicense->setText(f.readAll());
846    txtLicense->moveCursor(QTextCursor::Start);
847    txtLicense->setFrameShape(QFrame::NoFrame);
[7ed8b57eea]848#ifdef Q_OS_BLACKBERRY
849    txtLicense->setAttribute(Qt::WA_InputMethodEnabled, false);
850#endif
[1babbd6ba3]851
[9eb63a1598]852    bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
853    bb->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok"));
[3cadf24d00]854
[9eb63a1598]855    hb2->addWidget(bb);
[1babbd6ba3]856
[89e5214692]857#ifdef Q_OS_WINCE_WM
[9eb63a1598]858    vb->setMargin(3);
[89e5214692]859#endif // Q_OS_WINCE_WM
[9eb63a1598]860    vb->addLayout(hb1);
[1babbd6ba3]861#ifdef HANDHELD
[9eb63a1598]862    vb->addWidget(lblSubTitle);
[1babbd6ba3]863#endif // HANDHELD
[43c29c04ba]864
[9eb63a1598]865    tabs->addTab(txtAbout, tr("About"));
866    tabs->addTab(txtLicense, tr("License"));
867    tabs->addTab(txtCredits, tr("Credits"));
868    if (translation != "AUTHORS %1") {
[43c29c04ba]869QTextBrowser *txtTranslation = new QTextBrowser(dlg);
870//              txtTranslation->setWordWrapMode(QTextOption::NoWrap);
[9eb63a1598]871        txtTranslation->setOpenExternalLinks(true);
872        txtTranslation->setText(translation);
873        txtTranslation->moveCursor(QTextCursor::Start);
874        txtTranslation->setFrameShape(QFrame::NoFrame);
[43c29c04ba]875
[9eb63a1598]876        tabs->addTab(txtTranslation, tr("Translation"));
877    }
[43c29c04ba]878#ifndef HANDHELD
[9eb63a1598]879    tabs->setStyleSheet(QString("QTabWidget::pane {background-color: %1; border-color: %3; border-width: 1px; border-style: solid; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; padding: 1px;} QTabBar::tab {background-color: %2; border-color: %3; border-width: 1px; border-style: solid; border-bottom: none; border-top-left-radius: 4px; border-top-right-radius: 4px; padding: 2px 6px;} QTabBar::tab:selected {background-color: %4;} QTabBar::tab:!selected {margin-top: 1px;}").arg(palette().base().color().name(), palette().button().color().name(), palette().shadow().color().name(), palette().light().color().name()));
[43c29c04ba]880#endif // HANDHELD
881
[9eb63a1598]882    vb->addWidget(tabs);
883    vb->addLayout(hb2);
[1babbd6ba3]884
[9eb63a1598]885    dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
886    dlg->setWindowTitle(tr("About %1").arg(QCoreApplication::applicationName()));
887    dlg->setWindowIcon(GET_ICON("help-about"));
[d97db6d321]888
[9eb63a1598]889    dlg->setLayout(vb);
[1babbd6ba3]890
[9eb63a1598]891    connect(bb, SIGNAL(accepted()), dlg, SLOT(accept()));
[1babbd6ba3]892
[b8a2a118c4]893#ifndef HANDHELD
894    // Adding some eyecandy
[9eb63a1598]895    if (QtWin::isCompositionEnabled())  {
896        QtWin::enableBlurBehindWindow(dlg, true);
897    }
[b8a2a118c4]898#endif // HANDHELD
[1babbd6ba3]899
[5cbcd091ed]900#ifndef HANDHELD
[9eb63a1598]901    dlg->resize(450, 350);
[7ed8b57eea]902#elif defined(Q_OS_SYMBIAN) || defined(Q_OS_BLACKBERRY)
[1b40fef578]903    dlg->setWindowState(Qt::WindowMaximized);
[5cbcd091ed]904#endif
[9eb63a1598]905    QApplication::restoreOverrideCursor();
[1babbd6ba3]906
[9eb63a1598]907    dlg->exec();
[1babbd6ba3]908
[9eb63a1598]909    delete dlg;
[1babbd6ba3]910}
911
912void MainWindow::buttonBackToTaskClicked()
913{
[9eb63a1598]914    tabWidget->setCurrentIndex(0);
[1babbd6ba3]915}
916
917void MainWindow::buttonRandomClicked()
918{
[9eb63a1598]919    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
920    tspmodel->randomize();
921    QApplication::restoreOverrideCursor();
[1babbd6ba3]922}
923
924void MainWindow::buttonSolveClicked()
925{
[07e43cf61a]926    TSPSolver::TMatrix matrix;
927    QList<double> row;
928    int n = spinCities->value();
929    bool ok;
[9eb63a1598]930    for (int r = 0; r < n; r++) {
931        row.clear();
932        for (int c = 0; c < n; c++) {
933            row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
934            if (!ok) {
935                QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1));
936                return;
937            }
938        }
939        matrix.append(row);
940    }
[1babbd6ba3]941
942QProgressDialog pd(this);
943QProgressBar *pb = new QProgressBar(&pd);
[9eb63a1598]944    pb->setAlignment(Qt::AlignCenter);
945    pb->setFormat(tr("%v of %1 parts found").arg(n));
946    pd.setBar(pb);
[43c29c04ba]947QPushButton *cancel = new QPushButton(&pd);
[9eb63a1598]948    cancel->setIcon(GET_ICON("dialog-cancel"));
[019894f5ef]949    cancel->setText(QCoreApplication::translate("QDialogButtonBox", "Cancel", "No need to translate this. The translation will be taken from Qt translation files."));
[9eb63a1598]950    pd.setCancelButton(cancel);
951    pd.setMaximum(n);
[7ed8b57eea]952    pd.setAutoClose(false);
[9eb63a1598]953    pd.setAutoReset(false);
954    pd.setLabelText(tr("Calculating optimal route..."));
955    pd.setWindowTitle(tr("Solution Progress"));
956    pd.setWindowModality(Qt::ApplicationModal);
957    pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
958    pd.show();
[1babbd6ba3]959
[89e5214692]960#ifdef Q_OS_WIN32
[43c29c04ba]961HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID*)&tl);
[9eb63a1598]962    if (SUCCEEDED(hr)) {
963        hr = tl->HrInit();
964        if (FAILED(hr)) {
965            tl->Release();
966            tl = NULL;
967        } else {
[b0dfe0844e]968            tl->SetProgressValue(HWND(winId()), 0, n * 2);
[9eb63a1598]969        }
970    }
[43c29c04ba]971#endif
972
[07e43cf61a]973    TSPSolver::CTSPSolver solver;
[9eb63a1598]974    solver.setCleanupOnCancel(false);
975    connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
976    connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
[89e5214692]977#ifdef Q_OS_WIN32
[9eb63a1598]978    if (tl != NULL)
979        connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int)));
[43c29c04ba]980#endif
[07e43cf61a]981    TSPSolver::SStep *root = solver.solve(n, matrix);
[89e5214692]982#ifdef Q_OS_WIN32
[9eb63a1598]983    if (tl != NULL)
984        disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int)));
[43c29c04ba]985#endif
[9eb63a1598]986    disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
987    disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
988    if (!root) {
989        pd.reset();
990        if (!solver.wasCanceled()) {
[89e5214692]991#ifdef Q_OS_WIN32
[9eb63a1598]992            if (tl != NULL) {
[b0dfe0844e]993                tl->SetProgressState(HWND(winId()), TBPF_ERROR);
[9eb63a1598]994            }
[43c29c04ba]995#endif
[9eb63a1598]996            QApplication::alert(this);
997            QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution."));
998        }
[d97db6d321]999        pd.setLabelText(tr("Memory cleanup..."));
[9eb63a1598]1000        pd.setMaximum(0);
1001        pd.setCancelButton(NULL);
1002        pd.show();
[89e5214692]1003#ifdef Q_OS_WIN32
[9eb63a1598]1004        if (tl != NULL)
[b0dfe0844e]1005            tl->SetProgressState(HWND(winId()), TBPF_INDETERMINATE);
[43c29c04ba]1006#endif
[9eb63a1598]1007        QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
[43c29c04ba]1008
[a713b103e8]1009#ifndef QT_NO_CONCURRENT
[07e43cf61a]1010        QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
[9eb63a1598]1011        while (!f.isFinished()) {
1012            QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1013        }
[a713b103e8]1014#else
[9eb63a1598]1015        solver.cleanup(true);
[a713b103e8]1016#endif
[9eb63a1598]1017        pd.reset();
[89e5214692]1018#ifdef Q_OS_WIN32
[9eb63a1598]1019        if (tl != NULL) {
[b0dfe0844e]1020            tl->SetProgressState(HWND(winId()), TBPF_NOPROGRESS);
[9eb63a1598]1021            tl->Release();
1022            tl = NULL;
1023        }
[43c29c04ba]1024#endif
[9eb63a1598]1025        return;
1026    }
1027    pb->setFormat(tr("Generating header"));
1028    pd.setLabelText(tr("Generating solution output..."));
1029    pd.setMaximum(solver.getTotalSteps() + 1);
1030    pd.setValue(0);
[1babbd6ba3]1031
[89e5214692]1032#ifdef Q_OS_WIN32
[9eb63a1598]1033    if (tl != NULL)
[b0dfe0844e]1034        tl->SetProgressValue(HWND(winId()), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1);
[43c29c04ba]1035#endif
1036
[9eb63a1598]1037    solutionText->clear();
1038    solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value()));
[317ba0432e]1039
[345e7b6132]1040QPainter pic;
[8f2427aaf0]1041bool dograph = settings->value("Output/GenerateGraph", DEF_GENERATE_GRAPH).toBool();
1042    if (dograph) {
[9eb63a1598]1043        pic.begin(&graph);
1044        pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
[20e8115cee]1045QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE)));
[fddcfa4b55]1046        font.setStyleHint(QFont::TypeWriter);
[8f2427aaf0]1047        // Font size in pixels = graph node radius / 2.75.
1048        // See MainWindow::drawNode() for graph node radius calcualtion description.
[89e5214692]1049#ifndef Q_OS_SYMBIAN
[8f2427aaf0]1050        font.setPixelSize(logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5 / 2.75);
[fddcfa4b55]1051#else
1052        // Also, see again MainWindow::drawNode() for why is additional 1.3 divider added in Symbian.
1053        font.setPixelSize(logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5 / 2.75 / 1.3);
1054#endif
[9eb63a1598]1055        if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
1056            font.setWeight(QFont::DemiBold);
[8f2427aaf0]1057            font.setPixelSize(font.pixelSize() * HQ_FACTOR);
[9eb63a1598]1058        }
1059        pic.setFont(font);
1060        pic.setBrush(QBrush(QColor(Qt::white)));
1061        if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
[7aaa0b0ec7]1062QPen pen = pic.pen();
[8f2427aaf0]1063            pen.setWidth(HQ_FACTOR);
[9eb63a1598]1064            pic.setPen(pen);
1065        }
1066        pic.setBackgroundMode(Qt::OpaqueMode);
[8f2427aaf0]1067    } else {
1068        graph = QPicture();
[9eb63a1598]1069    }
[345e7b6132]1070
[317ba0432e]1071QTextDocument *doc = solutionText->document();
1072QTextCursor cur(doc);
1073
[9eb63a1598]1074    cur.beginEditBlock();
1075    cur.setBlockFormat(fmt_paragraph);
1076    cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default);
1077    cur.insertBlock(fmt_paragraph);
[a885c3d9d2]1078    cur.insertText(tr("Task:"), fmt_default);
[9eb63a1598]1079    outputMatrix(cur, matrix);
[8f2427aaf0]1080    if (dograph) {
[3cadf24d00]1081#ifdef _T_T_L_
[9eb63a1598]1082        _b_ _i_ _z_ _a_ _r_ _r_ _e_
[3cadf24d00]1083#endif
[9eb63a1598]1084        drawNode(pic, 0);
1085    }
1086    cur.insertHtml("<hr>");
1087    cur.insertBlock(fmt_paragraph);
[07e43cf61a]1088    int imgpos = cur.position();
[9eb63a1598]1089    cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
1090    cur.endEditBlock();
[317ba0432e]1091
[07e43cf61a]1092    TSPSolver::SStep *step = root;
1093    int c = n = 1;
[9eb63a1598]1094    pb->setFormat(tr("Generating step %v"));
[07e43cf61a]1095    while ((step->next != TSPSolver::SStep::NoNextStep) && (c < spinCities->value())) {
[9eb63a1598]1096        if (pd.wasCanceled()) {
[d97db6d321]1097            pd.setLabelText(tr("Memory cleanup..."));
[9eb63a1598]1098            pd.setMaximum(0);
1099            pd.setCancelButton(NULL);
1100            pd.show();
1101            QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
[89e5214692]1102#ifdef Q_OS_WIN32
[9eb63a1598]1103            if (tl != NULL)
[b0dfe0844e]1104                tl->SetProgressState(HWND(winId()), TBPF_INDETERMINATE);
[43c29c04ba]1105#endif
[a713b103e8]1106#ifndef QT_NO_CONCURRENT
[07e43cf61a]1107            QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
[9eb63a1598]1108            while (!f.isFinished()) {
1109                QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1110            }
[a713b103e8]1111#else
[9eb63a1598]1112            solver.cleanup(true);
[a713b103e8]1113#endif
[9eb63a1598]1114            solutionText->clear();
1115            toggleSolutionActions(false);
[89e5214692]1116#ifdef Q_OS_WIN32
[9eb63a1598]1117            if (tl != NULL) {
[b0dfe0844e]1118                tl->SetProgressState(HWND(winId()), TBPF_NOPROGRESS);
[9eb63a1598]1119                tl->Release();
1120                tl = NULL;
1121            }
[43c29c04ba]1122#endif
[9eb63a1598]1123            return;
1124        }
1125        pd.setValue(n);
[89e5214692]1126#ifdef Q_OS_WIN32
[9eb63a1598]1127        if (tl != NULL)
[b0dfe0844e]1128            tl->SetProgressValue(HWND(winId()), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1);
[43c29c04ba]1129#endif
[1babbd6ba3]1130
[9eb63a1598]1131        cur.beginEditBlock();
1132        cur.insertBlock(fmt_paragraph);
[a885c3d9d2]1133        cur.insertText(tr("Step #%1").arg(n), fmt_default);
[9eb63a1598]1134        if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && (!settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() || (settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())))) {
1135            outputMatrix(cur, *step);
1136        }
[8f2427aaf0]1137        if (step->alts.empty())
1138            cur.insertBlock(fmt_lastparagraph);
1139        else
1140            cur.insertBlock(fmt_paragraph);
[07e43cf61a]1141        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);
[9eb63a1598]1142        if (!step->alts.empty()) {
[07e43cf61a]1143            TSPSolver::SStep::SCandidate cand;
[9eb63a1598]1144            QString alts;
1145            foreach(cand, step->alts) {
1146                if (!alts.isEmpty())
1147                    alts += ", ";
1148                alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
1149            }
[8f2427aaf0]1150            cur.insertBlock(fmt_lastparagraph);
[9eb63a1598]1151            cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist);
1152        }
1153        cur.endEditBlock();
1154
[8f2427aaf0]1155        if (dograph) {
[9eb63a1598]1156            if (step->prNode != NULL)
1157                drawNode(pic, n, false, step->prNode);
1158            if (step->plNode != NULL)
1159                drawNode(pic, n, true, step->plNode);
1160        }
1161        n++;
1162
[07e43cf61a]1163        if (step->next == TSPSolver::SStep::RightBranch) {
[9eb63a1598]1164            c++;
1165            step = step->prNode;
[07e43cf61a]1166        } else if (step->next == TSPSolver::SStep::LeftBranch) {
[9eb63a1598]1167            step = step->plNode;
1168        } else
1169            break;
1170    }
1171    pb->setFormat(tr("Generating footer"));
1172    pd.setValue(n);
[89e5214692]1173#ifdef Q_OS_WIN32
[9eb63a1598]1174    if (tl != NULL)
[b0dfe0844e]1175        tl->SetProgressValue(HWND(winId()), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1);
[43c29c04ba]1176#endif
[1babbd6ba3]1177
[9eb63a1598]1178    cur.beginEditBlock();
1179    cur.insertBlock(fmt_paragraph);
1180    if (solver.isOptimal())
[8f2427aaf0]1181        cur.insertText(tr("Optimal path:"), fmt_default);
[9eb63a1598]1182    else
[8f2427aaf0]1183        cur.insertText(tr("Resulting path:"), fmt_default);
[9eb63a1598]1184
1185    cur.insertBlock(fmt_paragraph);
1186    cur.insertText("  " + solver.getSortedPath(tr("City %1")));
1187
[8f2427aaf0]1188    if (solver.isOptimal())
1189        cur.insertBlock(fmt_paragraph);
1190    else
1191        cur.insertBlock(fmt_lastparagraph);
[9eb63a1598]1192    if (isInteger(step->price))
1193        cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>");
1194    else
1195        cur.insertHtml("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>");
1196    if (!solver.isOptimal()) {
1197        cur.insertBlock(fmt_paragraph);
1198        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>");
1199    }
1200    cur.endEditBlock();
1201
[8f2427aaf0]1202    if (dograph) {
[9eb63a1598]1203        pic.end();
[345e7b6132]1204
[c8ed26ddf1]1205        QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
[79f83a3845]1206        i.fill(QColor(255, 255, 255, 0).rgba());
[9eb63a1598]1207        pic.begin(&i);
1208        pic.drawPicture(1, 1, graph);
1209        pic.end();
1210        doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i);
[345e7b6132]1211
1212QTextImageFormat img;
[9eb63a1598]1213        img.setName("tspsg://graph.pic");
1214        if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
[8f2427aaf0]1215            img.setWidth(i.width() / HQ_FACTOR);
1216            img.setHeight(i.height() / HQ_FACTOR);
[9eb63a1598]1217        } else {
1218            img.setWidth(i.width());
1219            img.setHeight(i.height());
1220        }
1221
1222        cur.setPosition(imgpos);
1223        cur.insertImage(img, QTextFrameFormat::FloatRight);
1224    }
1225
1226    if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
1227        // Scrolling to the end of the text.
1228        solutionText->moveCursor(QTextCursor::End);
1229    } else
1230        solutionText->moveCursor(QTextCursor::Start);
1231
[d97db6d321]1232    pd.setLabelText(tr("Memory cleanup..."));
[9eb63a1598]1233    pd.setMaximum(0);
1234    pd.setCancelButton(NULL);
1235    QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
[89e5214692]1236#ifdef Q_OS_WIN32
[9eb63a1598]1237    if (tl != NULL)
[b0dfe0844e]1238        tl->SetProgressState(HWND(winId()), TBPF_INDETERMINATE);
[43c29c04ba]1239#endif
[a713b103e8]1240#ifndef QT_NO_CONCURRENT
[07e43cf61a]1241    QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
[9eb63a1598]1242    while (!f.isFinished()) {
1243        QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1244    }
[a713b103e8]1245#else
[9eb63a1598]1246    solver.cleanup(true);
[a713b103e8]1247#endif
[9eb63a1598]1248    toggleSolutionActions();
1249    tabWidget->setCurrentIndex(1);
[89e5214692]1250#ifdef Q_OS_WIN32
[9eb63a1598]1251    if (tl != NULL) {
[b0dfe0844e]1252        tl->SetProgressState(HWND(winId()), TBPF_NOPROGRESS);
[9eb63a1598]1253        tl->Release();
1254        tl = NULL;
1255    }
[43c29c04ba]1256#endif
1257
[9eb63a1598]1258    pd.reset();
1259    QApplication::alert(this, 3000);
[1babbd6ba3]1260}
1261
1262void MainWindow::dataChanged()
1263{
[9eb63a1598]1264    setWindowModified(true);
[1babbd6ba3]1265}
1266
1267void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br)
1268{
[9eb63a1598]1269    setWindowModified(true);
1270    if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) {
1271        for (int k = tl.row(); k <= br.row(); k++)
1272            taskView->resizeRowToContents(k);
1273        for (int k = tl.column(); k <= br.column(); k++)
1274            taskView->resizeColumnToContents(k);
1275    }
[1babbd6ba3]1276}
1277
[89e5214692]1278#ifdef Q_OS_WINCE_WM
[1babbd6ba3]1279void MainWindow::changeEvent(QEvent *ev)
1280{
[9eb63a1598]1281    if ((ev->type() == QEvent::ActivationChange) && isActiveWindow())
1282        desktopResized(0);
[1babbd6ba3]1283
[9eb63a1598]1284    QWidget::changeEvent(ev);
[1babbd6ba3]1285}
1286
1287void MainWindow::desktopResized(int screen)
1288{
[9eb63a1598]1289    if ((screen != 0) || !isActiveWindow())
1290        return;
[1babbd6ba3]1291
1292QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
[9eb63a1598]1293    if (currentGeometry != availableGeometry) {
1294        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1295        /*!
1296         * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
1297         *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
1298         *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
1299         */
1300        if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
1301            setWindowState(windowState() | Qt::WindowMaximized);
1302        } else {
1303            if (windowState() & Qt::WindowMaximized)
1304                setWindowState(windowState() ^ Qt::WindowMaximized);
1305            setGeometry(availableGeometry);
1306        }
1307        currentGeometry = availableGeometry;
1308        QApplication::restoreOverrideCursor();
1309    }
[1babbd6ba3]1310}
[89e5214692]1311#endif // Q_OS_WINCE_WM
[1babbd6ba3]1312
1313void MainWindow::numCitiesChanged(int nCities)
1314{
[9eb63a1598]1315    blockSignals(true);
1316    spinCities->setValue(nCities);
1317    blockSignals(false);
[1babbd6ba3]1318}
1319
1320#ifndef QT_NO_PRINTER
1321void MainWindow::printPreview(QPrinter *printer)
1322{
[9eb63a1598]1323    solutionText->print(printer);
[1babbd6ba3]1324}
1325#endif // QT_NO_PRINTER
1326
[89e5214692]1327#ifdef Q_OS_WIN32
[43c29c04ba]1328void MainWindow::solverRoutePartFound(int n)
1329{
[b0dfe0844e]1330    tl->SetProgressValue(HWND(winId()), n, spinCities->value() * 2);
[43c29c04ba]1331}
[89e5214692]1332#endif // Q_OS_WIN32
[43c29c04ba]1333
[1babbd6ba3]1334void MainWindow::spinCitiesValueChanged(int n)
1335{
[9eb63a1598]1336    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[1babbd6ba3]1337int count = tspmodel->numCities();
[9eb63a1598]1338    tspmodel->setNumCities(n);
1339    if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool())
1340        for (int k = count; k < n; k++) {
1341            taskView->resizeColumnToContents(k);
1342            taskView->resizeRowToContents(k);
1343        }
1344    QApplication::restoreOverrideCursor();
[1babbd6ba3]1345}
1346
[f5c945d7ac]1347void MainWindow::check4Updates(bool silent)
1348{
[89e5214692]1349#ifdef Q_OS_WIN32
[9eb63a1598]1350    if (silent)
1351        QProcess::startDetached("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\" -silentcheck");
1352    else {
1353        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1354        QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\"");
1355        QApplication::restoreOverrideCursor();
1356    }
[0007f69c46]1357#else
[9eb63a1598]1358    Q_UNUSED(silent)
[f5c945d7ac]1359#endif
[9eb63a1598]1360    settings->setValue("Check4Updates/LastAttempt", QDate::currentDate().toString(Qt::ISODate));
[f5c945d7ac]1361}
1362
[1babbd6ba3]1363void MainWindow::closeEvent(QCloseEvent *ev)
1364{
[9eb63a1598]1365    if (!maybeSave()) {
1366        ev->ignore();
1367        return;
1368    }
1369    if (!settings->value("SettingsReset", false).toBool()) {
1370        settings->setValue("NumCities", spinCities->value());
1371
1372        // Saving Main Window state
[7bb19df196]1373#ifndef HANDHELD
[9eb63a1598]1374        if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
1375            settings->beginGroup("MainWindow");
1376            settings->setValue("Geometry", saveGeometry());
1377            settings->setValue("State", saveState());
1378            settings->setValue("Toolbars", toolBarManager->saveState());
1379            settings->endGroup();
1380        }
[a713b103e8]1381#else
[9eb63a1598]1382        settings->setValue("MainWindow/ToolbarVisible", toolBarMain->isVisible());
[7bb19df196]1383#endif // HANDHELD
[9eb63a1598]1384    } else {
1385        settings->remove("SettingsReset");
1386    }
[1babbd6ba3]1387
[9eb63a1598]1388    QMainWindow::closeEvent(ev);
[1babbd6ba3]1389}
1390
[b574c383b7]1391void MainWindow::dragEnterEvent(QDragEnterEvent *ev)
1392{
[9eb63a1598]1393    if (ev->mimeData()->hasUrls() && (ev->mimeData()->urls().count() == 1)) {
[b574c383b7]1394QFileInfo fi(ev->mimeData()->urls().first().toLocalFile());
[9eb63a1598]1395        if ((fi.suffix() == "tspt") || (fi.suffix() == "zkt"))
1396            ev->acceptProposedAction();
1397    }
[b574c383b7]1398}
1399
[07e43cf61a]1400void MainWindow::drawNode(QPainter &pic, int nstep, bool left, TSPSolver::SStep *step)
[345e7b6132]1401{
[8f2427aaf0]1402qreal r; // Radius of graph node
1403    // We calculate r from the full graph width in centimeters:
1404    //   r = width in pixels / 4.5.
1405    //   width in pixels = DPI * width in inches.
1406    //   width in inches = width in cm / cm in inch.
1407    r = logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5;
[9eb63a1598]1408    if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool())
[8f2427aaf0]1409        r *= HQ_FACTOR;
[89e5214692]1410#ifdef Q_OS_SYMBIAN
[144fbe6b96]1411    /*! \hack HACK: Solution graph on Symbian is visually larger than on
[23ad8db4a5]1412     *   Windows Mobile. This coefficient makes it about the same size.
1413     */
1414    r /= 1.3;
1415#endif
1416
[345e7b6132]1417qreal x, y;
[9eb63a1598]1418    if (step != NULL)
1419        x = left ? r : r * 3.5;
1420    else
1421        x = r * 2.25;
1422    y = r * (3 * nstep + 1);
[345e7b6132]1423
[3cadf24d00]1424#ifdef _T_T_L_
[9eb63a1598]1425    if (nstep == -481124) {
1426        _t_t_l_(pic, r, x);
1427        return;
1428    }
[3cadf24d00]1429#endif
1430
[9eb63a1598]1431    pic.drawEllipse(QPointF(x, y), r, r);
[345e7b6132]1432
[9eb63a1598]1433    if (step != NULL) {
[345e7b6132]1434QFont font;
[9eb63a1598]1435        if (left) {
1436            font = pic.font();
1437            font.setStrikeOut(true);
1438            pic.setFont(font);
1439        }
1440        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");
1441        if (left) {
1442            font.setStrikeOut(false);
1443            pic.setFont(font);
1444        }
1445        if (step->price != INFINITY) {
[5cbcd091ed]1446            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()));
[9eb63a1598]1447        } else {
[468fa8e7e5]1448            pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n" INFSTR);
[9eb63a1598]1449        }
1450    } else {
1451        pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root"));
1452    }
1453
1454    if (nstep == 1) {
1455        pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
1456    } else if (nstep > 1) {
[07e43cf61a]1457        pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == TSPSolver::SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
[9eb63a1598]1458    }
[345e7b6132]1459
1460}
1461
[b574c383b7]1462void MainWindow::dropEvent(QDropEvent *ev)
1463{
[9eb63a1598]1464    if (maybeSave() && tspmodel->loadTask(ev->mimeData()->urls().first().toLocalFile())) {
1465        setFileName(ev->mimeData()->urls().first().toLocalFile());
1466        tabWidget->setCurrentIndex(0);
1467        setWindowModified(false);
1468        solutionText->clear();
1469        toggleSolutionActions(false);
1470
1471        ev->setDropAction(Qt::CopyAction);
1472        ev->accept();
1473    }
[b574c383b7]1474}
1475
[b26dc16dcf]1476QByteArray MainWindow::generateImage(const QString &format)
1477{
1478    if (graph.isNull())
1479        return QByteArray();
1480
1481    QByteArray data;
1482    QBuffer buf(&data);
1483    // Saving solution graph in SVG or supported raster format (depending on settings and SVG support)
1484#if !defined(NOSVG)
1485    if (format == "svg") {
1486        QSvgGenerator svg;
1487        svg.setSize(QSize(graph.width() + 2, graph.height() + 2));
1488        svg.setResolution(graph.logicalDpiX());
1489        svg.setOutputDevice(&buf);
1490        svg.setTitle(tr("Solution Graph"));
1491        svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName()));
1492        QPainter p;
1493        p.begin(&svg);
1494        p.drawPicture(1, 1, graph);
1495        p.end();
1496    } else {
1497#endif // NOSVG
1498        QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
1499        i.fill(0x00FFFFFF);
1500        QPainter p;
1501        p.begin(&i);
1502        p.drawPicture(1, 1, graph);
1503        p.end();
1504        QImageWriter pic;
1505        pic.setDevice(&buf);
[7a39458d16]1506        pic.setFormat(format.toLatin1());
[b26dc16dcf]1507        if (pic.supportsOption(QImageIOHandler::Description)) {
1508            pic.setText("Title", "Solution Graph");
1509            pic.setText("Software", QCoreApplication::applicationName());
1510        }
1511        if (format == "png")
1512            pic.setQuality(5);
1513        else if (format == "jpeg")
1514            pic.setQuality(80);
1515        if (!pic.write(i)) {
[b96b44b6b7]1516            QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
[b26dc16dcf]1517            QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));
[b96b44b6b7]1518            QApplication::restoreOverrideCursor();
[b26dc16dcf]1519            return QByteArray();
1520        }
1521#if !defined(NOSVG)
1522    }
1523#endif // NOSVG
1524    return data;
1525}
1526
[1babbd6ba3]1527void MainWindow::initDocStyleSheet()
1528{
[9eb63a1598]1529    solutionText->document()->setDefaultFont(qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE))));
[317ba0432e]1530
[a885c3d9d2]1531    fmt_paragraph.setTopMargin(5);
[9eb63a1598]1532    fmt_paragraph.setRightMargin(10);
1533    fmt_paragraph.setBottomMargin(0);
1534    fmt_paragraph.setLeftMargin(10);
[8f2427aaf0]1535
1536    fmt_lastparagraph.setTopMargin(5);
1537    fmt_lastparagraph.setRightMargin(10);
1538    fmt_lastparagraph.setBottomMargin(15);
1539    fmt_lastparagraph.setLeftMargin(10);
[317ba0432e]1540
[0a4e16b182]1541    settings->beginGroup("Output/Colors");
1542
[9eb63a1598]1543    fmt_table.setTopMargin(5);
1544    fmt_table.setRightMargin(10);
[a885c3d9d2]1545    fmt_table.setBottomMargin(0);
[9eb63a1598]1546    fmt_table.setLeftMargin(10);
[0a4e16b182]1547    fmt_table.setBorder(1);
1548    fmt_table.setBorderBrush(QBrush(QColor(settings->value("TableBorder", DEF_TABLE_COLOR).toString())));
1549    fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
1550    fmt_table.setCellSpacing(0);
1551    fmt_table.setCellPadding(2);
[317ba0432e]1552
[9eb63a1598]1553    fmt_cell.setAlignment(Qt::AlignHCenter);
[317ba0432e]1554
[0a4e16b182]1555QColor color = QColor(settings->value("Text", DEF_TEXT_COLOR).toString());
[1babbd6ba3]1556QColor hilight;
[9eb63a1598]1557    if (color.value() < 192)
[356169a3d3]1558        hilight.setHsv(color.hue(), color.saturation(), 127 + (color.value() / 2));
[9eb63a1598]1559    else
1560        hilight.setHsv(color.hue(), color.saturation(), color.value() / 2);
[317ba0432e]1561
[89e5214692]1562#ifdef Q_OS_SYMBIAN
[5f49b20d9d]1563    /*!
1564     * \hack HACK: Fixing some weird behavior with default Symbian theme
1565     *  when text and background have the same color.
1566     */
1567    if (color != DEF_TEXT_COLOR) {
1568#endif
[9eb63a1598]1569    solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name()));
1570    fmt_default.setForeground(QBrush(color));
[89e5214692]1571#ifdef Q_OS_SYMBIAN
[5f49b20d9d]1572    }
1573#endif
[317ba0432e]1574
[0a4e16b182]1575    fmt_selected.setForeground(QBrush(QColor(settings->value("Selected", DEF_SELECTED_COLOR).toString())));
[9eb63a1598]1576    fmt_selected.setFontWeight(QFont::Bold);
[317ba0432e]1577
[0a4e16b182]1578    fmt_alternate.setForeground(QBrush(QColor(settings->value("Alternate", DEF_ALTERNATE_COLOR).toString())));
[9eb63a1598]1579    fmt_alternate.setFontWeight(QFont::Bold);
1580    fmt_altlist.setForeground(QBrush(hilight));
[317ba0432e]1581
[9eb63a1598]1582    settings->endGroup();
[1babbd6ba3]1583}
1584
1585void MainWindow::loadLangList()
1586{
[3cadf24d00]1587QMap<QString, QStringList> langlist;
1588QFileInfoList langs;
1589QFileInfo lang;
1590QStringList language, dirs;
1591QTranslator t;
1592QDir dir;
[9eb63a1598]1593    dir.setFilter(QDir::Files);
1594    dir.setNameFilters(QStringList("tspsg_*.qm"));
1595    dir.setSorting(QDir::NoSort);
1596
1597    dirs << PATH_L10N << ":/l10n";
1598    foreach (QString dirname, dirs) {
1599        dir.setPath(dirname);
1600        if (dir.exists()) {
1601            langs = dir.entryInfoList();
1602            for (int k = 0; k < langs.size(); k++) {
1603                lang = langs.at(k);
1604                if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && !langlist.contains(lang.completeBaseName().mid(6)) && t.load(lang.completeBaseName(), dirname)) {
1605
1606                    language.clear();
1607                    language.append(lang.completeBaseName().mid(6));
1608                    language.append(t.translate("--------", "COUNTRY", "Please, provide an ISO 3166-1 alpha-2 country code for this translation language here (eg., UA).").toLower());
1609                    language.append(t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here."));
1610                    language.append(t.translate("MainWindow", "Set application language to %1", "").arg(language.at(2)));
1611
1612                    langlist.insert(language.at(0), language);
1613                }
1614            }
1615        }
1616    }
[3cadf24d00]1617
1618QAction *a;
[9eb63a1598]1619    foreach (language, langlist) {
1620        a = menuSettingsLanguage->addAction(language.at(2));
[9adbc413c7]1621#ifndef QT_NO_STATUSTIP
[9eb63a1598]1622        a->setStatusTip(language.at(3));
[9adbc413c7]1623#endif
[356169a3d3]1624#if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
[9eb63a1598]1625        a->setIcon(QIcon::fromTheme(QString("flag-%1").arg(language.at(1)), QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1)))));
[2a436ea693]1626#else
[9eb63a1598]1627        a->setIcon(QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1))));
[2a436ea693]1628#endif
[9eb63a1598]1629        a->setData(language.at(0));
1630        a->setCheckable(true);
1631        a->setActionGroup(groupSettingsLanguageList);
1632        if (settings->value("Language", QLocale::system().name()).toString().startsWith(language.at(0)))
1633            a->setChecked(true);
1634    }
[1babbd6ba3]1635}
1636
1637bool MainWindow::loadLanguage(const QString &lang)
1638{
1639// i18n
1640bool ad = false;
1641QString lng = lang;
[9eb63a1598]1642    if (lng.isEmpty()) {
1643        ad = settings->value("Language").toString().isEmpty();
1644        lng = settings->value("Language", QLocale::system().name()).toString();
1645    }
[1babbd6ba3]1646static QTranslator *qtTranslator; // Qt library translator
[9eb63a1598]1647    if (qtTranslator) {
1648        qApp->removeTranslator(qtTranslator);
1649        delete qtTranslator;
1650        qtTranslator = NULL;
1651    }
[1babbd6ba3]1652static QTranslator *translator; // Application translator
[9eb63a1598]1653    if (translator) {
1654        qApp->removeTranslator(translator);
1655        delete translator;
1656        translator = NULL;
1657    }
1658
1659    if (lng == "en")
1660        return true;
1661
1662    // Trying to load system Qt library translation...
1663    qtTranslator = new QTranslator(this);
[b26801b000]1664    if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
[4cc94b19ad]1665        // Trying from QT_INSTALL_TRANSLATIONS directory
1666        qApp->installTranslator(qtTranslator);
1667    } else if (qtTranslator->load("qt_" + lng, PATH_L10N)) {
1668        // Than from l10n directory bundled with TSPSG
[9eb63a1598]1669        qApp->installTranslator(qtTranslator);
[b26801b000]1670    } else {
1671        // Qt library translation unavailable for this language.
1672        delete qtTranslator;
1673        qtTranslator = NULL;
[9eb63a1598]1674    }
1675
1676    // Now let's load application translation.
1677    translator = new QTranslator(this);
1678    if (translator->load("tspsg_" + lng, PATH_L10N)) {
1679        // We have a translation in the localization directory.
1680        qApp->installTranslator(translator);
1681    } else if (translator->load("tspsg_" + lng, ":/l10n")) {
1682        // We have a translation "built-in" into application resources.
1683        qApp->installTranslator(translator);
1684    } else {
1685        delete translator;
1686        translator = NULL;
1687        if (!ad) {
1688            settings->remove("Language");
1689            QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
1690            QMessageBox::warning(isVisible() ? this : NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection."));
1691            QApplication::restoreOverrideCursor();
1692        }
1693        return false;
1694    }
1695    return true;
[1babbd6ba3]1696}
1697
[e3533af1cf]1698void MainWindow::loadStyleList()
1699{
[9eb63a1598]1700    menuSettingsStyle->clear();
[e3533af1cf]1701QStringList styles = QStyleFactory::keys();
[9eb63a1598]1702    menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem);
1703    actionSettingsStyleSystem->setChecked(!settings->contains("Style"));
1704    menuSettingsStyle->addSeparator();
[e3533af1cf]1705QAction *a;
[9eb63a1598]1706    foreach (QString style, styles) {
1707        a = menuSettingsStyle->addAction(style);
1708        a->setData(false);
[9adbc413c7]1709#ifndef QT_NO_STATUSTIP
[9eb63a1598]1710        a->setStatusTip(tr("Set application style to %1").arg(style));
[9adbc413c7]1711#endif
[9eb63a1598]1712        a->setCheckable(true);
1713        a->setActionGroup(groupSettingsStyleList);
[5f8c8ea92c]1714        QRegExp rx(QString("^Q?%1(::(Style)?)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive);
1715        if ((style == settings->value("Style").toString()) || QApplication::style()->objectName().contains(rx)
[97e90f9be6]1716#ifndef Q_WS_MAEMO_5
[5f8c8ea92c]1717            || QString(QApplication::style()->metaObject()->className()).contains(rx)
[97e90f9be6]1718#endif
[9eb63a1598]1719        ) {
1720            a->setChecked(true);
1721        }
1722    }
[e3533af1cf]1723}
1724
[7bb19df196]1725void MainWindow::loadToolbarList()
1726{
[9eb63a1598]1727    menuSettingsToolbars->clear();
[7bb19df196]1728#ifndef HANDHELD
[9eb63a1598]1729    menuSettingsToolbars->insertAction(NULL, actionSettingsToolbarsConfigure);
1730    menuSettingsToolbars->addSeparator();
[7bb19df196]1731QList<QToolBar *> list = toolBarManager->toolBars();
[9eb63a1598]1732    foreach (QToolBar *t, list) {
1733        menuSettingsToolbars->insertAction(NULL, t->toggleViewAction());
1734    }
[7bb19df196]1735#else // HANDHELD
[9eb63a1598]1736    menuSettingsToolbars->insertAction(NULL, toolBarMain->toggleViewAction());
[7bb19df196]1737#endif // HANDHELD
1738}
1739
[1babbd6ba3]1740bool MainWindow::maybeSave()
1741{
[9eb63a1598]1742    if (!isWindowModified())
1743        return true;
[89e5214692]1744#ifdef Q_OS_SYMBIAN
[fddcfa4b55]1745    int res = QSMessageBox(this).exec();
1746#else
1747    int res = QMessageBox::warning(this, tr("Unsaved Changes"), tr("Would you like to save changes in the current task?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
1748#endif
[9eb63a1598]1749    if (res == QMessageBox::Save)
1750        return actionFileSaveTriggered();
1751    else if (res == QMessageBox::Cancel)
1752        return false;
1753    else
1754        return true;
[1babbd6ba3]1755}
1756
[07e43cf61a]1757void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix)
[1babbd6ba3]1758{
1759int n = spinCities->value();
[317ba0432e]1760QTextTable *table = cur.insertTable(n, n, fmt_table);
1761
[9eb63a1598]1762    for (int r = 0; r < n; r++) {
1763        for (int c = 0; c < n; c++) {
1764            cur = table->cellAt(r, c).firstCursorPosition();
1765            cur.setBlockFormat(fmt_cell);
1766            cur.setBlockCharFormat(fmt_default);
1767            if (matrix.at(r).at(c) == INFINITY)
1768                cur.insertText(INFSTR);
1769            else
1770                cur.insertText(isInteger(matrix.at(r).at(c)) ? QString("%1").arg(matrix.at(r).at(c)) : QString("%1").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()));
1771        }
1772        QCoreApplication::processEvents();
1773    }
1774    cur.movePosition(QTextCursor::End);
[1babbd6ba3]1775}
1776
[07e43cf61a]1777void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step)
[1babbd6ba3]1778{
1779int n = spinCities->value();
[317ba0432e]1780QTextTable *table = cur.insertTable(n, n, fmt_table);
1781
[9eb63a1598]1782    for (int r = 0; r < n; r++) {
1783        for (int c = 0; c < n; c++) {
1784            cur = table->cellAt(r, c).firstCursorPosition();
1785            cur.setBlockFormat(fmt_cell);
1786            if (step.matrix.at(r).at(c) == INFINITY)
1787                cur.insertText(INFSTR, fmt_default);
1788            else if ((r == step.candidate.nRow) && (c == step.candidate.nCol))
1789                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);
1790            else {
[07e43cf61a]1791    TSPSolver::SStep::SCandidate cand;
[9eb63a1598]1792                cand.nRow = r;
1793                cand.nCol = c;
1794                if (step.alts.contains(cand))
1795                    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_alternate);
1796                else
1797                    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_default);
1798            }
1799        }
1800        QCoreApplication::processEvents();
1801    }
1802
1803    cur.movePosition(QTextCursor::End);
[1babbd6ba3]1804}
1805
[89e5214692]1806#ifdef Q_OS_SYMBIAN
[1b40fef578]1807void MainWindow::resizeEvent(QResizeEvent *ev)
1808{
1809    static bool tb = toolBarMain->isVisible();
1810    if ((ev->size().width() < ev->size().height())
1811            && (ev->oldSize().width() > ev->oldSize().height())) {
1812        // From landscape to portrait
1813        if (tb)
1814            toolBarMain->show();
1815        setWindowState(Qt::WindowMaximized);
1816    } else if ((ev->size().width() > ev->size().height())
1817               && (ev->oldSize().width() < ev->oldSize().height())) {
1818        // From portrait to landscape
1819        if (tb = toolBarMain->isVisible())
1820            toolBarMain->hide();
1821        setWindowState(Qt::WindowFullScreen);
1822    }
1823
1824    QWidget::resizeEvent(ev);
1825}
[89e5214692]1826#endif // Q_OS_SYMBIAN
[1b40fef578]1827
[1babbd6ba3]1828void MainWindow::retranslateUi(bool all)
1829{
[9eb63a1598]1830    if (all)
1831        Ui_MainWindow::retranslateUi(this);
[1babbd6ba3]1832
[7ed8b57eea]1833#ifdef Q_OS_BLACKBERRY
1834    menuSettings->removeAction(menuSettingsStyle->menuAction());
1835#else
[9eb63a1598]1836    loadStyleList();
[7ed8b57eea]1837#endif
[9eb63a1598]1838    loadToolbarList();
[e3533af1cf]1839
[7ed8b57eea]1840#ifndef QT_NO_PRINTDIALOG
[9eb63a1598]1841    actionFilePrintPreview->setText(tr("P&rint Preview..."));
[1babbd6ba3]1842#ifndef QT_NO_TOOLTIP
[9eb63a1598]1843    actionFilePrintPreview->setToolTip(tr("Preview solution results"));
[1babbd6ba3]1844#endif // QT_NO_TOOLTIP
1845#ifndef QT_NO_STATUSTIP
[9eb63a1598]1846    actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing"));
[20e8115cee]1847#endif // QT_NO_STATUSTIP
1848
1849    actionFilePageSetup->setText(tr("Pa&ge Setup..."));
1850#ifndef QT_NO_TOOLTIP
1851    actionFilePageSetup->setToolTip(tr("Setup print options"));
1852#endif // QT_NO_TOOLTIP
1853#ifndef QT_NO_STATUSTIP
1854    actionFilePageSetup->setStatusTip(tr("Setup page-related options for printing"));
[88a59e4d65]1855#endif // QT_NO_STATUSTIP
[1babbd6ba3]1856
[9eb63a1598]1857    actionFilePrint->setText(tr("&Print..."));
[1babbd6ba3]1858#ifndef QT_NO_TOOLTIP
[9eb63a1598]1859    actionFilePrint->setToolTip(tr("Print solution"));
[1babbd6ba3]1860#endif // QT_NO_TOOLTIP
1861#ifndef QT_NO_STATUSTIP
[9eb63a1598]1862    actionFilePrint->setStatusTip(tr("Print current solution results"));
[1babbd6ba3]1863#endif // QT_NO_STATUSTIP
[7ed8b57eea]1864#ifndef QT_NO_SHORTCUT
[9eb63a1598]1865    actionFilePrint->setShortcut(tr("Ctrl+P"));
[7ed8b57eea]1866#endif // QT_NO_SHORTCUT
1867#endif // QT_NO_PRINTDIALOG
[8b0661d1ee]1868
[20e8115cee]1869#ifndef QT_NO_STATUSTIP
1870    actionFileExit->setStatusTip(tr("Exit %1").arg(QCoreApplication::applicationName()));
1871#endif // QT_NO_STATUSTIP
1872
[8b0661d1ee]1873#ifndef HANDHELD
[9eb63a1598]1874    actionSettingsToolbarsConfigure->setText(tr("Configure..."));
[8b0661d1ee]1875#ifndef QT_NO_STATUSTIP
[9eb63a1598]1876    actionSettingsToolbarsConfigure->setStatusTip(tr("Customize toolbars"));
[8b0661d1ee]1877#endif // QT_NO_STATUSTIP
1878#endif // HANDHELD
1879
[88a59e4d65]1880#ifndef QT_NO_STATUSTIP
[9eb63a1598]1881    actionHelpReportBug->setStatusTip(tr("Report about a bug in %1").arg(QCoreApplication::applicationName()));
[88a59e4d65]1882#endif // QT_NO_STATUSTIP
[9eb63a1598]1883    if (actionHelpCheck4Updates != NULL) {
1884        actionHelpCheck4Updates->setText(tr("Check for &Updates..."));
[1babbd6ba3]1885#ifndef QT_NO_STATUSTIP
[9eb63a1598]1886        actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QCoreApplication::applicationName()));
[1babbd6ba3]1887#endif // QT_NO_STATUSTIP
[9eb63a1598]1888    }
[88a59e4d65]1889#ifndef QT_NO_STATUSTIP
[9eb63a1598]1890    actionHelpAbout->setStatusTip(tr("About %1").arg(QCoreApplication::applicationName()));
[88a59e4d65]1891#endif // QT_NO_STATUSTIP
[23ad8db4a5]1892
[89e5214692]1893#ifdef Q_OS_SYMBIAN
[23ad8db4a5]1894    actionRightSoftKey->setText(tr("E&xit"));
1895#endif
[1babbd6ba3]1896}
1897
[2a5e50e0a9]1898bool MainWindow::saveTask()
1899{
1900    QStringList filters;
1901#ifdef Q_OS_BLACKBERRY
1902    filters << "*.tspt";
1903#else
1904    filters.append(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
[9eb63a1598]1905    filters.append(tr("All Files") + " (*)");
[2a5e50e0a9]1906#endif
[1babbd6ba3]1907QString file;
[9eb63a1598]1908    if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) {
[2a5e50e0a9]1909#ifdef Q_OS_BLACKBERRY
1910        file = settings->value(OS"/LastUsed/TaskSavePath", "/accounts/1000/shared/documents").toString();
1911#else
[9eb63a1598]1912        file = settings->value(OS"/LastUsed/TaskSavePath").toString();
[2a5e50e0a9]1913#endif
[9eb63a1598]1914        if (!file.isEmpty())
1915            file.append("/");
1916        file.append(fileName);
1917    } else if (fileName.endsWith(".tspt", Qt::CaseInsensitive))
1918        file = fileName;
1919    else
1920        file = QFileInfo(fileName).path() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt";
[1babbd6ba3]1921
[2a5e50e0a9]1922#ifdef Q_OS_BLACKBERRY
1923    FilePicker fd;
1924    fd.setMode(FilePickerMode::Saver);
1925    fd.setType(FileType::Document | FileType::Other);
1926    fd.setDefaultType(FileType::Document);
1927    fd.setAllowOverwrite(true);
1928    fd.setTitle(tr("Task Save"));
1929//    fd.setDirectories(QStringList(QFileInfo(file).path()));
1930    fd.setDefaultSaveFileNames(QStringList(file));
1931    fd.setFilter(filters);
1932    fd.open();
1933
1934    QEventLoop loop;
1935    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
1936    loop.exec();
1937
1938    if (fd.selectedFiles().count() < 1)
1939        return false;
1940    file = fd.selectedFiles().at(0);
1941#else
1942    QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
[9eb63a1598]1943    file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts);
1944    if (file.isEmpty())
1945        return false;
[2a5e50e0a9]1946#endif
1947    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
[9eb63a1598]1948        settings->setValue(OS"/LastUsed/TaskSavePath", QFileInfo(file).path());
[144fbe6b96]1949    if (QFileInfo(file).suffix().isEmpty()) {
1950        file.append(".tspt");
1951    }
[9eb63a1598]1952
1953    if (tspmodel->saveTask(file)) {
1954        setFileName(file);
1955        setWindowModified(false);
1956        return true;
1957    }
1958    return false;
[1babbd6ba3]1959}
1960
1961void MainWindow::setFileName(const QString &fileName)
1962{
[9eb63a1598]1963    this->fileName = fileName;
1964    setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(QCoreApplication::applicationName()));
[1babbd6ba3]1965}
1966
1967void MainWindow::setupUi()
1968{
[9eb63a1598]1969    Ui_MainWindow::setupUi(this);
[1babbd6ba3]1970
[89e5214692]1971#ifdef Q_OS_SYMBIAN
[1b40fef578]1972    setWindowFlags(windowFlags() | Qt::WindowSoftkeysVisibleHint);
[89e5214692]1973#endif // Q_OS_SYMBIAN
[1b40fef578]1974
[9eb63a1598]1975    // File Menu
1976    actionFileNew->setIcon(GET_ICON("document-new"));
1977    actionFileOpen->setIcon(GET_ICON("document-open"));
1978    actionFileSave->setIcon(GET_ICON("document-save"));
[7ed8b57eea]1979#if !defined(HANDHELD) || defined(Q_OS_BLACKBERRY)
[9eb63a1598]1980    menuFileSaveAs->setIcon(GET_ICON("document-save-as"));
[a713b103e8]1981#endif
[9eb63a1598]1982    actionFileExit->setIcon(GET_ICON("application-exit"));
1983    // Settings Menu
[7ed8b57eea]1984#if !defined(HANDHELD) || defined(Q_OS_BLACKBERRY)
[9eb63a1598]1985    menuSettingsLanguage->setIcon(GET_ICON("preferences-desktop-locale"));
[356169a3d3]1986#if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
[9eb63a1598]1987    actionSettingsLanguageEnglish->setIcon(QIcon::fromTheme("flag-gb", QIcon(":/images/icons/l10n/flag-gb.png")));
[356169a3d3]1988#else
[9eb63a1598]1989    actionSettingsLanguageEnglish->setIcon(QIcon(":/images/icons/l10n/flag-gb.png"));
[356169a3d3]1990#endif // QT_VERSION >= QT_VERSION_CHECK(4,6,0)
[9eb63a1598]1991    menuSettingsStyle->setIcon(GET_ICON("preferences-desktop-theme"));
[a713b103e8]1992#endif // HANDHELD
[9eb63a1598]1993    actionSettingsPreferences->setIcon(GET_ICON("preferences-system"));
1994    // Help Menu
[7ed8b57eea]1995#if !defined(HANDHELD) || defined(Q_OS_BLACKBERRY)
[9eb63a1598]1996    actionHelpContents->setIcon(GET_ICON("help-contents"));
1997    actionHelpContextual->setIcon(GET_ICON("help-contextual"));
1998    actionHelpOnlineSupport->setIcon(GET_ICON("applications-internet"));
1999    actionHelpReportBug->setIcon(GET_ICON("tools-report-bug"));
2000    actionHelpAbout->setIcon(GET_ICON("help-about"));
[7ed8b57eea]2001#ifdef Q_OS_BLACKBERRY
2002    // Qt about dialog is too big for the screen
2003    // and it's impossible to close it.
2004    menuHelp->removeAction(actionHelpAboutQt);
2005#else // Q_OS_BLACKBERRY
[356169a3d3]2006#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
[fddcfa4b55]2007    actionHelpAboutQt->setIcon(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"));
[7ed8b57eea]2008#else // QT_VERSION < QT_VERSION_CHECK(5,0,0)
[356169a3d3]2009    actionHelpAboutQt->setIcon(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"));
2010#endif // QT_VERSION < QT_VERSION_CHECK(5,0,0)
[7ed8b57eea]2011#endif // Q_OS_BLACKBERRY
[356169a3d3]2012#endif // HANDHELD
[9eb63a1598]2013    // Buttons
2014    buttonRandom->setIcon(GET_ICON("roll"));
2015    buttonSolve->setIcon(GET_ICON("dialog-ok"));
2016    buttonSaveSolution->setIcon(GET_ICON("document-save-as"));
2017    buttonBackToTask->setIcon(GET_ICON("go-previous"));
[3cadf24d00]2018
[2a436ea693]2019//      action->setIcon(GET_ICON(""));
[3cadf24d00]2020
[356169a3d3]2021#if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
[9eb63a1598]2022    setToolButtonStyle(Qt::ToolButtonFollowStyle);
[1babbd6ba3]2023#endif
2024
2025#ifndef HANDHELD
2026QStatusBar *statusbar = new QStatusBar(this);
[9eb63a1598]2027    statusbar->setObjectName("statusbar");
2028    setStatusBar(statusbar);
[1babbd6ba3]2029#endif // HANDHELD
2030
[89e5214692]2031#ifdef Q_OS_WINCE_WM
[9eb63a1598]2032    menuBar()->setDefaultAction(menuFile->menuAction());
[1babbd6ba3]2033
2034QScrollArea *scrollArea = new QScrollArea(this);
[9eb63a1598]2035    scrollArea->setFrameShape(QFrame::NoFrame);
2036    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
2037    scrollArea->setWidgetResizable(true);
2038    scrollArea->setWidget(tabWidget);
2039    setCentralWidget(scrollArea);
[1babbd6ba3]2040#else
[9eb63a1598]2041    setCentralWidget(tabWidget);
[89e5214692]2042#endif // Q_OS_WINCE_WM
[1babbd6ba3]2043
[9eb63a1598]2044    //! \hack HACK: A little hack for toolbar icons to have a sane size.
[97e90f9be6]2045#if defined(HANDHELD) && !defined(Q_WS_MAEMO_5)
[89e5214692]2046#ifdef Q_OS_SYMBIAN
[23ad8db4a5]2047    toolBarMain->setIconSize(QSize(logicalDpiX() / 5.2, logicalDpiY() / 5.2));
[5cbcd091ed]2048#else
[9eb63a1598]2049    toolBarMain->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4));
[89e5214692]2050#endif // Q_OS_SYMBIAN
[5cbcd091ed]2051#endif // HANDHELD && !Q_WS_MAEMO_5
[7bb19df196]2052QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave));
[5cbcd091ed]2053    if (tb != NULL) {
[9eb63a1598]2054        tb->setMenu(menuFileSaveAs);
2055        tb->setPopupMode(QToolButton::MenuButtonPopup);
2056    }
[1babbd6ba3]2057
[8b0661d1ee]2058//      solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>());
[9eb63a1598]2059    solutionText->setWordWrapMode(QTextOption::WordWrap);
[1babbd6ba3]2060
[7ed8b57eea]2061#ifndef QT_NO_PRINTDIALOG
[9eb63a1598]2062    actionFilePrintPreview = new QAction(this);
2063    actionFilePrintPreview->setObjectName("actionFilePrintPreview");
2064    actionFilePrintPreview->setEnabled(false);
2065    actionFilePrintPreview->setIcon(GET_ICON("document-print-preview"));
[1babbd6ba3]2066
[20e8115cee]2067    actionFilePageSetup = new QAction(this);
2068    actionFilePageSetup->setObjectName("actionFilePrintSetup");
2069//    actionFilePageSetup->setEnabled(false);
[356169a3d3]2070#if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
[20e8115cee]2071    actionFilePageSetup->setIcon(QIcon::fromTheme("document-page-setup", QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/page-setup-32.png")));
2072#else
2073    actionFilePageSetup->setIcon(QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/page-setup-32.png"));
2074#endif
2075
[9eb63a1598]2076    actionFilePrint = new QAction(this);
2077    actionFilePrint->setObjectName("actionFilePrint");
2078    actionFilePrint->setEnabled(false);
2079    actionFilePrint->setIcon(GET_ICON("document-print"));
[1babbd6ba3]2080
[20e8115cee]2081    menuFile->insertAction(actionFileExit, actionFilePrintPreview);
2082    menuFile->insertAction(actionFileExit, actionFilePageSetup);
2083    menuFile->insertAction(actionFileExit, actionFilePrint);
[9eb63a1598]2084    menuFile->insertSeparator(actionFileExit);
[1babbd6ba3]2085
[9eb63a1598]2086    toolBarMain->insertAction(actionSettingsPreferences, actionFilePrint);
[7ed8b57eea]2087#endif // QT_NO_PRINTDIALOG
[e51c78af27]2088
[9eb63a1598]2089    groupSettingsLanguageList = new QActionGroup(this);
[97e90f9be6]2090#ifdef Q_WS_MAEMO_5
[9eb63a1598]2091    groupSettingsLanguageList->addAction(actionSettingsLanguageAutodetect);
[97e90f9be6]2092#endif
[9eb63a1598]2093    actionSettingsLanguageEnglish->setData("en");
2094    actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
2095    loadLangList();
2096    actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
[e3533af1cf]2097
[9eb63a1598]2098    actionSettingsStyleSystem->setData(true);
2099    groupSettingsStyleList = new QActionGroup(this);
[97e90f9be6]2100#ifdef Q_WS_MAEMO_5
[9eb63a1598]2101    groupSettingsStyleList->addAction(actionSettingsStyleSystem);
[97e90f9be6]2102#endif
[e3533af1cf]2103
[7bb19df196]2104#ifndef HANDHELD
[9eb63a1598]2105    actionSettingsToolbarsConfigure = new QAction(this);
2106    actionSettingsToolbarsConfigure->setIcon(GET_ICON("configure-toolbars"));
[7bb19df196]2107#endif // HANDHELD
2108
[9eb63a1598]2109    if (hasUpdater()) {
2110        actionHelpCheck4Updates = new QAction(this);
2111        actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update"));
2112        actionHelpCheck4Updates->setEnabled(hasUpdater());
2113        menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates);
2114        menuHelp->insertSeparator(actionHelpAboutQt);
2115    } else
2116        actionHelpCheck4Updates = NULL;
[1babbd6ba3]2117
[47c811cc09]2118    spinCities->setMaximum(settings->value("Tweaks/MaxNumCities", MAX_NUM_CITIES).toInt());
[1babbd6ba3]2119
[94cd045fad]2120#ifndef HANDHELD
[20e8115cee]2121    toolBarManager = new QtToolBarManager(this);
[9eb63a1598]2122    toolBarManager->setMainWindow(this);
[7bb19df196]2123QString cat = toolBarMain->windowTitle();
[9eb63a1598]2124    toolBarManager->addToolBar(toolBarMain, cat);
[94cd045fad]2125#ifndef QT_NO_PRINTER
[9eb63a1598]2126    toolBarManager->addAction(actionFilePrintPreview, cat);
[20e8115cee]2127    toolBarManager->addAction(actionFilePageSetup, cat);
[94cd045fad]2128#endif // QT_NO_PRINTER
[9eb63a1598]2129    toolBarManager->addAction(actionHelpContents, cat);
2130    toolBarManager->addAction(actionHelpContextual, cat);
2131    toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray());
[a713b103e8]2132#else
[9eb63a1598]2133    toolBarMain->setVisible(settings->value("MainWindow/ToolbarVisible", true).toBool());
[94cd045fad]2134#endif // HANDHELD
[7bb19df196]2135
[89e5214692]2136#ifdef Q_OS_SYMBIAN
[23ad8db4a5]2137    // Replace Exit on the right soft key with our own exit action.
2138    // This makes it translatable.
2139    actionRightSoftKey = new QAction(this);
2140    actionRightSoftKey->setSoftKeyRole(QAction::NegativeSoftKey);
2141    connect(actionRightSoftKey, SIGNAL(triggered()), SLOT(close()));
2142    addAction(actionRightSoftKey);
2143#endif
2144
[9eb63a1598]2145    retranslateUi(false);
[7bb19df196]2146
[b8a2a118c4]2147#ifndef HANDHELD
2148    // Adding some eyecandy
[9eb63a1598]2149    if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
2150        toggleTranclucency(true);
2151    }
[b8a2a118c4]2152#endif // HANDHELD
[1babbd6ba3]2153}
2154
2155void MainWindow::toggleSolutionActions(bool enable)
2156{
[9eb63a1598]2157    buttonSaveSolution->setEnabled(enable);
2158    actionFileSaveAsSolution->setEnabled(enable);
2159    solutionText->setEnabled(enable);
[7ed8b57eea]2160#ifndef QT_NO_PRINTDIALOG
[9eb63a1598]2161    actionFilePrint->setEnabled(enable);
2162    actionFilePrintPreview->setEnabled(enable);
[7ed8b57eea]2163#endif // QT_NO_PRINTDIALOG
[1babbd6ba3]2164}
2165
2166void MainWindow::toggleTranclucency(bool enable)
2167{
[b8a2a118c4]2168#ifndef HANDHELD
[9eb63a1598]2169    toggleStyle(labelVariant, enable);
2170    toggleStyle(labelCities, enable);
2171    toggleStyle(statusBar(), enable);
2172    tabWidget->setDocumentMode(enable);
2173    QtWin::enableBlurBehindWindow(this, enable);
[1babbd6ba3]2174#else
[9eb63a1598]2175    Q_UNUSED(enable);
[b8a2a118c4]2176#endif // HANDHELD
[1babbd6ba3]2177}
[88a59e4d65]2178
2179void MainWindow::actionHelpOnlineSupportTriggered()
2180{
[9eb63a1598]2181    QDesktopServices::openUrl(QUrl("http://tspsg.info/goto/support"));
[88a59e4d65]2182}
2183
2184void MainWindow::actionHelpReportBugTriggered()
2185{
[9eb63a1598]2186    QDesktopServices::openUrl(QUrl("http://tspsg.info/goto/bugtracker"));
[88a59e4d65]2187}
[fddcfa4b55]2188
[89e5214692]2189#ifdef Q_OS_SYMBIAN
[fddcfa4b55]2190QSMessageBox::QSMessageBox(QWidget *parent)
2191    : QMessageBox(parent)
2192{
2193    setIcon(QMessageBox::Warning);
2194    setWindowTitle(QApplication::translate("MainWindow", "Unsaved Changes"));
2195    setText(QApplication::translate("MainWindow", "Would you like to save changes in the current task?"));
2196    setStandardButtons(QMessageBox::Save);
2197
2198    QMenu *m = new QMenu(this);
[019894f5ef]2199    m->addAction(QApplication::translate("QDialogButtonBox", "Discard", "No need to translate this. The translation will be taken from Qt translation files."),
[fddcfa4b55]2200                 this, SLOT(discard()));
[019894f5ef]2201    m->addAction(QApplication::translate("QDialogButtonBox", "Cancel", "No need to translate this. The translation will be taken from Qt translation files."),
[fddcfa4b55]2202                 this, SLOT(cancel()));
2203
[019894f5ef]2204    QAction *o = new QAction(QApplication::translate("QtToolBarDialog", "Actions"), this);
[fddcfa4b55]2205    o->setSoftKeyRole(QAction::NegativeSoftKey);
2206    o->setMenu(m);
2207    addAction(o);
2208}
2209
2210void QSMessageBox::cancel(){
2211    done(QMessageBox::Cancel);
2212}
2213
2214void QSMessageBox::discard() {
2215    done(QMessageBox::Discard);
2216}
[89e5214692]2217#endif // Q_OS_SYMBIAN
Note: See TracBrowser for help on using the repository browser.