source: tspsg/src/mainwindow.cpp @ ec54b4490b

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

+ Wait Cursor (a.k.a Hourglass) while application starts.
+ Open file, passed as command-line argument.

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