diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/manual/qlocale/currency.cpp | 28 | ||||
-rw-r--r-- | tests/manual/qlocale/currency.h | 3 | ||||
-rw-r--r-- | tests/manual/qlocale/dateformats.cpp | 179 | ||||
-rw-r--r-- | tests/manual/qlocale/dateformats.h | 78 | ||||
-rw-r--r-- | tests/manual/qlocale/languages.cpp | 11 | ||||
-rw-r--r-- | tests/manual/qlocale/main.cpp | 2 | ||||
-rw-r--r-- | tests/manual/qlocale/miscellaneous.cpp | 45 | ||||
-rw-r--r-- | tests/manual/qlocale/miscellaneous.h | 5 | ||||
-rw-r--r-- | tests/manual/qlocale/numberformats.cpp | 83 | ||||
-rw-r--r-- | tests/manual/qlocale/numberformats.h | 63 | ||||
-rw-r--r-- | tests/manual/qlocale/qlocale.pro | 4 | ||||
-rw-r--r-- | tests/manual/qlocale/window.cpp | 9 | ||||
-rw-r--r-- | tests/manual/qlocale/window.h | 4 |
13 files changed, 469 insertions, 45 deletions
diff --git a/tests/manual/qlocale/currency.cpp b/tests/manual/qlocale/currency.cpp index ec932ff..c55df3d 100644 --- a/tests/manual/qlocale/currency.cpp +++ b/tests/manual/qlocale/currency.cpp @@ -42,7 +42,7 @@ CurrencyWidget::CurrencyWidget() { - QGridLayout *l = new QGridLayout(this); + QGridLayout *l = new QGridLayout; currencySymbolLabel = new QLabel("Symbol:"); currencySymbol = new QLineEdit; @@ -54,7 +54,6 @@ CurrencyWidget::CurrencyWidget() currencyFormattingValue = new QLineEdit(QString::number(1234.56, 'f', 2)); currencyFormatting = new QLineEdit; - l->addWidget(currencySymbolLabel, 0, 0); l->addWidget(currencySymbol, 0, 1, 1, 2); l->addWidget(currencyISOLabel, 1, 0); @@ -65,19 +64,12 @@ CurrencyWidget::CurrencyWidget() l->addWidget(currencyFormattingValue, 3, 1); l->addWidget(currencyFormatting, 3, 2); + QVBoxLayout *v = new QVBoxLayout(this); + v->addLayout(l); + v->addStretch(); + connect(currencyFormattingValue, SIGNAL(textChanged(QString)), this, SLOT(updateCurrencyFormatting(QString))); - - update(QLocale()); -} - -void CurrencyWidget::update(const QLocale locale) -{ - currentLocale = locale; - currencySymbol->setText(locale.currencySymbol()); - currencyISO->setText(locale.currencySymbol(QLocale::CurrencyIsoCode)); - currencyName->setText(locale.currencySymbol(QLocale::CurrencyDisplayName)); - updateCurrencyFormatting(currencyFormattingValue->text()); } void CurrencyWidget::updateCurrencyFormatting(QString value) @@ -86,17 +78,21 @@ void CurrencyWidget::updateCurrencyFormatting(QString value) bool ok; int i = value.toInt(&ok); if (ok) { - result = currentLocale.toCurrencyString(i); + result = locale().toCurrencyString(i); } else { double d = value.toDouble(&ok); if (ok) - result = currentLocale.toCurrencyString(d); + result = locale().toCurrencyString(d); } currencyFormatting->setText(result); } void CurrencyWidget::localeChanged(QLocale locale) { - update(locale); + setLocale(locale); + currencySymbol->setText(locale.currencySymbol()); + currencyISO->setText(locale.currencySymbol(QLocale::CurrencyIsoCode)); + currencyName->setText(locale.currencySymbol(QLocale::CurrencyDisplayName)); + updateCurrencyFormatting(currencyFormattingValue->text()); } diff --git a/tests/manual/qlocale/currency.h b/tests/manual/qlocale/currency.h index 97e1dd9..5e43689 100644 --- a/tests/manual/qlocale/currency.h +++ b/tests/manual/qlocale/currency.h @@ -50,8 +50,6 @@ public: CurrencyWidget(); private: - QLocale currentLocale; - QLabel *currencySymbolLabel; QLineEdit *currencySymbol; QLabel *currencyISOLabel; @@ -64,7 +62,6 @@ private: private slots: void localeChanged(QLocale locale); - void update(const QLocale locale); void updateCurrencyFormatting(QString); }; diff --git a/tests/manual/qlocale/dateformats.cpp b/tests/manual/qlocale/dateformats.cpp new file mode 100644 index 0000000..25b3e7a --- /dev/null +++ b/tests/manual/qlocale/dateformats.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dateformats.h" + +DateFormatsWidget::DateFormatsWidget() +{ + scrollArea = new QScrollArea; + scrollAreaWidget = new QWidget; + scrollArea->setWidget(scrollAreaWidget); + scrollArea->setWidgetResizable(true); + layout = new QGridLayout(scrollAreaWidget); + QVBoxLayout *l = new QVBoxLayout(this); + l->addWidget(scrollArea); + + shortDateFormat = addItem("Date format (short):"); + longDateFormat = addItem("Date format (long):"); + shortTimeFormat = addItem("Time format (short):"); + longTimeFormat = addItem("Time format (long):"); + shortDateTimeFormat = addItem("DateTime format (short):"); + longDateTimeFormat = addItem("DateTime format (long):"); + amText = addItem("Before noon:"); + pmText = addItem("After noon:"); + firstDayOfWeek = addItem("First day of week:"); + + monthNamesShort = new QComboBox; + monthNamesLong = new QComboBox; + standaloneMonthNamesShort = new QComboBox; + standaloneMonthNamesLong = new QComboBox; + dayNamesShort = new QComboBox; + dayNamesLong = new QComboBox; + standaloneDayNamesShort = new QComboBox; + standaloneDayNamesLong = new QComboBox; + + int row = layout->rowCount(); + layout->addWidget(new QLabel("Month names [short/long]:"), row, 0); + layout->addWidget(monthNamesShort, row, 1); + layout->addWidget(monthNamesLong, row, 2); + row = layout->rowCount(); + layout->addWidget(new QLabel("Standalone month names [short/long]:"), row, 0); + layout->addWidget(standaloneMonthNamesShort, row, 1); + layout->addWidget(standaloneMonthNamesLong, row, 2); + row = layout->rowCount(); + layout->addWidget(new QLabel("Day names [short/long]:"), row, 0); + layout->addWidget(dayNamesShort, row, 1); + layout->addWidget(dayNamesLong, row, 2); + row = layout->rowCount(); + layout->addWidget(new QLabel("Standalone day names [short/long]:"), row, 0); + layout->addWidget(standaloneDayNamesShort, row, 1); + layout->addWidget(standaloneDayNamesLong, row, 2); +} + +QString toString(Qt::DayOfWeek dow) +{ + static const char *names[] = { + "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" + }; + return QString::fromLatin1(names[dow-1]); +} + +void DateFormatsWidget::localeChanged(QLocale locale) +{ + setLocale(locale); + QDateTime now = QDateTime::currentDateTime(); + shortDateFormat->setText(locale.toString(now.date(), QLocale::ShortFormat)); + shortDateFormat->setToolTip(locale.dateFormat(QLocale::ShortFormat)); + longDateFormat->setText(locale.toString(now.date(), QLocale::LongFormat)); + longDateFormat->setToolTip(locale.dateFormat(QLocale::LongFormat)); + shortTimeFormat->setText(locale.toString(now.time(), QLocale::ShortFormat)); + shortTimeFormat->setToolTip(locale.timeFormat(QLocale::ShortFormat)); + longTimeFormat->setText(locale.toString(now.time(), QLocale::LongFormat)); + longTimeFormat->setToolTip(locale.timeFormat(QLocale::LongFormat)); + shortDateTimeFormat->setText(locale.toString(now, QLocale::ShortFormat)); + shortDateTimeFormat->setToolTip(locale.dateTimeFormat(QLocale::ShortFormat)); + longDateTimeFormat->setText(locale.toString(now, QLocale::LongFormat)); + longDateTimeFormat->setToolTip(locale.dateTimeFormat(QLocale::LongFormat)); + amText->setText(locale.amText()); + pmText->setText(locale.pmText()); + firstDayOfWeek->setText(toString(locale.firstDayOfWeek())); + + int mns = monthNamesShort->currentIndex(); + int mnl = monthNamesLong->currentIndex(); + int smns = standaloneMonthNamesShort->currentIndex(); + int smnl = standaloneMonthNamesLong->currentIndex(); + int dnl = dayNamesLong->currentIndex(); + int dns = dayNamesShort->currentIndex(); + int sdnl = standaloneDayNamesLong->currentIndex(); + int sdns = standaloneDayNamesShort->currentIndex(); + + monthNamesShort->clear(); + monthNamesLong->clear(); + standaloneMonthNamesShort->clear(); + standaloneMonthNamesLong->clear(); + dayNamesLong->clear(); + dayNamesShort->clear(); + standaloneDayNamesLong->clear(); + standaloneDayNamesShort->clear(); + + for (int i = 1; i <= 12; ++i) + monthNamesShort->addItem(locale.monthName(i, QLocale::ShortFormat)); + monthNamesShort->setCurrentIndex(mns >= 0 ? mns : 0); + for (int i = 1; i <= 12; ++i) + monthNamesLong->addItem(locale.monthName(i, QLocale::LongFormat)); + monthNamesLong->setCurrentIndex(mnl >= 0 ? mnl : 0); + + for (int i = 1; i <= 12; ++i) + standaloneMonthNamesShort->addItem(locale.standaloneMonthName(i, QLocale::ShortFormat)); + standaloneMonthNamesShort->setCurrentIndex(smns >= 0 ? smns : 0); + for (int i = 1; i <= 12; ++i) + standaloneMonthNamesLong->addItem(locale.standaloneMonthName(i, QLocale::LongFormat)); + standaloneMonthNamesLong->setCurrentIndex(smnl >= 0 ? smnl : 0); + + for (int i = 1; i <= 7; ++i) + dayNamesLong->addItem(locale.dayName(i, QLocale::LongFormat)); + dayNamesLong->setCurrentIndex(dnl >= 0 ? dnl : 0); + for (int i = 1; i <= 7; ++i) + dayNamesShort->addItem(locale.dayName(i, QLocale::ShortFormat)); + dayNamesShort->setCurrentIndex(dns >= 0 ? dns : 0); + + for (int i = 1; i <= 7; ++i) + standaloneDayNamesLong->addItem(locale.standaloneDayName(i, QLocale::LongFormat)); + standaloneDayNamesLong->setCurrentIndex(sdnl >= 0 ? sdnl : 0); + for (int i = 1; i <= 7; ++i) + standaloneDayNamesShort->addItem(locale.standaloneDayName(i, QLocale::ShortFormat)); + standaloneDayNamesShort->setCurrentIndex(sdns >= 0 ? sdns : 0); +} + +void DateFormatsWidget::addItem(const QString &label, QWidget *w) +{ + QLabel *lbl = new QLabel(label); + int row = layout->rowCount(); + layout->addWidget(lbl, row, 0); + layout->addWidget(w, row, 1, 1, 2); +} + +QLineEdit *DateFormatsWidget::addItem(const QString &label) +{ + QLineEdit *le = new QLineEdit; + le->setReadOnly(true); + addItem(label, le); + return le; +} diff --git a/tests/manual/qlocale/dateformats.h b/tests/manual/qlocale/dateformats.h new file mode 100644 index 0000000..f05ad2a --- /dev/null +++ b/tests/manual/qlocale/dateformats.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DATEFORMATS_H +#define DATEFORMATS_H + +#include <QtGui> + +class DateFormatsWidget : public QWidget +{ + Q_OBJECT +public: + DateFormatsWidget(); + +private: + void addItem(const QString &label, QWidget *); + QLineEdit *addItem(const QString &label); + + QScrollArea *scrollArea; + QWidget *scrollAreaWidget; + QGridLayout *layout; + + QLineEdit *shortDateFormat; + QLineEdit *longDateFormat; + QLineEdit *shortTimeFormat; + QLineEdit *longTimeFormat; + QLineEdit *shortDateTimeFormat; + QLineEdit *longDateTimeFormat; + QLineEdit *amText; + QLineEdit *pmText; + QLineEdit *firstDayOfWeek; + QComboBox *monthNamesShort, *monthNamesLong; + QComboBox *standaloneMonthNamesShort, *standaloneMonthNamesLong; + QComboBox *dayNamesShort, *dayNamesLong; + QComboBox *standaloneDayNamesShort, *standaloneDayNamesLong; + +private slots: + void localeChanged(QLocale locale); +}; + +#endif diff --git a/tests/manual/qlocale/languages.cpp b/tests/manual/qlocale/languages.cpp index 65029c3..18d72d7 100644 --- a/tests/manual/qlocale/languages.cpp +++ b/tests/manual/qlocale/languages.cpp @@ -56,7 +56,16 @@ LanguagesWidget::LanguagesWidget() void LanguagesWidget::localeChanged(QLocale locale) { languagesList->clear(); - languagesList->addItems(locale.uiLanguages()); + foreach (const QString &lang, locale.uiLanguages()) { + QListWidgetItem *item = new QListWidgetItem(lang, languagesList); + QLocale l(lang); + if (l.language() != QLocale::C) { + QString language = QLocale::languageToString(l.language()); + QString country = QLocale::countryToString(l.country()); + QString tooltip = QString(QLatin1String("%1: %2/%3")).arg(l.name(), language, country); + item->setToolTip(tooltip); + } + } } diff --git a/tests/manual/qlocale/main.cpp b/tests/manual/qlocale/main.cpp index f96e0a2..b14a44f 100644 --- a/tests/manual/qlocale/main.cpp +++ b/tests/manual/qlocale/main.cpp @@ -40,8 +40,6 @@ #include <QtGui> -#include "calendar.h" -#include "currency.h" #include "window.h" int main(int argv, char *args[]) diff --git a/tests/manual/qlocale/miscellaneous.cpp b/tests/manual/qlocale/miscellaneous.cpp index a1a3139..0b2250a 100644 --- a/tests/manual/qlocale/miscellaneous.cpp +++ b/tests/manual/qlocale/miscellaneous.cpp @@ -42,14 +42,13 @@ MiscWidget::MiscWidget() { - QGridLayout *l = new QGridLayout(this); + QGridLayout *l = new QGridLayout; - textToQuoteLabel = new QLabel("Text to quote:"); - standardQuotedTextLabel = new QLabel("Standard quotes:"); - alternateQuotedTextLabel = new QLabel("Alternate quotes:"); - textToQuote = new QLineEdit("some text"); - standardQuotedText = new QLineEdit; - alternateQuotedText = new QLineEdit; + createLineEdit("Text to quote:", &textToQuoteLabel, &textToQuote); + createLineEdit("Standard quotes:", &standardQuotedTextLabel, &standardQuotedText); + createLineEdit("Alternate quotes:", &alternateQuotedTextLabel, &alternateQuotedText); + textToQuote->setText("some text"); + createLineEdit("Text direction:", &textDirectionLabel, &textDirection); l->addWidget(textToQuoteLabel, 0, 0); l->addWidget(textToQuote, 0, 1); @@ -57,27 +56,37 @@ MiscWidget::MiscWidget() l->addWidget(standardQuotedText, 0, 3); l->addWidget(alternateQuotedTextLabel, 1, 2); l->addWidget(alternateQuotedText, 1, 3); + l->addWidget(textDirectionLabel, 2, 0); + l->addWidget(textDirection, 2, 1, 1, 3); connect(textToQuote, SIGNAL(textChanged(QString)), this, SLOT(updateQuotedText(QString))); - update(QLocale()); -} - -void MiscWidget::update(const QLocale locale) -{ - currentLocale = locale; - updateQuotedText(textToQuote->text()); + QVBoxLayout *v = new QVBoxLayout(this); + v->addLayout(l); + v->addStretch(); } void MiscWidget::updateQuotedText(QString str) { - standardQuotedText->setText(currentLocale.quoteString(str)); - alternateQuotedText->setText(currentLocale.quoteString(str, QLocale::AlternateQuotation)); + standardQuotedText->setText(locale().quoteString(str)); + alternateQuotedText->setText(locale().quoteString(str, QLocale::AlternateQuotation)); } void MiscWidget::localeChanged(QLocale locale) { - update(locale); + setLocale(locale); + updateQuotedText(textToQuote->text()); + textDirection->setText(locale.textDirection() == Qt::LeftToRight ? "Left To Right" : "Right To Left"); } - +void MiscWidget::createLineEdit(const QString &label, QLabel **labelWidget, QLineEdit **lineEditWidget) +{ + QLabel *lbl = new QLabel(label); + QLineEdit *le = new QLineEdit; + le->setReadOnly(true); + lbl->setBuddy(le); + if (labelWidget) + *labelWidget = lbl; + if (lineEditWidget) + *lineEditWidget = le; +} diff --git a/tests/manual/qlocale/miscellaneous.h b/tests/manual/qlocale/miscellaneous.h index e4a1a36..33d8ef9 100644 --- a/tests/manual/qlocale/miscellaneous.h +++ b/tests/manual/qlocale/miscellaneous.h @@ -50,18 +50,19 @@ public: MiscWidget(); private: - QLocale currentLocale; + void createLineEdit(const QString &label, QLabel **labelWidget = 0, QLineEdit **lineEditWidget = 0); QLabel *textToQuoteLabel; QLabel *standardQuotedTextLabel; QLabel *alternateQuotedTextLabel; + QLabel *textDirectionLabel; QLineEdit *textToQuote; QLineEdit *standardQuotedText; QLineEdit *alternateQuotedText; + QLineEdit *textDirection; private slots: void localeChanged(QLocale locale); - void update(const QLocale locale); void updateQuotedText(QString str); }; diff --git a/tests/manual/qlocale/numberformats.cpp b/tests/manual/qlocale/numberformats.cpp new file mode 100644 index 0000000..7b5fce4 --- /dev/null +++ b/tests/manual/qlocale/numberformats.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "numberformats.h" + +NumberFormatsWidget::NumberFormatsWidget() +{ + QGridLayout *l = new QGridLayout; + + QLabel *numbersLabel = new QLabel("Numbers:"); + number1 = createLineEdit(); + number2 = createLineEdit(); + number3 = createLineEdit(); + + measurementLabel = new QLabel("Measurement units:"); + measurementSystem = createLineEdit(); + + l->addWidget(numbersLabel, 0, 0); + l->addWidget(number1, 0, 1); + l->addWidget(number2, 0, 2); + l->addWidget(number3, 0, 3); + + l->addWidget(measurementLabel, 1, 0); + l->addWidget(measurementSystem, 1, 1, 1, 3); + + QVBoxLayout *v = new QVBoxLayout(this); + v->addLayout(l); + v->addStretch(); +} + +void NumberFormatsWidget::localeChanged(QLocale locale) +{ + number1->setText(locale.toString(-123456)); + number2->setText(locale.toString(1234.56, 'f', 2)); + number3->setText(locale.toString(1234.56, 'e', 4)); + + measurementSystem->setText( + locale.measurementSystem() == QLocale::ImperialSystem ? "US" : "Metric"); +} + +QLineEdit *NumberFormatsWidget::createLineEdit() +{ + QLineEdit *le = new QLineEdit; + le->setReadOnly(true); + return le; +} diff --git a/tests/manual/qlocale/numberformats.h b/tests/manual/qlocale/numberformats.h new file mode 100644 index 0000000..4a3ab36 --- /dev/null +++ b/tests/manual/qlocale/numberformats.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NUMBERFORMATS_H +#define NUMBERFORMATS_H + +#include <QtGui> + +class NumberFormatsWidget : public QWidget +{ + Q_OBJECT +public: + NumberFormatsWidget(); + +private: + QLineEdit *createLineEdit(); + + QLineEdit *number1, *number2, *number3; + QLabel *measurementLabel; + QLineEdit *measurementSystem; + +private slots: + void localeChanged(QLocale locale); +}; + +#endif diff --git a/tests/manual/qlocale/qlocale.pro b/tests/manual/qlocale/qlocale.pro index 46eaa16..6f0bf88 100644 --- a/tests/manual/qlocale/qlocale.pro +++ b/tests/manual/qlocale/qlocale.pro @@ -4,5 +4,5 @@ DEPENDPATH += . INCLUDEPATH += . # Input -HEADERS += currency.h calendar.h languages.h window.h miscellaneous.h -SOURCES += currency.cpp main.cpp calendar.cpp languages.cpp window.cpp miscellaneous.cpp +HEADERS += currency.h calendar.h dateformats.h numberformats.h languages.h window.h miscellaneous.h +SOURCES += currency.cpp main.cpp calendar.cpp dateformats.cpp numberformats.cpp languages.cpp window.cpp miscellaneous.cpp diff --git a/tests/manual/qlocale/window.cpp b/tests/manual/qlocale/window.cpp index ebe5ea9..ed66c57 100644 --- a/tests/manual/qlocale/window.cpp +++ b/tests/manual/qlocale/window.cpp @@ -69,6 +69,10 @@ Window::Window() connect(this, SIGNAL(localeChanged(QLocale)), currency, SLOT(localeChanged(QLocale))); languages = new LanguagesWidget; connect(this, SIGNAL(localeChanged(QLocale)), languages, SLOT(localeChanged(QLocale))); + dateFormats = new DateFormatsWidget; + connect(this, SIGNAL(localeChanged(QLocale)), dateFormats, SLOT(localeChanged(QLocale))); + numberFormats = new NumberFormatsWidget; + connect(this, SIGNAL(localeChanged(QLocale)), numberFormats, SLOT(localeChanged(QLocale))); miscellaneous = new MiscWidget; connect(this, SIGNAL(localeChanged(QLocale)), miscellaneous, SLOT(localeChanged(QLocale))); @@ -86,7 +90,10 @@ Window::Window() tabWidget->addTab(calendar, "Calendar"); tabWidget->addTab(currency, "Currency"); tabWidget->addTab(languages, "Languages"); - tabWidget->addTab(miscellaneous, "Misc"); + tabWidget->addTab(dateFormats, "Date Formats"); + tabWidget->addTab(numberFormats, "Number Formats"); + tabWidget->addTab(miscellaneous, "Text"); + localeCombo->setCurrentIndex(0); systemLocaleChanged(); } diff --git a/tests/manual/qlocale/window.h b/tests/manual/qlocale/window.h index 35719ae..b75d3b2 100644 --- a/tests/manual/qlocale/window.h +++ b/tests/manual/qlocale/window.h @@ -46,6 +46,8 @@ #include "calendar.h" #include "currency.h" #include "languages.h" +#include "dateformats.h" +#include "numberformats.h" #include "miscellaneous.h" class Window : public QWidget @@ -60,6 +62,8 @@ public: CalendarWidget *calendar; CurrencyWidget *currency; LanguagesWidget *languages; + DateFormatsWidget *dateFormats; + NumberFormatsWidget *numberFormats; MiscWidget *miscellaneous; private: |