diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/doc/src/i18n.qdoc | 4 | ||||
-rw-r--r-- | examples/widgets/painting/shared/shared.pri | 2 | ||||
-rw-r--r-- | examples/widgets/tools/i18n/languagechooser.cpp | 12 | ||||
-rw-r--r-- | examples/widgets/tools/i18n/languagechooser.h | 3 | ||||
-rw-r--r-- | examples/widgets/tools/i18n/main.cpp | 4 |
5 files changed, 19 insertions, 6 deletions
diff --git a/examples/widgets/doc/src/i18n.qdoc b/examples/widgets/doc/src/i18n.qdoc index ae97a4869b..07bbee6aed 100644 --- a/examples/widgets/doc/src/i18n.qdoc +++ b/examples/widgets/doc/src/i18n.qdoc @@ -32,7 +32,9 @@ \brief The Internationalization (I18N) example demonstrates Qt's support for translated text. Developers can write the initial application text in one language, and - translations can be provided later without any modifications to the code. + translations can be provided later without any modifications to the code. It also + demonstrates how to detect the system language settings and show the UI in the appropriate + language. \image i18n-example.png */ diff --git a/examples/widgets/painting/shared/shared.pri b/examples/widgets/painting/shared/shared.pri index 1b8be82d03..af027e081a 100644 --- a/examples/widgets/painting/shared/shared.pri +++ b/examples/widgets/painting/shared/shared.pri @@ -1,6 +1,6 @@ INCLUDEPATH += $$PWD -qtHaveModule(opengl) { +qtHaveModule(opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { DEFINES += QT_OPENGL_SUPPORT QT += opengl widgets } diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp index 0728e29547..2bd1de4f1e 100644 --- a/examples/widgets/tools/i18n/languagechooser.cpp +++ b/examples/widgets/tools/i18n/languagechooser.cpp @@ -49,7 +49,7 @@ extern void qt_mac_set_menubar_merge(bool merge); QT_END_NAMESPACE #endif -LanguageChooser::LanguageChooser(QWidget *parent) +LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent) : QDialog(parent, Qt::WindowStaysOnTopHint) { groupBox = new QGroupBox("Languages"); @@ -61,6 +61,8 @@ LanguageChooser::LanguageChooser(QWidget *parent) QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i])); qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]); connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled())); + if (languageMatch(defaultLang, qmFiles[i])) + checkBox->setCheckState(Qt::Checked); groupBoxLayout->addWidget(checkBox, i / 2, i % 2); } groupBox->setLayout(groupBoxLayout); @@ -87,6 +89,14 @@ LanguageChooser::LanguageChooser(QWidget *parent) setWindowTitle("I18N"); } +bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile) +{ + //qmFile: i18n_xx.qm + const QString prefix = "i18n_"; + const int langTokenLength = 2; /*FIXME: is checking two chars enough?*/ + return qmFile.midRef(qmFile.indexOf(prefix) + prefix.length(), langTokenLength) == lang.leftRef(langTokenLength); +} + bool LanguageChooser::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Close) { diff --git a/examples/widgets/tools/i18n/languagechooser.h b/examples/widgets/tools/i18n/languagechooser.h index 4d350674e5..8cbf1e67c3 100644 --- a/examples/widgets/tools/i18n/languagechooser.h +++ b/examples/widgets/tools/i18n/languagechooser.h @@ -58,7 +58,7 @@ class LanguageChooser : public QDialog Q_OBJECT public: - LanguageChooser(QWidget *parent = 0); + explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0); protected: bool eventFilter(QObject *object, QEvent *event); @@ -73,6 +73,7 @@ private: QStringList findQmFiles(); QString languageName(const QString &qmFile); QColor colorForLanguage(const QString &language); + static bool languageMatch(const QString& lang, const QString& qmFile); QGroupBox *groupBox; QDialogButtonBox *buttonBox; diff --git a/examples/widgets/tools/i18n/main.cpp b/examples/widgets/tools/i18n/main.cpp index f57f2b4b2e..09213a69bb 100644 --- a/examples/widgets/tools/i18n/main.cpp +++ b/examples/widgets/tools/i18n/main.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ #include <QApplication> - +#include <QLocale> #include "languagechooser.h" #include "mainwindow.h" @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(i18n); QApplication app(argc, argv); - LanguageChooser chooser; + LanguageChooser chooser(QLocale::system().name()); chooser.show(); return app.exec(); } |