Commit 73bfdcff authored by Akseli Lahtinen's avatar Akseli Lahtinen Committed by Nate Graham
Browse files

kcms/regionandlang: Add default paper size (LC_PAPER) customizability

This adds LC_PAPER as a setting to Region and Language settings, so
it becomes possible to choose the default paper size.

BUG: 420928
FIXED-IN: 5.26
parent 9f771ae3
Pipeline #205720 passed with stage
in 8 minutes and 57 seconds
......@@ -39,3 +39,14 @@ QString Utility::numericExample(const QLocale &locale)
{
return locale.toString(1000.01);
}
QString Utility::paperSizeExample(const QLocale &locale)
{
QString paperSizeExample;
if (locale.measurementSystem() == QLocale::ImperialUSSystem || locale.measurementSystem() == QLocale::ImperialSystem) {
paperSizeExample = i18nc("PaperSize combobox", "Letter");
} else {
paperSizeExample = i18nc("PaperSize combobox", "A4");
}
return paperSizeExample;
}
......@@ -19,4 +19,5 @@ public:
static QString shortTimeExample(const QLocale &locale);
static QString measurementExample(const QLocale &locale);
static QString monetaryExample(const QLocale &locale);
static QString paperSizeExample(const QLocale &locale);
};
......@@ -78,6 +78,9 @@ void KCMRegionAndLang::save()
if (settings()->isDefaultSetting(SettingType::Currency)) {
locales.append(settings()->monetary());
}
if (settings()->isDefaultSetting(SettingType::PaperSize)) {
locales.append(settings()->paperSize());
}
if (!settings()->language().isEmpty()) {
QStringList languages = settings()->language().split(QLatin1Char(':'));
for (const QString &lang : languages) {
......@@ -125,9 +128,12 @@ void KCMRegionAndLang::unset(SettingType setting)
} else if (setting == SettingType::Measurement) {
entry = "LC_MEASUREMENT";
settings()->setMeasurement(settings()->defaultMeasurementValue());
} else {
} else if (setting == SettingType::Currency) {
entry = "LC_MONETARY";
settings()->setMonetary(settings()->defaultMonetaryValue());
} else {
entry = "LC_PAPER";
settings()->setPaperSize(settings()->defaultPaperSizeValue());
}
settings()->config()->group(QStringLiteral("Formats")).deleteEntry(entry);
}
......
......@@ -128,6 +128,11 @@ QString LanguageListModel::timeExample() const
return exampleHelper(Utility::timeExample);
}
QString LanguageListModel::paperSizeExample() const
{
return exampleHelper(Utility::paperSizeExample);
}
QString LanguageListModel::metric() const
{
return exampleHelper(Utility::measurementExample);
......
......@@ -37,6 +37,7 @@ public:
QString numberExample() const;
QString currencyExample() const;
QString timeExample() const;
QString paperSizeExample() const;
QString metric() const;
// currently unused, but we need it if we want preview examples in add langauge overlay
......
......@@ -101,6 +101,8 @@ QVariant LocaleListModel::data(const QModelIndex &index, int role) const
return Utility::monetaryExample(data.locale);
case Measurement:
return Utility::measurementExample(data.locale);
case PaperSize:
return Utility::paperSizeExample(data.locale);
}
return {};
}
......
......@@ -24,7 +24,8 @@ OptionsModel::OptionsModel(KCMRegionAndLang *parent)
{i18nc("@info:title", "Numbers"), SettingType::Numeric},
{i18nc("@info:title", "Time"), SettingType::Time},
{i18nc("@info:title", "Currency"), SettingType::Currency},
{i18nc("@info:title", "Measurements"), SettingType::Measurement}}};
{i18nc("@info:title", "Measurements"), SettingType::Measurement},
{i18nc("@info:title", "Paper Size"), SettingType::PaperSize}}};
connect(m_settings, &RegionAndLangSettings::langChanged, this, &OptionsModel::handleLangChange);
connect(m_settings, &RegionAndLangSettings::numericChanged, this, [this] {
QLocale locale(m_settings->LC_LocaleWithLang(SettingType::Numeric));
......@@ -46,12 +47,18 @@ OptionsModel::OptionsModel(KCMRegionAndLang *parent)
m_measurementExample = Utility::measurementExample(locale);
Q_EMIT dataChanged(createIndex(4, 0), createIndex(4, 0), {Subtitle, Example});
});
connect(m_settings, &RegionAndLangSettings::paperSizeChanged, this, [this] {
QLocale locale(m_settings->LC_LocaleWithLang(SettingType::PaperSize));
m_measurementExample = Utility::measurementExample(locale);
Q_EMIT dataChanged(createIndex(5, 0), createIndex(5, 0), {Subtitle, Example});
});
// initialize examples
m_numberExample = Utility::numericExample(QLocale(m_settings->LC_LocaleWithLang(SettingType::Numeric)));
m_timeExample = Utility::timeExample(QLocale(m_settings->LC_LocaleWithLang(SettingType::Time)));
m_measurementExample = Utility::measurementExample(QLocale(m_settings->LC_LocaleWithLang(SettingType::Measurement)));
m_currencyExample = Utility::monetaryExample(QLocale(m_settings->LC_LocaleWithLang(SettingType::Currency)));
m_paperSizeExample = Utility::paperSizeExample(QLocale(m_settings->LC_LocaleWithLang(SettingType::PaperSize)));
}
int OptionsModel::rowCount(const QModelIndex &parent) const
......@@ -104,6 +111,11 @@ QVariant OptionsModel::data(const QModelIndex &index, int role) const
return getNativeName(m_settings->measurement());
}
break;
case PaperSize:
if (m_settings->isDefaultSetting(SettingType::PaperSize)) {
return getNativeName(m_settings->paperSize());
}
break;
}
return {}; // implicit locale
}
......@@ -139,6 +151,13 @@ QVariant OptionsModel::data(const QModelIndex &index, int role) const
}
return example;
}
case PaperSize: {
QString example = m_paperSizeExample;
if (m_settings->isDefaultSetting(SettingType::PaperSize)) {
example += implicitFormatExampleMsg();
}
return example;
}
}
return {};
}
......@@ -176,6 +195,10 @@ void OptionsModel::handleLangChange()
m_measurementExample = Utility::measurementExample(lang);
Q_EMIT dataChanged(createIndex(4, 0), createIndex(4, 0), {Subtitle, Example});
}
if (m_settings->isDefaultSetting(SettingType::PaperSize)) {
m_paperSizeExample = Utility::measurementExample(lang);
Q_EMIT dataChanged(createIndex(5, 0), createIndex(5, 0), {Subtitle, Example});
}
}
QString OptionsModel::implicitFormatExampleMsg() const
......
......@@ -37,8 +37,9 @@ private:
QString m_timeExample;
QString m_currencyExample;
QString m_measurementExample;
QString m_paperSizeExample;
std::array<std::pair<QString, KCM_RegionAndLang::SettingType>, 5> m_staticNames; // title, page
std::array<std::pair<QString, KCM_RegionAndLang::SettingType>, 6> m_staticNames; // title, page
RegionAndLangSettings *m_settings;
};
......@@ -164,6 +164,8 @@ KCM.ScrollViewKCM {
return i18n("Currency");
case SettingType.Measurement:
return i18n("Measurements");
case SettingType.PaperSize:
return i18n("Paper Size");
}
console.warn("Invalid setting passed: ", setting);
return "Invalid"; // guard
......@@ -225,6 +227,9 @@ KCM.ScrollViewKCM {
case SettingType.Measurement:
kcm.settings.measurement = localeName;
break;
case SettingType.PaperSize:
kcm.settings.paperSize = localeName;
break;
}
} else {
kcm.unset(setting);
......
......@@ -24,6 +24,8 @@ bool RegionAndLangSettings::isDefaultSetting(SettingType setting) const
return monetary() == defaultMonetaryValue();
case SettingType::Measurement:
return measurement() == defaultMeasurementValue();
case SettingType::PaperSize:
return paperSize() == defaultMeasurementValue();
}
return false;
......@@ -56,6 +58,8 @@ QString RegionAndLangSettings::LC_LocaleWithLang(SettingType setting) const
return monetary();
case SettingType::Measurement:
return measurement();
case SettingType::PaperSize:
return paperSize();
case SettingType::Lang:
Q_UNREACHABLE();
}
......
......@@ -26,6 +26,9 @@
<entry key="LC_MEASUREMENT" name="measurement" type="String">
<default code="true">i18n("Inherit Language")</default>
</entry>
<entry key="LC_PAGE" name="paperSize" type="String">
<default code="true">i18n("Inherit Language")</default>
</entry>
<entry key="LC_CTYPE" name="ctype" type="String">
<default code="true">i18n("Inherit Language")</default>
</entry>
......
......@@ -12,6 +12,6 @@
namespace KCM_RegionAndLang
{
Q_NAMESPACE_EXPORT()
enum SettingType { Lang, Numeric, Time, Currency, Measurement };
enum SettingType { Lang, Numeric, Time, Currency, Measurement, PaperSize };
Q_ENUM_NS(SettingType)
} // namespace KCM_RegionAndLang
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment