source: tspsg/src/mainwindow.cpp @ 43c29c04ba

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 43c29c04ba was 43c29c04ba, checked in by Oleksii Serdiuk, 14 years ago

+ Added support for Windows 7 Taskbar Extensions (namely, Progress Bars).

  • Cleanup is done in a separate thread now, so progress bar runs more smooth.
  • "Tabified" About dialog. Added GPL License and Credits.
  • Updated translations and tspsg.tag file.
  • Property mode set to 100644
File size: 55.4 KB
Line 
1/*
2 *  TSPSG: TSP Solver and Generator
3 *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
4 *
5 *  $Id$
6 *  $URL$
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
12 *  the Free Software Foundation, either version 3 of the License, or
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"
25
26#ifdef Q_OS_WIN32
27        #include "shobjidl.h"
28#endif
29
30#ifdef _T_T_L_
31#include "_.h"
32_C_ _R_ _Y_ _P_ _T_
33#endif
34
35/*!
36 * \brief Class constructor.
37 * \param parent Main Window parent widget.
38 *
39 *  Initializes Main Window and creates its layout based on target OS.
40 *  Loads TSPSG settings and opens a task file if it was specified as a commandline parameter.
41 */
42MainWindow::MainWindow(QWidget *parent)
43        : QMainWindow(parent)
44{
45        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
46
47        if (settings->contains("Style")) {
48QStyle *s = QStyleFactory::create(settings->value("Style").toString());
49                if (s != NULL)
50                        QApplication::setStyle(s);
51                else
52                        settings->remove("Style");
53        }
54
55        loadLanguage();
56        setupUi();
57        setAcceptDrops(true);
58
59        initDocStyleSheet();
60
61#ifndef QT_NO_PRINTER
62        printer = new QPrinter(QPrinter::HighResolution);
63#endif // QT_NO_PRINTER
64
65#ifdef Q_OS_WINCE_WM
66        currentGeometry = QApplication::desktop()->availableGeometry(0);
67        // We need to react to SIP show/hide and resize the window appropriately
68        connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
69#endif // Q_OS_WINCE_WM
70        connect(actionFileNew, SIGNAL(triggered()), SLOT(actionFileNewTriggered()));
71        connect(actionFileOpen, SIGNAL(triggered()), SLOT(actionFileOpenTriggered()));
72        connect(actionFileSave, SIGNAL(triggered()), SLOT(actionFileSaveTriggered()));
73        connect(actionFileSaveAsTask, SIGNAL(triggered()), SLOT(actionFileSaveAsTaskTriggered()));
74        connect(actionFileSaveAsSolution, SIGNAL(triggered()), SLOT(actionFileSaveAsSolutionTriggered()));
75#ifndef QT_NO_PRINTER
76        connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered()));
77        connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered()));
78#endif // QT_NO_PRINTER
79#ifndef HANDHELD
80        connect(actionSettingsToolbarsConfigure, SIGNAL(triggered()), SLOT(actionSettingsToolbarsConfigureTriggered()));
81#endif // HANDHELD
82        connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered()));
83#ifdef Q_OS_WIN32
84        connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered()));
85#endif // Q_OS_WIN32
86        connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
87        connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *)));
88        connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool)));
89        connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*)));
90        connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
91        connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered()));
92
93        connect(buttonSolve, SIGNAL(clicked()), SLOT(buttonSolveClicked()));
94        connect(buttonRandom, SIGNAL(clicked()), SLOT(buttonRandomClicked()));
95        connect(buttonBackToTask, SIGNAL(clicked()), SLOT(buttonBackToTaskClicked()));
96        connect(spinCities, SIGNAL(valueChanged(int)), SLOT(spinCitiesValueChanged(int)));
97
98#ifndef HANDHELD
99        // Centering main window
100QRect rect = geometry();
101        rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
102        setGeometry(rect);
103        if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
104                // Loading of saved window state
105                settings->beginGroup("MainWindow");
106                restoreGeometry(settings->value("Geometry").toByteArray());
107                restoreState(settings->value("State").toByteArray());
108                settings->endGroup();
109        }
110#endif // HANDHELD
111
112        tspmodel = new CTSPModel(this);
113        taskView->setModel(tspmodel);
114        connect(tspmodel, SIGNAL(numCitiesChanged(int)), SLOT(numCitiesChanged(int)));
115        connect(tspmodel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
116        connect(tspmodel, SIGNAL(layoutChanged()), SLOT(dataChanged()));
117        if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
118                setFileName(QCoreApplication::arguments().at(1));
119        else {
120                setFileName();
121                spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
122                spinCitiesValueChanged(spinCities->value());
123        }
124        setWindowModified(false);
125}
126
127MainWindow::~MainWindow()
128{
129#ifndef QT_NO_PRINTER
130        delete printer;
131#endif
132}
133
134/* Privates **********************************************************/
135
136void MainWindow::actionFileNewTriggered()
137{
138        if (!maybeSave())
139                return;
140        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
141        tspmodel->clear();
142        setFileName();
143        setWindowModified(false);
144        tabWidget->setCurrentIndex(0);
145        solutionText->clear();
146        toggleSolutionActions(false);
147        QApplication::restoreOverrideCursor();
148}
149
150void MainWindow::actionFileOpenTriggered()
151{
152        if (!maybeSave())
153                return;
154
155QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)");
156        filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)");
157        filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
158        filters.append(tr("All Files") + " (*)");
159
160QString file = QFileInfo(fileName).canonicalPath();
161QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
162        file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts);
163        if (file.isEmpty() || !QFileInfo(file).isFile())
164                return;
165        if (!tspmodel->loadTask(file))
166                return;
167        setFileName(file);
168        tabWidget->setCurrentIndex(0);
169        setWindowModified(false);
170        solutionText->clear();
171        toggleSolutionActions(false);
172}
173
174bool MainWindow::actionFileSaveTriggered()
175{
176        if ((fileName == tr("Untitled") + ".tspt") || (!fileName.endsWith(".tspt", Qt::CaseInsensitive)))
177                return saveTask();
178        else
179                if (tspmodel->saveTask(fileName)) {
180                        setWindowModified(false);
181                        return true;
182                } else
183                        return false;
184}
185
186void MainWindow::actionFileSaveAsTaskTriggered()
187{
188        saveTask();
189}
190
191void MainWindow::actionFileSaveAsSolutionTriggered()
192{
193static QString selectedFile;
194        if (selectedFile.isEmpty())
195                selectedFile = QFileInfo(fileName).canonicalPath();
196        else
197                selectedFile = QFileInfo(selectedFile).canonicalPath();
198        if (!selectedFile.isEmpty())
199                selectedFile += "/";
200        if (fileName == tr("Untitled") + ".tspt") {
201#ifndef QT_NO_PRINTER
202                selectedFile += "solution.pdf";
203#else
204                selectedFile += "solution.html";
205#endif // QT_NO_PRINTER
206        } else {
207#ifndef QT_NO_PRINTER
208                selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf";
209#else
210                selectedFile += QFileInfo(fileName).completeBaseName() + ".html";
211#endif // QT_NO_PRINTER
212        }
213
214QStringList filters;
215#ifndef QT_NO_PRINTER
216        filters.append(tr("PDF Files") + " (*.pdf)");
217#endif
218        filters.append(tr("HTML Files") + " (*.html *.htm)");
219#if QT_VERSION >= 0x040500
220        filters.append(tr("OpenDocument Files") + " (*.odt)");
221#endif // QT_VERSION >= 0x040500
222        filters.append(tr("All Files") + " (*)");
223
224QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog);
225QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts);
226        if (file.isEmpty())
227                return;
228        selectedFile = file;
229        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
230#ifndef QT_NO_PRINTER
231        if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) {
232QPrinter printer(QPrinter::HighResolution);
233                printer.setOutputFormat(QPrinter::PdfFormat);
234                printer.setOutputFileName(selectedFile);
235                solutionText->document()->print(&printer);
236                QApplication::restoreOverrideCursor();
237                return;
238        }
239#endif
240        if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) {
241QFile file(selectedFile);
242                if (!file.open(QFile::WriteOnly)) {
243                        QApplication::restoreOverrideCursor();
244                        QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString()));
245                        return;
246                }
247QFileInfo fi(selectedFile);
248QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString();
249#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
250        if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) {
251#else // NOSVG && QT_VERSION >= 0x040500
252        if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) {
253#endif // NOSVG && QT_VERSION >= 0x040500
254                format = DEF_GRAPH_IMAGE_FORMAT;
255                settings->remove("Output/GraphImageFormat");
256        }
257QString html = solutionText->document()->toHtml("UTF-8"),
258                img =  fi.completeBaseName() + "." + format;
259                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 2).arg(graph.height() + 2).arg(tr("Solution Graph")));
260
261                // Saving solution text as HTML
262QTextStream ts(&file);
263                ts.setCodec(QTextCodec::codecForName("UTF-8"));
264                ts << html;
265                file.close();
266
267                // Saving solution graph as SVG or PNG (depending on settings and SVG support)
268#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
269                if (format == "svg") {
270QSvgGenerator svg;
271                        svg.setSize(QSize(graph.width(), graph.height()));
272                        svg.setResolution(graph.logicalDpiX());
273                        svg.setFileName(fi.path() + "/" + img);
274                        svg.setTitle(tr("Solution Graph"));
275                        svg.setDescription(tr("Generated with %1").arg(QApplication::applicationName()));
276QPainter p;
277                        p.begin(&svg);
278                        p.drawPicture(1, 1, graph);
279                        p.end();
280                } else {
281#endif // NOSVG && QT_VERSION >= 0x040500
282QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
283                        i.fill(0x00FFFFFF);
284QPainter p;
285                        p.begin(&i);
286                        p.drawPicture(1, 1, graph);
287                        p.end();
288QImageWriter pic(fi.path() + "/" + img);
289                        if (pic.supportsOption(QImageIOHandler::Description)) {
290                                pic.setText("Title", "Solution Graph");
291                                pic.setText("Software", QApplication::applicationName());
292                        }
293                        if (format == "png")
294                                pic.setQuality(5);
295                        else if (format == "jpeg")
296                                pic.setQuality(80);
297                        if (!pic.write(i)) {
298                                QApplication::restoreOverrideCursor();
299                                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));
300                                return;
301                        }
302#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
303                }
304#endif // NOSVG && QT_VERSION >= 0x040500
305
306// Qt < 4.5 has no QTextDocumentWriter class
307#if QT_VERSION >= 0x040500
308        } else {
309QTextDocumentWriter dw(selectedFile);
310                if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive))
311                        dw.setFormat("plaintext");
312                if (!dw.write(solutionText->document()))
313                        QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString()));
314#endif // QT_VERSION >= 0x040500
315        }
316        QApplication::restoreOverrideCursor();
317}
318
319#ifndef QT_NO_PRINTER
320void MainWindow::actionFilePrintPreviewTriggered()
321{
322QPrintPreviewDialog ppd(printer, this);
323        connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
324        ppd.exec();
325}
326
327void MainWindow::actionFilePrintTriggered()
328{
329QPrintDialog pd(printer,this);
330        if (pd.exec() != QDialog::Accepted)
331                return;
332        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
333        solutionText->print(printer);
334        QApplication::restoreOverrideCursor();
335}
336#endif // QT_NO_PRINTER
337
338void MainWindow::actionSettingsPreferencesTriggered()
339{
340SettingsDialog sd(this);
341        if (sd.exec() != QDialog::Accepted)
342                return;
343        if (sd.colorChanged() || sd.fontChanged()) {
344                if (!solutionText->document()->isEmpty() && sd.colorChanged())
345                        QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output."));
346                initDocStyleSheet();
347        }
348        if (sd.translucencyChanged() != 0)
349                toggleTranclucency(sd.translucencyChanged() == 1);
350}
351
352void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked)
353{
354        if (checked) {
355                settings->remove("Language");
356                QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QApplication::applicationName()));
357        } else
358                settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());
359}
360
361void MainWindow::groupSettingsLanguageListTriggered(QAction *action)
362{
363        if (actionSettingsLanguageAutodetect->isChecked()) {
364                // We have language autodetection. It needs to be disabled to change language.
365                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) {
366                        actionSettingsLanguageAutodetect->trigger();
367                } else
368                        return;
369        }
370bool untitled = (fileName == tr("Untitled") + ".tspt");
371        if (loadLanguage(action->data().toString())) {
372                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
373                settings->setValue("Language",action->data().toString());
374                retranslateUi();
375                if (untitled)
376                        setFileName();
377#ifdef Q_OS_WIN32
378                if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
379                        toggleStyle(labelVariant, true);
380                        toggleStyle(labelCities, true);
381                }
382#endif
383                QApplication::restoreOverrideCursor();
384                if (!solutionText->document()->isEmpty())
385                        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."));
386        }
387}
388
389void MainWindow::actionSettingsStyleSystemTriggered(bool checked)
390{
391        if (checked) {
392                settings->remove("Style");
393                QMessageBox::information(this, tr("Style Change"), tr("To apply the default style you need to restart %1.").arg(QApplication::applicationName()));
394        } else {
395                settings->setValue("Style", groupSettingsStyleList->checkedAction()->text());
396        }
397}
398
399void MainWindow::groupSettingsStyleListTriggered(QAction *action)
400{
401QStyle *s = QStyleFactory::create(action->text());
402        if (s != NULL) {
403                QApplication::setStyle(s);
404                settings->setValue("Style", action->text());
405                actionSettingsStyleSystem->setChecked(false);
406        }
407}
408
409#ifndef HANDHELD
410void MainWindow::actionSettingsToolbarsConfigureTriggered()
411{
412QtToolBarDialog dlg(this);
413        dlg.setToolBarManager(toolBarManager);
414        dlg.exec();
415QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave));
416        if (tb != NULL) {
417                tb->setMenu(menuFileSaveAs);
418                tb->setPopupMode(QToolButton::MenuButtonPopup);
419                tb->resize(tb->sizeHint());
420        }
421
422        loadToolbarList();
423}
424#endif // HANDHELD
425
426#ifdef Q_OS_WIN32
427void MainWindow::actionHelpCheck4UpdatesTriggered()
428{
429        if (!hasUpdater()) {
430                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."));
431                return;
432        }
433
434        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
435        QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\"");
436        QApplication::restoreOverrideCursor();
437}
438#endif // Q_OS_WIN32
439
440void MainWindow::actionHelpAboutTriggered()
441{
442        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
443
444QString title;
445#ifdef HANDHELD
446        title += QString("<b>TSPSG<br>TSP Solver and Generator</b><br>");
447#else
448        title += QString("<b>%1</b><br>").arg(QApplication::applicationName());
449#endif // HANDHELD
450        title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion());
451#ifndef HANDHELD
452        title += QString("<b>&copy; 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName());
453        title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sourceforge.net/</a></b>");
454#else
455        title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sf.net/</a></b>");
456#endif // HANDHELD
457
458QString about;
459        about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), OS);
460#ifndef STATIC_BUILD
461        about += QString("%1 (%2):<br>").arg(tr("Qt library"), tr("shared"));
462        about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR);
463        about += QString("&nbsp;&nbsp;&nbsp;&nbsp;%1: <b>%2</b><br>").arg(tr("Runtime"), qVersion());
464#else
465        about += QString("%1: <b>%2</b> (%3)<br>").arg(tr("Qt library"), QT_VERSION_STR, tr("static"));
466#endif // STATIC_BUILD
467        about += tr("Buid <b>%1</b>, built on <b>%2</b> at <b>%3</b>").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__) + "<br>";
468        about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId());
469        about += "<br>";
470        about += tr("This program is free software: you can redistribute it and/or modify<br>\n"
471                "it under the terms of the GNU General Public License as published by<br>\n"
472                "the Free Software Foundation, either version 3 of the License, or<br>\n"
473                "(at your option) any later version.<br>\n"
474                "<br>\n"
475                "This program is distributed in the hope that it will be useful,<br>\n"
476                "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>\n"
477                "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>\n"
478                "GNU General Public License for more details.<br>\n"
479                "<br>\n"
480                "You should have received a copy of the GNU General Public License<br>\n"
481                "along with TSPSG.  If not, see <a href=\"http://www.gnu.org/licenses/\">www.gnu.org/licenses/</a>.");
482
483QString credits;
484        credits += tr("This software was created using LGPL version of <b>Qt framework</b>,<br>\n"
485                "see <a href=\"http://qt.nokia.com/\">qt.nokia.com</a><br>\n"
486                "<br>\n"
487                "Most icons used in this software are part of <b>Oxygen Icons</b> project "
488                "licensed according to the GNU Lesser General Public License,<br>\n"
489                "see <a href=\"http://www.oxygen-icons.org/\">www.oxygen-icons.org</a><br>\n"
490                "<br>\n"
491                "Country flag icons used in this software are part of the free "
492                "<b>Flag Icons</b> collection created by <b>IconDrawer</b>,<br>\n"
493                "see <a href=\"http://www.icondrawer.com/\">www.icondrawer.com</a>");
494
495QFile f(":/files/COPYING");
496        f.open(QIODevice::ReadOnly);
497
498QString translation = QApplication::translate("--------", "AUTHORS %1", "Please, provide translator credits here. %1 will be replaced with VERSION");
499        if ((translation != "AUTHORS %1") && (translation.contains("%1"))) {
500QString about = QApplication::translate("--------", "VERSION", "Please, provide your translation version here.");
501                if (about != "VERSION")
502                        translation = translation.arg(about);
503        }
504
505QDialog *dlg = new QDialog(this);
506QLabel *lblIcon = new QLabel(dlg),
507        *lblTitle = new QLabel(dlg);
508#ifdef HANDHELD
509QLabel *lblSubTitle = new QLabel(QString("<b>&copy; 2007-%1 <a href=\"http://%2/\">%3</a></b>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName()), dlg);
510#endif // HANDHELD
511QTabWidget *tabs = new QTabWidget(dlg);
512QTextBrowser *txtAbout = new QTextBrowser(dlg);
513QTextBrowser *txtLicense = new QTextBrowser(dlg);
514QTextBrowser *txtCredits = new QTextBrowser(dlg);
515QVBoxLayout *vb = new QVBoxLayout();
516QHBoxLayout *hb1 = new QHBoxLayout(),
517        *hb2 = new QHBoxLayout();
518QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg);
519
520        lblTitle->setOpenExternalLinks(true);
521        lblTitle->setText(title);
522        lblTitle->setAlignment(Qt::AlignTop);
523        lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
524#ifndef HANDHELD
525        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()));
526#endif // HANDHELD
527
528        lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToHeight(lblTitle->sizeHint().height(), Qt::SmoothTransformation));
529        lblIcon->setAlignment(Qt::AlignVCenter);
530#ifndef HANDHELD
531        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()));
532#endif // HANDHELD
533
534        hb1->addWidget(lblIcon);
535        hb1->addWidget(lblTitle);
536
537        txtAbout->setWordWrapMode(QTextOption::NoWrap);
538        txtAbout->setOpenExternalLinks(true);
539        txtAbout->setHtml(about);
540        txtAbout->moveCursor(QTextCursor::Start);
541        txtAbout->setFrameShape(QFrame::NoFrame);
542
543//      txtCredits->setWordWrapMode(QTextOption::NoWrap);
544        txtCredits->setOpenExternalLinks(true);
545        txtCredits->setHtml(credits);
546        txtCredits->moveCursor(QTextCursor::Start);
547        txtCredits->setFrameShape(QFrame::NoFrame);
548
549        txtLicense->setWordWrapMode(QTextOption::NoWrap);
550        txtLicense->setOpenExternalLinks(true);
551        txtLicense->setText(f.readAll());
552        txtLicense->moveCursor(QTextCursor::Start);
553        txtLicense->setFrameShape(QFrame::NoFrame);
554
555        bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
556
557        hb2->addWidget(bb);
558
559#ifdef Q_OS_WINCE_WM
560        vb->setMargin(3);
561#endif // Q_OS_WINCE_WM
562        vb->addLayout(hb1);
563#ifdef HANDHELD
564        vb->addWidget(lblSubTitle);
565#endif // HANDHELD
566
567        tabs->addTab(txtAbout, tr("About"));
568        tabs->addTab(txtLicense, tr("License"));
569        tabs->addTab(txtCredits, tr("Credits"));
570        if (translation != "AUTHORS %1") {
571QTextBrowser *txtTranslation = new QTextBrowser(dlg);
572//              txtTranslation->setWordWrapMode(QTextOption::NoWrap);
573                txtTranslation->setOpenExternalLinks(true);
574                txtTranslation->setText(translation);
575                txtTranslation->moveCursor(QTextCursor::Start);
576                txtTranslation->setFrameShape(QFrame::NoFrame);
577
578                tabs->addTab(txtTranslation, tr("Translation"));
579        }
580#ifndef HANDHELD
581        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()));
582#endif // HANDHELD
583
584        vb->addWidget(tabs);
585        vb->addLayout(hb2);
586
587        dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
588        dlg->setWindowTitle(tr("About %1").arg(QApplication::applicationName()));
589        dlg->setWindowIcon(QIcon::fromTheme("help-about", QIcon(":/images/icons/help-about.png")));
590        dlg->setLayout(vb);
591
592        connect(bb, SIGNAL(accepted()), dlg, SLOT(accept()));
593
594#ifdef Q_OS_WIN32
595        // Adding some eyecandy in Vista and 7 :-)
596        if (QtWin::isCompositionEnabled())  {
597                QtWin::enableBlurBehindWindow(dlg, true);
598        }
599#endif // Q_OS_WIN32
600
601        dlg->resize(450, 350);
602        QApplication::restoreOverrideCursor();
603
604        dlg->exec();
605
606        delete dlg;
607}
608
609void MainWindow::buttonBackToTaskClicked()
610{
611        tabWidget->setCurrentIndex(0);
612}
613
614void MainWindow::buttonRandomClicked()
615{
616        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
617        tspmodel->randomize();
618        QApplication::restoreOverrideCursor();
619}
620
621void MainWindow::buttonSolveClicked()
622{
623TMatrix matrix;
624QList<double> row;
625int n = spinCities->value();
626bool ok;
627        for (int r = 0; r < n; r++) {
628                row.clear();
629                for (int c = 0; c < n; c++) {
630                        row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
631                        if (!ok) {
632                                QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1));
633                                return;
634                        }
635                }
636                matrix.append(row);
637        }
638
639QProgressDialog pd(this);
640QProgressBar *pb = new QProgressBar(&pd);
641        pb->setAlignment(Qt::AlignCenter);
642        pb->setFormat(tr("%v of %1 parts found").arg(n));
643        pd.setBar(pb);
644QPushButton *cancel = new QPushButton(&pd);
645        cancel->setIcon(QIcon::fromTheme("dialog-cancel", QIcon(":/images/icons/dialog-cancel.png")));
646        cancel->setText(QApplication::translate("QProgressDialog", "Cancel", "No need to translate this. This translation will be taken from Qt translation files."));
647        pd.setCancelButton(cancel);
648        pd.setMaximum(n);
649        pd.setAutoReset(false);
650        pd.setLabelText(tr("Calculating optimal route..."));
651        pd.setWindowTitle(tr("Solution Progress"));
652        pd.setWindowModality(Qt::ApplicationModal);
653        pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
654        pd.show();
655
656#ifdef Q_OS_WIN32
657HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID*)&tl);
658        if (SUCCEEDED(hr)) {
659                hr = tl->HrInit();
660                if (FAILED(hr)) {
661                        tl->Release();
662                        tl = NULL;
663                } else {
664//                      tl->SetProgressState(winId(), TBPF_INDETERMINATE);
665                        tl->SetProgressValue(winId(), 0, n * 2);
666                }
667        }
668#endif
669
670CTSPSolver solver;
671        solver.setCleanupOnCancel(false);
672        connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
673        connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
674#ifdef Q_OS_WIN32
675        if (tl != NULL)
676                connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int)));
677#endif
678SStep *root = solver.solve(n, matrix);
679#ifdef Q_OS_WIN32
680        if (tl != NULL)
681                disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int)));
682#endif
683        disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
684        disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel()));
685        if (!root) {
686                pd.reset();
687                if (!solver.wasCanceled()) {
688#ifdef Q_OS_WIN32
689                        if (tl != NULL) {
690//                              tl->SetProgressValue(winId(), n, n * 2);
691                                tl->SetProgressState(winId(), TBPF_ERROR);
692                        }
693#endif
694                        QApplication::alert(this);
695                        QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution."));
696                }
697                pd.setLabelText(tr("Cleaning up..."));
698                pd.setMaximum(0);
699                pd.setCancelButton(NULL);
700                pd.show();
701#ifdef Q_OS_WIN32
702                if (tl != NULL)
703                        tl->SetProgressState(winId(), TBPF_INDETERMINATE);
704#endif
705                QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
706
707QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
708                while (!f.isFinished()) {
709                        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
710                }
711                pd.reset();
712#ifdef Q_OS_WIN32
713                if (tl != NULL) {
714                        tl->SetProgressState(winId(), TBPF_NOPROGRESS);
715                        tl->Release();
716                        tl = NULL;
717                }
718#endif
719                return;
720        }
721        pb->setFormat(tr("Generating header"));
722        pd.setLabelText(tr("Generating solution output..."));
723        pd.setMaximum(solver.getTotalSteps() + 1);
724        pd.setValue(0);
725
726#ifdef Q_OS_WIN32
727        if (tl != NULL)
728                tl->SetProgressValue(winId(), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1);
729#endif
730
731        solutionText->clear();
732        solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value()));
733
734QPainter pic;
735        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
736                pic.begin(&graph);
737                pic.setRenderHint(QPainter::Antialiasing);
738                pic.setFont(settings->value("Output/Font", QFont(getDefaultFont(), 9)).value<QFont>());
739                pic.setBrush(QBrush(QColor(Qt::white)));
740                pic.setBackgroundMode(Qt::OpaqueMode);
741        }
742
743QTextDocument *doc = solutionText->document();
744QTextCursor cur(doc);
745
746        cur.beginEditBlock();
747        cur.setBlockFormat(fmt_paragraph);
748        cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default);
749        cur.insertBlock(fmt_paragraph);
750        cur.insertText(tr("Task:"));
751        outputMatrix(cur, matrix);
752        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
753#ifdef _T_T_L_
754                _b_ _i_ _z_ _a_ _r_ _r_ _e_
755#endif
756                drawNode(pic, 0);
757        }
758        cur.insertHtml("<hr>");
759        cur.insertBlock(fmt_paragraph);
760int imgpos = cur.position();
761        cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
762        cur.endEditBlock();
763
764SStep *step = root;
765int c = n = 1;
766        pb->setFormat(tr("Generating step %v"));
767        while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) {
768                if (pd.wasCanceled()) {
769                        pd.setLabelText(tr("Cleaning up..."));
770                        pd.setMaximum(0);
771                        pd.setCancelButton(NULL);
772                        pd.show();
773                        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
774#ifdef Q_OS_WIN32
775                        if (tl != NULL)
776                                tl->SetProgressState(winId(), TBPF_INDETERMINATE);
777#endif
778QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
779                        while (!f.isFinished()) {
780                                QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
781                        }
782                        solutionText->clear();
783                        toggleSolutionActions(false);
784#ifdef Q_OS_WIN32
785                        if (tl != NULL) {
786                                tl->SetProgressState(winId(), TBPF_NOPROGRESS);
787                                tl->Release();
788                                tl = NULL;
789                        }
790#endif
791                        return;
792                }
793                pd.setValue(n);
794#ifdef Q_OS_WIN32
795                if (tl != NULL)
796                        tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1);
797#endif
798
799                cur.beginEditBlock();
800                cur.insertBlock(fmt_paragraph);
801                cur.insertText(tr("Step #%1").arg(n));
802                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())))) {
803                        outputMatrix(cur, *step);
804                }
805                cur.insertBlock(fmt_paragraph);
806                cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
807                if (!step->alts.empty()) {
808                        SStep::SCandidate cand;
809                        QString alts;
810                        foreach(cand, step->alts) {
811                                if (!alts.isEmpty())
812                                        alts += ", ";
813                                alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
814                        }
815                        cur.insertBlock(fmt_paragraph);
816                        cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist);
817                }
818                cur.insertBlock(fmt_paragraph);
819                cur.insertText(" ", fmt_default);
820                cur.endEditBlock();
821
822                if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
823                        if (step->prNode != NULL)
824                                drawNode(pic, n, false, step->prNode);
825                        if (step->plNode != NULL)
826                                drawNode(pic, n, true, step->plNode);
827                }
828                n++;
829
830                if (step->next == SStep::RightBranch) {
831                        c++;
832                        step = step->prNode;
833                } else if (step->next == SStep::LeftBranch) {
834                        step = step->plNode;
835                } else
836                        break;
837        }
838        pb->setFormat(tr("Generating footer"));
839        pd.setValue(n);
840#ifdef Q_OS_WIN32
841        if (tl != NULL)
842                tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1);
843#endif
844
845        cur.beginEditBlock();
846        cur.insertBlock(fmt_paragraph);
847        if (solver.isOptimal())
848                cur.insertText(tr("Optimal path:"));
849        else
850                cur.insertText(tr("Resulting path:"));
851
852        cur.insertBlock(fmt_paragraph);
853        cur.insertText("  " + solver.getSortedPath(tr("City %1")));
854
855        cur.insertBlock(fmt_paragraph);
856        if (isInteger(step->price))
857                cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>");
858        else
859                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>");
860        if (!solver.isOptimal()) {
861                cur.insertBlock(fmt_paragraph);
862                cur.insertText(" ");
863                cur.insertBlock(fmt_paragraph);
864                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>");
865        }
866        cur.endEditBlock();
867
868        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
869                pic.end();
870
871QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
872                i.fill(0);
873                pic.begin(&i);
874                pic.drawPicture(1, 1, graph);
875                pic.end();
876                doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i);
877
878QTextImageFormat img;
879                img.setName("tspsg://graph.pic");
880
881                cur.setPosition(imgpos);
882                cur.insertImage(img, QTextFrameFormat::FloatRight);
883        }
884
885        if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
886                // Scrolling to the end of the text.
887                solutionText->moveCursor(QTextCursor::End);
888        } else
889                solutionText->moveCursor(QTextCursor::Start);
890
891        pd.setLabelText(tr("Cleaning up..."));
892        pd.setMaximum(0);
893        pd.setCancelButton(NULL);
894        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
895#ifdef Q_OS_WIN32
896        if (tl != NULL)
897                tl->SetProgressState(winId(), TBPF_INDETERMINATE);
898#endif
899QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
900        while (!f.isFinished()) {
901                QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
902        }
903        toggleSolutionActions();
904        tabWidget->setCurrentIndex(1);
905#ifdef Q_OS_WIN32
906        if (tl != NULL) {
907                tl->SetProgressState(winId(), TBPF_NOPROGRESS);
908                tl->Release();
909                tl = NULL;
910        }
911#endif
912
913        pd.reset();
914        QApplication::alert(this, 3000);
915}
916
917void MainWindow::dataChanged()
918{
919        setWindowModified(true);
920}
921
922void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br)
923{
924        setWindowModified(true);
925        if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) {
926                for (int k = tl.row(); k <= br.row(); k++)
927                        taskView->resizeRowToContents(k);
928                for (int k = tl.column(); k <= br.column(); k++)
929                        taskView->resizeColumnToContents(k);
930        }
931}
932
933#ifdef Q_OS_WINCE_WM
934void MainWindow::changeEvent(QEvent *ev)
935{
936        if ((ev->type() == QEvent::ActivationChange) && isActiveWindow())
937                desktopResized(0);
938
939        QWidget::changeEvent(ev);
940}
941
942void MainWindow::desktopResized(int screen)
943{
944        if ((screen != 0) || !isActiveWindow())
945                return;
946
947QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
948        if (currentGeometry != availableGeometry) {
949                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
950                /*!
951                 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
952                 *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
953                 *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
954                 */
955                if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
956                        setWindowState(windowState() | Qt::WindowMaximized);
957                } else {
958                        if (windowState() & Qt::WindowMaximized)
959                                setWindowState(windowState() ^ Qt::WindowMaximized);
960                        setGeometry(availableGeometry);
961                }
962                currentGeometry = availableGeometry;
963                QApplication::restoreOverrideCursor();
964        }
965}
966#endif // Q_OS_WINCE_WM
967
968void MainWindow::numCitiesChanged(int nCities)
969{
970        blockSignals(true);
971        spinCities->setValue(nCities);
972        blockSignals(false);
973}
974
975#ifndef QT_NO_PRINTER
976void MainWindow::printPreview(QPrinter *printer)
977{
978        solutionText->print(printer);
979}
980#endif // QT_NO_PRINTER
981
982#ifdef Q_OS_WIN32
983void MainWindow::solverRoutePartFound(int n)
984{
985#ifdef Q_OS_WIN32
986        tl->SetProgressValue(winId(), n, spinCities->value() * 2);
987#else
988        Q_UNUSED(n);
989#endif // Q_OS_WIN32
990}
991#endif // Q_OS_WIN32
992
993void MainWindow::spinCitiesValueChanged(int n)
994{
995        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
996int count = tspmodel->numCities();
997        tspmodel->setNumCities(n);
998        if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool())
999                for (int k = count; k < n; k++) {
1000                        taskView->resizeColumnToContents(k);
1001                        taskView->resizeRowToContents(k);
1002                }
1003        QApplication::restoreOverrideCursor();
1004}
1005
1006void MainWindow::closeEvent(QCloseEvent *ev)
1007{
1008        if (!maybeSave()) {
1009                ev->ignore();
1010                return;
1011        }
1012        if (!settings->value("SettingsReset", false).toBool()) {
1013                settings->setValue("NumCities", spinCities->value());
1014
1015                // Saving Main Window state
1016#ifndef HANDHELD
1017                if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
1018                        settings->beginGroup("MainWindow");
1019                        settings->setValue("Geometry", saveGeometry());
1020                        settings->setValue("State", saveState());
1021                        settings->setValue("Toolbars", toolBarManager->saveState());
1022                        settings->endGroup();
1023                }
1024#endif // HANDHELD
1025        } else {
1026                settings->remove("SettingsReset");
1027        }
1028
1029        QMainWindow::closeEvent(ev);
1030}
1031
1032void MainWindow::dragEnterEvent(QDragEnterEvent *ev)
1033{
1034        if (ev->mimeData()->hasUrls() && (ev->mimeData()->urls().count() == 1)) {
1035QFileInfo fi(ev->mimeData()->urls().first().toLocalFile());
1036                if ((fi.suffix() == "tspt") || (fi.suffix() == "zkt"))
1037                        ev->acceptProposedAction();
1038        }
1039}
1040
1041void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
1042{
1043const int r = 35;
1044qreal x, y;
1045        if (step != NULL)
1046                x = left ? r : r * 3.5;
1047        else
1048                x = r * 2.25;
1049        y = r * (3 * nstep + 1);
1050
1051#ifdef _T_T_L_
1052        if (nstep == -481124) {
1053                _t_t_l_(pic, r, x);
1054                return;
1055        }
1056#endif
1057
1058        pic.drawEllipse(QPointF(x, y), r, r);
1059
1060        if (step != NULL) {
1061QFont font;
1062                if (left) {
1063                        font = pic.font();
1064                        font.setStrikeOut(true);
1065                        pic.setFont(font);
1066                }
1067                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");
1068                if (left) {
1069                        font.setStrikeOut(false);
1070                        pic.setFont(font);
1071                }
1072                if (step->price != INFINITY) {
1073                        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()));
1074                } else {
1075                        pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR);
1076                }
1077        } else {
1078                pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root"));
1079        }
1080
1081        if (nstep == 1) {
1082                pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
1083        } else if (nstep > 1) {
1084                pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
1085        }
1086
1087}
1088
1089void MainWindow::dropEvent(QDropEvent *ev)
1090{
1091        if (maybeSave() && tspmodel->loadTask(ev->mimeData()->urls().first().toLocalFile())) {
1092                setFileName(ev->mimeData()->urls().first().toLocalFile());
1093                tabWidget->setCurrentIndex(0);
1094                setWindowModified(false);
1095                solutionText->clear();
1096                toggleSolutionActions(false);
1097
1098                ev->setDropAction(Qt::CopyAction);
1099                ev->accept();
1100        }
1101}
1102
1103bool MainWindow::hasUpdater() const
1104{
1105#ifdef Q_OS_WIN32
1106        return QFile::exists("updater/Update.exe");
1107#else // Q_OS_WIN32
1108        return false;
1109#endif // Q_OS_WIN32
1110}
1111
1112void MainWindow::initDocStyleSheet()
1113{
1114        solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(getDefaultFont(), DEF_FONT_SIZE)).value<QFont>());
1115
1116        fmt_paragraph.setTopMargin(0);
1117        fmt_paragraph.setRightMargin(10);
1118        fmt_paragraph.setBottomMargin(0);
1119        fmt_paragraph.setLeftMargin(10);
1120
1121        fmt_table.setTopMargin(5);
1122        fmt_table.setRightMargin(10);
1123        fmt_table.setBottomMargin(5);
1124        fmt_table.setLeftMargin(10);
1125        fmt_table.setBorder(0);
1126        fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_None);
1127        fmt_table.setCellSpacing(5);
1128
1129        fmt_cell.setAlignment(Qt::AlignHCenter);
1130
1131        settings->beginGroup("Output/Colors");
1132
1133QColor color = settings->value("Text", DEF_TEXT_COLOR).value<QColor>();
1134QColor hilight;
1135        if (color.value() < 192)
1136                hilight.setHsv(color.hue(), color.saturation(), 127 + qRound(color.value() / 2));
1137        else
1138                hilight.setHsv(color.hue(), color.saturation(), color.value() / 2);
1139
1140        solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name()));
1141        fmt_default.setForeground(QBrush(color));
1142
1143        fmt_selected.setForeground(QBrush(settings->value("Selected", DEF_SELECTED_COLOR).value<QColor>()));
1144        fmt_selected.setFontWeight(QFont::Bold);
1145
1146        fmt_alternate.setForeground(QBrush(settings->value("Alternate", DEF_ALTERNATE_COLOR).value<QColor>()));
1147        fmt_alternate.setFontWeight(QFont::Bold);
1148        fmt_altlist.setForeground(QBrush(hilight));
1149
1150        settings->endGroup();
1151
1152        solutionText->setTextColor(color);
1153}
1154
1155void MainWindow::loadLangList()
1156{
1157QMap<QString, QStringList> langlist;
1158QFileInfoList langs;
1159QFileInfo lang;
1160QString name;
1161QStringList language, dirs;
1162QTranslator t;
1163QDir dir;
1164        dir.setFilter(QDir::Files);
1165        dir.setNameFilters(QStringList("tspsg_*.qm"));
1166        dir.setSorting(QDir::NoSort);
1167
1168        dirs << PATH_L10N << ":/l10n";
1169        foreach (QString dirname, dirs) {
1170                dir.setPath(dirname);
1171                if (dir.exists()) {
1172                        langs = dir.entryInfoList();
1173                        for (int k = 0; k < langs.size(); k++) {
1174                                lang = langs.at(k);
1175                                if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && !langlist.contains(lang.completeBaseName().mid(6)) && t.load(lang.completeBaseName(), dirname)) {
1176
1177                                        language.clear();
1178                                        language.append(lang.completeBaseName().mid(6));
1179                                        language.append(t.translate("--------", "COUNTRY", "Please, provide an ISO 3166-1 alpha-2 country code for this translation language here (eg., UA).").toLower());
1180                                        language.append(t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here."));
1181                                        language.append(t.translate("MainWindow", "Set application language to %1", "").arg(name));
1182
1183                                        langlist.insert(language.at(0), language);
1184                                }
1185                        }
1186                }
1187        }
1188
1189QAction *a;
1190        foreach (language, langlist) {
1191                a = menuSettingsLanguage->addAction(language.at(2));
1192                a->setStatusTip(language.at(3));
1193                a->setIcon(QIcon::fromTheme(QString("flag-%1").arg(language.at(1)), QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1)))));
1194                a->setData(language.at(0));
1195                a->setCheckable(true);
1196                a->setActionGroup(groupSettingsLanguageList);
1197                if (settings->value("Language", QLocale::system().name()).toString().startsWith(language.at(0)))
1198                        a->setChecked(true);
1199        }
1200}
1201
1202bool MainWindow::loadLanguage(const QString &lang)
1203{
1204// i18n
1205bool ad = false;
1206QString lng = lang;
1207        if (lng.isEmpty()) {
1208                ad = settings->value("Language", "").toString().isEmpty();
1209                lng = settings->value("Language", QLocale::system().name()).toString();
1210        }
1211static QTranslator *qtTranslator; // Qt library translator
1212        if (qtTranslator) {
1213                qApp->removeTranslator(qtTranslator);
1214                delete qtTranslator;
1215                qtTranslator = NULL;
1216        }
1217static QTranslator *translator; // Application translator
1218        if (translator) {
1219                qApp->removeTranslator(translator);
1220                delete translator;
1221                translator = NULL;
1222        }
1223
1224        if (lng == "en")
1225                return true;
1226
1227        // Trying to load system Qt library translation...
1228        qtTranslator = new QTranslator(this);
1229        if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
1230                qApp->installTranslator(qtTranslator);
1231        else {
1232                // No luck. Let's try to load a bundled one.
1233                if (qtTranslator->load("qt_" + lng, PATH_L10N)) {
1234                        // We have a translation in the localization direcotry.
1235                        qApp->installTranslator(qtTranslator);
1236                } else if (qtTranslator->load("qt_" + lng, ":/l10n")) {
1237                        // We have a translation "built-in" into application resources.
1238                        qApp->installTranslator(qtTranslator);
1239                } else {
1240                        // Qt library translation unavailable for this language.
1241                        delete qtTranslator;
1242                        qtTranslator = NULL;
1243                }
1244        }
1245
1246        // Now let's load application translation.
1247        translator = new QTranslator(this);
1248        if (translator->load("tspsg_" + lng, PATH_L10N)) {
1249                // We have a translation in the localization directory.
1250                qApp->installTranslator(translator);
1251        } else if (translator->load("tspsg_" + lng, ":/l10n")) {
1252                // We have a translation "built-in" into application resources.
1253                qApp->installTranslator(translator);
1254        } else {
1255                delete translator;
1256                translator = NULL;
1257                if (!ad) {
1258                        settings->remove("Language");
1259                        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
1260                        QMessageBox::warning(isVisible() ? this : NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection."));
1261                        QApplication::restoreOverrideCursor();
1262                }
1263                return false;
1264        }
1265        return true;
1266}
1267
1268void MainWindow::loadStyleList()
1269{
1270        menuSettingsStyle->clear();
1271QStringList styles = QStyleFactory::keys();
1272        menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem);
1273        actionSettingsStyleSystem->setChecked(!settings->contains("Style"));
1274        menuSettingsStyle->addSeparator();
1275QAction *a;
1276        foreach (QString style, styles) {
1277                a = menuSettingsStyle->addAction(style);
1278                a->setData(false);
1279                a->setStatusTip(tr("Set application style to %1").arg(style));
1280                a->setCheckable(true);
1281                a->setActionGroup(groupSettingsStyleList);
1282                if ((style == settings->value("Style").toString())
1283                        || QString(QApplication::style()->metaObject()->className()).contains(QRegExp(QString("^Q?%1(Style)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive))) {
1284                        a->setChecked(true);
1285                }
1286        }
1287}
1288
1289void MainWindow::loadToolbarList()
1290{
1291        menuSettingsToolbars->clear();
1292#ifndef HANDHELD
1293        menuSettingsToolbars->insertAction(NULL, actionSettingsToolbarsConfigure);
1294        menuSettingsToolbars->addSeparator();
1295QList<QToolBar *> list = toolBarManager->toolBars();
1296        foreach (QToolBar *t, list) {
1297                menuSettingsToolbars->insertAction(NULL, t->toggleViewAction());
1298        }
1299#else // HANDHELD
1300        menuSettingsToolbars->insertAction(NULL, toolBarMain->toggleViewAction());
1301#endif // HANDHELD
1302}
1303
1304bool MainWindow::maybeSave()
1305{
1306        if (!isWindowModified())
1307                return true;
1308int res = QMessageBox::warning(this, tr("Unsaved Changes"), tr("Would you like to save changes in the current task?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
1309        if (res == QMessageBox::Save)
1310                return actionFileSaveTriggered();
1311        else if (res == QMessageBox::Cancel)
1312                return false;
1313        else
1314                return true;
1315}
1316
1317void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix)
1318{
1319int n = spinCities->value();
1320QTextTable *table = cur.insertTable(n, n, fmt_table);
1321
1322        for (int r = 0; r < n; r++) {
1323                for (int c = 0; c < n; c++) {
1324                        cur = table->cellAt(r, c).firstCursorPosition();
1325                        cur.setBlockFormat(fmt_cell);
1326                        cur.setBlockCharFormat(fmt_default);
1327                        if (matrix.at(r).at(c) == INFINITY)
1328                                cur.insertText(INFSTR);
1329                        else
1330                                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()));
1331                }
1332                QApplication::processEvents();
1333        }
1334        cur.movePosition(QTextCursor::End);
1335}
1336
1337void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step)
1338{
1339int n = spinCities->value();
1340QTextTable *table = cur.insertTable(n, n, fmt_table);
1341
1342        for (int r = 0; r < n; r++) {
1343                for (int c = 0; c < n; c++) {
1344                        cur = table->cellAt(r, c).firstCursorPosition();
1345                        cur.setBlockFormat(fmt_cell);
1346                        if (step.matrix.at(r).at(c) == INFINITY)
1347                                cur.insertText(INFSTR, fmt_default);
1348                        else if ((r == step.candidate.nRow) && (c == step.candidate.nCol))
1349                                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);
1350                        else {
1351SStep::SCandidate cand;
1352                                cand.nRow = r;
1353                                cand.nCol = c;
1354                                if (step.alts.contains(cand))
1355                                        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);
1356                                else
1357                                        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);
1358                        }
1359                }
1360                QApplication::processEvents();
1361        }
1362
1363        cur.movePosition(QTextCursor::End);
1364}
1365
1366void MainWindow::retranslateUi(bool all)
1367{
1368        if (all)
1369                Ui::MainWindow::retranslateUi(this);
1370
1371        loadStyleList();
1372        loadToolbarList();
1373
1374#ifndef QT_NO_PRINTER
1375        actionFilePrintPreview->setText(tr("P&rint Preview..."));
1376#ifndef QT_NO_TOOLTIP
1377        actionFilePrintPreview->setToolTip(tr("Preview solution results"));
1378#endif // QT_NO_TOOLTIP
1379#ifndef QT_NO_STATUSTIP
1380        actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing"));
1381#endif // QT_NO_STATUSTIP
1382
1383        actionFilePrint->setText(tr("&Print..."));
1384#ifndef QT_NO_TOOLTIP
1385        actionFilePrint->setToolTip(tr("Print solution"));
1386#endif // QT_NO_TOOLTIP
1387#ifndef QT_NO_STATUSTIP
1388        actionFilePrint->setStatusTip(tr("Print current solution results"));
1389#endif // QT_NO_STATUSTIP
1390        actionFilePrint->setShortcut(tr("Ctrl+P"));
1391#endif // QT_NO_PRINTER
1392
1393#ifndef HANDHELD
1394        actionSettingsToolbarsConfigure->setText(tr("Configure..."));
1395#ifndef QT_NO_STATUSTIP
1396        actionSettingsToolbarsConfigure->setStatusTip(tr("Customize toolbars"));
1397#endif // QT_NO_STATUSTIP
1398#endif // HANDHELD
1399
1400#ifdef Q_OS_WIN32
1401        actionHelpCheck4Updates->setText(tr("Check for &Updates..."));
1402#ifndef QT_NO_STATUSTIP
1403        actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName()));
1404#endif // QT_NO_STATUSTIP
1405#endif // Q_OS_WIN32
1406}
1407
1408bool MainWindow::saveTask() {
1409QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
1410        filters.append(tr("All Files") + " (*)");
1411QString file;
1412        if (fileName.endsWith(".tspt", Qt::CaseInsensitive))
1413                file = fileName;
1414        else
1415                file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt";
1416
1417QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
1418        file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts);
1419
1420        if (file.isEmpty())
1421                return false;
1422        if (tspmodel->saveTask(file)) {
1423                setFileName(file);
1424                setWindowModified(false);
1425                return true;
1426        }
1427        return false;
1428}
1429
1430void MainWindow::setFileName(const QString &fileName)
1431{
1432        this->fileName = fileName;
1433        setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(QApplication::applicationName()));
1434}
1435
1436void MainWindow::setupUi()
1437{
1438        Ui::MainWindow::setupUi(this);
1439
1440        // File Menu
1441        actionFileNew->setIcon(QIcon::fromTheme("document-new", QIcon(":/images/icons/document-new.png")));
1442        actionFileOpen->setIcon(QIcon::fromTheme("document-open", QIcon(":/images/icons/document-open.png")));
1443        actionFileSave->setIcon(QIcon::fromTheme("document-save", QIcon(":/images/icons/document-save.png")));
1444        menuFileSaveAs->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/images/icons/document-save-as.png")));
1445        actionFileExit->setIcon(QIcon::fromTheme("application-exit", QIcon(":/images/icons/application-exit.png")));
1446        // Settings Menu
1447        menuSettingsLanguage->setIcon(QIcon::fromTheme("preferences-desktop-locale", QIcon(":/images/icons/preferences-desktop-locale.png")));
1448        actionSettingsLanguageEnglish->setIcon(QIcon::fromTheme("flag-gb", QIcon(":/images/icons/l10n/flag-gb.png")));
1449        menuSettingsStyle->setIcon(QIcon::fromTheme("preferences-desktop-theme", QIcon(":/images/icons/preferences-desktop-theme.png")));
1450        actionSettingsPreferences->setIcon(QIcon::fromTheme("preferences-system", QIcon(":/images/icons/preferences-system.png")));
1451        // Help Menu
1452        actionHelpContents->setIcon(QIcon::fromTheme("help-contents", QIcon(":/images/icons/help-contents.png")));
1453        actionHelpContextual->setIcon(QIcon::fromTheme("help-contextual", QIcon(":/images/icons/help-contextual.png")));
1454        actionHelpAbout->setIcon(QIcon::fromTheme("help-about", QIcon(":/images/icons/help-about.png")));
1455        // Buttons
1456        buttonRandom->setIcon(QIcon::fromTheme("roll", QIcon(":/images/icons/roll.png")));
1457        buttonSolve->setIcon(QIcon::fromTheme("dialog-ok", QIcon(":/images/icons/dialog-ok.png")));
1458        buttonSaveSolution->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/images/icons/document-save-as.png")));
1459        buttonBackToTask->setIcon(QIcon::fromTheme("go-previous", QIcon(":/images/icons/go-previous.png")));
1460
1461//      action->setIcon(QIcon::fromTheme("", QIcon(":/images/icons/.png")));
1462
1463#if QT_VERSION >= 0x040600
1464        setToolButtonStyle(Qt::ToolButtonFollowStyle);
1465#endif
1466
1467#ifndef HANDHELD
1468QStatusBar *statusbar = new QStatusBar(this);
1469        statusbar->setObjectName("statusbar");
1470        setStatusBar(statusbar);
1471#endif // HANDHELD
1472
1473#ifdef Q_OS_WINCE_WM
1474        menuBar()->setDefaultAction(menuFile->menuAction());
1475
1476QScrollArea *scrollArea = new QScrollArea(this);
1477        scrollArea->setFrameShape(QFrame::NoFrame);
1478        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1479        scrollArea->setWidgetResizable(true);
1480        scrollArea->setWidget(tabWidget);
1481        setCentralWidget(scrollArea);
1482#else
1483        setCentralWidget(tabWidget);
1484#endif // Q_OS_WINCE_WM
1485
1486        //! \hack HACK: A little hack for toolbar icons to have a sane size.
1487#ifdef HANDHELD
1488        toolBarMain->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4));
1489#endif // HANDHELD
1490QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave));
1491        if (tb != NULL)  {
1492                tb->setMenu(menuFileSaveAs);
1493                tb->setPopupMode(QToolButton::MenuButtonPopup);
1494        }
1495
1496//      solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>());
1497        solutionText->setWordWrapMode(QTextOption::WordWrap);
1498
1499#ifndef QT_NO_PRINTER
1500        actionFilePrintPreview = new QAction(this);
1501        actionFilePrintPreview->setObjectName("actionFilePrintPreview");
1502        actionFilePrintPreview->setEnabled(false);
1503        actionFilePrintPreview->setIcon(QIcon::fromTheme("document-print-preview", QIcon(":/images/icons/document-print-preview.png")));
1504
1505        actionFilePrint = new QAction(this);
1506        actionFilePrint->setObjectName("actionFilePrint");
1507        actionFilePrint->setEnabled(false);
1508        actionFilePrint->setIcon(QIcon::fromTheme("document-print", QIcon(":/images/icons/document-print.png")));
1509
1510        menuFile->insertAction(actionFileExit,actionFilePrintPreview);
1511        menuFile->insertAction(actionFileExit,actionFilePrint);
1512        menuFile->insertSeparator(actionFileExit);
1513
1514        toolBarMain->insertAction(actionSettingsPreferences, actionFilePrint);
1515#endif // QT_NO_PRINTER
1516
1517        groupSettingsLanguageList = new QActionGroup(this);
1518        actionSettingsLanguageEnglish->setData("en");
1519        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
1520        loadLangList();
1521        actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
1522
1523        actionSettingsStyleSystem->setData(true);
1524        groupSettingsStyleList = new QActionGroup(this);
1525
1526#ifndef HANDHELD
1527        actionSettingsToolbarsConfigure = new QAction(this);
1528        actionSettingsToolbarsConfigure->setIcon(QIcon::fromTheme("configure-toolbars", QIcon(":/images/icons/configure-toolbars.png")));
1529#endif // HANDHELD
1530
1531#ifdef Q_OS_WIN32
1532        actionHelpCheck4Updates = new QAction(this);
1533        actionHelpCheck4Updates->setIcon(QIcon::fromTheme("system-software-update", QIcon(":/images/icons/system-software-update.png")));
1534        actionHelpCheck4Updates->setEnabled(hasUpdater());
1535        menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates);
1536        menuHelp->insertSeparator(actionHelpAboutQt);
1537#endif // Q_OS_WIN32
1538
1539        spinCities->setMaximum(MAX_NUM_CITIES);
1540
1541#ifndef HANDHELD
1542        toolBarManager = new QtToolBarManager;
1543        toolBarManager->setMainWindow(this);
1544QString cat = toolBarMain->windowTitle();
1545        toolBarManager->addToolBar(toolBarMain, cat);
1546#ifndef QT_NO_PRINTER
1547        toolBarManager->addAction(actionFilePrintPreview, cat);
1548#endif // QT_NO_PRINTER
1549        toolBarManager->addAction(actionHelpContents, cat);
1550        toolBarManager->addAction(actionHelpContextual, cat);
1551//      toolBarManager->addAction(action, cat);
1552        toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray());
1553#endif // HANDHELD
1554
1555        retranslateUi(false);
1556
1557#ifdef Q_OS_WIN32
1558        // Adding some eyecandy in Vista and 7 :-)
1559        if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool())  {
1560                toggleTranclucency(true);
1561        }
1562#endif // Q_OS_WIN32
1563}
1564
1565void MainWindow::toggleSolutionActions(bool enable)
1566{
1567        buttonSaveSolution->setEnabled(enable);
1568        actionFileSaveAsSolution->setEnabled(enable);
1569        solutionText->setEnabled(enable);
1570#ifndef QT_NO_PRINTER
1571        actionFilePrint->setEnabled(enable);
1572        actionFilePrintPreview->setEnabled(enable);
1573#endif // QT_NO_PRINTER
1574}
1575
1576void MainWindow::toggleTranclucency(bool enable)
1577{
1578#ifdef Q_OS_WIN32
1579        toggleStyle(labelVariant, enable);
1580        toggleStyle(labelCities, enable);
1581        toggleStyle(statusBar(), enable);
1582        tabWidget->setDocumentMode(enable);
1583        QtWin::enableBlurBehindWindow(this, enable);
1584#else
1585        Q_UNUSED(enable);
1586#endif // Q_OS_WIN32
1587}
Note: See TracBrowser for help on using the repository browser.