Commit e13eada7 authored by David Jarvie's avatar David Jarvie
Browse files

Show numbers in localised form

parent 39eff588
Pipeline #94716 failed with stage
in 6 minutes and 16 seconds
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.18.80")
set(PIM_VERSION ${PIM_VERSION})
set(RELEASE_SERVICE_VERSION "21.11.80")
set(KALARM_VERSION "3.3.2")
set(KALARM_VERSION "3.3.3")
project(kalarm VERSION ${KALARM_VERSION})
......
KAlarm Change Log
=== Version 3.3.3 (KDE Applications 21.12) --- 6 November 2021 ===
* Show numbers in localised form.
=== Version 3.3.2 (KDE Applications 21.08.3) --- 30 October 2021 ===
* Make time edit field arrows work with Breeze application style [KDE Bug 443062]
* Fix display errors in time edit field arrows.
......
......@@ -10,6 +10,7 @@
#include <QLabel>
#include <QMouseEvent>
#include <QLocale>
Slider::Slider(QWidget* parent)
......@@ -51,6 +52,21 @@ void Slider::setValueLabel(QLabel* label, const QString& format, bool hideIfDisa
mValueLabelHide = hideIfDisabled;
connect(this, &QAbstractSlider::valueChanged, this, &Slider::valueHasChanged);
connect(mValueLabel, &QObject::destroyed, this, &Slider::valueLabelDestroyed);
// Substitute any '%' character with the locale's percent symbol.
for (int i = 0; i < mValueFormat.size(); ++i)
{
if (mValueFormat.at(i) == QLatin1Char('%'))
{
if (i < mValueFormat.size() - 1 && mValueFormat.at(i + 1) == QLatin1Char('1'))
{
// Convert "%1" to "%L1" to display the value in localised form.
mValueFormat.insert(++i, QLatin1Char('L'));
continue;
}
mValueFormat[i] = QLocale().percent();
}
}
}
else
disconnect(this, &QAbstractSlider::valueChanged, this, &Slider::valueHasChanged);
......
......@@ -60,8 +60,11 @@ public:
/** Set a label to display the slider's value.
* The label will be updated whenever the slider value changes.
* The value will be displayed in localised form.
* @param label The label to display the slider's value.
* @param format Format string for the value to display.
* @param format Format string for the value to display, containing "%1"
* where the value is to be substituted. Any other '%'
* will be substituted with the locale's percent symbol.
* @param hideIfDisabled Hide the label if the slider is disabled.
*/
void setValueLabel(QLabel* label, const QString& format = QStringLiteral("%1"), bool hideIfDisabled = false);
......@@ -87,5 +90,4 @@ private:
bool mReadOnly {false}; // value cannot be changed by the user
};
// vim: et sw=4:
......@@ -1308,11 +1308,12 @@ MonthYearRule::MonthYearRule(const QString& freqText, const QString& freqWhatsTh
mDayButton->setWhatsThis(i18nc("@info:whatsthis", "Repeat the alarm on the selected day of the month"));
boxLayout->addWidget(mDayButton, 0, 0);
QLocale locale;
mDayCombo = new ComboBox(this);
mDayCombo->setEditable(false);
mDayCombo->setMaxVisibleItems(11);
for (int i = 0; i < 31; ++i)
mDayCombo->addItem(QString::number(i + 1));
mDayCombo->addItem(locale.toString(i + 1));
mDayCombo->addItem(i18nc("@item:inlistbox Last day of month", "Last"));
mDayCombo->setReadOnly(readOnly);
mDayCombo->setWhatsThis(i18nc("@info:whatsthis", "Select the day of the month on which to repeat the alarm"));
......@@ -1354,7 +1355,6 @@ MonthYearRule::MonthYearRule(const QString& freqText, const QString& freqWhatsTh
mDayOfWeekCombo = new ComboBox(this);
mDayOfWeekCombo->setEditable(false);
QLocale locale;
for (int i = 0; i < 7; ++i)
{
int day = Locale::localeDayInWeek_to_weekDay(i);
......
......@@ -653,7 +653,6 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
{
// Whether the date and time contain leading zeroes.
static bool leadingZeroesChecked = false;
static QString dateFormat; // date format for current locale
static QString timeFormat; // time format for current locale
static QString timeFullFormat; // time format with leading zero, if different from 'timeFormat'
static int hourOffset = 0; // offset within time string to the hour
......@@ -670,10 +669,6 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
// Note that if leading zeroes are not included in other components, no
// alignment will be attempted.
// Check the date format. 'dd' provides leading zeroes; single 'd'
// provides no leading zeroes.
dateFormat = locale.dateFormat(QLocale::ShortFormat);
// Check the time format.
// Remove all but hours, minutes and AM/PM, since alarms are on minute
// boundaries. Preceding separators are also removed.
......@@ -738,7 +733,7 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
}
const KADateTime kdt = dateTime.effectiveKDateTime().toTimeSpec(Preferences::timeSpec());
QString dateTimeText = locale.toString(kdt.date(), dateFormat);
QString dateTimeText = locale.toString(kdt.date(), QLocale::ShortFormat);
if (!dateTime.isDateOnly() || kdt.utcOffset() != dateTime.utcOffset())
{
......@@ -762,28 +757,29 @@ QString ResourceDataModelBase::timeToAlarmText(const DateTime& dateTime)
{
if (!dateTime.isValid())
return i18nc("@info Alarm never occurs", "Never");
KADateTime now = KADateTime::currentUtcDateTime();
const KADateTime now = KADateTime::currentUtcDateTime();
if (dateTime.isDateOnly())
{
int days = now.date().daysTo(dateTime.date());
const int days = now.date().daysTo(dateTime.date());
// xgettext: no-c-format
return i18nc("@info n days", "%1d", days);
}
int mins = (now.secsTo(dateTime.effectiveKDateTime()) + 59) / 60;
const int mins = (now.secsTo(dateTime.effectiveKDateTime()) + 59) / 60;
if (mins <= 0)
return QString();
char minutes[3] = "00";
minutes[0] = (mins%60) / 10 + '0';
minutes[1] = (mins%60) % 10 + '0';
QLocale locale;
QString minutes = locale.toString(mins % 60);
if (minutes.size() == 1)
minutes.prepend(locale.zeroDigit());
if (mins < 24*60)
return i18nc("@info hours:minutes", "%1:%2", mins/60, QLatin1String(minutes));
return i18nc("@info hours:minutes", "%1:%2", mins/60, minutes);
// If we render a day count, then we zero-pad the hours, to make the days line up and be more scanable.
int hrs = mins / 60;
char hours[3] = "00";
hours[0] = (hrs%24) / 10 + '0';
hours[1] = (hrs%24) % 10 + '0';
int days = hrs / 24;
return i18nc("@info days hours:minutes", "%1d %2:%3", days, QLatin1String(hours), QLatin1String(minutes));
const int hrs = mins / 60;
QString hours = locale.toString(hrs % 24);
if (hours.size() == 1)
hours.prepend(locale.zeroDigit());
const QString days = locale.toString(hrs / 24);
return i18nc("@info days hours:minutes", "%1d %2:%3", days, hours, minutes);
}
// vim: et sw=4:
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