source: tspsg/src/mainwindow.cpp @ 56dca709c9

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 56dca709c9 was 56dca709c9, checked in by Oleksii Serdiuk, 15 years ago

Implemented printing of solution results (not supported under wince).

  • Property mode set to 100644
File size: 20.9 KB
Line 
1/*
2 *  TSPSG: TSP Solver and Generator
3 *  Copyright (C) 2007-2009 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
26MainWindow::MainWindow(QWidget *parent)
27        : QMainWindow(parent)
28{
29        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
30        loadLanguage();
31        setupUi(this);
32        initDocStyleSheet();
33        solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
34        solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>());
35        solutionText->setWordWrapMode(QTextOption::WordWrap);
36#ifdef Q_OS_WINCE
37        // A little hack for toolbar icons to have sane size.
38int s = qMin(QApplication::desktop()->screenGeometry().width(),QApplication::desktop()->screenGeometry().height());
39        toolBar->setIconSize(QSize(s / 10,s / 10));
40#endif
41#ifndef Q_OS_WINCE
42        printer = new QPrinter(QPrinter::HighResolution);
43#endif // Q_OS_WINCE
44        groupSettingsLanguageList = new QActionGroup(this);
45        actionSettingsLanguageEnglish->setData("en");
46        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
47        loadLangList();
48        spinCities->setMaximum(MAX_NUM_CITIES);
49        actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
50        connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
51        connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
52        connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered()));
53        connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
54        connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
55        connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered()));
56        connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
57        connect(groupSettingsLanguageList,SIGNAL(triggered(QAction *)),this,SLOT(groupSettingsLanguageListTriggered(QAction *)));
58        connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
59        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
60#ifndef Q_OS_WINCE
61        connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered()));
62        connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered()));
63#endif // Q_OS_WINCE
64        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
65        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
66        connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
67        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
68        setCentralWidget(tabWidget);
69QRect rect = geometry();
70#ifndef Q_OS_WINCE
71        if (settings->value("SavePos",false).toBool()) {
72                // Loading of saved window state
73                settings->beginGroup("MainWindow");
74                resize(settings->value("Size",size()).toSize());
75                move(settings->value("Position",pos()).toPoint());
76                if (settings->value("Maximized",false).toBool())
77                        setWindowState(windowState() | Qt::WindowMaximized);
78                settings->endGroup();
79        } else {
80                // Centering main window
81                rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
82                setGeometry(rect);
83        }
84#endif // Q_OS_WINCE
85        qsrand(QDateTime().currentDateTime().toTime_t());
86        tspmodel = new CTSPModel();
87        taskView->setModel(tspmodel);
88        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
89        connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
90        connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
91        if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
92                setFileName(QCoreApplication::arguments().at(1));
93        else {
94                setFileName();
95                spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
96                spinCitiesValueChanged(spinCities->value());
97        }
98        setWindowModified(false);
99}
100
101void MainWindow::enableSolutionActions(bool enable)
102{
103        buttonSaveSolution->setEnabled(enable);
104        actionFileSaveAsSolution->setEnabled(enable);
105        solutionText->setEnabled(enable);
106        if (!enable)
107                output.clear();
108#ifndef Q_OS_WINCE
109        actionFilePrint->setEnabled(enable);
110        actionFilePrintPreview->setEnabled(enable);
111#endif // Q_OS_WINCE
112}
113
114bool MainWindow::loadLanguage(QString lang)
115{
116// i18n
117bool ad = false;
118        if (lang.isEmpty()) {
119                ad = settings->value("Language","").toString().isEmpty();
120                lang = settings->value("Language",QLocale::system().name()).toString();
121        }
122static QTranslator *qtTranslator; // Qt library translator
123        if (qtTranslator) {
124                qApp->removeTranslator(qtTranslator);
125                delete qtTranslator;
126                qtTranslator = NULL;
127        }
128        qtTranslator = new QTranslator();
129static QTranslator *translator; // Application translator
130        if (translator) {
131                qApp->removeTranslator(translator);
132                delete translator;
133        }
134        translator = new QTranslator();
135        if (lang.compare("en") && !lang.startsWith("en_")) {
136                // Trying to load system Qt library translation...
137                if (qtTranslator->load("qt_" + lang,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
138                        qApp->installTranslator(qtTranslator);
139                else
140                        // No luck. Let's try to load bundled one.
141                        if (qtTranslator->load("qt_" + lang,"i18n"))
142                                qApp->installTranslator(qtTranslator);
143                        else {
144                                // Qt library translation unavailable
145                                delete qtTranslator;
146                                qtTranslator = NULL;
147                        }
148                // Now let's load application translation.
149                if (translator->load(lang,"i18n"))
150                        qApp->installTranslator(translator);
151                else {
152                        if (!ad)
153                                QMessageBox(QMessageBox::Warning,trUtf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
154                        delete translator;
155                        translator = NULL;
156                        return false;
157                }
158        }
159        return true;
160}
161
162void MainWindow::initDocStyleSheet()
163{
164QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>();
165QColor hilight;
166        if (color.value() < 192)
167                hilight.setHsv(color.hue(),color.saturation(),127 + qRound(color.value() / 2));
168        else
169                hilight.setHsv(color.hue(),color.saturation(),color.value() / 2);
170        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;}");
171        solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
172}
173
174void MainWindow::setFileName(QString fileName)
175{
176        this->fileName = fileName;
177        setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem")));
178}
179
180void MainWindow::spinCitiesValueChanged(int n)
181{
182int count = tspmodel->numCities();
183        tspmodel->setNumCities(n);
184        if (n > count)
185                for (int k = count; k < n; k++) {
186                        taskView->resizeColumnToContents(k);
187                        taskView->resizeRowToContents(k);
188                }
189}
190
191bool MainWindow::maybeSave()
192{
193        if (!isWindowModified())
194                return true;
195int res = QMessageBox(QMessageBox::Warning,trUtf8("Unsaved Changes"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec();
196        if (res == QMessageBox::Save)
197                return saveTask();
198        else if (res == QMessageBox::Cancel)
199                return false;
200        else
201                return true;
202}
203
204void MainWindow::actionFileNewTriggered()
205{
206        if (!maybeSave())
207                return;
208        tspmodel->clear();
209        taskView->resizeColumnsToContents();
210        taskView->resizeRowsToContents();
211        setFileName();
212        setWindowModified(false);
213        tabWidget->setCurrentIndex(0);
214        solutionText->clear();
215        enableSolutionActions(false);
216}
217
218void MainWindow::actionFileOpenTriggered()
219{
220        if (!maybeSave())
221                return;
222QFileDialog od(this);
223        od.setAcceptMode(QFileDialog::AcceptOpen);
224        od.setFileMode(QFileDialog::ExistingFile);
225QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)");
226        filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)");
227        filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
228        filters.append(trUtf8("All Files") + " (*)");
229        od.setNameFilters(filters);
230        if (od.exec() != QDialog::Accepted)
231                return;
232QStringList files = od.selectedFiles();
233        if (files.empty())
234                return;
235        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
236        if (!tspmodel->loadTask(files.first())) {
237                QApplication::restoreOverrideCursor();
238                return;
239        }
240        setFileName(files.first());
241        taskView->resizeColumnsToContents();
242        taskView->resizeRowsToContents();
243        tabWidget->setCurrentIndex(0);
244        setWindowModified(false);
245        solutionText->clear();
246        enableSolutionActions(false);
247        QApplication::restoreOverrideCursor();
248}
249
250void MainWindow::actionFileSaveTriggered()
251{
252        if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
253                saveTask();
254        else {
255                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
256                if (tspmodel->saveTask(fileName))
257                        setWindowModified(false);
258                QApplication::restoreOverrideCursor();
259        }
260}
261
262void MainWindow::actionFileSaveAsTaskTriggered()
263{
264        saveTask();
265}
266
267void MainWindow::actionFileSaveAsSolutionTriggered()
268{
269static QString selectedFile;
270        if (selectedFile.isEmpty())
271                selectedFile = "solution.html";
272QFileDialog sd(this);
273        sd.setAcceptMode(QFileDialog::AcceptSave);
274QStringList filters(trUtf8("HTML Files") + " (*.html *.htm)");
275#if QT_VERSION >= 0x040500
276        filters.append(trUtf8("OpenDocument Files") + " (*.odt)");
277#endif // QT_VERSION >= 0x040500
278        filters.append(trUtf8("All Files") + " (*)");
279        sd.setNameFilters(filters);
280        sd.selectFile(selectedFile);
281        if (sd.exec() != QDialog::Accepted)
282                return;
283QStringList files = sd.selectedFiles();
284        if (files.empty())
285                return;
286        selectedFile = files.first();
287        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
288#if QT_VERSION >= 0x040500
289QTextDocumentWriter dw(selectedFile);
290        if (!(selectedFile.endsWith(".htm",Qt::CaseInsensitive) || selectedFile.endsWith(".html",Qt::CaseInsensitive) || selectedFile.endsWith(".odt",Qt::CaseInsensitive) || selectedFile.endsWith(".txt",Qt::CaseInsensitive)))
291                dw.setFormat("plaintext");
292        dw.write(solutionText->document());
293#else
294        // Qt < 4.5 has no QTextDocumentWriter class
295QFile file(selectedFile);
296        if (!file.open(QFile::WriteOnly)) {
297                QApplication::restoreOverrideCursor();
298                return;
299        }
300QTextStream ts(&file);
301        ts.setCodec(QTextCodec::codecForName("UTF-8"));
302        ts << solutionText->document()->toHtml("UTF-8");
303        file.close();
304#endif // QT_VERSION >= 0x040500
305        QApplication::restoreOverrideCursor();
306}
307
308bool MainWindow::saveTask() {
309QFileDialog sd(this);
310        sd.setAcceptMode(QFileDialog::AcceptSave);
311QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)");
312        filters.append(trUtf8("All Files") + " (*)");
313        sd.setNameFilters(filters);
314        sd.setDefaultSuffix("tspt");
315        if (fileName.endsWith(".tspt",Qt::CaseInsensitive))
316                sd.selectFile(fileName);
317        else
318                sd.selectFile(QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt");
319        if (sd.exec() != QDialog::Accepted)
320                return false;
321QStringList files = sd.selectedFiles();
322        if (files.empty())
323                return false;
324        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
325        if (tspmodel->saveTask(files.first())) {
326                setFileName(files.first());
327                setWindowModified(false);
328                QApplication::restoreOverrideCursor();
329                return true;
330        }
331        QApplication::restoreOverrideCursor();
332        return false;
333}
334
335void MainWindow::actionSettingsPreferencesTriggered()
336{
337SettingsDialog sd(this);
338        if (sd.exec() != QDialog::Accepted)
339                return;
340        if (sd.colorChanged() || sd.fontChanged()) {
341                initDocStyleSheet();
342                if (!output.isEmpty() && sd.colorChanged() && (QMessageBox(QMessageBox::Question,trUtf8("Settings Changed"),trUtf8("You have changed color settings.\nDo you wish to apply them to current solution text?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes)) {
343                        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
344                        solutionText->clear();
345                        solutionText->setHtml(output.join(""));
346                        QApplication::restoreOverrideCursor();
347                }
348        }
349}
350
351#ifndef Q_OS_WINCE
352void MainWindow::printPreview(QPrinter *printer)
353{
354        solutionText->print(printer);
355}
356
357void MainWindow::actionFilePrintPreviewTriggered()
358{
359QPrintPreviewDialog ppd(printer, this);
360    connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
361    ppd.exec();
362}
363
364void MainWindow::actionFilePrintTriggered()
365{
366QPrintDialog pd(printer,this);
367#if QT_VERSION >= 0x040500
368        // No such methods in Qt < 4.5
369        pd.setOption(QAbstractPrintDialog::PrintSelection,false);
370        pd.setOption(QAbstractPrintDialog::PrintPageRange,false);
371#endif
372        if (pd.exec() != QDialog::Accepted)
373                return;
374        solutionText->document()->print(printer);
375}
376#endif // Q_OS_WINCE
377
378void MainWindow::buttonRandomClicked()
379{
380        tspmodel->randomize();
381        setWindowModified(true);
382        taskView->resizeColumnsToContents();
383        taskView->resizeRowsToContents();
384}
385
386void MainWindow::buttonBackToTaskClicked()
387{
388        tabWidget->setCurrentIndex(0);
389}
390
391void MainWindow::outputMatrix(tMatrix matrix, QStringList &output, int nRow, int nCol)
392{
393int n = spinCities->value();
394QString line="";
395        output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
396        for (int r = 0; r < n; r++) {
397                line = "<tr>";
398                for (int c = 0; c < n; c++) {
399                        if (matrix[r][c] == INFINITY)
400                                line += "<td align=\"center\">"INFSTR"</td>";
401                        else if ((r == nRow) && (c == nCol))
402                                line += "<td align=\"center\" class=\"selected\">" + QVariant(matrix[r][c]).toString() + "</td>";
403                        else
404                                line += "<td align=\"center\">" + QVariant(matrix[r][c]).toString() + "</td>";
405                }
406                line += "</tr>";
407                output.append(line);
408        }
409        output.append("</table>");
410}
411
412void MainWindow::buttonSolveClicked()
413{
414tMatrix matrix;
415QList<double> row;
416int n = spinCities->value();
417bool ok;
418        for (int r = 0; r < n; r++) {
419                row.clear();
420                for (int c = 0; c < n; c++) {
421                        row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
422                        if (!ok) {
423                                QMessageBox(QMessageBox::Critical,trUtf8("Data error"),trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
424                                return;
425                        }
426                }
427                matrix.append(row);
428        }
429CTSPSolver solver;
430sStep *root = solver.solve(n,matrix,this);
431        if (!root)
432                return;
433        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
434QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>();
435        output.clear();
436        output.append("<p>" + trUtf8("Variant #%1").arg(spinVariant->value()) + "</p>");
437        output.append("<p>" + trUtf8("Task:") + "</p>");
438        outputMatrix(matrix,output);
439        output.append("<hr>");
440        output.append("<p>" + trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>");
441sStep *step = root;
442        n = 1;
443QString path = "";
444        while (n <= spinCities->value()) {
445                if (step->prNode->prNode != NULL || (step->prNode->prNode == NULL && step->plNode->prNode == NULL)) {
446                        if (n != spinCities->value()) {
447                                output.append("<p>" + trUtf8("Step #%1").arg(n++) + "</p>");
448                                outputMatrix(step->matrix,output,step->candidate.nRow,step->candidate.nCol);
449                                if (step->alts)
450                                        output.append("<p class=\"hasalts\">" + trUtf8("This step has alternate candidates for branching.") + "</p>");
451                                output.append("<p>&nbsp;</p>");
452                        }
453                        path += QString(" (%1,%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1);
454                }
455                if (step->prNode->prNode != NULL)
456                        step = step->prNode;
457                else if (step->plNode->prNode != NULL)
458                        step = step->plNode;
459                else
460                        break;
461        }
462        output.append("<p>" + trUtf8("Optimal path:") + "</p>");
463        output.append("<p>&nbsp;&nbsp;" + path + "</p>");
464        output.append("<p>" + trUtf8("The price is <b>%1</b> units.").arg(step->price) + "</p>");
465        solutionText->setHtml(output.join(""));
466        solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()));
467        enableSolutionActions();
468        tabWidget->setCurrentIndex(1);
469        QApplication::restoreOverrideCursor();
470}
471
472void MainWindow::actionHelpAboutTriggered()
473{
474        // TODO: Normal about window :-)
475QString about = QString::fromUtf8("TSPSG - TSP Solver and Generator\n");
476        about += QString::fromUtf8("    Version: "BUILD_VERSION"\n");
477        about += QString::fromUtf8("    Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n").arg(QDate::currentDate().toString("yyyy"));
478        about += QString::fromUtf8("Target OS: %1\n").arg(OS);
479        about += "Qt library:\n";
480        about += QString::fromUtf8("    Compile time: %1\n").arg(QT_VERSION_STR);
481        about += QString::fromUtf8("    Runtime: %1\n").arg(qVersion());
482        about += QString::fromUtf8("Built on %1 at %2\n").arg(__DATE__).arg(__TIME__);
483        about += "\n";
484        about += "TSPSG is licensed under the terms of the GNU General Public License. You should have received a copy of the GNU General Public License along with TSPSG.";
485        QMessageBox(QMessageBox::Information,"About",about,QMessageBox::Ok,this).exec();
486}
487
488void MainWindow::loadLangList()
489{
490QSettings langinfo("i18n/languages.ini",QSettings::IniFormat);
491#if QT_VERSION >= 0x040500
492        // In Qt < 4.5 QSettings doesn't have method setIniCodec.
493        langinfo.setIniCodec("UTF-8");
494#endif
495QDir dir("i18n","*.qm",QDir::Name | QDir::IgnoreCase,QDir::Files);
496        if (!dir.exists())
497                return;
498QFileInfoList langs = dir.entryInfoList();
499        if (langs.size() <= 0)
500                return;
501QAction *a;
502        for (int k = 0; k < langs.size(); k++) {
503                QFileInfo lang = langs.at(k);
504                if (!lang.completeBaseName().startsWith("qt_") && lang.completeBaseName().compare("en")) {
505#if QT_VERSION >= 0x040500
506                        a = menuSettingsLanguage->addAction(langinfo.value(lang.completeBaseName() + "/NativeName",lang.completeBaseName()).toString());
507#else
508                        // We use Name if Qt < 4.5 because NativeName is in UTF-8, QSettings
509                        // reads .ini file as ASCII and there is no way to set file encoding.
510                        a = menuSettingsLanguage->addAction(langinfo.value(lang.completeBaseName() + "/Name",lang.completeBaseName()).toString());
511#endif
512                        a->setData(lang.completeBaseName());
513                        a->setCheckable(true);
514                        a->setActionGroup(groupSettingsLanguageList);
515                        if (settings->value("Language",QLocale::system().name()).toString().startsWith(lang.completeBaseName()))
516                                a->setChecked(true);
517                }
518        }
519}
520
521void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked)
522{
523        if (checked) {
524                settings->remove("Language");
525                QMessageBox(QMessageBox::Information,trUtf8("Language change"),trUtf8("Language will be autodetected on next application start."),QMessageBox::Ok,this).exec();
526        } else
527                settings->setValue("Language",groupSettingsLanguageList->checkedAction()->data().toString());
528}
529
530void MainWindow::groupSettingsLanguageListTriggered(QAction *action)
531{
532        if (actionSettingsLanguageAutodetect->isChecked()) {
533                // We have language autodetection. It needs to be disabled to change language.
534                if (QMessageBox(QMessageBox::Question,trUtf8("Language change"),trUtf8("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes) {
535                        actionSettingsLanguageAutodetect->trigger();
536                } else
537                        return;
538        }
539bool untitled = (fileName == trUtf8("Untitled") + ".tspt");
540        if (loadLanguage(action->data().toString())) {
541                settings->setValue("Language",action->data().toString());
542                retranslateUi(this);
543                if (untitled)
544                        setFileName();
545        }
546}
547
548void MainWindow::closeEvent(QCloseEvent *event)
549{
550        if (!maybeSave()) {
551                event->ignore();
552                return;
553        }
554        settings->setValue("NumCities",spinCities->value());
555#ifndef Q_OS_WINCE
556        // Saving windows state
557        if (settings->value("SavePos",false).toBool()) {
558                settings->beginGroup("MainWindow");
559                settings->setValue("Maximized",isMaximized());
560                if (!isMaximized()) {
561                        settings->setValue("Size",size());
562                        settings->setValue("Position",pos());
563                }
564                settings->endGroup();
565        }
566#endif // Q_OS_WINCE
567        QMainWindow::closeEvent(event);
568}
569
570void MainWindow::dataChanged()
571{
572        setWindowModified(true);
573}
574
575void MainWindow::numCitiesChanged(int nCities)
576{
577        blockSignals(true);
578        spinCities->setValue(nCities);
579        blockSignals(false);
580}
Note: See TracBrowser for help on using the repository browser.