aboutsummaryrefslogtreecommitdiff
path: root/demos/widgetsgallery
diff options
context:
space:
mode:
authorMike FABIAN <mike.fabian@basyskom.de>2010-08-26 13:40:58 +0200
committerMike FABIAN <mike.fabian@basyskom.de>2010-08-26 16:38:42 +0200
commit3fd55b6792bf549f5c8d40f7420f39619d61e9db (patch)
tree6195a843c5236d24d4533dd4103b192c3be3a2f9 /demos/widgetsgallery
parentb546f40e302cd16cc02f4aeaf741ae46f15fb029 (diff)
Changes: add combobox to language page in widgetsgallery to select 24/12 hour mode
RevBy: TrustMe
Diffstat (limited to 'demos/widgetsgallery')
-rw-r--r--demos/widgetsgallery/languagepage.cpp113
-rw-r--r--demos/widgetsgallery/languagepage.h3
2 files changed, 102 insertions, 14 deletions
diff --git a/demos/widgetsgallery/languagepage.cpp b/demos/widgetsgallery/languagepage.cpp
index cbb3ac07..909bfc13 100644
--- a/demos/widgetsgallery/languagepage.cpp
+++ b/demos/widgetsgallery/languagepage.cpp
@@ -38,10 +38,12 @@
LanguagePage::LanguagePage()
: TemplatePage(TemplatePage::ApplicationView),
- comboBoxLanguage(0),
+ comboBoxLanguage(0),
modelLanguage(0),
comboBoxLcTime(0),
modelLcTime(0),
+ comboBoxLcTimeFormat24h(0),
+ modelLcTimeFormat24h(0),
comboBoxLcCollate(0),
modelLcCollate(0),
comboBoxLcNumeric(0),
@@ -79,6 +81,7 @@ void LanguagePage::createContent()
comboBoxLanguage = new MComboBox;
policy->addItem(comboBoxLanguage, 1, 1);
comboBoxLcTime = new MComboBox;
+ comboBoxLcTimeFormat24h = new MComboBox;
comboBoxLcCollate = new MComboBox;
comboBoxLcNumeric = new MComboBox;
comboBoxLcMonetary = new MComboBox;
@@ -95,19 +98,20 @@ void LanguagePage::createContent()
labelFontTest->setWordWrap(true);
policy->addItem(comboBoxLcTime, 2, 1);
- policy->addItem(comboBoxLcCollate, 3, 1);
- policy->addItem(comboBoxLcNumeric, 4, 1);
- policy->addItem(comboBoxLcMonetary, 5, 1);
- policy->addItem(labelHaveGconf, 6, 1);
- policy->addItem(labelHaveIcu, 7, 1);
- policy->addItem(labelExampleNumber, 8, 1);
- policy->addItem(labelExampleDateTime, 9, 1);
- policy->addItem(labelExampleWeekNumber, 10, 1);
- policy->addItem(labelExampleCurrency, 11, 1);
- policy->addItem(labelExampleTranslation1, 12, 1);
- policy->addItem(labelExampleTranslation2, 13, 1);
- policy->addItem(labelExampleTranslation3, 14, 1);
- policy->addItem(labelFontTest, 15, 1);
+ policy->addItem(comboBoxLcTimeFormat24h, 3, 1);
+ policy->addItem(comboBoxLcCollate, 4, 1);
+ policy->addItem(comboBoxLcNumeric, 5, 1);
+ policy->addItem(comboBoxLcMonetary, 6, 1);
+ policy->addItem(labelHaveGconf, 7, 1);
+ policy->addItem(labelHaveIcu, 8, 1);
+ policy->addItem(labelExampleNumber, 9, 1);
+ policy->addItem(labelExampleDateTime, 10, 1);
+ policy->addItem(labelExampleWeekNumber, 11, 1);
+ policy->addItem(labelExampleCurrency, 12, 1);
+ policy->addItem(labelExampleTranslation1, 13, 1);
+ policy->addItem(labelExampleTranslation2, 14, 1);
+ policy->addItem(labelExampleTranslation3, 15, 1);
+ policy->addItem(labelFontTest, 16, 1);
retranslateUi();
}
@@ -123,6 +127,8 @@ void LanguagePage::retranslateUi()
this, SLOT(changeLanguage(int)));
disconnect(comboBoxLcTime, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeLcTime(int)));
+ disconnect(comboBoxLcTimeFormat24h, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(changeLcTimeFormat24h(int)));
disconnect(comboBoxLcCollate, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeLcCollate(int)));
disconnect(comboBoxLcNumeric, SIGNAL(currentIndexChanged(int)),
@@ -210,6 +216,23 @@ void LanguagePage::retranslateUi()
int rowsLocaleCount = rowsLocale.count();
+ QList<QStringList> rowsTimeFormat24h;
+ rowsTimeFormat24h
+ << (QStringList()
+ //% "Locale default"
+ << qtTrId("xx_timeformat24h_locale_default")
+ << "")
+ << (QStringList()
+ //% "24 hour mode"
+ << qtTrId("xx_timeformat24h_24_hour_mode")
+ << "24")
+ << (QStringList()
+ //% "12 hour mode"
+ << qtTrId("xx_timeformat24h_12_hour_mode")
+ << "12");
+
+ int rowsTimeFormat24hCount = rowsTimeFormat24h.count();
+
MLocale currentLocale;
QStandardItemModel *newModelLanguage
@@ -247,6 +270,38 @@ void LanguagePage::retranslateUi()
comboBoxLcTime->setCurrentIndex(i);
}
+ QStandardItemModel *newModelLcTimeFormat24h
+ = new QStandardItemModel(rowsTimeFormat24h.count(), 2, this);
+ Q_CHECK_PTR(newModelLcTimeFormat24h);
+ for (int i = 0; i < rowsTimeFormat24hCount; ++i)
+ for (int j = 0; j < 2; ++j)
+ newModelLcTimeFormat24h->setItem(i, j, new QStandardItem(rowsTimeFormat24h[i][j]));
+
+ comboBoxLcTimeFormat24h->setItemModel(newModelLcTimeFormat24h);
+ if (modelLcTimeFormat24h && modelLcTimeFormat24h->QObject::parent() == this)
+ delete modelLcTimeFormat24h;
+ modelLcTimeFormat24h = newModelLcTimeFormat24h;
+ MLocale::TimeFormat24h currentLcTimeFormat24h = currentLocale.timeFormat24h();
+ QString currentLcTimeFormat24hString;
+ switch(currentLcTimeFormat24h) {
+ case MLocale::TwentyFourHourTimeFormat24h:
+ currentLcTimeFormat24hString = "24";
+ break;
+ case MLocale::TwelveHourTimeFormat24h:
+ currentLcTimeFormat24hString = "12";
+ break;
+ case MLocale::LocaleDefaultTimeFormat24h:
+ currentLcTimeFormat24hString = "";
+ break;
+ default:
+ currentLcTimeFormat24hString = "";
+ break;
+ }
+ for (int i = 0; i < rowsTimeFormat24hCount; ++i) {
+ if (currentLcTimeFormat24hString == modelLcTimeFormat24h->item(i, 1)->text())
+ comboBoxLcTimeFormat24h->setCurrentIndex(i);
+ }
+
QStandardItemModel *newModelLcCollate
= new QStandardItemModel(rowsLocale.count(), 2, this);
Q_CHECK_PTR(newModelLcCollate);
@@ -302,6 +357,8 @@ void LanguagePage::retranslateUi()
comboBoxLanguage->setTitle(qtTrId("xx_language_combobox_title"));
//% "Locale for time"
comboBoxLcTime->setTitle(qtTrId("xx_language_combobox_lctime_title"));
+ //% "Choose 12/24 hour mode"
+ comboBoxLcTimeFormat24h->setTitle(qtTrId("xx_language_combobox_lctimeformat24h_title"));
//% "Locale for collation"
comboBoxLcCollate->setTitle(qtTrId("xx_language_combobox_lccollate_title"));
//% "Locale for numbers"
@@ -388,6 +445,8 @@ void LanguagePage::retranslateUi()
this, SLOT(changeLanguage(int)));
connect(comboBoxLcTime, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeLcTime(int)));
+ connect(comboBoxLcTimeFormat24h, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(changeLcTimeFormat24h(int)));
connect(comboBoxLcCollate, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeLcCollate(int)));
connect(comboBoxLcNumeric, SIGNAL(currentIndexChanged(int)),
@@ -434,6 +493,32 @@ void LanguagePage::changeLcTime(int index)
#endif
}
+void LanguagePage::changeLcTimeFormat24h(int index)
+{
+ if (index < 0 || index >= modelLcTimeFormat24h->rowCount())
+ return;
+ QString newLcTimeFormat24hString = modelLcTimeFormat24h->item(index, 1)->text();
+ MLocale::TimeFormat24h newLcTimeFormat24h;
+ if (newLcTimeFormat24hString == "24")
+ newLcTimeFormat24h = MLocale::TwentyFourHourTimeFormat24h;
+ else if (newLcTimeFormat24hString == "12")
+ newLcTimeFormat24h = MLocale::TwelveHourTimeFormat24h;
+ else
+ newLcTimeFormat24h = MLocale::LocaleDefaultTimeFormat24h;
+#ifdef HAVE_GCONF
+ MGConfItem lcTimeFormat24hItem("/meegotouch/i18n/lc_timeformat24h");
+ if (newLcTimeFormat24hString != lcTimeFormat24hItem.value().toString()) {
+ lcTimeFormat24hItem.set(newLcTimeFormat24hString);
+ }
+#else
+ MLocale currentLocale;
+ if (newLcTimeFormat24h != currentLocale.timeFormat24h()) {
+ currentLocale.setTimeFormat24h(newTimeFormat24h);
+ MLocale::setDefault(currentLocale);
+ }
+#endif
+}
+
void LanguagePage::changeLcCollate(int index)
{
if (index < 0 || index >= modelLcCollate->rowCount())
diff --git a/demos/widgetsgallery/languagepage.h b/demos/widgetsgallery/languagepage.h
index 6212a5d3..ad736bc7 100644
--- a/demos/widgetsgallery/languagepage.h
+++ b/demos/widgetsgallery/languagepage.h
@@ -41,6 +41,7 @@ public:
public slots:
void changeLanguage(int index);
void changeLcTime(int index);
+ void changeLcTimeFormat24h(int index);
void changeLcCollate(int index);
void changeLcNumeric(int index);
void changeLcMonetary(int index);
@@ -53,6 +54,8 @@ private:
QStandardItemModel *modelLanguage;
MComboBox *comboBoxLcTime;
QStandardItemModel *modelLcTime;
+ MComboBox *comboBoxLcTimeFormat24h;
+ QStandardItemModel *modelLcTimeFormat24h;
MComboBox *comboBoxLcCollate;
QStandardItemModel *modelLcCollate;
MComboBox *comboBoxLcNumeric;