Changeset aecdf994f9 in tspsg


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.
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • resources/tspsg.qrc

    r799ba1e3f2 raecdf994f9  
    11<RCC>
    2     <qresource prefix="/images" >
    3         <file>About.bmp</file>
    4         <file>Icon.png</file>
    5         <file>Settings.png</file>
    6         <file>Task.bmp</file>
    7     </qresource>
    8     <qresource prefix="/images/buttons" >
    9         <file>buttons/Critical.png</file>
    10         <file>buttons/Delete.png</file>
    11         <file>buttons/Document.png</file>
    12         <file>buttons/Font.png</file>
    13         <file>buttons/Help.png</file>
    14         <file>buttons/NoAction.png</file>
    15         <file>buttons/OK.png</file>
    16         <file>buttons/OpenFolder.png</file>
    17         <file>buttons/Print.png</file>
    18         <file>buttons/PrintSetup.png</file>
    19         <file>buttons/Properties.png</file>
    20         <file>buttons/Save.png</file>
    21         <file>buttons/book_open.png</file>
    22         <file>buttons/infoBubble.png</file>
    23     </qresource>
     2  <qresource prefix="/images" >
     3    <file>About.bmp</file>
     4    <file>Icon.png</file>
     5    <file>Settings.png</file>
     6    <file>Task.bmp</file>
     7  </qresource>
     8  <qresource prefix="/images/buttons" >
     9    <file>buttons/Color.png</file>
     10    <file>buttons/Critical.png</file>
     11    <file>buttons/Delete.png</file>
     12    <file>buttons/Document.png</file>
     13    <file>buttons/Font.png</file>
     14    <file>buttons/Help.png</file>
     15    <file>buttons/NoAction.png</file>
     16    <file>buttons/OK.png</file>
     17    <file>buttons/OpenFolder.png</file>
     18    <file>buttons/Print.png</file>
     19    <file>buttons/PrintSetup.png</file>
     20    <file>buttons/Properties.png</file>
     21    <file>buttons/Save.png</file>
     22    <file>buttons/book_open.png</file>
     23    <file>buttons/infoBubble.png</file>
     24  </qresource>
    2425</RCC>
  • 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;
  • ui/mainwindow.ce.ui

    r799ba1e3f2 raecdf994f9  
    350350    <string>Сохранить ход и граф решения</string>
    351351   </property>
    352    <property name="shortcut">
    353     <string>Ctrl+S</string>
    354    </property>
    355352  </action>
    356353  <action name="actionFileNew">
  • ui/mainwindow.ui

    r799ba1e3f2 raecdf994f9  
    369369    <string>Сохранить ход и граф решения</string>
    370370   </property>
    371    <property name="shortcut">
    372     <string>Ctrl+S</string>
    373    </property>
    374371  </action>
    375372  <action name="actionFileNew">
  • ui/settingsdialog.ce.ui

    r799ba1e3f2 raecdf994f9  
    77    <x>0</x>
    88    <y>0</y>
    9     <width>229</width>
     9    <width>235</width>
    1010    <height>264</height>
    1111   </rect>
     
    195195        </item>
    196196        <item>
     197         <widget class="QPushButton" name="buttonColor">
     198          <property name="text">
     199           <string>&amp;Цвет...</string>
     200          </property>
     201          <property name="icon">
     202           <iconset resource="../resources/tspsg.qrc">
     203            <normaloff>:/images/buttons/buttons/Color.png</normaloff>:/images/buttons/buttons/Color.png</iconset>
     204          </property>
     205         </widget>
     206        </item>
     207        <item>
    197208         <widget class="QPushButton" name="buttonFont">
    198209          <property name="cursor">
     
    226237       </spacer>
    227238      </item>
    228       <item>
    229        <layout class="QHBoxLayout" name="horizontalLayout">
    230         <item>
    231          <spacer name="horizontalSpacer">
    232           <property name="orientation">
    233            <enum>Qt::Horizontal</enum>
    234           </property>
    235           <property name="sizeHint" stdset="0">
    236            <size>
    237             <width>40</width>
    238             <height>20</height>
    239            </size>
    240           </property>
    241          </spacer>
    242         </item>
    243         <item>
    244          <widget class="QCheckBox" name="checkBox">
    245           <property name="cursor">
    246            <cursorShape>PointingHandCursor</cursorShape>
    247           </property>
    248           <property name="statusTip">
    249            <string>Восстанавливать состояние и размеры окна после перезапуска программы</string>
    250           </property>
    251           <property name="text">
    252            <string>Сохранять состояние и
    253 положение главного окна</string>
    254           </property>
    255           <property name="checked">
    256            <bool>false</bool>
    257           </property>
    258          </widget>
    259         </item>
    260         <item>
    261          <spacer name="horizontalSpacer_2">
    262           <property name="orientation">
    263            <enum>Qt::Horizontal</enum>
    264           </property>
    265           <property name="sizeHint" stdset="0">
    266            <size>
    267             <width>40</width>
    268             <height>20</height>
    269            </size>
    270           </property>
    271          </spacer>
    272         </item>
    273        </layout>
    274       </item>
    275239     </layout>
    276240    </widget>
  • ui/settingsdialog.ui

    r799ba1e3f2 raecdf994f9  
    77    <x>0</x>
    88    <y>0</y>
    9     <width>436</width>
     9    <width>466</width>
    1010    <height>172</height>
    1111   </rect>
     
    235235             <string>Настройки печати:</string>
    236236            </property>
    237             <layout class="QVBoxLayout">
     237            <layout class="QVBoxLayout" name="verticalLayout">
    238238             <item>
    239239              <layout class="QHBoxLayout">
     
    270270             </item>
    271271             <item>
    272               <widget class="QPushButton" name="buttonFont">
    273                <property name="cursor">
    274                 <cursorShape>PointingHandCursor</cursorShape>
     272              <widget class="QSplitter" name="splitter">
     273               <property name="orientation">
     274                <enum>Qt::Horizontal</enum>
    275275               </property>
    276                <property name="statusTip">
    277                 <string>Задать параметры шрифта, используемого при печати</string>
    278                </property>
    279                <property name="text">
    280                 <string>&amp;Шрифт...</string>
    281                </property>
    282                <property name="icon">
    283                 <iconset resource="../resources/tspsg.qrc">
    284                  <normaloff>:/images/buttons/buttons/Font.png</normaloff>:/images/buttons/buttons/Font.png</iconset>
    285                </property>
     276               <widget class="QPushButton" name="buttonColor">
     277                <property name="cursor">
     278                 <cursorShape>PointingHandCursor</cursorShape>
     279                </property>
     280                <property name="text">
     281                 <string>&amp;Цвет...</string>
     282                </property>
     283                <property name="icon">
     284                 <iconset resource="../resources/tspsg.qrc">
     285                  <normaloff>:/images/buttons/buttons/Color.png</normaloff>:/images/buttons/buttons/Color.png</iconset>
     286                </property>
     287               </widget>
     288               <widget class="QPushButton" name="buttonFont">
     289                <property name="cursor">
     290                 <cursorShape>PointingHandCursor</cursorShape>
     291                </property>
     292                <property name="statusTip">
     293                 <string>Задать параметры шрифта, используемого при печати</string>
     294                </property>
     295                <property name="text">
     296                 <string>&amp;Шрифт...</string>
     297                </property>
     298                <property name="icon">
     299                 <iconset resource="../resources/tspsg.qrc">
     300                  <normaloff>:/images/buttons/buttons/Font.png</normaloff>:/images/buttons/buttons/Font.png</iconset>
     301                </property>
     302               </widget>
    286303              </widget>
    287304             </item>
     
    292309        </item>
    293310        <item>
    294          <widget class="QCheckBox" name="checkBox">
     311         <widget class="QCheckBox" name="cbSaveState">
    295312          <property name="cursor">
    296313           <cursorShape>PointingHandCursor</cursorShape>
     
    427444 <resources>
    428445  <include location="../resources/tspsg.qrc"/>
     446  <include location="../resources/tspsg.qrc"/>
    429447 </resources>
    430448 <connections/>
Note: See TracChangeset for help on using the changeset viewer.