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

Fix formatting of times in alarm list, when "am"/"pm" are translated

parent 3a5927dd
Pipeline #91309 canceled with stage
......@@ -42,23 +42,24 @@ void AlarmListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt
if (i >= 0)
{
painter->save();
opt.displayAlignment = Qt::AlignRight;
opt.displayAlignment = Qt::AlignLeft;
const QVariant value = index.data(Qt::ForegroundRole);
if (value.isValid())
opt.palette.setColor(QPalette::Text, value.value<QColor>());
drawBackground(painter, opt, index);
const QString time = str.mid(i + 1);
QRect timeRect;
if (i > 0)
{
QRect displayRect;
QString str0 = str;
str0[i] = QLatin1Char('0');
displayRect = textRect(str0, painter, opt);
opt.displayAlignment = Qt::AlignLeft;
QRect displayRect = textRect(str0, painter, opt);
timeRect = textRect(time, painter, opt);
timeRect.moveRight(displayRect.right());
drawDisplay(painter, opt, displayRect, str.left(i)); // date
opt.displayAlignment = Qt::AlignRight;
}
const QString time = str.mid(i + 1);
const QRect timeRect = textRect(time, painter, opt);
else
timeRect = textRect(time, painter, opt);
drawDisplay(painter, opt, timeRect, time);
painter->restore();
return;
......
......@@ -54,7 +54,6 @@ TimePeriod::TimePeriod(bool allowHourMinute, QWidget* parent)
connect(mTimeSpinBox, &TimeSpinBox::valueChanged, this, &TimePeriod::slotTimeChanged);
mSpinStack->addWidget(mTimeSpinBox);
mSpinStack->setFixedSize(mSpinBox->sizeHint().expandedTo(mTimeSpinBox->sizeHint()));
mHourMinuteRaised = mNoHourMinute;
showHourMin(!mNoHourMinute);
layout->addWidget(mSpinStack);
......@@ -72,7 +71,6 @@ TimePeriod::TimePeriod(bool allowHourMinute, QWidget* parent)
mUnitsCombo->addItem(i18n_days());
mUnitsCombo->addItem(i18n_weeks());
mMaxUnitShown = Weeks;
mUnitsCombo->setFixedSize(mUnitsCombo->sizeHint());
connect(mUnitsCombo, &ComboBox::activated, this, &TimePeriod::slotUnitsSelected);
layout->addWidget(mUnitsCombo);
......
......@@ -273,7 +273,7 @@ QVariant ResourceDataModelBase::eventData(int role, int column, const KAEvent& e
return alarmTimeText(event.startDateTime(), '~');
return alarmTimeText(event.nextTrigger(KAEvent::DISPLAY_TRIGGER), '~');
case Qt::TextAlignmentRole:
return Qt::AlignRight;
return Qt::AlignLeft;
case SortRole:
{
DateTime due;
......@@ -737,8 +737,9 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
leadingZeroesChecked = true;
}
QLocale locale;
const KADateTime kdt = dateTime.effectiveKDateTime().toTimeSpec(Preferences::timeSpec());
QString dateTimeText = kdt.date().toString(dateFormat);
QString dateTimeText = locale.toString(kdt.date(), dateFormat);
if (!dateTime.isDateOnly() || kdt.utcOffset() != dateTime.utcOffset())
{
......@@ -747,7 +748,7 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
dateTimeText += QLatin1Char(' ');
// Don't try to align right-to-left languages...
const bool useFullFormat = QApplication::isLeftToRight() && leadingZero && !timeFullFormat.isEmpty();
QString timeText = kdt.time().toString(useFullFormat ? timeFullFormat : timeFormat);
QString timeText = locale.toString(kdt.time(), (useFullFormat ? timeFullFormat : timeFormat));
if (useFullFormat && leadingZero != '0' && timeText.at(hourOffset) == QLatin1Char('0'))
timeText[hourOffset] = QChar::fromLatin1(leadingZero);
dateTimeText += timeText;
......
Markdown is supported
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