Changeset 278bc7818f in tspsg


Ignore:
Timestamp:
Feb 27, 2010, 2:13:50 PM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
162d5c5f94
Parents:
b2bf8e3b6b
Message:

+ Added Symmetric mode: in this mode the cost of travel from city 1 to city 2 and vice versa is the same.
+ Added the ability to reset all settings to their defaults: hold Shift while clicking Save button in Settings Dialog.

  • Better SIP show/hide handling under wince: no need to resize the Main Window, when it isn't active.
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/defaults.h

    rb2bf8e3b6b r278bc7818f  
    4545#endif // Q_OS_WINCE
    4646//! Default for "Save main window state and position"
    47 #define DEF_SAVEPOS false
     47#define DEF_SAVEPOS true
    4848//! Default for "Use translucency effects in Vista/7"
    4949#define DEF_USE_TRANSLUCENCY true
     
    5858//! Default for "Fractional random values"
    5959#define DEF_FRACTIONAL_RANDOM false
     60//! Default for "Symmetric tasks mode"
     61#define DEF_SYMMETRIC_MODE false
    6062
    6163//////// OUTPUT
     
    6769#define DEF_SHOW_MATRIX_LIMIT 15
    6870//! Default for "Scroll to the end of output after solving"
    69 #define DEF_SCROLL_TO_END true
     71#define DEF_SCROLL_TO_END false
    7072/*!
    7173 * \def DEF_FONT_FAMILY
  • src/mainwindow.cpp

    rb2bf8e3b6b r278bc7818f  
    7171
    7272#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
     73        // Centering main window
     74QRect rect = geometry();
     75        rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
     76        setGeometry(rect);
    7377        if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
    7478                // Loading of saved window state
     
    7781                restoreState(settings->value("State").toByteArray());
    7882                settings->endGroup();
    79         } else {
    80                 // Centering main window
    81 QRect rect = geometry();
    82                 rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
    83                 setGeometry(rect);
    8483        }
    8584#else
     
    500499
    501500#ifdef Q_OS_WINCE
     501void MainWindow::changeEvent(QEvent *ev)
     502{
     503        if ((ev->type() == QEvent::ActivationChange) && isActiveWindow())
     504                desktopResized(0);
     505
     506        QWidget::changeEvent(ev);
     507}
     508
    502509void MainWindow::desktopResized(int screen)
    503510{
    504         if (screen != 0)
     511        if ((screen != 0) || !isActiveWindow())
    505512                return;
    506513
    507514QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
    508515        if (currentGeometry != availableGeometry) {
     516                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    509517                /*!
    510518                 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
     
    519527                        setGeometry(availableGeometry);
    520528                }
    521         }
    522         currentGeometry = availableGeometry;
     529                currentGeometry = availableGeometry;
     530                QApplication::restoreOverrideCursor();
     531        }
    523532}
    524533#endif // Q_OS_WINCE
     
    557566                return;
    558567        }
    559         settings->setValue("NumCities", spinCities->value());
    560 
    561         // Saving Main Window state
    562         if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
    563                 settings->beginGroup("MainWindow");
     568        if (!settings->value("SettingsReset", false).toBool()) {
     569                settings->setValue("NumCities", spinCities->value());
     570
     571                // Saving Main Window state
     572                if (settings->value("SavePos", DEF_SAVEPOS).toBool()) {
     573                        settings->beginGroup("MainWindow");
    564574#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
    565                 settings->setValue("Geometry", saveGeometry());
     575                        settings->setValue("Geometry", saveGeometry());
    566576#endif // Q_OS_WINCE
    567                 settings->setValue("State", saveState());
    568                 settings->endGroup();
     577                        settings->setValue("State", saveState());
     578                        settings->endGroup();
     579                }
     580        } else {
     581                settings->remove("SettingsReset");
    569582        }
    570583
  • src/mainwindow.h

    rb2bf8e3b6b r278bc7818f  
    7272        void dataChanged(const QModelIndex &tl, const QModelIndex &br);
    7373#ifdef Q_OS_WINCE
     74        void changeEvent(QEvent *ev);
    7475        void desktopResized(int screen);
    7576#endif // Q_OS_WINCE
  • src/settingsdialog.cpp

    rb2bf8e3b6b r278bc7818f  
    5454        scrollArea->setWidgetResizable(true);
    5555        scrollArea->setWidget(bgWhite);
     56#else
     57        buttons->insertStretch(buttons->indexOf(buttonHelp) + 1);
    5658#endif // Q_OS_WINCE
    5759
     
    146148
    147149#ifdef Q_OS_WINCE
    148         currentGeometry = QApplication::desktop()->availableGeometry(0);
    149150        // We need to react to SIP show/hide and resize the window appropriately
    150151        connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
     
    153154        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
    154155        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
    155 //      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
    156156        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
    157157#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
     
    161161
    162162        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
     163        settings->remove("SettingsReset");
    163164
    164165        cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
     
    173174
    174175        settings->beginGroup("Task");
     176        cbSymmetricMode->setChecked(settings->value("SymmetricMode", DEF_SYMMETRIC_MODE).toBool());
    175177        spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
    176178        spinRandMin->setMaximum(MAX_RAND_VALUE);
     
    194196        settings->endGroup();
    195197
     198#ifndef Q_OS_WINCE
    196199        adjustSize();
     200#endif // Q_OS_WINCE
    197201}
    198202
     
    230234void SettingsDialog::accept()
    231235{
     236        if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
     237                if (QMessageBox::question(this, tr("Settings Reset"), tr("Do you really want to <b>reset all application settings to their defaults</b>?"), QMessageBox::RestoreDefaults | QMessageBox::Cancel) == QMessageBox::RestoreDefaults) {
     238                        _newFont = (font != QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE));
     239                        _newColor = (color != DEF_FONT_COLOR);
     240                        settings->remove("");
     241                        settings->setValue("SettingsReset", true);
     242                        QDialog::accept();
     243                        QMessageBox::information(this, tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
     244                        return;
     245                } else
     246                        return;
     247        }
    232248#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
    233249        settings->setValue("SavePos", cbSaveState->isChecked());
     
    246262
    247263        settings->beginGroup("Task");
     264        settings->setValue("SymmetricMode", cbSymmetricMode->isChecked());
    248265        settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
    249266        settings->setValue("RandMin", spinRandMin->value());
     
    293310QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
    294311        if (currentGeometry != availableGeometry) {
     312                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    295313                /*!
    296314                 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
     
    305323                        setGeometry(availableGeometry);
    306324                }
    307         }
    308         currentGeometry = availableGeometry;
     325                currentGeometry = availableGeometry;
     326                QApplication::restoreOverrideCursor();
     327        }
     328}
     329
     330void SettingsDialog::showEvent(QShowEvent *ev)
     331{
     332        desktopResized(0);
     333
     334        QWidget::showEvent(ev);
    309335}
    310336#endif // Q_OS_WINCE
  • src/settingsdialog.h

    rb2bf8e3b6b r278bc7818f  
    7676#ifdef Q_OS_WINCE
    7777        void desktopResized(int screen);
     78        void showEvent(QShowEvent *ev);
    7879#endif // Q_OS_WINCE
    7980        void spinRandMinValueChanged(int val);
  • src/tspmodel.cpp

    rb2bf8e3b6b r278bc7818f  
    191191void CTSPModel::randomize()
    192192{
    193 int randMin = settings->value("Task/RandMin",DEF_RAND_MIN).toInt();
    194 int randMax = settings->value("Task/RandMax",DEF_RAND_MAX).toInt();
    195         for (int r = 0; r < nCities; r++)
    196                 for (int c = 0; c < nCities; c++)
    197                         if (r != c)
    198                                 table[r][c] = rand(randMin,randMax);
    199         emit dataChanged(index(0,0),index(nCities - 1,nCities - 1));
     193int randMin = settings->value("Task/RandMin", DEF_RAND_MIN).toInt();
     194int randMax = settings->value("Task/RandMax", DEF_RAND_MAX).toInt();
     195        if (settings->value("Task/SymmetricMode", DEF_SYMMETRIC_MODE).toBool()) {
     196                for (int r = 0; r < nCities; r++)
     197                        for (int c = 0; c < r; c++)
     198                                table[c][r] = table[r][c] = rand(randMin, randMax);
     199        } else {
     200                for (int r = 0; r < nCities; r++)
     201                        for (int c = 0; c < nCities; c++)
     202                                if (r != c)
     203                                        table[r][c] = rand(randMin, randMax);
     204        }
     205        emit dataChanged(index(0,0), index(nCities - 1, nCities - 1));
    200206}
    201207
     
    315321                        if (!ok || tmp < 0)
    316322                                return false;
    317                         else
     323                        else {
    318324                                table[index.row()][index.column()] = tmp;
     325                                if (settings->value("Task/SymmetricMode", DEF_SYMMETRIC_MODE).toBool())
     326                                        table[index.column()][index.row()] = tmp;
     327                        }
    319328                }
    320329                emit dataChanged(index,index);
  • tspsg.pro

    rb2bf8e3b6b r278bc7818f  
    5555        share.files = COPYING README
    5656        i18n.path = /share/tspsg/i18n
    57         i18n.files = i18n/languages.ini i18n/*.qm
     57        i18n.files = i18n/*.qm
    5858        docs.path = /share/doc/tspsg
    5959#       docs.files = docs/*
     
    7272        share.files = COPYING README
    7373        i18n.path = "\tspsg\i18n"
    74         i18n.files = i18n\languages.ini i18n\*.qm
     74        i18n.files = i18n/*.qm
    7575        docs.path = "\tspsg\help"
    7676#       docs.files = docs\*
     
    8787        share.sources = COPYING README
    8888        share.path = "\Storage Card\Program Files\tspsg"
    89         i18n.sources = i18n\languages.ini i18n\*.qm
     89        i18n.sources = i18n/*.qm
    9090        i18n.path = "\Storage Card\Program Files\tspsg\i18n"
    9191#       docs.sources = docs\*
     
    100100                "\"COPYING\" - \"\", FILETEXT, TEXTEXIT"
    101101        share.sources = COPYING README
    102         i18n.sources = i18n/languages.ini i18n/*.qm
     102        i18n.sources = i18n/*.qm
    103103        i18n.path = i18n
    104104#       docs.sources = docs/*
  • ui/mainwindow.ui

    rb2bf8e3b6b r278bc7818f  
    88    <x>0</x>
    99    <y>0</y>
    10     <width>301</width>
    11     <height>352</height>
     10    <width>500</width>
     11    <height>450</height>
    1212   </rect>
    1313  </property>
     
    253253     <x>0</x>
    254254     <y>0</y>
    255      <width>301</width>
     255     <width>500</width>
    256256     <height>21</height>
    257257    </rect>
  • ui/settingsdialog.ui

    rb2bf8e3b6b r278bc7818f  
    229229        <string>Task generation and solving settings</string>
    230230       </attribute>
    231        <layout class="QVBoxLayout" name="_5">
    232         <item>
    233          <layout class="QHBoxLayout" name="_10">
    234           <item>
     231       <layout class="QVBoxLayout" name="_9">
     232        <item>
     233         <layout class="QFormLayout" name="_5">
     234          <property name="fieldGrowthPolicy">
     235           <enum>QFormLayout::ExpandingFieldsGrow</enum>
     236          </property>
     237          <item row="0" column="0">
    235238           <widget class="QLabel" name="labelFractionalAccuracy">
    236239            <property name="text">
     
    239242           </widget>
    240243          </item>
    241           <item>
     244          <item row="0" column="1">
    242245           <widget class="QSpinBox" name="spinFractionalAccuracy">
    243246            <property name="cursor">
     
    252255           </widget>
    253256          </item>
    254           <item>
    255            <spacer name="spacer_3">
    256             <property name="orientation">
    257              <enum>Qt::Horizontal</enum>
    258             </property>
    259             <property name="sizeHint" stdset="0">
    260              <size>
    261               <width>0</width>
    262               <height>0</height>
    263              </size>
    264             </property>
    265            </spacer>
    266           </item>
    267257         </layout>
    268258        </item>
    269259        <item>
    270          <layout class="QHBoxLayout" name="_7">
    271           <item>
    272            <widget class="QGroupBox" name="groupBox">
    273             <property name="title">
    274              <string>Random numbers</string>
    275             </property>
    276             <layout class="QVBoxLayout" name="_8">
    277              <item>
    278               <layout class="QFormLayout" name="_9">
    279                <property name="fieldGrowthPolicy">
    280                 <enum>QFormLayout::ExpandingFieldsGrow</enum>
    281                </property>
    282                <item row="0" column="0">
    283                 <widget class="QLabel" name="labelRandMin">
    284                  <property name="text">
    285                   <string>&amp;Minimal:</string>
    286                  </property>
    287                  <property name="buddy">
    288                   <cstring>spinRandMin</cstring>
    289                  </property>
    290                 </widget>
    291                </item>
    292                <item row="0" column="1">
    293                 <widget class="QSpinBox" name="spinRandMin">
    294                  <property name="cursor">
    295                   <cursorShape>PointingHandCursor</cursorShape>
    296                  </property>
    297                  <property name="statusTip">
    298                   <string>Minimum for random number generation</string>
    299                  </property>
    300                 </widget>
    301                </item>
    302                <item row="1" column="0">
    303                 <widget class="QLabel" name="labelRandMax">
    304                  <property name="text">
    305                   <string>Ma&amp;ximal:</string>
    306                  </property>
    307                  <property name="buddy">
    308                   <cstring>spinRandMax</cstring>
    309                  </property>
    310                 </widget>
    311                </item>
    312                <item row="1" column="1">
    313                 <widget class="QSpinBox" name="spinRandMax">
    314                  <property name="cursor">
    315                   <cursorShape>PointingHandCursor</cursorShape>
    316                  </property>
    317                  <property name="statusTip">
    318                   <string>Maximum for random number generation</string>
    319                  </property>
    320                 </widget>
    321                </item>
    322               </layout>
     260         <widget class="QCheckBox" name="cbSymmetricMode">
     261          <property name="cursor">
     262           <cursorShape>PointingHandCursor</cursorShape>
     263          </property>
     264          <property name="statusTip">
     265           <string>In this mode the cost of travel from city 1 to city 2 and vice versa is the same</string>
     266          </property>
     267          <property name="text">
     268           <string>Symmetric mode</string>
     269          </property>
     270         </widget>
     271        </item>
     272        <item>
     273         <widget class="QGroupBox" name="gbTaskGeneration">
     274          <property name="title">
     275           <string>Task generation</string>
     276          </property>
     277          <layout class="QVBoxLayout" name="_7">
     278           <item>
     279            <layout class="QFormLayout" name="_8">
     280             <property name="fieldGrowthPolicy">
     281              <enum>QFormLayout::ExpandingFieldsGrow</enum>
     282             </property>
     283             <item row="0" column="0">
     284              <widget class="QLabel" name="labelRandMin">
     285               <property name="text">
     286                <string>Minimal random:</string>
     287               </property>
     288               <property name="buddy">
     289                <cstring>spinRandMin</cstring>
     290               </property>
     291              </widget>
    323292             </item>
    324              <item>
    325               <widget class="QCheckBox" name="cbFractionalRandom">
     293             <item row="0" column="1">
     294              <widget class="QSpinBox" name="spinRandMin">
    326295               <property name="cursor">
    327296                <cursorShape>PointingHandCursor</cursorShape>
    328297               </property>
    329298               <property name="statusTip">
    330                 <string>Generate fractional random values with the Fractional accuracy</string>
    331                </property>
     299                <string>Minimum for random number generation</string>
     300               </property>
     301              </widget>
     302             </item>
     303             <item row="1" column="0">
     304              <widget class="QLabel" name="labelRandMax">
    332305               <property name="text">
    333                 <string>Fractional random values</string>
     306                <string>Maximal random:</string>
     307               </property>
     308               <property name="buddy">
     309                <cstring>spinRandMax</cstring>
     310               </property>
     311              </widget>
     312             </item>
     313             <item row="1" column="1">
     314              <widget class="QSpinBox" name="spinRandMax">
     315               <property name="cursor">
     316                <cursorShape>PointingHandCursor</cursorShape>
     317               </property>
     318               <property name="statusTip">
     319                <string>Maximum for random number generation</string>
    334320               </property>
    335321              </widget>
    336322             </item>
    337323            </layout>
    338            </widget>
    339           </item>
    340           <item>
    341            <spacer name="spacer_2">
    342             <property name="orientation">
    343              <enum>Qt::Horizontal</enum>
    344             </property>
    345             <property name="sizeHint" stdset="0">
    346              <size>
    347               <width>0</width>
    348               <height>0</height>
    349              </size>
    350             </property>
    351            </spacer>
    352           </item>
    353          </layout>
    354         </item>
    355         <item>
    356          <spacer name="spacer_5">
     324           </item>
     325           <item>
     326            <widget class="QCheckBox" name="cbFractionalRandom">
     327             <property name="cursor">
     328              <cursorShape>PointingHandCursor</cursorShape>
     329             </property>
     330             <property name="statusTip">
     331              <string>Generate fractional random values with the Fractional accuracy</string>
     332             </property>
     333             <property name="text">
     334              <string>Fractional random values</string>
     335             </property>
     336            </widget>
     337           </item>
     338          </layout>
     339         </widget>
     340        </item>
     341        <item>
     342         <spacer name="spacer_2">
    357343          <property name="orientation">
    358344           <enum>Qt::Vertical</enum>
     
    360346          <property name="sizeHint" stdset="0">
    361347           <size>
    362             <width>0</width>
     348            <width>10</width>
    363349            <height>0</height>
    364350           </size>
     
    395381          </property>
    396382          <item>
    397            <spacer name="spacer_4">
     383           <spacer name="spacer_3">
    398384            <property name="orientation">
    399385             <enum>Qt::Horizontal</enum>
     
    437423          </item>
    438424          <item>
    439            <spacer name="spacer_6">
     425           <spacer name="spacer_4">
    440426            <property name="orientation">
    441427             <enum>Qt::Horizontal</enum>
     
    471457             <string>Output font settings</string>
    472458            </property>
    473             <layout class="QHBoxLayout" name="horizontalLayout">
     459            <layout class="QHBoxLayout" name="_13">
    474460             <item>
    475461              <widget class="QPushButton" name="buttonFont">
     
    506492              </widget>
    507493             </item>
     494             <item>
     495              <spacer name="spacer_5">
     496               <property name="orientation">
     497                <enum>Qt::Horizontal</enum>
     498               </property>
     499               <property name="sizeHint" stdset="0">
     500                <size>
     501                 <width>0</width>
     502                 <height>0</height>
     503                </size>
     504               </property>
     505              </spacer>
     506             </item>
    508507            </layout>
    509508           </widget>
    510509          </item>
    511           <item>
    512            <spacer name="spacer_7">
    513             <property name="orientation">
    514              <enum>Qt::Horizontal</enum>
    515             </property>
    516             <property name="sizeHint" stdset="0">
    517              <size>
    518               <width>0</width>
    519               <height>0</height>
    520              </size>
    521             </property>
    522            </spacer>
    523           </item>
    524510         </layout>
    525511        </item>
    526512        <item>
    527          <spacer name="verticalSpacer">
     513         <spacer name="spacer_6">
    528514          <property name="orientation">
    529515           <enum>Qt::Vertical</enum>
Note: See TracChangeset for help on using the changeset viewer.