source: tspsg/src/mainwindow.cpp @ f44855d99e

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

Fixed wrong signal sender in mainwindow.ce.ui.

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