Changeset 21 in tspsg-svn for trunk/src/mainwindow.cpp


Ignore:
Timestamp:
Jun 22, 2009, 1:37:12 AM (15 years ago)
Author:
laleppa
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:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11*.idb
         2*.ini
        23*.ncb
        34*.pdb
  • trunk/src/mainwindow.cpp

    r17 r21  
    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
Note: See TracChangeset for help on using the changeset viewer.