Changeset 4ccf855df8 in tspsg for src


Ignore:
Timestamp:
Dec 22, 2009, 8:56:21 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:
f1fb54b9f7
Parents:
3bcb7e8910
Message:

+ Added Wait Cursor on city number change, because it can take some time (e.g. when changing from 5 to 50 cities).

  • Moved platform specific action definitions from .ui to source.
  • Changed random generation to include defined maximum (it was up to maximum previously).
  • Reverted from native to Qt open/save file dialog under WinCE, because it is more convenient than the native one.
  • English translation is now always loaded at application start before any other language is loaded. This is done to support plurals and some special characters that Qt translation system doesn't "like".
  • Updated translations to reflect recent changes.
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main.cpp

    r3bcb7e8910 r4ccf855df8  
    5353        qsrand(QDateTime::currentDateTime().toTime_t() ^ QCursor::pos().x() ^ QCursor::pos().y());
    5454
     55QTranslator en;
     56        if (en.load("en", PATH_I18N))
     57                app.installTranslator(&en);
     58
    5559MainWindow mainwindow;
    5660        mainwindow.show();
  • src/mainwindow.cpp

    r3bcb7e8910 r4ccf855df8  
    3434        : QMainWindow(parent)
    3535{
    36         settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
     36        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
    3737        loadLanguage();
    38         setupUi(this);
    39 #ifndef Q_OS_WINCE
    40 QStatusBar *statusbar = new QStatusBar(this);
    41         statusbar->setObjectName("statusbar");
    42         setStatusBar(statusbar);
    43 #endif // Q_OS_WINCE
     38        setupUi();
     39
    4440        initDocStyleSheet();
    45         solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
    46         solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>());
    47         solutionText->setWordWrapMode(QTextOption::WordWrap);
    48 #ifdef Q_OS_WINCE
    49         // A little hack for toolbar icons to have a sane size.
    50         toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4));
    51 #endif
     41
    5242#ifndef QT_NO_PRINTER
    5343        printer = new QPrinter(QPrinter::HighResolution);
    5444#endif // QT_NO_PRINTER
    55         groupSettingsLanguageList = new QActionGroup(this);
    56         actionSettingsLanguageEnglish->setData("en");
    57         actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
    58         loadLangList();
    59         spinCities->setMaximum(MAX_NUM_CITIES);
    60         actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
     45
    6146        connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
    6247        connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
     
    6449        connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
    6550        connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
     51#ifndef QT_NO_PRINTER
     52        connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered()));
     53        connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered()));
     54#endif // QT_NO_PRINTER
    6655        connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered()));
    6756        connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
     
    6958        connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
    7059        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
    71 #ifndef QT_NO_PRINTER
    72         menuFile->insertAction(actionFileExit,actionFilePrintPreview);
    73         menuFile->insertAction(actionFileExit,actionFilePrint);
    74         menuFile->insertSeparator(actionFileExit);
    75         toolBar->insertAction(actionSettingsPreferences,actionFilePrint);
    76         connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered()));
    77         connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered()));
    78 #endif // QT_NO_PRINTER
     60
    7961        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
    8062        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
    8163        connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
    8264        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
    83         setCentralWidget(tabWidget);
    8465
    8566        if (settings->value("SavePos", false).toBool()) {
     
    10081        }
    10182
    102         qsrand(QDateTime().currentDateTime().toTime_t());
    10383        tspmodel = new CTSPModel(this);
    10484        taskView->setModel(tspmodel);
     
    11696}
    11797
     98MainWindow::~MainWindow()
     99{
     100#ifndef QT_NO_PRINTER
     101        delete printer;
     102#endif
     103}
     104
    118105/* Privates **********************************************************/
    119106
     
    142129        filters.append(trUtf8("All Files") + " (*)");
    143130
     131#ifdef Q_OS_WINCE
     132        QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog);
     133#else
    144134QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;"));
     135#endif // Q_OS_WINCE
    145136        if (file.isEmpty() || !QFileInfo(file).isFile())
    146137                return;
     
    197188        filters.append(trUtf8("All Files") + " (*)");
    198189
     190#ifdef Q_OS_WINCE
     191QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog);
     192#else
    199193QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"));
     194#endif
    200195        if (file.isEmpty())
    201196                return;
     
    292287bool untitled = (fileName == trUtf8("Untitled") + ".tspt");
    293288        if (loadLanguage(action->data().toString())) {
     289                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    294290                settings->setValue("Language",action->data().toString());
    295                 retranslateUi(this);
     291                retranslateUi();
    296292                if (untitled)
    297293                        setFileName();
     294                QApplication::restoreOverrideCursor();
    298295        }
    299296}
     
    348345        lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation));
    349346        lblIcon->setAlignment(Qt::AlignTop);
     347        lblTitle->setOpenExternalLinks(true);
    350348        lblTitle->setText(title);
    351349
     
    452450                output.append("<p>" + trUtf8("Resulting path:") + "</p>");
    453451        output.append("<p>&nbsp;&nbsp;" + solver.getSortedPath() + "</p>");
    454         output.append("<p>" + trUtf8("The price is <b>%1</b> units.").arg(step->price) + "</p>");
     452        output.append("<p>" + trUtf8("The price is <b>%n</b> unit(s).", "", step->price) + "</p>");
    455453        if (!solver.isOptimal()) {
    456454                output.append("<p>&nbsp;</p>");
     
    502500void MainWindow::spinCitiesValueChanged(int n)
    503501{
     502        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    504503int count = tspmodel->numCities();
    505504        tspmodel->setNumCities(n);
     
    509508                        taskView->resizeRowToContents(k);
    510509                }
     510        QApplication::restoreOverrideCursor();
    511511}
    512512
     
    596596                qApp->removeTranslator(translator);
    597597                delete translator;
    598         }
    599         translator = new QTranslator();
    600         if ((lng.compare("en") != 0) && !lng.startsWith("en_")) {
    601                 // Trying to load system Qt library translation...
    602                 qtTranslator = new QTranslator();
    603                 if (qtTranslator->load("qt_" + lng,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
     598                translator = NULL;
     599        }
     600
     601        if (lng == "en")
     602                return true;
     603
     604        // Trying to load system Qt library translation...
     605        qtTranslator = new QTranslator(this);
     606        if (qtTranslator->load("qt_" + lng,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
     607                qApp->installTranslator(qtTranslator);
     608        else {
     609                // No luck. Let's try to load a bundled one.
     610                if (qtTranslator->load("qt_" + lng,PATH_I18N))
    604611                        qApp->installTranslator(qtTranslator);
    605612                else {
    606                         // No luck. Let's try to load a bundled one.
    607                         if (qtTranslator->load("qt_" + lng,PATH_I18N))
    608                                 qApp->installTranslator(qtTranslator);
    609                         else {
    610                                 // Qt library translation unavailable
    611                                 delete qtTranslator;
    612                                 qtTranslator = NULL;
    613                         }
     613                        // Qt library translation unavailable
     614                        delete qtTranslator;
     615                        qtTranslator = NULL;
    614616                }
    615617        }
     618
    616619        // Now let's load application translation.
     620        translator = new QTranslator(this);
    617621        if (translator->load(lng,PATH_I18N))
    618622                qApp->installTranslator(translator);
     
    620624                delete translator;
    621625                translator = NULL;
    622                 if ((lng.compare("en") != 0) && !lng.startsWith("en_")) {
    623                         if (!ad)
    624                                 QMessageBox(QMessageBox::Warning,trUtf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
    625                         return false;
    626                 }
     626                if (!ad)
     627                        QMessageBox(QMessageBox::Warning,trUtf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
     628                return false;
    627629        }
    628630        return true;
     
    689691}
    690692
     693void MainWindow::retranslateUi(bool all)
     694{
     695        if (all)
     696                Ui::MainWindow::retranslateUi(this);
     697
     698#ifndef QT_NO_PRINTER
     699        actionFilePrintPreview->setText(QApplication::translate("MainWindow", "P&rint Preview...", 0, QApplication::UnicodeUTF8));
     700#ifndef QT_NO_TOOLTIP
     701        actionFilePrintPreview->setToolTip(QApplication::translate("MainWindow", "Preview solution results", 0, QApplication::UnicodeUTF8));
     702#endif // QT_NO_TOOLTIP
     703#ifndef QT_NO_STATUSTIP
     704        actionFilePrintPreview->setStatusTip(QApplication::translate("MainWindow", "Preview current solution results before printing", 0, QApplication::UnicodeUTF8));
     705#endif // QT_NO_STATUSTIP
     706
     707        actionFilePrint->setText(QApplication::translate("MainWindow", "&Print...", 0, QApplication::UnicodeUTF8));
     708#ifndef QT_NO_TOOLTIP
     709        actionFilePrint->setToolTip(QApplication::translate("MainWindow", "Print solution", 0, QApplication::UnicodeUTF8));
     710#endif // QT_NO_TOOLTIP
     711#ifndef QT_NO_STATUSTIP
     712        actionFilePrint->setStatusTip(QApplication::translate("MainWindow", "Print current solution results", 0, QApplication::UnicodeUTF8));
     713#endif // QT_NO_STATUSTIP
     714        actionFilePrint->setShortcut(QApplication::translate("MainWindow", "Ctrl+P", 0, QApplication::UnicodeUTF8));
     715#endif // QT_NO_PRINTER
     716}
     717
    691718bool MainWindow::saveTask() {
    692719QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)");
     
    698725                file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt";
    699726
     727#ifdef Q_OS_WINCE
     728        file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog);
     729#else
    700730        file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;"));
     731#endif // Q_OS_WINCE
     732
    701733        if (file.isEmpty())
    702734                return false;
     
    715747}
    716748
     749void MainWindow::setupUi()
     750{
     751        Ui::MainWindow::setupUi(this);
     752
     753#if QT_VERSION >= 0x040600
     754        setToolButtonStyle(Qt::ToolButtonFollowStyle);
     755#endif
     756
     757#ifndef Q_OS_WINCE
     758QStatusBar *statusbar = new QStatusBar(this);
     759        statusbar->setObjectName("statusbar");
     760        setStatusBar(statusbar);
     761#endif // Q_OS_WINCE
     762
     763#ifdef Q_OS_WINCE
     764        //! \hack HACK: A little hack for toolbar icons to have a sane size.
     765        toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4));
     766#endif
     767
     768        solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>());
     769        solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>());
     770        solutionText->setWordWrapMode(QTextOption::WordWrap);
     771
     772#ifndef QT_NO_PRINTER
     773        actionFilePrintPreview = new QAction(this);
     774        actionFilePrintPreview->setObjectName("actionFilePrintPreview");
     775        actionFilePrintPreview->setEnabled(false);
     776        actionFilePrintPreview->setIcon(QIcon(":/images/icons/document_preview.png"));
     777
     778        actionFilePrint = new QAction(this);
     779        actionFilePrint->setObjectName("actionFilePrint");
     780        actionFilePrint->setEnabled(false);
     781        actionFilePrint->setIcon(QIcon(":/images/icons/fileprint.png"));
     782
     783        menuFile->insertAction(actionFileExit,actionFilePrintPreview);
     784        menuFile->insertAction(actionFileExit,actionFilePrint);
     785        menuFile->insertSeparator(actionFileExit);
     786
     787        toolBar->insertAction(actionSettingsPreferences,actionFilePrint);
     788#endif // QT_NO_PRINTER
     789
     790        groupSettingsLanguageList = new QActionGroup(this);
     791        actionSettingsLanguageEnglish->setData("en");
     792        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
     793        loadLangList();
     794        actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
     795
     796        spinCities->setMaximum(MAX_NUM_CITIES);
     797
     798        retranslateUi(false);
     799
     800        setCentralWidget(tabWidget);
     801}
     802
    717803void MainWindow::toggleSolutionActions(bool enable)
    718804{
  • src/mainwindow.h

    r3bcb7e8910 r4ccf855df8  
    4747public:
    4848        MainWindow(QWidget *parent = 0);
     49        ~MainWindow();
    4950
    5051private slots:
     
    8283#ifndef QT_NO_PRINTER
    8384        QPrinter *printer;
     85        QAction *actionFilePrintPreview;
     86        QAction *actionFilePrint;
    8487#endif // QT_NO_PRINTER
    8588        QSettings *settings;
     
    9396        void outputMatrix(const TMatrix &matrix, QStringList &output);
    9497        void outputMatrix(const SStep &step, QStringList &output);
     98        void retranslateUi(bool all = true);
    9599        bool saveTask();
    96100        void setFileName(const QString &fileName = trUtf8("Untitled") + ".tspt");
     101        void setupUi();
    97102        void toggleSolutionActions(bool enable = true);
    98103};
  • src/settingsdialog.cpp

    r3bcb7e8910 r4ccf855df8  
    181181        labelHint->setText(labelHint->statusTip());
    182182#endif // Q_OS_WINCE
    183         settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
     183
     184        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
     185
    184186        spinRandMin->setMaximum(MAX_RAND_VALUE);
    185187        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
  • src/tspmodel.cpp

    r3bcb7e8910 r4ccf855df8  
    3131        : QAbstractTableModel(parent), nCities(0)
    3232{
    33         settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
     33        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
    3434}
    3535
     
    468468inline int CTSPModel::rand(int min, int max) const
    469469{
    470         return min + (int)(((float)qrand() / RAND_MAX) * (max - min));
    471 }
     470        return min + (int)floor(((double)qrand() / RAND_MAX) * (max + 1 - min));
     471}
Note: See TracChangeset for help on using the changeset viewer.