source: tspsg/src/mainwindow.cpp @ 0621172ec1

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

+ Status tip for font color selection button in settings.

  • Number of cities wasn't saved in wince version.
  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[5515c2c2a7]1/*
[bb994a7ff8]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 <QtGui>
[5354a01311]25#ifndef Q_OS_WINCE
26        #include <QPrintDialog>
27#endif // Q_OS_WINCE
[aecdf994f9]28#include "defines.h"
[5515c2c2a7]29#include "mainwindow.h"
30
31MainWindow::MainWindow(QWidget *parent)
[aecdf994f9]32        : QMainWindow(parent)
[5515c2c2a7]33{
34        setupUi(this);
[665d32434f]35        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
36        spinCities->setValue(settings->value("NumCities",5).toInt());
[5515c2c2a7]37        connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
[aecdf994f9]38        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
[5354a01311]39#ifndef Q_OS_WINCE
40        connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
41#endif // Q_OS_WINCE
[bb994a7ff8]42        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
43        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
[003e4193be]44        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
[5354a01311]45QRect rect = geometry();
46#ifdef Q_OS_WINCE
47        // HACK: Fix for all tabWidget elements becoming "unclickable" if making it central widget.
48        rect.setSize(QApplication::desktop()->availableGeometry().size());
49        rect.setHeight(rect.height() - (QApplication::desktop()->screenGeometry().height() - QApplication::desktop()->availableGeometry().height()));
50        tabWidget->resize(rect.width(),rect.height() - toolBar->size().height());
51#else
[665d32434f]52        if (settings->value("SavePos",false).toBool()) {
[aecdf994f9]53                // Loading of saved window state
[665d32434f]54                settings->beginGroup("MainWindow");
55                resize(settings->value("Size",size()).toSize());
56                move(settings->value("Position",pos()).toPoint());
57                if (settings->value("Maximized",false).toBool())
[aecdf994f9]58                        setWindowState(windowState() | Qt::WindowMaximized);
[665d32434f]59                settings->endGroup();
[aecdf994f9]60        } else {
61                // Centering main window
62                rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
63                setGeometry(rect);
64        }
[5354a01311]65#endif // Q_OS_WINCE
[fc9f661ded]66        qsrand(QDateTime().currentDateTime().toTime_t());
[2bc8e278b7]67        tspmodel = new CTSPModel();
68        tspmodel->setNumCities(spinCities->value());
69        taskView->setModel(tspmodel);
[aecdf994f9]70#ifdef Q_OS_WINCE
71        taskView->resizeColumnsToContents();
72        taskView->resizeRowsToContents();
73#endif // Q_OS_WINCE
[003e4193be]74}
[052d1b9331]75
[003e4193be]76void MainWindow::CitiesNumberChanged(int n)
77{
[aecdf994f9]78#ifdef Q_OS_WINCE
79int count = tspmodel->numCities();
80#endif // Q_OS_WINCE
[2bc8e278b7]81        tspmodel->setNumCities(n);
[aecdf994f9]82#ifdef Q_OS_WINCE
83        if (n > count)
84                for (int k = count; k < n; k++) {
85                        taskView->resizeColumnToContents(k);
86                        taskView->resizeRowToContents(k);
87                }
88#endif // Q_OS_WINCE
[5515c2c2a7]89}
90
91void MainWindow::ChangeSettings()
92{
93SettingsDialog sd(this);
[aecdf994f9]94        sd.exec();
[5515c2c2a7]95}
[bb994a7ff8]96
[5354a01311]97#ifndef Q_OS_WINCE
98void MainWindow::PrintSetup()
99{
100QPrintDialog pd;
101        pd.exec();
102}
103#endif // Q_OS_WINCE
104
[bb994a7ff8]105void MainWindow::Random()
106{
[2bc8e278b7]107        tspmodel->randomize();
[aecdf994f9]108#ifdef Q_OS_WINCE
109        taskView->resizeColumnsToContents();
110        taskView->resizeRowsToContents();
111#endif // Q_OS_WINCE
[bb994a7ff8]112}
113
114void MainWindow::Solve()
115{
116        // TODO: Task solving goes here :-)
[e664262f7d]117tMatrix matrix;
118double *row;
[2bc8e278b7]119int n = spinCities->value();
[e664262f7d]120bool ok;
[2bc8e278b7]121        for (int r = 0; r < n; r++) {
122                row = new double[n];
123                for (int c = 0; c < n; c++) {
124                        row[c] = tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok);
125                        if (!ok) {
126                                QMessageBox(QMessageBox::Critical,trUtf8("Ошибка в данных"),QString(trUtf8("Ошибка в ячейке [Строка %1; Колонка %2]: Неверный формат данных.")).arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
127                                return;
[e664262f7d]128                        }
129                }
130                matrix.append(row);
131        }
132CTSPSolver solver;
133sStep *root = solver.solve(spinCities->value(),matrix);
134        if (!root)
135                QMessageBox(QMessageBox::Critical,trUtf8("Ошибка при решении"),trUtf8("Во время решения задачи возникла ошибка"),QMessageBox::Ok,this).exec();
136        // tabWidget->setCurrentIndex(1);
[bb994a7ff8]137}
[aecdf994f9]138
139void MainWindow::showAbout()
140{
141        // TODO: Normal about window :-)
142QString about = QString::fromUtf8("TSPSG - TSP Solver and Generator\n\
143    Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n\
144Qt library versions:\n\
145    Compile time: %2\n\
146    Runtime: %3\n\
147\n\
148TSPSG 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.").arg(QDate().toString("%Y"),QT_VERSION_STR,qVersion());
149        QMessageBox(QMessageBox::Information,"About",about).exec();
150}
151
152void MainWindow::closeEvent(QCloseEvent *event)
153{
[665d32434f]154        settings->setValue("NumCities",spinCities->value());
[0621172ec1]155#ifndef Q_OS_WINCE
156        // Saving windows state
[665d32434f]157        if (settings->value("SavePos",false).toBool()) {
158                settings->beginGroup("MainWindow");
159                settings->setValue("Maximized",isMaximized());
[aecdf994f9]160                if (!isMaximized()) {
[665d32434f]161                        settings->setValue("Size",size());
162                        settings->setValue("Position",pos());
[aecdf994f9]163                }
[665d32434f]164                settings->endGroup();
[aecdf994f9]165        }
[0621172ec1]166#endif // Q_OS_WINCE
[aecdf994f9]167        QMainWindow::closeEvent(event);
168}
Note: See TracBrowser for help on using the repository browser.