Changeset aecdf994f9 in tspsg for src


Ignore:
Timestamp:
Jun 22, 2009, 1:37:12 AM (15 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
d5384ee64e
Parents:
799ba1e3f2
Message:

+ Settings are now saved and restored.
+ Font color selection in settings.
+ Primitive about dialog.
+ Automatic resizing of cells to its contents in wince.

  • No "Save window position" checkbox in wince.
Location:
src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/main.cpp

    r799ba1e3f2 raecdf994f9  
    3030{
    3131QApplication app(argc, argv);
     32        app.setOrganizationName("..::Lёppsville::..");
     33        app.setOrganizationDomain("www.leppsville.com");
     34        app.setApplicationName("TSPSG");
    3235/*/ i18n
    3336// TODO: Make English as program's "native" language
  • src/mainwindow.cpp

    r799ba1e3f2 raecdf994f9  
    2626        #include <QPrintDialog>
    2727#endif // Q_OS_WINCE
     28#include "defines.h"
    2829#include "mainwindow.h"
    2930
    30 // TODO: Saving window state on close
    31 
    3231MainWindow::MainWindow(QWidget *parent)
    33         : QMainWindow(parent), randMin(1), randMax(10)
     32        : QMainWindow(parent)
    3433{
    3534        setupUi(this);
     35QSettings settings(INI_FILE,QSettings::IniFormat);
     36        spinCities->setValue(settings.value("NumCities",5).toInt());
    3637        connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
     38        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
    3739#ifndef Q_OS_WINCE
    3840        connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
     
    4850        tabWidget->resize(rect.width(),rect.height() - toolBar->size().height());
    4951#else
    50         // Centering MainWindow
    51         // TODO: Loading of saved window state
    52         rect.moveCenter(QApplication::desktop()->availableGeometry().center());
     52        if (settings.value("SavePos",false).toBool()) {
     53                // Loading of saved window state
     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())
     58                        setWindowState(windowState() | Qt::WindowMaximized);
     59                settings.endGroup();
     60        } else {
     61                // Centering main window
     62                rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
     63                setGeometry(rect);
     64        }
    5365#endif // Q_OS_WINCE
    54         setGeometry(rect);
    5566        qsrand(QDateTime().currentDateTime().toTime_t());
    5667        tspmodel = new CTSPModel();
    57         tspmodel->randMin = randMin;
    58         tspmodel->randMax = randMax;
    5968        tspmodel->setNumCities(spinCities->value());
    6069        taskView->setModel(tspmodel);
     70#ifdef Q_OS_WINCE
     71        taskView->resizeColumnsToContents();
     72        taskView->resizeRowsToContents();
     73#endif // Q_OS_WINCE
    6174}
    6275
    6376void MainWindow::CitiesNumberChanged(int n)
    6477{
     78#ifdef Q_OS_WINCE
     79int count = tspmodel->numCities();
     80#endif // Q_OS_WINCE
    6581        tspmodel->setNumCities(n);
     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
    6689}
    6790
     
    6992{
    7093SettingsDialog sd(this);
    71         sd.spinRandMin->setValue(randMin);
    72         sd.spinRandMax->setValue(randMax);
    73         if (sd.exec() == QDialog::Accepted) {
    74                 randMin = sd.spinRandMin->value();
    75                 randMax = sd.spinRandMax->value();
    76         }
     94        sd.exec();
    7795}
    7896
     
    88106{
    89107        tspmodel->randomize();
     108#ifdef Q_OS_WINCE
     109        taskView->resizeColumnsToContents();
     110        taskView->resizeRowsToContents();
     111#endif // Q_OS_WINCE
    90112}
    91113
     
    114136        // tabWidget->setCurrentIndex(1);
    115137}
     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
     152#ifndef Q_OS_WINCE
     153void MainWindow::closeEvent(QCloseEvent *event)
     154{
     155        // Saving windows state
     156QSettings settings(INI_FILE,QSettings::IniFormat);
     157        settings.setValue("NumCities",spinCities->value());
     158        if (settings.value("SavePos",false).toBool()) {
     159                settings.beginGroup("MainWindow");
     160                settings.setValue("Maximized",isMaximized());
     161                if (!isMaximized()) {
     162                        settings.setValue("Size",size());
     163                        settings.setValue("Position",pos());
     164                }
     165                settings.endGroup();
     166        }
     167        QMainWindow::closeEvent(event);
     168}
     169#endif // Q_OS_WINCE
  • src/mainwindow.h

    r799ba1e3f2 raecdf994f9  
    4040public:
    4141        MainWindow(QWidget *parent = 0);
     42#ifndef Q_OS_WINCE
     43        void closeEvent(QCloseEvent *event);
     44#endif // Q_OS_WINCE
    4245private slots:
    4346        void ChangeSettings();
     47        void showAbout();
    4448#ifndef Q_OS_WINCE
    4549        void PrintSetup();
     
    5054private:
    5155        CTSPModel *tspmodel;
    52         int randMin;
    53         int randMax;
    5456};
    5557
  • src/settingsdialog.cpp

    r799ba1e3f2 raecdf994f9  
    2525#include <QStatusTipEvent>
    2626#include <QFontDialog>
     27#include <QColorDialog>
     28#include "defines.h"
    2729#include "settingsdialog.h"
    2830
     
    3537        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
    3638        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
     39        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
    3740//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
    3841        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
     
    4750        labelHint->setMinimumHeight(labelHint->height());
    4851#endif // Q_OS_WINCE
     52        settings = new QSettings(INI_FILE,QSettings::IniFormat);
     53        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
     54        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
     55#ifndef Q_OS_WINCE
     56        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
     57#endif // Q_OS_WINCE
     58        settings->beginGroup("Print");
     59        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
     60        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
     61#ifndef Q_OS_WINCE
     62        spinLeftMargin->setValue(settings->value("Offset",DEF_OFFSET).toInt());
     63#endif // Q_OS_WINCE
     64        settings->endGroup();
    4965}
    5066
     
    6985void SettingsDialog::buttonFontClicked()
    7086{
    71         // TODO: Pass current font to dialog and save selected.
    72 QFontDialog fd;
    73         fd.exec();
     87bool ok;
     88QFont font = QFontDialog::getFont(&ok,this->font,this);
     89        if (ok)
     90                this->font = font;
    7491}
     92
     93void SettingsDialog::buttonColorClicked()
     94{
     95QColorDialog cd(color,this);
     96        if (cd.exec() == QDialog::Accepted)
     97                color = cd.selectedColor();
     98}
     99
     100void SettingsDialog::accept()
     101{
     102#ifndef Q_OS_WINCE
     103        settings->setValue("SavePos",cbSaveState->isChecked());
     104#endif // Q_OS_WINCE
     105        settings->setValue("MinCost",spinRandMin->value());
     106        settings->setValue("MaxCost",spinRandMax->value());
     107        settings->beginGroup("Print");
     108        settings->setValue("Font",font);
     109        settings->setValue("Color",color);
     110#ifndef Q_OS_WINCE
     111        settings->setValue("Offset",spinLeftMargin->value());
     112#endif // Q_OS_WINCE
     113        settings->endGroup();
     114        QDialog::accept();
     115}
  • src/settingsdialog.h

    r799ba1e3f2 raecdf994f9  
    2626
    2727#include <QDialog>
     28#include <QSettings>
    2829#ifdef Q_OS_WINCE
    2930        #include "ui_settingsdialog.ce.h"
     
    3940
    4041private:
    41 #ifndef WINCE
     42        QSettings *settings;
     43        QFont font;
     44        QColor color;
     45#ifndef Q_OS_WINCE
    4246        bool event(QEvent *);
    4347#endif
    4448
    4549private slots:
     50        void accept();
    4651        void spinRandMinValueChanged(int val) { spinRandMax->setMinimum(val + 1); }
    4752        void buttonFontClicked();
     53        void buttonColorClicked();
    4854};
    4955
  • src/tspmodel.cpp

    r799ba1e3f2 raecdf994f9  
    2323
    2424#include <QtGui>
     25#include "defines.h"
    2526#include "tspmodel.h"
    2627
    2728CTSPModel::CTSPModel(QObject *parent)
    28         : QAbstractTableModel(parent), randMin(1), randMax(10), nCities(0)
     29        : QAbstractTableModel(parent), nCities(0)
    2930{
     31        settings = new QSettings(INI_FILE,QSettings::IniFormat);
    3032}
    3133
     
    115117void CTSPModel::setNumCities(int n)
    116118{
     119int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();
     120int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();
    117121        if (n == nCities)
    118122                return;
     
    140144void CTSPModel::randomize()
    141145{
     146int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();
     147int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();
    142148        for (int r = 0; r < nCities; r++)
    143149                for (int c = 0; c < nCities; c++)
  • src/tspmodel.h

    r799ba1e3f2 raecdf994f9  
    3131#define MAX_CITIES 100
    3232// This value means infinity :-)
    33 #define INFINITY 1.7E+308
     33#ifndef INFINITY
     34        #define INFINITY 1.7E+308
     35#endif
    3436// This is string, which represents infinite value in table
    3537#define INFSTR "---"
    3638
    3739#include <QAbstractTableModel>
     40#include <QSettings>
    3841
    3942class CTSPModel: public QAbstractTableModel
     
    5154        void setNumCities(int);
    5255        void randomize();
    53         int randMin;
    54         int randMax;
    5556private:
     57        QSettings *settings;
    5658        double table[MAX_CITIES][MAX_CITIES];
    5759        int nCities;
Note: See TracChangeset for help on using the changeset viewer.