mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 00:05:25 +08:00
qt 6.5.1 original
This commit is contained in:
23
tests/manual/qlocale/CMakeLists.txt
Normal file
23
tests/manual/qlocale/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## qlocale Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(qlocale
|
||||
GUI
|
||||
SOURCES
|
||||
calendar.cpp calendar.h
|
||||
currency.cpp currency.h
|
||||
dateformats.cpp dateformats.h
|
||||
info.cpp info.h
|
||||
languages.cpp languages.h
|
||||
main.cpp
|
||||
miscellaneous.cpp miscellaneous.h
|
||||
numberformats.cpp numberformats.h
|
||||
window.cpp window.h
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
375
tests/manual/qlocale/calendar.cpp
Normal file
375
tests/manual/qlocale/calendar.cpp
Normal file
@ -0,0 +1,375 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "calendar.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QCalendarWidget>
|
||||
#include <QLabel>
|
||||
#include <QDateEdit>
|
||||
#include <QCheckBox>
|
||||
#include <QTextCharFormat>
|
||||
|
||||
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(QDate date)
|
||||
{
|
||||
calendar->setMinimumDate(date);
|
||||
maximumDateEdit->setDate(calendar->maximumDate());
|
||||
}
|
||||
|
||||
void CalendarWidget::maximumDateChanged(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"), QColor(Qt::red));
|
||||
comboBox->addItem(tr("Blue"), QColor(Qt::blue));
|
||||
comboBox->addItem(tr("Black"), QColor(Qt::black));
|
||||
comboBox->addItem(tr("Magenta"), QColor(Qt::magenta));
|
||||
return comboBox;
|
||||
}
|
88
tests/manual/qlocale/calendar.h
Normal file
88
tests/manual/qlocale/calendar.h
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef CALENDAR_H
|
||||
#define CALENDAR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDate>
|
||||
#include <QLocale>
|
||||
|
||||
class QComboBox;
|
||||
class QGridLayout;
|
||||
class QGroupBox;
|
||||
class QCalendarWidget;
|
||||
class QLabel;
|
||||
class QDateEdit;
|
||||
class QCheckBox;
|
||||
|
||||
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(QDate date);
|
||||
void maximumDateChanged(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
|
76
tests/manual/qlocale/currency.cpp
Normal file
76
tests/manual/qlocale/currency.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "currency.h"
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLocale>
|
||||
|
||||
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();
|
||||
}
|
||||
|
37
tests/manual/qlocale/currency.h
Normal file
37
tests/manual/qlocale/currency.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef CURRENCY_H
|
||||
#define CURRENCY_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
|
||||
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
|
149
tests/manual/qlocale/dateformats.cpp
Normal file
149
tests/manual/qlocale/dateformats.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "dateformats.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QScrollArea>
|
||||
#include <QGridLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QDateTime>
|
||||
|
||||
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;
|
||||
}
|
47
tests/manual/qlocale/dateformats.h
Normal file
47
tests/manual/qlocale/dateformats.h
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef DATEFORMATS_H
|
||||
#define DATEFORMATS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLineEdit;
|
||||
class QScrollArea;
|
||||
class QGridLayout;
|
||||
class QComboBox;
|
||||
|
||||
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
|
61
tests/manual/qlocale/info.cpp
Normal file
61
tests/manual/qlocale/info.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "info.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QScrollArea>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLocale>
|
||||
|
||||
InfoWidget::InfoWidget()
|
||||
{
|
||||
scrollArea = new QScrollArea;
|
||||
scrollAreaWidget = new QWidget;
|
||||
scrollArea->setWidget(scrollAreaWidget);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
layout = new QGridLayout();
|
||||
QVBoxLayout *v = new QVBoxLayout(scrollAreaWidget);
|
||||
v->addLayout(layout);
|
||||
v->addStretch();
|
||||
|
||||
QVBoxLayout *l = new QVBoxLayout(this);
|
||||
l->addWidget(scrollArea);
|
||||
|
||||
name = addItem("Name:");
|
||||
bcp47Name = addItem("Bcp47 name:");
|
||||
languageName = addItem("Language name:");
|
||||
nativeLanguageName = addItem("Native language name:");
|
||||
scriptName = addItem("Script name:");
|
||||
territoryName = addItem("Territory name:");
|
||||
nativeTerritoryName = addItem("Native territory name:");
|
||||
}
|
||||
|
||||
void InfoWidget::localeChanged(QLocale locale)
|
||||
{
|
||||
setLocale(locale);
|
||||
name->setText(locale.name());
|
||||
bcp47Name->setText(locale.bcp47Name());
|
||||
languageName->setText(QLocale::languageToString(locale.language()));
|
||||
nativeLanguageName->setText(locale.nativeLanguageName());
|
||||
scriptName->setText(QLocale::scriptToString(locale.script()));
|
||||
territoryName->setText(QLocale::territoryToString(locale.territory()));
|
||||
nativeTerritoryName->setText(locale.nativeTerritoryName());
|
||||
}
|
||||
|
||||
void InfoWidget::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 *InfoWidget::addItem(const QString &label)
|
||||
{
|
||||
QLineEdit *le = new QLineEdit;
|
||||
le->setReadOnly(true);
|
||||
addItem(label, le);
|
||||
return le;
|
||||
}
|
40
tests/manual/qlocale/info.h
Normal file
40
tests/manual/qlocale/info.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef INFO_H
|
||||
#define INFO_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLineEdit;
|
||||
class QScrollArea;
|
||||
class QGridLayout;
|
||||
|
||||
class InfoWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
InfoWidget();
|
||||
|
||||
private:
|
||||
void addItem(const QString &label, QWidget *);
|
||||
QLineEdit *addItem(const QString &label);
|
||||
|
||||
QScrollArea *scrollArea;
|
||||
QWidget *scrollAreaWidget;
|
||||
QGridLayout *layout;
|
||||
|
||||
QLineEdit *name;
|
||||
QLineEdit *bcp47Name;
|
||||
QLineEdit *languageName;
|
||||
QLineEdit *nativeLanguageName;
|
||||
QLineEdit *scriptName;
|
||||
QLineEdit *territoryName;
|
||||
QLineEdit *nativeTerritoryName;
|
||||
|
||||
private slots:
|
||||
void localeChanged(QLocale locale);
|
||||
};
|
||||
|
||||
#endif
|
38
tests/manual/qlocale/languages.cpp
Normal file
38
tests/manual/qlocale/languages.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "languages.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
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::territoryToString(l.territory());
|
||||
QString tooltip = QString(QLatin1String("%1: %2/%3")).arg(l.name(), language, country);
|
||||
item->setToolTip(tooltip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
29
tests/manual/qlocale/languages.h
Normal file
29
tests/manual/qlocale/languages.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef LANGUAGES_H
|
||||
#define LANGUAGES_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLabel;
|
||||
class QListWidget;
|
||||
|
||||
class LanguagesWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LanguagesWidget();
|
||||
|
||||
private:
|
||||
QLocale currentLocale;
|
||||
|
||||
QLabel *languagesLabel;
|
||||
QListWidget *languagesList;
|
||||
|
||||
private slots:
|
||||
void localeChanged(QLocale locale);
|
||||
};
|
||||
|
||||
#endif
|
14
tests/manual/qlocale/main.cpp
Normal file
14
tests/manual/qlocale/main.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
int main(int argv, char *args[])
|
||||
{
|
||||
QApplication app(argv, args);
|
||||
Window window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
}
|
70
tests/manual/qlocale/miscellaneous.cpp
Normal file
70
tests/manual/qlocale/miscellaneous.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "miscellaneous.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
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;
|
||||
}
|
39
tests/manual/qlocale/miscellaneous.h
Normal file
39
tests/manual/qlocale/miscellaneous.h
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef MISCELLANEOUS_H
|
||||
#define MISCELLANEOUS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLineEdit;
|
||||
class QLabel;
|
||||
|
||||
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
|
52
tests/manual/qlocale/numberformats.cpp
Normal file
52
tests/manual/qlocale/numberformats.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "numberformats.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QLocale>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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;
|
||||
}
|
30
tests/manual/qlocale/numberformats.h
Normal file
30
tests/manual/qlocale/numberformats.h
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef NUMBERFORMATS_H
|
||||
#define NUMBERFORMATS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLocale>
|
||||
|
||||
class QLineEdit;
|
||||
class QLabel;
|
||||
|
||||
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
|
3
tests/manual/qlocale/qlocale.pro
Normal file
3
tests/manual/qlocale/qlocale.pro
Normal file
@ -0,0 +1,3 @@
|
||||
QT += widgets
|
||||
HEADERS += currency.h calendar.h dateformats.h numberformats.h languages.h window.h miscellaneous.h info.h
|
||||
SOURCES += currency.cpp main.cpp calendar.cpp dateformats.cpp numberformats.cpp languages.cpp window.cpp miscellaneous.cpp info.cpp
|
108
tests/manual/qlocale/window.cpp
Normal file
108
tests/manual/qlocale/window.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "window.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLocale>
|
||||
#include <QLabel>
|
||||
#include <QTabWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QEvent>
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
localeCombo = new QComboBox;
|
||||
|
||||
localeCombo->addItem("System", QLocale::system());
|
||||
|
||||
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyTerritory);
|
||||
foreach (const QLocale &locale, locales) {
|
||||
QString label = QLocale::languageToString(locale.language());
|
||||
label += QLatin1Char('/');
|
||||
if (locale.script() != QLocale::AnyScript) {
|
||||
label += QLocale::scriptToString(locale.script());
|
||||
label += QLatin1Char('/');
|
||||
}
|
||||
label += QLocale::territoryToString(locale.territory());
|
||||
localeCombo->addItem(label, locale);
|
||||
}
|
||||
|
||||
connect(localeCombo, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(localeChanged(int)));
|
||||
|
||||
tabWidget = new QTabWidget;
|
||||
info = new InfoWidget;
|
||||
connect(this, SIGNAL(localeChanged(QLocale)), info, SLOT(localeChanged(QLocale)));
|
||||
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(info, "Info");
|
||||
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 territory = QLocale::territoryToString(l.territory());
|
||||
if (l.script() != QLocale::AnyScript)
|
||||
localeCombo->setItemText(0, QString("System: %1-%2-%3").arg(lang, script, territory));
|
||||
else
|
||||
localeCombo->setItemText(0, QString("System: %1-%2").arg(lang, territory));
|
||||
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);
|
||||
}
|
48
tests/manual/qlocale/window.h
Normal file
48
tests/manual/qlocale/window.h
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "calendar.h"
|
||||
#include "currency.h"
|
||||
#include "languages.h"
|
||||
#include "dateformats.h"
|
||||
#include "numberformats.h"
|
||||
#include "miscellaneous.h"
|
||||
#include "info.h"
|
||||
|
||||
class QLabel;
|
||||
class QComboBox;
|
||||
|
||||
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;
|
||||
InfoWidget *info;
|
||||
|
||||
private:
|
||||
bool event(QEvent *);
|
||||
void systemLocaleChanged();
|
||||
|
||||
signals:
|
||||
void localeChanged(QLocale);
|
||||
|
||||
private slots:
|
||||
void localeChanged(int);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user