Changeset 94 in tspsg-svn for trunk/src


Ignore:
Timestamp:
Feb 25, 2010, 9:48:46 PM (15 years ago)
Author:
laleppa
Message:

+ Added SIP show/hide handling under wince.

  • Renamed translation files to follow common conventions.
  • Language name is now stored in the translation file. No need for language.ini anymore.
  • Updated translations.
Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defaults.h

    r93 r94  
    6969#define DEF_SCROLL_TO_END true
    7070/*!
    71  * \def DEF_FON_FAMILY
     71 * \def DEF_FONT_FAMILY
    7272 * \brief Default font name.
    7373 */
  • trunk/src/main.cpp

    r93 r94  
    5454
    5555QTranslator en;
    56         if (en.load("en", PATH_I18N))
     56        if (en.load("tspsg_en", PATH_I18N))
    5757                app.installTranslator(&en);
    5858
  • trunk/src/mainwindow.cpp

    r93 r94  
    3535{
    3636        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
     37
    3738        loadLanguage();
    3839        setupUi();
     
    4445#endif // QT_NO_PRINTER
    4546
     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
    4652        connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
    4753        connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
     
    7884        }
    7985#else
    80         setWindowState(windowState() | Qt::WindowMaximized);
     86        setWindowState(Qt::WindowMaximized);
    8187#endif // Q_OS_WINCE
    8288
     
    268274        if (checked) {
    269275                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."));
    271277        } else
    272                 settings->setValue("Language",groupSettingsLanguageList->checkedAction()->data().toString());
     278                settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());
    273279}
    274280
     
    493499}
    494500
     501#ifdef Q_OS_WINCE
     502void MainWindow::desktopResized(int screen)
     503{
     504        if (screen != 0)
     505                return;
     506
     507QRect 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
    495526void MainWindow::numCitiesChanged(int nCities)
    496527{
     
    555586void MainWindow::loadLangList()
    556587{
    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);
     588QDir dir(PATH_I18N, "tspsg_*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files);
    563589        if (!dir.exists())
    564590                return;
     
    567593                return;
    568594QAction *a;
     595QTranslator t;
     596QString name;
    569597        for (int k = 0; k < langs.size(); k++) {
    570598                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));
    580604                        a->setCheckable(true);
    581605                        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)))
    583607                                a->setChecked(true);
    584608                }
     
    628652        // Now let's load application translation.
    629653        translator = new QTranslator(this);
    630         if (translator->load(lng, PATH_I18N))
     654        if (translator->load("tspsg_" + lng, PATH_I18N))
    631655                qApp->installTranslator(translator);
    632656        else {
    633657                delete translator;
    634658                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                }
    637668                return false;
    638669        }
     
    705736                Ui::MainWindow::retranslateUi(this);
    706737
     738        actionSettingsLanguageEnglish->setStatusTip(tr("Set application language to %1").arg("English"));
     739
    707740#ifndef QT_NO_PRINTER
    708741        actionFilePrintPreview->setText(QApplication::translate("MainWindow", "P&rint Preview...", 0, QApplication::UnicodeUTF8));
     
    769802#ifdef Q_OS_WINCE
    770803        menuBar()->setDefaultAction(menuFile->menuAction());
     804
     805QScrollArea *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);
    771811#endif // Q_OS_WINCE
    772812
     
    804844        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
    805845        loadLangList();
    806         actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
     846        actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
    807847
    808848        spinCities->setMaximum(MAX_NUM_CITIES);
  • trunk/src/mainwindow.h

    r92 r94  
    7171        void dataChanged();
    7272        void dataChanged(const QModelIndex &tl, const QModelIndex &br);
     73#ifdef Q_OS_WINCE
     74        void desktopResized(int screen);
     75#endif // Q_OS_WINCE
    7376        void numCitiesChanged(int nCities);
    7477#ifndef QT_NO_PRINTER
     
    8891        QSettings *settings;
    8992        CTSPModel *tspmodel;
     93#ifdef Q_OS_WINCE
     94        QRect currentGeometry;
     95#endif // Q_OS_WINCE
    9096
    9197        void closeEvent(QCloseEvent *ev);
  • trunk/src/settingsdialog.cpp

    r93 r94  
    4343
    4444#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
    45         // Layout helper elements
    46 QVBoxLayout *vbox1;
    47 QHBoxLayout *hbox1;
     45QVBoxLayout *vbox1; // Layout helper
     46
     47#ifdef Q_OS_WINCE
     48        // On screens with small height when SIP is shown and the window is resized
     49        // there is not enought space for all elements.
     50        //  So we show scrollbars to be able to access them.
     51QScrollArea *scrollArea = new QScrollArea(this);
     52        scrollArea->setFrameShape(QFrame::NoFrame);
     53        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     54        scrollArea->setWidgetResizable(true);
     55        scrollArea->setWidget(bgWhite);
     56#endif // Q_OS_WINCE
    4857
    4958        bgWhite->layout()->setMargin(0);
    50 
    51         // Bottom part (with grey bg)
    52         hbox1 = new QHBoxLayout(bgGrey);
    53         hbox1->setMargin(6);
    54         hbox1->setSpacing(6);
    55         hbox1->addWidget(buttonHelp);
    56         hbox1->addStretch();
    5759
    5860        // Central layout
     
    6062        vbox1->setMargin(0);
    6163        vbox1->setSpacing(0);
     64#ifdef Q_OS_WINCE
     65        vbox1->addWidget(scrollArea);
     66#else
    6267        vbox1->addWidget(bgWhite);
    63         vbox1->addWidget(lineHorizontal);
     68#endif // Q_OS_WINCE
    6469        vbox1->addWidget(bgGrey);
     70        setLayout(vbox1);
    6571#else
    6672        // Layout helper elements
    6773QVBoxLayout *vbox1, *vbox2;
    68 QHBoxLayout *hbox1, *hbox2;
     74QHBoxLayout *hbox1;
    6975
    7076        if (QtWin::isCompositionEnabled()) {
     
    8995        imgIcon->setObjectName("imgIcon");
    9096        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
    91         imgIcon->setFrameShape(QFrame::Panel);
    92         imgIcon->setLineWidth(0);
     97        imgIcon->setFrameShape(QFrame::NoFrame);
    9398        imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png"));
    9499        imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
     
    128133#endif // Q_OS_WIN32
    129134
    130         // Bottom part (with grey bg)
    131         hbox2 = new QHBoxLayout(bgGrey);
    132         hbox2->setMargin(6);
    133         hbox2->setSpacing(6);
    134         hbox2->addWidget(buttonHelp);
    135         hbox2->addWidget(labelHint);
    136         hbox2->addWidget(buttonBox);
     135        // Inserting label for hints to the bottom part (with grey bg)
     136        buttons->insertWidget(buttons->indexOf(buttonHelp) + 1, labelHint, 1);
    137137
    138138        // Central layout
     
    141141        vbox2->setSpacing(0);
    142142        vbox2->addLayout(hbox1);
    143         vbox2->addWidget(lineHorizontal);
    144143        vbox2->addWidget(bgGrey);
    145 #endif // Q_OS_WINCE
    146 
     144        setLayout(vbox2);
     145#endif // Q_OS_WINCE
     146
     147#ifdef Q_OS_WINCE
     148        currentGeometry = QApplication::desktop()->availableGeometry(0);
     149        // We need to react to SIP show/hide and resize the window appropriately
     150        connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
     151#endif // Q_OS_WINCE
    147152        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
    148153        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
     
    211216
    212217/*!
    213  *
     218 * \brief Indicates whether and how the translucency setting was changed
     219 * \retval -1 the translucency was \em disabled.
     220 * \retval  0 the translucency was <em>not changed</em>.
     221 * \retval  1 the translucency was \em enabled.
    214222 */
    215223qint8 SettingsDialog::translucencyChanged() const
     
    277285}
    278286
     287#ifdef Q_OS_WINCE
     288void SettingsDialog::desktopResized(int screen)
     289{
     290        if (screen != 0)
     291                return;
     292
     293QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
     294        if (currentGeometry != availableGeometry) {
     295                /*!
     296                 * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
     297                 *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
     298                 *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
     299                 */
     300                if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
     301                        setWindowState(windowState() | Qt::WindowMaximized);
     302                } else {
     303                        if (windowState() & Qt::WindowMaximized)
     304                                setWindowState(windowState() ^ Qt::WindowMaximized);
     305                        setGeometry(availableGeometry);
     306                }
     307        }
     308        currentGeometry = availableGeometry;
     309}
     310#endif // Q_OS_WINCE
     311
    279312void SettingsDialog::spinRandMinValueChanged(int val) {
    280313        spinRandMax->setMinimum(val);
  • trunk/src/settingsdialog.h

    r93 r94  
    5959        QCheckBox *cbUseTranslucency;
    6060#endif // Q_OS_WIN32
    61 #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
     61#ifdef Q_OS_WINCE
     62        QRect currentGeometry;
     63#elif !defined(Q_OS_SYMBIAN)
    6264        QCheckBox *cbSaveState;
    6365        QLabel *imgIcon;
     
    6668
    6769        bool event(QEvent *ev);
    68 #endif
     70#endif // Q_OS_WINCE
    6971
    7072private slots:
     
    7274        void buttonColorClicked();
    7375        void buttonFontClicked();
     76#ifdef Q_OS_WINCE
     77        void desktopResized(int screen);
     78#endif // Q_OS_WINCE
    7479        void spinRandMinValueChanged(int val);
    7580};
Note: See TracChangeset for help on using the changeset viewer.