source: tspsg-svn/trunk/src/mainwindow.cpp @ 99

Last change on this file since 99 was 99, checked in by laleppa, 14 years ago
  • Fixed a bug when a solution couldn't be found for some tasks while the task had at least one solution (mostly, tasks with a lot of restrictions).
  • Fixed a bug when Save As dialog always appeared (even for non-Untitled files) when selecting Save in Unsaved Changes dialog.
  • Improved the solution algorithm.
  • Moved progress dialog from CTSPSolver to MainWindow?. CTSPSolver doesn't contain any GUI related code now.

+ Added routePartFound() signal to CTSPSolver which is emitted once every time a part of the route is found.
+ Added cancel() slot and wasCanceled() public function to CTSPSolver to be able to cancel a solution process and to know whether it was canceled.
+ Progress is now shown when generating a solution output.
+ Check for updates functionality (only in Windows version at this moment).

  • Property svn:keywords set to Id URL
File size: 38.5 KB
RevLine 
[45]1/*
[42]2 *  TSPSG: TSP Solver and Generator
[87]3 *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
[1]4 *
[6]5 *  $Id: mainwindow.cpp 99 2010-03-22 20:45:16Z laleppa $
6 *  $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/mainwindow.cpp $
[4]7 *
[6]8 *  This file is part of TSPSG.
[1]9 *
[6]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
12 *  the Free Software Foundation, either version 3 of the License, or
13 *  (at your option) any later version.
[1]14 *
[6]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.
[1]19 *
[6]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/>.
[1]22 */
23
24#include "mainwindow.h"
25
[65]26/*!
27 * \brief Class constructor.
28 * \param parent Main Window parent widget.
29 *
30 *  Initializes Main Window and creates its layout based on target OS.
31 *  Loads TSPSG settings and opens a task file if it was specified as a commandline parameter.
32 */
[1]33MainWindow::MainWindow(QWidget *parent)
[21]34        : QMainWindow(parent)
[1]35{
[80]36        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
[94]37
[29]38        loadLanguage();
[80]39        setupUi();
40
[42]41        initDocStyleSheet();
[80]42
[54]43#ifndef QT_NO_PRINTER
[52]44        printer = new QPrinter(QPrinter::HighResolution);
[54]45#endif // QT_NO_PRINTER
[80]46
[94]47#ifdef Q_OS_WINCE
48        currentGeometry = QApplication::desktop()->availableGeometry(0);
49        // We need to react to SIP show/hide and resize the window appropriately
50        connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
51#endif // Q_OS_WINCE
[29]52        connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
[31]53        connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
[50]54        connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered()));
[42]55        connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
56        connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
[80]57#ifndef QT_NO_PRINTER
58        connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered()));
59        connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered()));
60#endif // QT_NO_PRINTER
[29]61        connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered()));
[99]62#ifdef Q_OS_WIN32
63        connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered()));
64#endif // Q_OS_WIN32
[29]65        connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
66        connect(groupSettingsLanguageList,SIGNAL(triggered(QAction *)),this,SLOT(groupSettingsLanguageListTriggered(QAction *)));
[37]67        connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
[29]68        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
[80]69
[29]70        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
71        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
[50]72        connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
[29]73        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
[71]74
[93]75#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
[95]76        // Centering main window
77QRect rect = geometry();
78        rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
79        setGeometry(rect);
[82]80        if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
[21]81                // Loading of saved window state
[23]82                settings->beginGroup("MainWindow");
[71]83                restoreGeometry(settings->value("Geometry").toByteArray());
84                restoreState(settings->value("State").toByteArray());
[23]85                settings->endGroup();
[93]86        }
87#else
[94]88        setWindowState(Qt::WindowMaximized);
[71]89#endif // Q_OS_WINCE
90
91        tspmodel = new CTSPModel(this);
[52]92        taskView->setModel(tspmodel);
[31]93        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
[57]94        connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
[37]95        connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
[50]96        if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
[47]97                setFileName(QCoreApplication::arguments().at(1));
[50]98        else {
[47]99                setFileName();
[50]100                spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
[52]101                spinCitiesValueChanged(spinCities->value());
[50]102        }
103        setWindowModified(false);
[6]104}
105
[80]106MainWindow::~MainWindow()
107{
108#ifndef QT_NO_PRINTER
109        delete printer;
110#endif
111}
112
[67]113/* Privates **********************************************************/
[42]114
[29]115void MainWindow::actionFileNewTriggered()
[1]116{
[47]117        if (!maybeSave())
118                return;
[54]119        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[29]120        tspmodel->clear();
[47]121        setFileName();
[37]122        setWindowModified(false);
[42]123        tabWidget->setCurrentIndex(0);
124        solutionText->clear();
[78]125        toggleSolutionActions(false);
[54]126        QApplication::restoreOverrideCursor();
[29]127}
128
[31]129void MainWindow::actionFileOpenTriggered()
130{
[47]131        if (!maybeSave())
132                return;
[78]133
[87]134QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)");
135        filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)");
136        filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
137        filters.append(tr("All Files") + " (*)");
[78]138
[99]139QString file = QFileInfo(fileName).canonicalPath();
[82]140QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
[99]141        file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts);
[78]142        if (file.isEmpty() || !QFileInfo(file).isFile())
[31]143                return;
[78]144        if (!tspmodel->loadTask(file))
[31]145                return;
[78]146        setFileName(file);
[47]147        tabWidget->setCurrentIndex(0);
[37]148        setWindowModified(false);
[42]149        solutionText->clear();
[78]150        toggleSolutionActions(false);
[31]151}
152
[99]153bool MainWindow::actionFileSaveTriggered()
[50]154{
[96]155        if ((fileName == tr("Untitled") + ".tspt") || (!fileName.endsWith(".tspt", Qt::CaseInsensitive)))
[99]156                return saveTask();
[59]157        else
[99]158                if (tspmodel->saveTask(fileName)) {
[50]159                        setWindowModified(false);
[99]160                        return true;
161                } else
162                        return false;
[50]163}
164
[42]165void MainWindow::actionFileSaveAsTaskTriggered()
[31]166{
[37]167        saveTask();
168}
169
[42]170void MainWindow::actionFileSaveAsSolutionTriggered()
171{
172static QString selectedFile;
[99]173        if (selectedFile.isEmpty())
174                selectedFile = QFileInfo(fileName).canonicalPath();
175        else
176                selectedFile = QFileInfo(selectedFile).canonicalPath();
177        if (!selectedFile.isEmpty())
178                selectedFile += "/";
179        if (fileName == tr("Untitled") + ".tspt") {
[55]180#ifndef QT_NO_PRINTER
[99]181                selectedFile += "solution.pdf";
[55]182#else
[99]183                selectedFile += "solution.html";
[55]184#endif // QT_NO_PRINTER
[99]185        } else {
[78]186#ifndef QT_NO_PRINTER
[99]187                selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf";
[78]188#else
[99]189                selectedFile += QFileInfo(fileName).completeBaseName() + ".html";
[78]190#endif // QT_NO_PRINTER
191        }
192
[55]193QStringList filters;
194#ifndef QT_NO_PRINTER
[87]195        filters.append(tr("PDF Files") + " (*.pdf)");
[55]196#endif
[87]197        filters.append(tr("HTML Files") + " (*.html *.htm)");
[45]198#if QT_VERSION >= 0x040500
[87]199        filters.append(tr("OpenDocument Files") + " (*.odt)");
[45]200#endif // QT_VERSION >= 0x040500
[87]201        filters.append(tr("All Files") + " (*)");
[78]202
[99]203QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog);
[82]204QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts);
[78]205        if (file.isEmpty())
[42]206                return;
[78]207        selectedFile = file;
[51]208        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[55]209#ifndef QT_NO_PRINTER
210        if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) {
211QPrinter printer(QPrinter::HighResolution);
212                printer.setOutputFormat(QPrinter::PdfFormat);
213                printer.setOutputFileName(selectedFile);
214                solutionText->document()->print(&printer);
215                QApplication::restoreOverrideCursor();
216                return;
217        }
218#endif
[45]219#if QT_VERSION >= 0x040500
[42]220QTextDocumentWriter dw(selectedFile);
221        if (!(selectedFile.endsWith(".htm",Qt::CaseInsensitive) || selectedFile.endsWith(".html",Qt::CaseInsensitive) || selectedFile.endsWith(".odt",Qt::CaseInsensitive) || selectedFile.endsWith(".txt",Qt::CaseInsensitive)))
222                dw.setFormat("plaintext");
[99]223        if (!dw.write(solutionText->document()))
224                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString()));
225#else // QT_VERSION >= 0x040500
[45]226        // Qt < 4.5 has no QTextDocumentWriter class
227QFile file(selectedFile);
[51]228        if (!file.open(QFile::WriteOnly)) {
229                QApplication::restoreOverrideCursor();
[99]230                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file->errorString()));
[45]231                return;
[51]232        }
[45]233QTextStream ts(&file);
234        ts.setCodec(QTextCodec::codecForName("UTF-8"));
235        ts << solutionText->document()->toHtml("UTF-8");
[51]236        file.close();
[45]237#endif // QT_VERSION >= 0x040500
[51]238        QApplication::restoreOverrideCursor();
[42]239}
240
[67]241#ifndef QT_NO_PRINTER
242void MainWindow::actionFilePrintPreviewTriggered()
243{
244QPrintPreviewDialog ppd(printer, this);
[92]245        connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
246        ppd.exec();
[31]247}
248
[67]249void MainWindow::actionFilePrintTriggered()
250{
251QPrintDialog pd(printer,this);
252#if QT_VERSION >= 0x040500
253        // No such methods in Qt < 4.5
254        pd.setOption(QAbstractPrintDialog::PrintSelection,false);
255        pd.setOption(QAbstractPrintDialog::PrintPageRange,false);
256#endif
257        if (pd.exec() != QDialog::Accepted)
258                return;
259        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
260        solutionText->document()->print(printer);
261        QApplication::restoreOverrideCursor();
262}
263#endif // QT_NO_PRINTER
264
[29]265void MainWindow::actionSettingsPreferencesTriggered()
266{
[1]267SettingsDialog sd(this);
[42]268        if (sd.exec() != QDialog::Accepted)
269                return;
270        if (sd.colorChanged() || sd.fontChanged()) {
271                initDocStyleSheet();
[99]272                if (!solutionText->document()->isEmpty() && sd.colorChanged())
273                        QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output."));
[42]274        }
[99]275        if (sd.translucencyChanged() != 0)
[92]276                toggleTranclucency(sd.translucencyChanged() == 1);
[1]277}
[6]278
[67]279void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked)
[17]280{
[67]281        if (checked) {
282                settings->remove("Language");
[94]283                QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on next application start."));
[67]284        } else
[94]285                settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());
[52]286}
287
[67]288void MainWindow::groupSettingsLanguageListTriggered(QAction *action)
[52]289{
[67]290        if (actionSettingsLanguageAutodetect->isChecked()) {
291                // We have language autodetection. It needs to be disabled to change language.
[99]292                if (QMessageBox::question(this, tr("Language change"), tr("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
[67]293                        actionSettingsLanguageAutodetect->trigger();
294                } else
295                        return;
296        }
[87]297bool untitled = (fileName == tr("Untitled") + ".tspt");
[67]298        if (loadLanguage(action->data().toString())) {
[80]299                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[67]300                settings->setValue("Language",action->data().toString());
[80]301                retranslateUi();
[67]302                if (untitled)
303                        setFileName();
[98]304#ifdef Q_OS_WIN32
305                if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
306                        toggleStyle(labelVariant, true);
307                        toggleStyle(labelCities, true);
308                }
309#endif
[80]310                QApplication::restoreOverrideCursor();
[99]311                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."));
[67]312        }
[52]313}
314
[99]315#ifdef Q_OS_WIN32
316void MainWindow::actionHelpCheck4UpdatesTriggered()
317{
318        if (!hasUpdater()) {
319                QMessageBox::warning(this, tr("Unsupported Feature"), tr("Sorry, but this feature is not supported on your platform\nor support for this feature was not installed."));
320                return;
321        }
322
323        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
324        QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\"");
325        QApplication::restoreOverrideCursor();
326}
327#endif // Q_OS_WIN32
328
[67]329void MainWindow::actionHelpAboutTriggered()
[52]330{
[78]331QString title;
[93]332#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
[98]333        title += QString("<b>TSPSG<br>TSP Solver and Generator</b><br>");
[78]334#else
[98]335        title += QString("<b>TSPSG: TSP Solver and Generator</b><br>");
336#endif // Q_OS_WINCE || Q_OS_SYMBIAN
[99]337        title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion());
[98]338#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
[99]339        title += QString("<b>&copy; 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName());
[98]340        title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sourceforge.net/</a></b>");
341#else
342        title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sf.net/</a></b>");
343#endif // Q_OS_WINCE && Q_OS_SYMBIAN
344
[78]345QString about;
[98]346        about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), OS);
[78]347#ifndef STATIC_BUILD
[98]348        about += QString("%1 (%2):<br>").arg(tr("Qt library"), tr("shared"));
349        about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR);
350        about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Runtime"), qVersion());
[78]351#else
[98]352        about += QString("%1: <b>%2</b> (%3)<br>").arg(tr("Qt library"), QT_VERSION_STR, tr("static"));
[78]353#endif // STATIC_BUILD
[98]354        about += tr("Buid <b>%1</b>, built on <b>%2</b> at <b>%3</b>").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__) + "<br>";
355        about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId());
[74]356        about += "<br>";
[98]357        about += tr("TSPSG is free software: you can redistribute it and/or modify it<br>"
[74]358                "under the terms of the GNU General Public License as published<br>"
359                "by the Free Software Foundation, either version 3 of the License,<br>"
360                "or (at your option) any later version.<br>"
361                "<br>"
362                "TSPSG is distributed in the hope that it will be useful, but<br>"
363                "WITHOUT ANY WARRANTY; without even the implied warranty of<br>"
364                "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>"
365                "GNU General Public License for more details.<br>"
366                "<br>"
367                "You should have received a copy of the GNU General Public License<br>"
[98]368                "along with TSPSG.  If not, see <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>.");
[74]369
370QDialog *dlg = new QDialog(this);
[78]371QLabel *lblIcon = new QLabel(dlg),
[98]372        *lblTitle = new QLabel(dlg),
373        *lblTranslated = new QLabel(dlg);
374#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
375QLabel *lblSubTitle = new QLabel(QString("<b>&copy; 2007-%1 Oleksii \"Lёppa\" Serdiuk</b>").arg(QDate::currentDate().toString("yyyy")), dlg);
376#endif // Q_OS_WINCE || Q_OS_SYMBIAN
[74]377QTextBrowser *txtAbout = new QTextBrowser(dlg);
[78]378QVBoxLayout *vb = new QVBoxLayout();
[98]379QHBoxLayout *hb1 = new QHBoxLayout(),
380        *hb2 = new QHBoxLayout();
[74]381QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg);
382
[78]383        lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation));
384        lblIcon->setAlignment(Qt::AlignTop);
[98]385#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
386        lblIcon->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().windowText().color().name()));
387#endif
388
[80]389        lblTitle->setOpenExternalLinks(true);
[78]390        lblTitle->setText(title);
[98]391        lblTitle->setAlignment(Qt::AlignTop);
392        lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
393#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
394        lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name()));
395#endif
[74]396
[98]397        hb1->addWidget(lblIcon);
398        hb1->addWidget(lblTitle);
[74]399
400        txtAbout->setWordWrapMode(QTextOption::NoWrap);
401        txtAbout->setOpenExternalLinks(true);
402        txtAbout->setHtml(about);
403        txtAbout->moveCursor(QTextCursor::Start);
[98]404#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
405        txtAbout->setStyleSheet(QString("QTextBrowser {border-color: %1; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().shadow().color().name()));
406#endif
[74]407
[92]408        bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
409
[98]410        lblTranslated->setText(QApplication::translate("--------", "TRANSLATION", "Please, provide translator credits here."));
411        if (lblTranslated->text() == "TRANSLATION")
412                lblTranslated->hide();
413        else {
414                lblTranslated->setOpenExternalLinks(true);
415#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
416                lblTranslated->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name()));
417#endif
418                hb2->addWidget(lblTranslated);
419        }
420
421        hb2->addWidget(bb);
422
423#if defined(Q_OS_WINCE)
424        vb->setMargin(3);
425#endif
426        vb->addLayout(hb1);
427#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
428        vb->addWidget(lblSubTitle);
429#endif // Q_OS_WINCE || Q_OS_SYMBIAN
[78]430        vb->addWidget(txtAbout);
[98]431        vb->addLayout(hb2);
[74]432
[99]433        dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
[87]434        dlg->setWindowTitle(tr("About TSPSG"));
[78]435        dlg->setLayout(vb);
[74]436
437        connect(bb, SIGNAL(accepted()), dlg, SLOT(accept()));
438
[96]439#ifdef Q_OS_WIN32
[92]440        // Adding some eyecandy in Vista and 7 :-)
441        if (QtWin::isCompositionEnabled())  {
442                QtWin::enableBlurBehindWindow(dlg, true);
443        }
[96]444#endif // Q_OS_WIN32
[92]445
[98]446        dlg->resize(450, 350);
447
[74]448        dlg->exec();
449
450        delete dlg;
[17]451}
452
[50]453void MainWindow::buttonBackToTaskClicked()
454{
455        tabWidget->setCurrentIndex(0);
456}
457
[67]458void MainWindow::buttonRandomClicked()
[42]459{
[67]460        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
461        tspmodel->randomize();
462        QApplication::restoreOverrideCursor();
[42]463}
464
[29]465void MainWindow::buttonSolveClicked()
[6]466{
[74]467TMatrix matrix;
[89]468QList<double> row;
[15]469int n = spinCities->value();
[13]470bool ok;
[15]471        for (int r = 0; r < n; r++) {
[42]472                row.clear();
[15]473                for (int c = 0; c < n; c++) {
[89]474                        row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
[15]475                        if (!ok) {
[99]476                                QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1));
[15]477                                return;
[13]478                        }
479                }
480                matrix.append(row);
481        }
[99]482
483QProgressDialog pd(this);
484QProgressBar *pb = new QProgressBar(&pd);
485        pb->setAlignment(Qt::AlignCenter);
486        pb->setFormat(tr("%v of %1 parts found").arg(n));
487        pd.setBar(pb);
488        pd.setMaximum(n * 2 + 3);
489        pd.setMinimumDuration(1000);
490        pd.setLabelText(tr("Calculating optimal route..."));
491        pd.setWindowTitle(tr("Solution Progress"));
492        pd.setWindowModality(Qt::ApplicationModal);
493        pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
494        pd.setValue(0);
495
[13]496CTSPSolver solver;
[99]497        connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
498        connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
499SStep *root = solver.solve(n, matrix);
500        disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
501        disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
502        if (!root) {
503                pd.reset();
504                if (!solver.wasCanceled())
505                        QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution."));
[42]506                return;
[99]507        }
508        pb->setFormat("%p%");
509        pd.setLabelText(tr("Generating solution output..."));
510        pd.setValue(n + 1);
511
512        solutionText->clear();
513        pd.setValue(n + 2);
514
515        solutionText->setDocumentTitle(tr("Solution of Variant #%1 task").arg(spinVariant->value()));
516        solutionText->append("<p>" + tr("Variant #%1").arg(spinVariant->value()) + "</p>");
517        solutionText->append("<p>" + tr("Task:") + "</p>");
518        solutionText->append(outputMatrix(matrix));
519        solutionText->append("<hr><p>" + tr("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>");
[74]520SStep *step = root;
[42]521        n = 1;
522        while (n <= spinCities->value()) {
[99]523                if (pd.wasCanceled()) {
524                        solutionText->clear();
525                        return;
526                }
527                pd.setValue(spinCities->value() + 2 + n);
528
[74]529                if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) {
[42]530                        if (n != spinCities->value()) {
[99]531                                solutionText->append("<p>" + tr("Step #%1").arg(n++) + "</p>");
[91]532                                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())))) {
[99]533                                        solutionText->append(outputMatrix(*step));
[78]534                                }
[99]535                                solutionText->append("<p>" + tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>");
[74]536                                if (!step->alts.empty()) {
[76]537SCandidate cand;
[74]538QString alts;
539                                        foreach(cand, step->alts) {
540                                                if (!alts.isEmpty())
541                                                        alts += ", ";
[87]542                                                alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
[74]543                                        }
[99]544                                        solutionText->append("<p class=\"hasalts\">" + tr("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>");
[74]545                                }
[99]546                                solutionText->append("<p>&nbsp;</p>");
[42]547                        }
548                }
549                if (step->prNode->prNode != NULL)
550                        step = step->prNode;
551                else if (step->plNode->prNode != NULL)
552                        step = step->plNode;
553                else
554                        break;
555        }
[99]556        pd.setValue(spinCities->value() + 2 + n);
557
[60]558        if (solver.isOptimal())
[99]559                solutionText->append("<p>" + tr("Optimal path:") + "</p>");
[60]560        else
[99]561                solutionText->append("<p>" + tr("Resulting path:") + "</p>");
562        solutionText->append("<p>&nbsp;&nbsp;" + solver.getSortedPath() + "</p>");
[81]563        if (isInteger(step->price))
[99]564                solutionText->append("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>");
[81]565        else
[99]566                solutionText->append("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>");
[60]567        if (!solver.isOptimal()) {
[99]568                solutionText->append("<p>&nbsp;</p>");
569                solutionText->append("<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>");
[60]570        }
[78]571
[81]572        if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
573                // Scrolling to the end of text.
574                solutionText->moveCursor(QTextCursor::End);
[99]575        } else
576                solutionText->moveCursor(QTextCursor::Start);
[65]577
[99]578        pd.setLabelText(tr("Cleaning up..."));
579        pd.setMaximum(0);
580        pd.setCancelButton(NULL);
581        pd.adjustSize();
582        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
583        solver.cleanup(true);
[78]584        toggleSolutionActions();
[42]585        tabWidget->setCurrentIndex(1);
[6]586}
[21]587
[67]588void MainWindow::dataChanged()
[21]589{
[67]590        setWindowModified(true);
[21]591}
592
[67]593void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br)
594{
595        setWindowModified(true);
[82]596        if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) {
[67]597                for (int k = tl.row(); k <= br.row(); k++)
598                        taskView->resizeRowToContents(k);
599                for (int k = tl.column(); k <= br.column(); k++)
600                        taskView->resizeColumnToContents(k);
601        }
602}
603
[94]604#ifdef Q_OS_WINCE
[95]605void MainWindow::changeEvent(QEvent *ev)
606{
607        if ((ev->type() == QEvent::ActivationChange) && isActiveWindow())
608                desktopResized(0);
609
610        QWidget::changeEvent(ev);
611}
612
[94]613void MainWindow::desktopResized(int screen)
614{
[95]615        if ((screen != 0) || !isActiveWindow())
[94]616                return;
617
618QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
619        if (currentGeometry != availableGeometry) {
[95]620                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[94]621                /*!
622                 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
623                 *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
624                 *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
625                 */
626                if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
627                        setWindowState(windowState() | Qt::WindowMaximized);
628                } else {
629                        if (windowState() & Qt::WindowMaximized)
630                                setWindowState(windowState() ^ Qt::WindowMaximized);
631                        setGeometry(availableGeometry);
632                }
[95]633                currentGeometry = availableGeometry;
634                QApplication::restoreOverrideCursor();
[94]635        }
636}
637#endif // Q_OS_WINCE
638
[67]639void MainWindow::numCitiesChanged(int nCities)
640{
641        blockSignals(true);
642        spinCities->setValue(nCities);
643        blockSignals(false);
644}
645
646#ifndef QT_NO_PRINTER
647void MainWindow::printPreview(QPrinter *printer)
648{
649        solutionText->print(printer);
650}
651#endif // QT_NO_PRINTER
652
653void MainWindow::spinCitiesValueChanged(int n)
654{
[80]655        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
[67]656int count = tspmodel->numCities();
657        tspmodel->setNumCities(n);
[82]658        if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool())
[67]659                for (int k = count; k < n; k++) {
660                        taskView->resizeColumnToContents(k);
661                        taskView->resizeRowToContents(k);
662                }
[80]663        QApplication::restoreOverrideCursor();
[67]664}
665
[71]666void MainWindow::closeEvent(QCloseEvent *ev)
[69]667{
668        if (!maybeSave()) {
[71]669                ev->ignore();
[69]670                return;
671        }
[95]672        if (!settings->value("SettingsReset", false).toBool()) {
673                settings->setValue("NumCities", spinCities->value());
[71]674
[95]675                // Saving Main Window state
676                if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
677                        settings->beginGroup("MainWindow");
[93]678#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
[95]679                        settings->setValue("Geometry", saveGeometry());
[71]680#endif // Q_OS_WINCE
[95]681                        settings->setValue("State", saveState());
682                        settings->endGroup();
683                }
684        } else {
685                settings->remove("SettingsReset");
[69]686        }
[71]687
688        QMainWindow::closeEvent(ev);
[69]689}
690
[99]691bool MainWindow::hasUpdater() const
692{
693#ifdef Q_OS_WIN32
694        return QFile::exists("updater/Update.exe");
695#else // Q_OS_WIN32
696        return false;
697#endif // Q_OS_WIN32
698}
699
[67]700void MainWindow::initDocStyleSheet()
701{
702QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>();
703QColor hilight;
704        if (color.value() < 192)
705                hilight.setHsv(color.hue(),color.saturation(),127 + qRound(color.value() / 2));
706        else
707                hilight.setHsv(color.hue(),color.saturation(),color.value() / 2);
708        solutionText->document()->setDefaultStyleSheet("* {color: " + color.name() +";} p {margin: 0px 10px;} table {margin: 5px;} td {padding: 1px 5px;} .hasalts {color: " + hilight.name() + ";} .selected {color: #A00000; font-weight: bold;} .alternate {color: #008000; font-weight: bold;}");
709        solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
710}
711
[29]712void MainWindow::loadLangList()
713{
[96]714QDir dir(PATH_L10N, "tspsg_*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files);
[29]715        if (!dir.exists())
716                return;
717QFileInfoList langs = dir.entryInfoList();
718        if (langs.size() <= 0)
719                return;
720QAction *a;
[94]721QTranslator t;
722QString name;
[29]723        for (int k = 0; k < langs.size(); k++) {
724                QFileInfo lang = langs.at(k);
[96]725                if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && t.load(lang.completeBaseName(), PATH_L10N)) {
[94]726                        name = t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here.");
727                        a = menuSettingsLanguage->addAction(name);
728                        a->setStatusTip(QString("Set application language to %1").arg(name));
729                        a->setData(lang.completeBaseName().mid(6));
[29]730                        a->setCheckable(true);
731                        a->setActionGroup(groupSettingsLanguageList);
[94]732                        if (settings->value("Language", QLocale::system().name()).toString().startsWith(lang.completeBaseName().mid(6)))
[29]733                                a->setChecked(true);
734                }
735        }
736}
737
[71]738bool MainWindow::loadLanguage(const QString &lang)
[29]739{
[67]740// i18n
741bool ad = false;
[71]742QString lng = lang;
743        if (lng.isEmpty()) {
[93]744                ad = settings->value("Language", "").toString().isEmpty();
745                lng = settings->value("Language", QLocale::system().name()).toString();
[29]746        }
[67]747static QTranslator *qtTranslator; // Qt library translator
748        if (qtTranslator) {
749                qApp->removeTranslator(qtTranslator);
750                delete qtTranslator;
751                qtTranslator = NULL;
[29]752        }
[67]753static QTranslator *translator; // Application translator
754        if (translator) {
755                qApp->removeTranslator(translator);
756                delete translator;
[80]757                translator = NULL;
[37]758        }
[80]759
760        if (lng == "en")
761                return true;
762
763        // Trying to load system Qt library translation...
764        qtTranslator = new QTranslator(this);
[93]765        if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
[80]766                qApp->installTranslator(qtTranslator);
767        else {
768                // No luck. Let's try to load a bundled one.
[96]769                if (qtTranslator->load("qt_" + lng, PATH_L10N))
[67]770                        qApp->installTranslator(qtTranslator);
[74]771                else {
[80]772                        // Qt library translation unavailable
773                        delete qtTranslator;
774                        qtTranslator = NULL;
[74]775                }
776        }
[80]777
[74]778        // Now let's load application translation.
[80]779        translator = new QTranslator(this);
[96]780        if (translator->load("tspsg_" + lng, PATH_L10N))
[74]781                qApp->installTranslator(translator);
782        else {
783                delete translator;
784                translator = NULL;
[94]785                if (!ad) {
786                        settings->remove("Language");
[99]787                        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
[94]788                        if (isVisible())
789                                QMessageBox::warning(this, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection."));
790                        else
791                                QMessageBox::warning(NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection."));
[99]792                        QApplication::restoreOverrideCursor();
[94]793                }
[80]794                return false;
[21]795        }
[67]796        return true;
[21]797}
[31]798
[67]799bool MainWindow::maybeSave()
[37]800{
[67]801        if (!isWindowModified())
802                return true;
[99]803int res = QMessageBox::warning(this, tr("Unsaved Changes"), tr("Would you like to save changes in the current task?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
[67]804        if (res == QMessageBox::Save)
[99]805                return actionFileSaveTriggered();
[67]806        else if (res == QMessageBox::Cancel)
807                return false;
808        else
809                return true;
[37]810}
811
[99]812QString MainWindow::outputMatrix(const TMatrix &matrix) const
[57]813{
[67]814int n = spinCities->value();
[99]815QString output(""), line;
[67]816        output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
817        for (int r = 0; r < n; r++) {
818                line = "<tr>";
819                for (int c = 0; c < n; c++) {
[71]820                        if (matrix.at(r).at(c) == INFINITY)
[67]821                                line += "<td align=\"center\">"INFSTR"</td>";
822                        else
[87]823                                line += isInteger(matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
[67]824                }
825                line += "</tr>";
826                output.append(line);
[57]827        }
[67]828        output.append("</table>");
[99]829        return output;
[57]830}
831
[99]832QString MainWindow::outputMatrix(const SStep &step) const
[74]833{
834int n = spinCities->value();
[99]835QString output(""), line;
[74]836        output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
837        for (int r = 0; r < n; r++) {
838                line = "<tr>";
839                for (int c = 0; c < n; c++) {
840                        if (step.matrix.at(r).at(c) == INFINITY)
841                                line += "<td align=\"center\">"INFSTR"</td>";
842                        else if ((r == step.candidate.nRow) && (c == step.candidate.nCol))
[87]843                                line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
[74]844                        else {
[76]845SCandidate cand;
[74]846                                cand.nRow = r;
847                                cand.nCol = c;
848                                if (step.alts.contains(cand))
[87]849                                        line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
[74]850                                else
[87]851                                        line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
[74]852                        }
853                }
854                line += "</tr>";
855                output.append(line);
856        }
857        output.append("</table>");
[99]858        return output;
[74]859}
860
[80]861void MainWindow::retranslateUi(bool all)
862{
863        if (all)
864                Ui::MainWindow::retranslateUi(this);
865
[94]866        actionSettingsLanguageEnglish->setStatusTip(tr("Set application language to %1").arg("English"));
867
[80]868#ifndef QT_NO_PRINTER
869        actionFilePrintPreview->setText(QApplication::translate("MainWindow", "P&rint Preview...", 0, QApplication::UnicodeUTF8));
870#ifndef QT_NO_TOOLTIP
871        actionFilePrintPreview->setToolTip(QApplication::translate("MainWindow", "Preview solution results", 0, QApplication::UnicodeUTF8));
872#endif // QT_NO_TOOLTIP
873#ifndef QT_NO_STATUSTIP
874        actionFilePrintPreview->setStatusTip(QApplication::translate("MainWindow", "Preview current solution results before printing", 0, QApplication::UnicodeUTF8));
875#endif // QT_NO_STATUSTIP
876
877        actionFilePrint->setText(QApplication::translate("MainWindow", "&Print...", 0, QApplication::UnicodeUTF8));
878#ifndef QT_NO_TOOLTIP
879        actionFilePrint->setToolTip(QApplication::translate("MainWindow", "Print solution", 0, QApplication::UnicodeUTF8));
880#endif // QT_NO_TOOLTIP
881#ifndef QT_NO_STATUSTIP
882        actionFilePrint->setStatusTip(QApplication::translate("MainWindow", "Print current solution results", 0, QApplication::UnicodeUTF8));
883#endif // QT_NO_STATUSTIP
884        actionFilePrint->setShortcut(QApplication::translate("MainWindow", "Ctrl+P", 0, QApplication::UnicodeUTF8));
885#endif // QT_NO_PRINTER
[99]886#ifdef Q_OS_WIN32
887        actionHelpCheck4Updates->setText(tr("Check for &Updates..."));
888#ifndef QT_NO_TOOLTIP
889        actionHelpCheck4Updates->setToolTip(tr("Check for %1 updates").arg(QApplication::applicationName()));
890#endif // QT_NO_TOOLTIP
891#ifndef QT_NO_STATUSTIP
892        actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName()));
893#endif // QT_NO_STATUSTIP
894#endif // Q_OS_WIN32
[80]895}
896
[67]897bool MainWindow::saveTask() {
[87]898QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
899        filters.append(tr("All Files") + " (*)");
[78]900QString file;
901        if (fileName.endsWith(".tspt", Qt::CaseInsensitive))
902                file = fileName;
[67]903        else
[78]904                file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt";
905
[82]906QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
[87]907        file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts);
[80]908
[78]909        if (file.isEmpty())
[67]910                return false;
[78]911        if (tspmodel->saveTask(file)) {
912                setFileName(file);
[67]913                setWindowModified(false);
914                return true;
915        }
916        return false;
917}
918
[71]919void MainWindow::setFileName(const QString &fileName)
[31]920{
[67]921        this->fileName = fileName;
[87]922        setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(tr("Travelling Salesman Problem")));
[31]923}
[78]924
[80]925void MainWindow::setupUi()
926{
927        Ui::MainWindow::setupUi(this);
928
929#if QT_VERSION >= 0x040600
930        setToolButtonStyle(Qt::ToolButtonFollowStyle);
931#endif
932
[93]933#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
[80]934QStatusBar *statusbar = new QStatusBar(this);
935        statusbar->setObjectName("statusbar");
936        setStatusBar(statusbar);
937#endif // Q_OS_WINCE
938
939#ifdef Q_OS_WINCE
[92]940        menuBar()->setDefaultAction(menuFile->menuAction());
[94]941
942QScrollArea *scrollArea = new QScrollArea(this);
943        scrollArea->setFrameShape(QFrame::NoFrame);
944        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
945        scrollArea->setWidgetResizable(true);
946        scrollArea->setWidget(tabWidget);
947        setCentralWidget(scrollArea);
[98]948#else
949        setCentralWidget(tabWidget);
[92]950#endif // Q_OS_WINCE
951
[93]952        //! \hack HACK: A little hack for toolbar icons to have a sane size.
[92]953#ifdef Q_OS_WINCE
[80]954        toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4));
[93]955#elif defined(Q_OS_SYMBIAN)
956        toolBar->setIconSize(QSize(logicalDpiX() / 5, logicalDpiY() / 5));
[92]957#endif // Q_OS_WINCE
[80]958
959        solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
960        solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>());
961        solutionText->setWordWrapMode(QTextOption::WordWrap);
962
963#ifndef QT_NO_PRINTER
964        actionFilePrintPreview = new QAction(this);
965        actionFilePrintPreview->setObjectName("actionFilePrintPreview");
966        actionFilePrintPreview->setEnabled(false);
967        actionFilePrintPreview->setIcon(QIcon(":/images/icons/document_preview.png"));
968
969        actionFilePrint = new QAction(this);
970        actionFilePrint->setObjectName("actionFilePrint");
971        actionFilePrint->setEnabled(false);
972        actionFilePrint->setIcon(QIcon(":/images/icons/fileprint.png"));
973
974        menuFile->insertAction(actionFileExit,actionFilePrintPreview);
975        menuFile->insertAction(actionFileExit,actionFilePrint);
976        menuFile->insertSeparator(actionFileExit);
977
978        toolBar->insertAction(actionSettingsPreferences,actionFilePrint);
979#endif // QT_NO_PRINTER
[99]980#ifdef Q_OS_WIN32
981        actionHelpCheck4Updates = new QAction(this);
982        actionHelpCheck4Updates->setEnabled(hasUpdater());
983        menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates);
984        menuHelp->insertSeparator(actionHelpAboutQt);
985#endif // Q_OS_WIN32
[80]986
987        groupSettingsLanguageList = new QActionGroup(this);
988        actionSettingsLanguageEnglish->setData("en");
989        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
990        loadLangList();
[94]991        actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
[80]992
993        spinCities->setMaximum(MAX_NUM_CITIES);
994
995        retranslateUi(false);
996
[96]997#ifdef Q_OS_WIN32
[92]998        // Adding some eyecandy in Vista and 7 :-)
999        if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
1000                toggleTranclucency(true);
1001        }
[96]1002#endif // Q_OS_WIN32
[80]1003}
1004
[78]1005void MainWindow::toggleSolutionActions(bool enable)
1006{
1007        buttonSaveSolution->setEnabled(enable);
1008        actionFileSaveAsSolution->setEnabled(enable);
1009        solutionText->setEnabled(enable);
1010#ifndef QT_NO_PRINTER
1011        actionFilePrint->setEnabled(enable);
1012        actionFilePrintPreview->setEnabled(enable);
1013#endif // QT_NO_PRINTER
1014}
[92]1015
1016void MainWindow::toggleTranclucency(bool enable)
1017{
[96]1018#ifdef Q_OS_WIN32
[98]1019        toggleStyle(labelVariant, enable);
1020        toggleStyle(labelCities, enable);
1021        toggleStyle(statusBar(), enable);
[97]1022        tabWidget->setDocumentMode(enable);
[92]1023        QtWin::enableBlurBehindWindow(this, enable);
[96]1024#else
1025        Q_UNUSED(enable);
1026#endif // Q_OS_WIN32
[92]1027}
Note: See TracBrowser for help on using the repository browser.