Commit 4274c01f authored by David Jarvie's avatar David Jarvie
Browse files

Make time edit use am/pm if that is the user's default time format

parent 9b36d2e5
/*
* timeedit.cpp - time-of-day edit widget, with AM/PM shown depending on locale
* Program: kalarm
* Copyright © 2001-2006 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2006,2016 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,12 +24,17 @@
#include "timespinbox.h"
#include "timeedit.h"
#include <KLocale>
#include <KLocalizedString>
#include <QHBoxLayout>
#include <QLocale>
#include <QTime>
namespace
{
bool use12HourClock();
}
TimeEdit::TimeEdit(QWidget* parent)
: QWidget(parent),
mAmPm(Q_NULLPTR),
......@@ -41,7 +46,7 @@ TimeEdit::TimeEdit(QWidget* parent)
layout->setMargin(0);
layout->setSpacing(0);
setLayout(layout);
bool use12hour = KLocale::global()->use12Clock();
bool use12hour = use12HourClock();
mSpinBox = new TimeSpinBox(!use12hour, this);
mSpinBox->setFixedSize(mSpinBox->sizeHint());
connect(mSpinBox, static_cast<void (TimeSpinBox::*)(int)>(&TimeSpinBox::valueChanged), this, &TimeEdit::slotValueChanged);
......@@ -214,4 +219,15 @@ void TimeEdit::setAmPmCombo(int am, int pm)
}
}
namespace
{
bool use12HourClock()
{
const QString fmt = QLocale::system().timeFormat();
// 'A' or 'a' = show am/pm; 'H' displays 24-hour format regardless.
return fmt.contains(QLatin1Char('a'), Qt::CaseInsensitive) && !fmt.contains(QLatin1Char('H'));
}
}
// vim: et sw=4:
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