tools/linguist/linguist/translationsettingsdialog.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the Qt Linguist of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 
00025 #include "translationsettingsdialog.h"
00026 #include "messagemodel.h"
00027 #include <QtCore/QLocale>
00028 
00029 TranslationSettingsDialog::TranslationSettingsDialog(QWidget *w /*= 0*/) : QDialog(w)
00030 {
00031     m_ui.setupUi(this);    
00032 
00033     for (int i = QLocale::C + 1; i < QLocale::LastLanguage; ++i) {
00034         QString lang = QLocale::languageToString(QLocale::Language(i));
00035         m_ui.cbLanguageList->addItem(lang, QVariant(int(i)));
00036     }
00037     m_ui.cbLanguageList->model()->sort(0, Qt::AscendingOrder);
00038 
00039     for (int i = QLocale::AnyCountry; i < QLocale::LastCountry; ++i) {
00040         QString country = QLocale::countryToString(QLocale::Country(i));
00041         m_ui.cbCountryList->addItem(country, QVariant(int(i)));
00042     }
00043     m_ui.cbCountryList->model()->sort(0, Qt::AscendingOrder);
00044     m_ui.cbCountryList->insertItem(0, tr("Any Country"), QVariant(0));
00045 
00046 }
00047 
00048 void TranslationSettingsDialog::setMessageModel(MessageModel *model)
00049 {
00050     m_messageModel = model;
00051 }
00052 
00053 void TranslationSettingsDialog::on_buttonBox_accepted()
00054 {
00055     int itemindex = m_ui.cbLanguageList->currentIndex();
00056     QVariant var = m_ui.cbLanguageList->itemData(itemindex);
00057     QLocale::Language lang = QLocale::Language(var.toInt());
00058     m_messageModel->setLanguage(lang);
00059 
00060     itemindex = m_ui.cbCountryList->currentIndex();
00061     var = m_ui.cbCountryList->itemData(itemindex);
00062     QLocale::Country country = QLocale::Country(var.toInt());
00063     m_messageModel->setCountry(country);
00064     accept();
00065 }
00066 
00067 void TranslationSettingsDialog::showEvent(QShowEvent *e)
00068 {
00069     Q_UNUSED(e);
00070     QLocale::Language lang = m_messageModel->language();
00071     int itemindex = m_ui.cbLanguageList->findData(QVariant(int(lang)));
00072     m_ui.cbLanguageList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
00073 
00074 
00075     QLocale::Country country = m_messageModel->country();
00076     itemindex = m_ui.cbCountryList->findData(QVariant(int(country)));
00077     m_ui.cbCountryList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
00078 }

Generated on Thu Mar 15 12:01:46 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1