Changeset 278bc7818f in tspsg for src


Ignore:
Timestamp:
Feb 27, 2010, 2:13:50 PM (15 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.
Location:
src
Files:
6 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);
Note: See TracChangeset for help on using the changeset viewer.