diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-03-24 09:37:54 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-03-24 09:37:54 (GMT) |
commit | f1a7f339109ee72059aa135381defeaf6f564977 (patch) | |
tree | 6a5e8e28849c025efc58096bd57eb1ece7382fc6 /tests/manual | |
parent | cea4ae150bef0f24b0e8385d47b06a9f6b8197c3 (diff) | |
parent | 52dc52dffb80f3ffd321156639564b524263810a (diff) | |
download | Qt-f1a7f339109ee72059aa135381defeaf6f564977.zip Qt-f1a7f339109ee72059aa135381defeaf6f564977.tar.gz Qt-f1a7f339109ee72059aa135381defeaf6f564977.tar.bz2 |
Merge remote branch 'earth-team/master-i18n' into 4.8-earth
Conflicts:
src/corelib/tools/tools.pri
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/qlocale/calendar.cpp | 405 | ||||
-rw-r--r-- | tests/manual/qlocale/calendar.h | 115 | ||||
-rw-r--r-- | tests/manual/qlocale/currency.cpp | 109 | ||||
-rw-r--r-- | tests/manual/qlocale/currency.h | 70 | ||||
-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 | 71 | ||||
-rw-r--r-- | tests/manual/qlocale/languages.h | 62 | ||||
-rw-r--r-- | tests/manual/qlocale/main.cpp | 55 | ||||
-rw-r--r-- | tests/manual/qlocale/miscellaneous.cpp | 103 | ||||
-rw-r--r-- | tests/manual/qlocale/miscellaneous.h | 72 | ||||
-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 | 8 | ||||
-rw-r--r-- | tests/manual/qlocale/window.cpp | 136 | ||||
-rw-r--r-- | tests/manual/qlocale/window.h | 80 |
16 files changed, 1689 insertions, 0 deletions
diff --git a/tests/manual/qlocale/calendar.cpp b/tests/manual/qlocale/calendar.cpp new file mode 100644 index 0000000..bd4756e --- /dev/null +++ b/tests/manual/qlocale/calendar.cpp @@ -0,0 +1,405 @@ +/**************************************************************************** +** +** 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 <QtGui> + +#include "calendar.h" + +CalendarWidget::CalendarWidget() +{ + createPreviewGroupBox(); + createGeneralOptionsGroupBox(); + createDatesGroupBox(); + createTextFormatsGroupBox(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(previewGroupBox, 0, 0); + layout->addWidget(generalOptionsGroupBox, 0, 1); + layout->addWidget(datesGroupBox, 1, 0); + layout->addWidget(textFormatsGroupBox, 1, 1); + layout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(layout); + + previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height()); + previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width()); + + setWindowTitle(tr("Calendar Widget")); +} + +void CalendarWidget::localeChanged(QLocale locale) +{ + calendar->setLocale(locale); + firstDayCombo->setCurrentIndex(locale.firstDayOfWeek()-1); + updateWeekendDays(); +} + +void CalendarWidget::firstDayChanged(int index) +{ + calendar->setFirstDayOfWeek(Qt::DayOfWeek( + firstDayCombo->itemData(index).toInt())); +} + +void CalendarWidget::selectionModeChanged(int index) +{ + calendar->setSelectionMode(QCalendarWidget::SelectionMode( + selectionModeCombo->itemData(index).toInt())); +} + +void CalendarWidget::horizontalHeaderChanged(int index) +{ + calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat( + horizontalHeaderCombo->itemData(index).toInt())); +} + +void CalendarWidget::verticalHeaderChanged(int index) +{ + calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat( + verticalHeaderCombo->itemData(index).toInt())); +} + +void CalendarWidget::selectedDateChanged() +{ + currentDateEdit->setDate(calendar->selectedDate()); +} + +void CalendarWidget::minimumDateChanged(const QDate &date) +{ + calendar->setMinimumDate(date); + maximumDateEdit->setDate(calendar->maximumDate()); +} + +void CalendarWidget::maximumDateChanged(const QDate &date) +{ + calendar->setMaximumDate(date); + minimumDateEdit->setDate(calendar->minimumDate()); +} + +bool CalendarWidget::isWeekendDay(Qt::DayOfWeek day) { + QList<Qt::DayOfWeek> week = calendar->locale().weekdays(); + return !week.contains(day); +} + +void CalendarWidget::updateWeekendDays() { + QTextCharFormat weekFormat, weekendFormat; + weekFormat.setForeground(qvariant_cast<QColor>( + weekdayColorCombo->itemData(weekdayColorCombo->currentIndex()))); + weekendFormat.setForeground(qvariant_cast<QColor>( + weekendColorCombo->itemData(weekendColorCombo->currentIndex()))); + + calendar->setWeekdayTextFormat(Qt::Monday, isWeekendDay(Qt::Monday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Tuesday, isWeekendDay(Qt::Tuesday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Wednesday, isWeekendDay(Qt::Wednesday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Thursday, isWeekendDay(Qt::Thursday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Friday, isWeekendDay(Qt::Friday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Saturday, isWeekendDay(Qt::Saturday) ? weekendFormat : weekFormat); + calendar->setWeekdayTextFormat(Qt::Sunday, isWeekendDay(Qt::Sunday) ? weekendFormat : weekFormat); +} + +void CalendarWidget::weekdayFormatChanged() +{ + updateWeekendDays(); +} + +void CalendarWidget::weekendFormatChanged() +{ + updateWeekendDays(); +} + +void CalendarWidget::reformatHeaders() +{ + QString text = headerTextFormatCombo->currentText(); + QTextCharFormat format; + + if (text == tr("Bold")) { + format.setFontWeight(QFont::Bold); + } else if (text == tr("Italic")) { + format.setFontItalic(true); + } else if (text == tr("Green")) { + format.setForeground(Qt::green); + } + calendar->setHeaderTextFormat(format); +} + +void CalendarWidget::reformatCalendarPage() +{ + if (firstFridayCheckBox->isChecked()) { + QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1); + while (firstFriday.dayOfWeek() != Qt::Friday) + firstFriday = firstFriday.addDays(1); + QTextCharFormat firstFridayFormat; + firstFridayFormat.setForeground(Qt::blue); + calendar->setDateTextFormat(firstFriday, firstFridayFormat); + } + + //May First in Red takes precedence + if (mayFirstCheckBox->isChecked()) { + const QDate mayFirst(calendar->yearShown(), 5, 1); + QTextCharFormat mayFirstFormat; + mayFirstFormat.setForeground(Qt::red); + calendar->setDateTextFormat(mayFirst, mayFirstFormat); + } +} + +void CalendarWidget::createPreviewGroupBox() +{ + previewGroupBox = new QGroupBox(tr("Preview")); + + calendar = new QCalendarWidget; + calendar->setMinimumDate(QDate(1900, 1, 1)); + calendar->setMaximumDate(QDate(3000, 1, 1)); + calendar->setGridVisible(true); + + connect(calendar, SIGNAL(currentPageChanged(int,int)), + this, SLOT(reformatCalendarPage())); + + previewLayout = new QGridLayout; + previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter); + previewGroupBox->setLayout(previewLayout); +} + +void CalendarWidget::createGeneralOptionsGroupBox() +{ + generalOptionsGroupBox = new QGroupBox(tr("General Options")); + + firstDayCombo = new QComboBox; + firstDayCombo->addItem(tr("Monday"), Qt::Monday); + firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday); + firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday); + firstDayCombo->addItem(tr("Thursday"), Qt::Thursday); + firstDayCombo->addItem(tr("Friday"), Qt::Friday); + firstDayCombo->addItem(tr("Saturday"), Qt::Saturday); + firstDayCombo->addItem(tr("Sunday"), Qt::Sunday); + + firstDayLabel = new QLabel(tr("Wee&k starts on:")); + firstDayLabel->setBuddy(firstDayCombo); + + selectionModeCombo = new QComboBox; + selectionModeCombo->addItem(tr("Single selection"), + QCalendarWidget::SingleSelection); + selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection); + + selectionModeLabel = new QLabel(tr("&Selection mode:")); + selectionModeLabel->setBuddy(selectionModeCombo); + + gridCheckBox = new QCheckBox(tr("&Grid")); + gridCheckBox->setChecked(calendar->isGridVisible()); + + navigationCheckBox = new QCheckBox(tr("&Navigation bar")); + navigationCheckBox->setChecked(true); + + horizontalHeaderCombo = new QComboBox; + horizontalHeaderCombo->addItem(tr("Single letter day names"), + QCalendarWidget::SingleLetterDayNames); + horizontalHeaderCombo->addItem(tr("Short day names"), + QCalendarWidget::ShortDayNames); + horizontalHeaderCombo->addItem(tr("None"), + QCalendarWidget::NoHorizontalHeader); + horizontalHeaderCombo->setCurrentIndex(1); + + horizontalHeaderLabel = new QLabel(tr("&Horizontal header:")); + horizontalHeaderLabel->setBuddy(horizontalHeaderCombo); + + verticalHeaderCombo = new QComboBox; + verticalHeaderCombo->addItem(tr("ISO week numbers"), + QCalendarWidget::ISOWeekNumbers); + verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader); + + verticalHeaderLabel = new QLabel(tr("&Vertical header:")); + verticalHeaderLabel->setBuddy(verticalHeaderCombo); + + connect(firstDayCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(firstDayChanged(int))); + connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(selectionModeChanged(int))); + connect(gridCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setGridVisible(bool))); + connect(navigationCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setNavigationBarVisible(bool))); + connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(horizontalHeaderChanged(int))); + connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(verticalHeaderChanged(int))); + + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(gridCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(navigationCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(firstDayLabel, 0, 0); + outerLayout->addWidget(firstDayCombo, 0, 1); + outerLayout->addWidget(selectionModeLabel, 1, 0); + outerLayout->addWidget(selectionModeCombo, 1, 1); + outerLayout->addLayout(checkBoxLayout, 2, 0, 1, 2); + outerLayout->addWidget(horizontalHeaderLabel, 3, 0); + outerLayout->addWidget(horizontalHeaderCombo, 3, 1); + outerLayout->addWidget(verticalHeaderLabel, 4, 0); + outerLayout->addWidget(verticalHeaderCombo, 4, 1); + generalOptionsGroupBox->setLayout(outerLayout); + + firstDayChanged(firstDayCombo->currentIndex()); + selectionModeChanged(selectionModeCombo->currentIndex()); + horizontalHeaderChanged(horizontalHeaderCombo->currentIndex()); + verticalHeaderChanged(verticalHeaderCombo->currentIndex()); +} + +void CalendarWidget::createDatesGroupBox() +{ + datesGroupBox = new QGroupBox(tr("Dates")); + + minimumDateEdit = new QDateEdit; + minimumDateEdit->setDisplayFormat("MMM d yyyy"); + minimumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + minimumDateEdit->setDate(calendar->minimumDate()); + + minimumDateLabel = new QLabel(tr("&Minimum Date:")); + minimumDateLabel->setBuddy(minimumDateEdit); + + currentDateEdit = new QDateEdit; + currentDateEdit->setDisplayFormat("MMM d yyyy"); + currentDateEdit->setDate(calendar->selectedDate()); + currentDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + + currentDateLabel = new QLabel(tr("&Current Date:")); + currentDateLabel->setBuddy(currentDateEdit); + + maximumDateEdit = new QDateEdit; + maximumDateEdit->setDisplayFormat("MMM d yyyy"); + maximumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + maximumDateEdit->setDate(calendar->maximumDate()); + + maximumDateLabel = new QLabel(tr("Ma&ximum Date:")); + maximumDateLabel->setBuddy(maximumDateEdit); + + connect(currentDateEdit, SIGNAL(dateChanged(QDate)), + calendar, SLOT(setSelectedDate(QDate))); + connect(calendar, SIGNAL(selectionChanged()), + this, SLOT(selectedDateChanged())); + connect(minimumDateEdit, SIGNAL(dateChanged(QDate)), + this, SLOT(minimumDateChanged(QDate))); + connect(maximumDateEdit, SIGNAL(dateChanged(QDate)), + this, SLOT(maximumDateChanged(QDate))); + + QGridLayout *dateBoxLayout = new QGridLayout; + dateBoxLayout->addWidget(currentDateLabel, 1, 0); + dateBoxLayout->addWidget(currentDateEdit, 1, 1); + dateBoxLayout->addWidget(minimumDateLabel, 0, 0); + dateBoxLayout->addWidget(minimumDateEdit, 0, 1); + dateBoxLayout->addWidget(maximumDateLabel, 2, 0); + dateBoxLayout->addWidget(maximumDateEdit, 2, 1); + dateBoxLayout->setRowStretch(3, 1); + + datesGroupBox->setLayout(dateBoxLayout); +} + +void CalendarWidget::createTextFormatsGroupBox() +{ + textFormatsGroupBox = new QGroupBox(tr("Text Formats")); + + weekdayColorCombo = createColorComboBox(); + weekdayColorCombo->setCurrentIndex( + weekdayColorCombo->findText(tr("Black"))); + + weekdayColorLabel = new QLabel(tr("&Weekday color:")); + weekdayColorLabel->setBuddy(weekdayColorCombo); + + weekendColorCombo = createColorComboBox(); + weekendColorCombo->setCurrentIndex( + weekendColorCombo->findText(tr("Red"))); + + weekendColorLabel = new QLabel(tr("Week&end color:")); + weekendColorLabel->setBuddy(weekendColorCombo); + + headerTextFormatCombo = new QComboBox; + headerTextFormatCombo->addItem(tr("Bold")); + headerTextFormatCombo->addItem(tr("Italic")); + headerTextFormatCombo->addItem(tr("Plain")); + + headerTextFormatLabel = new QLabel(tr("&Header text:")); + headerTextFormatLabel->setBuddy(headerTextFormatCombo); + + firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue")); + + mayFirstCheckBox = new QCheckBox(tr("May &1 in red")); + + connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekdayFormatChanged())); + connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekendFormatChanged())); + connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)), + this, SLOT(reformatHeaders())); + connect(firstFridayCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + connect(mayFirstCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(firstFridayCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(mayFirstCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(weekdayColorLabel, 0, 0); + outerLayout->addWidget(weekdayColorCombo, 0, 1); + outerLayout->addWidget(weekendColorLabel, 1, 0); + outerLayout->addWidget(weekendColorCombo, 1, 1); + outerLayout->addWidget(headerTextFormatLabel, 2, 0); + outerLayout->addWidget(headerTextFormatCombo, 2, 1); + outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); + textFormatsGroupBox->setLayout(outerLayout); + + weekdayFormatChanged(); + weekendFormatChanged(); + reformatHeaders(); + reformatCalendarPage(); +} + +QComboBox *CalendarWidget::createColorComboBox() +{ + QComboBox *comboBox = new QComboBox; + comboBox->addItem(tr("Red"), Qt::red); + comboBox->addItem(tr("Blue"), Qt::blue); + comboBox->addItem(tr("Black"), Qt::black); + comboBox->addItem(tr("Magenta"), Qt::magenta); + return comboBox; +} diff --git a/tests/manual/qlocale/calendar.h b/tests/manual/qlocale/calendar.h new file mode 100644 index 0000000..b5bb3c9 --- /dev/null +++ b/tests/manual/qlocale/calendar.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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 CALENDAR_H +#define CALENDAR_H + +#include <QtGui> + +class CalendarWidget : public QWidget +{ + Q_OBJECT + +public: + CalendarWidget(); + +private slots: + void localeChanged(QLocale locale); + void firstDayChanged(int index); + void selectionModeChanged(int index); + void horizontalHeaderChanged(int index); + void verticalHeaderChanged(int index); + void selectedDateChanged(); + void minimumDateChanged(const QDate &date); + void maximumDateChanged(const QDate &date); + void updateWeekendDays(); + void weekdayFormatChanged(); + void weekendFormatChanged(); + void reformatHeaders(); + void reformatCalendarPage(); + +private: + bool isWeekendDay(Qt::DayOfWeek); + void createPreviewGroupBox(); + void createGeneralOptionsGroupBox(); + void createDatesGroupBox(); + void createTextFormatsGroupBox(); + QComboBox *createColorComboBox(); + + QGroupBox *previewGroupBox; + QGridLayout *previewLayout; + QCalendarWidget *calendar; + + QGroupBox *generalOptionsGroupBox; + QLabel *localeLabel; + QLabel *firstDayLabel; + + QLabel *selectionModeLabel; + QLabel *horizontalHeaderLabel; + QLabel *verticalHeaderLabel; + QComboBox *localeCombo; + QComboBox *firstDayCombo; + QComboBox *selectionModeCombo; + QCheckBox *gridCheckBox; + QCheckBox *navigationCheckBox; + QComboBox *horizontalHeaderCombo; + QComboBox *verticalHeaderCombo; + + QGroupBox *datesGroupBox; + QLabel *currentDateLabel; + QLabel *minimumDateLabel; + QLabel *maximumDateLabel; + QDateEdit *currentDateEdit; + QDateEdit *minimumDateEdit; + QDateEdit *maximumDateEdit; + + QGroupBox *textFormatsGroupBox; + QLabel *weekdayColorLabel; + QLabel *weekendColorLabel; + QLabel *headerTextFormatLabel; + QComboBox *weekdayColorCombo; + QComboBox *weekendColorCombo; + QComboBox *headerTextFormatCombo; + + QCheckBox *firstFridayCheckBox; + QCheckBox *mayFirstCheckBox; +}; + +#endif diff --git a/tests/manual/qlocale/currency.cpp b/tests/manual/qlocale/currency.cpp new file mode 100644 index 0000000..4ef157c --- /dev/null +++ b/tests/manual/qlocale/currency.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 "currency.h" + +CurrencyWidget::CurrencyWidget() +{ + QGridLayout *l = new QGridLayout; + + currencySymbolLabel = new QLabel("Symbol:"); + currencySymbol = new QLineEdit; + currencyISOLabel = new QLabel("ISO Code:"); + currencyISO = new QLineEdit; + currencyNameLabel = new QLabel("Display name:"); + currencyName = new QLineEdit; + currencyFormattingLabel = new QLabel("Currency formatting:"); + currencyFormattingValue = new QLineEdit(QString::number(1234.56, 'f', 2)); + currencyFormattingSymbolLabel = new QLabel("currency:"); + currencyFormattingSymbol = new QLineEdit; + currencyFormatting = new QLineEdit; + + currencyFormattingValue->setFixedWidth(150); + currencyFormattingSymbol->setFixedWidth(50); + + l->addWidget(currencySymbolLabel, 0, 0); + l->addWidget(currencySymbol, 0, 1, 1, 4); + l->addWidget(currencyISOLabel, 1, 0); + l->addWidget(currencyISO, 1, 1, 1, 4); + l->addWidget(currencyNameLabel, 2, 0); + l->addWidget(currencyName, 2, 1, 1, 4); + l->addWidget(currencyFormattingLabel, 3, 0); + l->addWidget(currencyFormattingValue, 3, 1); + l->addWidget(currencyFormattingSymbolLabel, 3, 2); + l->addWidget(currencyFormattingSymbol, 3, 3); + l->addWidget(currencyFormatting, 3, 4); + + QVBoxLayout *v = new QVBoxLayout(this); + v->addLayout(l); + v->addStretch(); + + connect(currencyFormattingSymbol, SIGNAL(textChanged(QString)), + this, SLOT(updateCurrencyFormatting())); + connect(currencyFormattingValue, SIGNAL(textChanged(QString)), + this, SLOT(updateCurrencyFormatting())); +} + +void CurrencyWidget::updateCurrencyFormatting() +{ + QString result; + bool ok; + QString symbol = currencyFormattingSymbol->text(); + QString value = currencyFormattingValue->text(); + int i = value.toInt(&ok); + if (ok) { + result = locale().toCurrencyString(i, symbol); + } else { + double d = value.toDouble(&ok); + if (ok) + result = locale().toCurrencyString(d, symbol); + } + currencyFormatting->setText(result); +} + +void CurrencyWidget::localeChanged(QLocale locale) +{ + setLocale(locale); + currencySymbol->setText(locale.currencySymbol()); + currencyISO->setText(locale.currencySymbol(QLocale::CurrencyIsoCode)); + currencyName->setText(locale.currencySymbol(QLocale::CurrencyDisplayName)); + updateCurrencyFormatting(); +} + diff --git a/tests/manual/qlocale/currency.h b/tests/manual/qlocale/currency.h new file mode 100644 index 0000000..3a12553 --- /dev/null +++ b/tests/manual/qlocale/currency.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 CURRENCY_H +#define CURRENCY_H + +#include <QtGui> + +class CurrencyWidget : public QWidget +{ + Q_OBJECT +public: + CurrencyWidget(); + +private: + QLabel *currencySymbolLabel; + QLineEdit *currencySymbol; + QLabel *currencyISOLabel; + QLineEdit *currencyISO; + QLabel *currencyNameLabel; + QLineEdit *currencyName; + QLabel *currencyFormattingLabel; + QLineEdit *currencyFormattingValue; + QLabel *currencyFormattingSymbolLabel; + QLineEdit *currencyFormattingSymbol; + QLineEdit *currencyFormatting; + +private slots: + void localeChanged(QLocale locale); + void updateCurrencyFormatting(); +}; + +#endif 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 new file mode 100644 index 0000000..18d72d7 --- /dev/null +++ b/tests/manual/qlocale/languages.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 "languages.h" + +LanguagesWidget::LanguagesWidget() +{ + QVBoxLayout *l = new QVBoxLayout(this); + + languagesLabel = new QLabel("Preferred languages:"); + languagesList = new QListWidget; + + l->addWidget(languagesLabel); + l->addWidget(languagesList); + + localeChanged(QLocale()); +} + +void LanguagesWidget::localeChanged(QLocale locale) +{ + languagesList->clear(); + 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/languages.h b/tests/manual/qlocale/languages.h new file mode 100644 index 0000000..18e503f --- /dev/null +++ b/tests/manual/qlocale/languages.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 LANGUAGES_H +#define LANGUAGES_H + +#include <QtGui> + +class LanguagesWidget : public QWidget +{ + Q_OBJECT +public: + LanguagesWidget(); + +private: + QLocale currentLocale; + + QLabel *languagesLabel; + QListWidget *languagesList; + +private slots: + void localeChanged(QLocale locale); +}; + +#endif diff --git a/tests/manual/qlocale/main.cpp b/tests/manual/qlocale/main.cpp new file mode 100644 index 0000000..c85bd19 --- /dev/null +++ b/tests/manual/qlocale/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 <QtGui> + +#include "window.h" + +int main(int argv, char *args[]) +{ + QApplication app(argv, args); + Window window; +#if !defined(Q_OS_SYMBIAN) + window.show(); +#else + window.showFullScreen(); +#endif + return app.exec(); +} diff --git a/tests/manual/qlocale/miscellaneous.cpp b/tests/manual/qlocale/miscellaneous.cpp new file mode 100644 index 0000000..89c80dc --- /dev/null +++ b/tests/manual/qlocale/miscellaneous.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 "miscellaneous.h" + +MiscWidget::MiscWidget() +{ + QGridLayout *l = new QGridLayout; + + 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); + createLineEdit("List to separated string:", &listToSeparatedStringLabel, &listToSeparatedStringText); + + l->addWidget(textToQuoteLabel, 0, 0); + l->addWidget(textToQuote, 0, 1); + l->addWidget(standardQuotedTextLabel, 0, 2); + 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); + l->addWidget(listToSeparatedStringLabel, 3, 0); + l->addWidget(listToSeparatedStringText, 3, 1, 1, 3); + + connect(textToQuote, SIGNAL(textChanged(QString)), this, SLOT(updateQuotedText(QString))); + + QVBoxLayout *v = new QVBoxLayout(this); + v->addLayout(l); + v->addStretch(); +} + +void MiscWidget::updateQuotedText(QString str) +{ + standardQuotedText->setText(locale().quoteString(str)); + alternateQuotedText->setText(locale().quoteString(str, QLocale::AlternateQuotation)); +} + +void MiscWidget::updateListToSeparatedStringText() +{ + QStringList test; + test << "aaa" << "bbb" << "ccc" << "ddd"; + listToSeparatedStringText->setText(locale().createSeparatedList(test)); +} + +void MiscWidget::localeChanged(QLocale locale) +{ + setLocale(locale); + updateQuotedText(textToQuote->text()); + updateListToSeparatedStringText(); + 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 new file mode 100644 index 0000000..3b635b8 --- /dev/null +++ b/tests/manual/qlocale/miscellaneous.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 MISCELLANEOUS_H +#define MISCELLANEOUS_H + +#include <QtGui> + +class MiscWidget : public QWidget +{ + Q_OBJECT +public: + MiscWidget(); + +private: + void createLineEdit(const QString &label, QLabel **labelWidget = 0, QLineEdit **lineEditWidget = 0); + + QLabel *textToQuoteLabel; + QLabel *standardQuotedTextLabel; + QLabel *alternateQuotedTextLabel; + QLabel *textDirectionLabel; + QLabel *listToSeparatedStringLabel; + QLineEdit *textToQuote; + QLineEdit *standardQuotedText; + QLineEdit *alternateQuotedText; + QLineEdit *textDirection; + QLineEdit *listToSeparatedStringText; + +private slots: + void localeChanged(QLocale locale); + void updateQuotedText(QString str); + void updateListToSeparatedStringText(); +}; + +#endif // MISCELLANEOUS_H 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 new file mode 100644 index 0000000..6f0bf88 --- /dev/null +++ b/tests/manual/qlocale/qlocale.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +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 new file mode 100644 index 0000000..89e3ec6 --- /dev/null +++ b/tests/manual/qlocale/window.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** 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 "window.h" + +Window::Window() +{ + localeCombo = new QComboBox; + + localeCombo->addItem("System", QLocale::system()); + + QStringList locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + foreach (const QString &name, locales) { + QLocale locale(name); + QString label = QLocale::languageToString(locale.language()); + label += QLatin1Char('/'); + if (locale.script() != QLocale::AnyScript) { + label += QLocale::scriptToString(locale.script()); + label += QLatin1Char('/'); + } + label += QLocale::countryToString(locale.country()); + localeCombo->addItem(label, locale); + } + + connect(localeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(localeChanged(int))); + + tabWidget = new QTabWidget; + calendar = new CalendarWidget; + connect(this, SIGNAL(localeChanged(QLocale)), calendar, SLOT(localeChanged(QLocale))); + currency = new CurrencyWidget; + 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))); + + localeName = new QLabel("Locale: foo_BAR"); + + QWidget *w = new QWidget; + QHBoxLayout *headerLayout = new QHBoxLayout(w); + headerLayout->addWidget(localeCombo); + headerLayout->addWidget(localeName); + + QWidget *central = new QWidget; + QVBoxLayout *l = new QVBoxLayout(central); + l->addWidget(w); + l->addWidget(tabWidget); + + tabWidget->addTab(calendar, "Calendar"); + tabWidget->addTab(currency, "Currency"); + tabWidget->addTab(languages, "Languages"); + tabWidget->addTab(dateFormats, "Date Formats"); + tabWidget->addTab(numberFormats, "Number Formats"); + tabWidget->addTab(miscellaneous, "Text"); + + localeCombo->setCurrentIndex(0); + systemLocaleChanged(); + + setCentralWidget(central); +} + +void Window::systemLocaleChanged() +{ + QLocale l = QLocale::system(); + QString lang = QLocale::languageToString(l.language()); + QString script = QLocale::scriptToString(l.script()); + QString country = QLocale::countryToString(l.country()); + if (l.script() != QLocale::AnyScript) + localeCombo->setItemText(0, QString("System: %1-%2-%3").arg(lang, script, country)); + else + localeCombo->setItemText(0, QString("System: %1-%2").arg(lang, country)); + emit localeChanged(0); +} + +void Window::localeChanged(int idx) +{ + QLocale locale = localeCombo->itemData(idx).toLocale(); + localeName->setText(QString("Locale: %1 (%2)").arg(locale.bcp47Name(), locale.name())); + emit localeChanged(locale); +} + +bool Window::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::LocaleChange: { + if (localeCombo->currentIndex() == 0) + systemLocaleChanged(); + return true; + } + default: + break; + } + return QMainWindow::event(event); +} diff --git a/tests/manual/qlocale/window.h b/tests/manual/qlocale/window.h new file mode 100644 index 0000000..dfef895 --- /dev/null +++ b/tests/manual/qlocale/window.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 WINDOW_H +#define WINDOW_H + +#include <QtGui> + +#include "calendar.h" +#include "currency.h" +#include "languages.h" +#include "dateformats.h" +#include "numberformats.h" +#include "miscellaneous.h" + +class Window : public QMainWindow +{ + Q_OBJECT +public: + Window(); + + QLabel *localeName; + QComboBox *localeCombo; + QTabWidget *tabWidget; + CalendarWidget *calendar; + CurrencyWidget *currency; + LanguagesWidget *languages; + DateFormatsWidget *dateFormats; + NumberFormatsWidget *numberFormats; + MiscWidget *miscellaneous; + +private: + bool event(QEvent *); + void systemLocaleChanged(); + +signals: + void localeChanged(QLocale); + +private slots: + void localeChanged(int); +}; + +#endif |