Changeset 94 in tspsg-svn for trunk/src/mainwindow.cpp
- Timestamp:
- Feb 25, 2010, 9:48:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mainwindow.cpp
r93 r94 35 35 { 36 36 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); 37 37 38 loadLanguage(); 38 39 setupUi(); … … 44 45 #endif // QT_NO_PRINTER 45 46 47 #ifdef Q_OS_WINCE 48 currentGeometry = QApplication::desktop()->availableGeometry(0); 49 // We need to react to SIP show/hide and resize the window appropriately 50 connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int))); 51 #endif // Q_OS_WINCE 46 52 connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); 47 53 connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); … … 78 84 } 79 85 #else 80 setWindowState( windowState() |Qt::WindowMaximized);86 setWindowState(Qt::WindowMaximized); 81 87 #endif // Q_OS_WINCE 82 88 … … 268 274 if (checked) { 269 275 settings->remove("Language"); 270 QMessageBox (QMessageBox::Information,tr("Language change"),tr("Language will be autodetected on next application start."),QMessageBox::Ok,this).exec();276 QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on next application start.")); 271 277 } else 272 settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());278 settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString()); 273 279 } 274 280 … … 493 499 } 494 500 501 #ifdef Q_OS_WINCE 502 void MainWindow::desktopResized(int screen) 503 { 504 if (screen != 0) 505 return; 506 507 QRect availableGeometry = QApplication::desktop()->availableGeometry(0); 508 if (currentGeometry != availableGeometry) { 509 /*! 510 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height. 511 * If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the 512 * window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile? 513 */ 514 if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) { 515 setWindowState(windowState() | Qt::WindowMaximized); 516 } else { 517 if (windowState() & Qt::WindowMaximized) 518 setWindowState(windowState() ^ Qt::WindowMaximized); 519 setGeometry(availableGeometry); 520 } 521 } 522 currentGeometry = availableGeometry; 523 } 524 #endif // Q_OS_WINCE 525 495 526 void MainWindow::numCitiesChanged(int nCities) 496 527 { … … 555 586 void MainWindow::loadLangList() 556 587 { 557 QSettings langinfo(PATH_I18N"/languages.ini", QSettings::IniFormat); 558 #if QT_VERSION >= 0x040500 559 // In Qt < 4.5 QSettings doesn't have method setIniCodec. 560 langinfo.setIniCodec("UTF-8"); 561 #endif 562 QDir dir(PATH_I18N, "*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files); 588 QDir dir(PATH_I18N, "tspsg_*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files); 563 589 if (!dir.exists()) 564 590 return; … … 567 593 return; 568 594 QAction *a; 595 QTranslator t; 596 QString name; 569 597 for (int k = 0; k < langs.size(); k++) { 570 598 QFileInfo lang = langs.at(k); 571 if (!lang.completeBaseName().startsWith("qt_") && lang.completeBaseName().compare("en")) { 572 #if QT_VERSION >= 0x040500 573 a = menuSettingsLanguage->addAction(langinfo.value(lang.completeBaseName() + "/NativeName", lang.completeBaseName()).toString()); 574 #else 575 // We use Name if Qt < 4.5 because NativeName is in UTF-8, QSettings 576 // reads .ini file as ASCII and there is no way to set file encoding. 577 a = menuSettingsLanguage->addAction(langinfo.value(lang.completeBaseName() + "/Name", lang.completeBaseName()).toString()); 578 #endif 579 a->setData(lang.completeBaseName()); 599 if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && t.load(lang.completeBaseName(), PATH_I18N)) { 600 name = t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here."); 601 a = menuSettingsLanguage->addAction(name); 602 a->setStatusTip(QString("Set application language to %1").arg(name)); 603 a->setData(lang.completeBaseName().mid(6)); 580 604 a->setCheckable(true); 581 605 a->setActionGroup(groupSettingsLanguageList); 582 if (settings->value("Language", QLocale::system().name()).toString().startsWith(lang.completeBaseName() ))606 if (settings->value("Language", QLocale::system().name()).toString().startsWith(lang.completeBaseName().mid(6))) 583 607 a->setChecked(true); 584 608 } … … 628 652 // Now let's load application translation. 629 653 translator = new QTranslator(this); 630 if (translator->load( lng, PATH_I18N))654 if (translator->load("tspsg_" + lng, PATH_I18N)) 631 655 qApp->installTranslator(translator); 632 656 else { 633 657 delete translator; 634 658 translator = NULL; 635 if (!ad) 636 QMessageBox::warning(this, tr("Language Change"), tr("Unable to load translation language.")); 659 if (!ad) { 660 settings->remove("Language"); 661 if (QApplication::overrideCursor() != 0) 662 QApplication::restoreOverrideCursor(); 663 if (isVisible()) 664 QMessageBox::warning(this, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); 665 else 666 QMessageBox::warning(NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); 667 } 637 668 return false; 638 669 } … … 705 736 Ui::MainWindow::retranslateUi(this); 706 737 738 actionSettingsLanguageEnglish->setStatusTip(tr("Set application language to %1").arg("English")); 739 707 740 #ifndef QT_NO_PRINTER 708 741 actionFilePrintPreview->setText(QApplication::translate("MainWindow", "P&rint Preview...", 0, QApplication::UnicodeUTF8)); … … 769 802 #ifdef Q_OS_WINCE 770 803 menuBar()->setDefaultAction(menuFile->menuAction()); 804 805 QScrollArea *scrollArea = new QScrollArea(this); 806 scrollArea->setFrameShape(QFrame::NoFrame); 807 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 808 scrollArea->setWidgetResizable(true); 809 scrollArea->setWidget(tabWidget); 810 setCentralWidget(scrollArea); 771 811 #endif // Q_OS_WINCE 772 812 … … 804 844 actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); 805 845 loadLangList(); 806 actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());846 actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty()); 807 847 808 848 spinCities->setMaximum(MAX_NUM_CITIES);
Note: See TracChangeset
for help on using the changeset viewer.