- Timestamp:
- Dec 22, 2009, 8:56:21 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main.cpp
r71 r80 53 53 qsrand(QDateTime::currentDateTime().toTime_t() ^ QCursor::pos().x() ^ QCursor::pos().y()); 54 54 55 QTranslator en; 56 if (en.load("en", PATH_I18N)) 57 app.installTranslator(&en); 58 55 59 MainWindow mainwindow; 56 60 mainwindow.show(); -
trunk/src/mainwindow.cpp
r78 r80 34 34 : QMainWindow(parent) 35 35 { 36 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,"TSPSG","tspsg");36 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); 37 37 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 44 40 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 52 42 #ifndef QT_NO_PRINTER 53 43 printer = new QPrinter(QPrinter::HighResolution); 54 44 #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 61 46 connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); 62 47 connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); … … 64 49 connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered())); 65 50 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 66 55 connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered())); 67 56 connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool))); … … 69 58 connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt())); 70 59 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 79 61 connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked())); 80 62 connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked())); 81 63 connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked())); 82 64 connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int))); 83 setCentralWidget(tabWidget);84 65 85 66 if (settings->value("SavePos", false).toBool()) { … … 100 81 } 101 82 102 qsrand(QDateTime().currentDateTime().toTime_t());103 83 tspmodel = new CTSPModel(this); 104 84 taskView->setModel(tspmodel); … … 116 96 } 117 97 98 MainWindow::~MainWindow() 99 { 100 #ifndef QT_NO_PRINTER 101 delete printer; 102 #endif 103 } 104 118 105 /* Privates **********************************************************/ 119 106 … … 142 129 filters.append(trUtf8("All Files") + " (*)"); 143 130 131 #ifdef Q_OS_WINCE 132 QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog); 133 #else 144 134 QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;")); 135 #endif // Q_OS_WINCE 145 136 if (file.isEmpty() || !QFileInfo(file).isFile()) 146 137 return; … … 197 188 filters.append(trUtf8("All Files") + " (*)"); 198 189 190 #ifdef Q_OS_WINCE 191 QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog); 192 #else 199 193 QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;")); 194 #endif 200 195 if (file.isEmpty()) 201 196 return; … … 292 287 bool untitled = (fileName == trUtf8("Untitled") + ".tspt"); 293 288 if (loadLanguage(action->data().toString())) { 289 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 294 290 settings->setValue("Language",action->data().toString()); 295 retranslateUi( this);291 retranslateUi(); 296 292 if (untitled) 297 293 setFileName(); 294 QApplication::restoreOverrideCursor(); 298 295 } 299 296 } … … 348 345 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation)); 349 346 lblIcon->setAlignment(Qt::AlignTop); 347 lblTitle->setOpenExternalLinks(true); 350 348 lblTitle->setText(title); 351 349 … … 452 450 output.append("<p>" + trUtf8("Resulting path:") + "</p>"); 453 451 output.append("<p> " + 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>"); 455 453 if (!solver.isOptimal()) { 456 454 output.append("<p> </p>"); … … 502 500 void MainWindow::spinCitiesValueChanged(int n) 503 501 { 502 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 504 503 int count = tspmodel->numCities(); 505 504 tspmodel->setNumCities(n); … … 509 508 taskView->resizeRowToContents(k); 510 509 } 510 QApplication::restoreOverrideCursor(); 511 511 } 512 512 … … 596 596 qApp->removeTranslator(translator); 597 597 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)) 604 611 qApp->installTranslator(qtTranslator); 605 612 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; 614 616 } 615 617 } 618 616 619 // Now let's load application translation. 620 translator = new QTranslator(this); 617 621 if (translator->load(lng,PATH_I18N)) 618 622 qApp->installTranslator(translator); … … 620 624 delete translator; 621 625 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; 627 629 } 628 630 return true; … … 689 691 } 690 692 693 void 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 691 718 bool MainWindow::saveTask() { 692 719 QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)"); … … 698 725 file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; 699 726 727 #ifdef Q_OS_WINCE 728 file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;"), NULL, QFileDialog::DontUseNativeDialog); 729 #else 700 730 file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;")); 731 #endif // Q_OS_WINCE 732 701 733 if (file.isEmpty()) 702 734 return false; … … 715 747 } 716 748 749 void 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 758 QStatusBar *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 717 803 void MainWindow::toggleSolutionActions(bool enable) 718 804 { -
trunk/src/mainwindow.h
r78 r80 47 47 public: 48 48 MainWindow(QWidget *parent = 0); 49 ~MainWindow(); 49 50 50 51 private slots: … … 82 83 #ifndef QT_NO_PRINTER 83 84 QPrinter *printer; 85 QAction *actionFilePrintPreview; 86 QAction *actionFilePrint; 84 87 #endif // QT_NO_PRINTER 85 88 QSettings *settings; … … 93 96 void outputMatrix(const TMatrix &matrix, QStringList &output); 94 97 void outputMatrix(const SStep &step, QStringList &output); 98 void retranslateUi(bool all = true); 95 99 bool saveTask(); 96 100 void setFileName(const QString &fileName = trUtf8("Untitled") + ".tspt"); 101 void setupUi(); 97 102 void toggleSolutionActions(bool enable = true); 98 103 }; -
trunk/src/settingsdialog.cpp
r78 r80 181 181 labelHint->setText(labelHint->statusTip()); 182 182 #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 184 186 spinRandMin->setMaximum(MAX_RAND_VALUE); 185 187 spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt()); -
trunk/src/tspmodel.cpp
r71 r80 31 31 : QAbstractTableModel(parent), nCities(0) 32 32 { 33 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,"TSPSG","tspsg");33 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); 34 34 } 35 35 … … 468 468 inline int CTSPModel::rand(int min, int max) const 469 469 { 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.