preferences: support a pre-defined list of time formats

Add a combo-box that holds a list of pre-defined time formats
in the Language preferences.

The user is still allowed to enter a custom time format.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-11-10 17:28:09 +02:00 committed by Dirk Hohndel
parent 4fde26fb2c
commit 513f5a0230
2 changed files with 33 additions and 20 deletions

View file

@ -30,6 +30,10 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu
ui->dateFormatEntry->addItem(format);
connect(ui->dateFormatEntry, SIGNAL(currentIndexChanged(const QString&)),
this, SLOT(dateFormatChanged(const QString&)));
ui->timeFormatEntry->addItem("hh:mm");
ui->timeFormatEntry->addItem("h:mm AP");
ui->timeFormatEntry->addItem("hh:mm AP");
}
PreferencesLanguage::~PreferencesLanguage()
@ -47,7 +51,7 @@ void PreferencesLanguage::refreshSettings()
ui->languageSystemDefault->setChecked(prefs.locale.use_system_language);
ui->timeFormatSystemDefault->setChecked(!prefs.time_format_override);
ui->dateFormatSystemDefault->setChecked(!prefs.date_format_override);
ui->timeFormatEntry->setText(prefs.time_format);
ui->timeFormatEntry->setCurrentText(prefs.time_format);
ui->dateFormatEntry->setCurrentText(prefs.date_format);
ui->shortDateFormatEntry->setText(prefs.date_format_short);
QAbstractItemModel *m = ui->languageDropdown->model();
@ -84,14 +88,14 @@ void PreferencesLanguage::syncSettings()
lang->setUseSystemLanguage(ui->languageSystemDefault->isChecked());
lang->setTimeFormatOverride(!ui->timeFormatSystemDefault->isChecked());
lang->setDateFormatOverride(!ui->dateFormatSystemDefault->isChecked());
lang->setTimeFormat(ui->timeFormatEntry->text());
lang->setTimeFormat(ui->timeFormatEntry->currentText());
lang->setDateFormat(ui->dateFormatEntry->currentText());
lang->setDateFormatShort(ui->shortDateFormatEntry->text());
uiLanguage(NULL);
QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString");
QRegExp tfillegalchars("[^hHmszaApPt\\s:;\\.,]");
if (tfillegalchars.indexIn(ui->timeFormatEntry->text()) >= 0)
if (tfillegalchars.indexIn(ui->timeFormatEntry->currentText()) >= 0)
QMessageBox::warning(this, tr("Literal characters"),
tr("Non-special character(s) in time format.\n") + qDateTimeWeb);

View file

@ -140,10 +140,19 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="timeFormatEntry">
<widget class="QComboBox" name="timeFormatEntry">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Preferred time format&lt;/p&gt;&lt;p&gt;Commonly used format specifiers are&lt;/p&gt;&lt;p&gt;h (hours in 12h format)&lt;/p&gt;&lt;p&gt;H (hours in 24h format)&lt;/p&gt;&lt;p&gt;mm (2 digit minutes)&lt;/p&gt;&lt;p&gt;ss (2 digit seconds)&lt;/p&gt;&lt;p&gt;t/tt (a/p or am/pm)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -211,22 +220,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>timeFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
<receiver>timeFormatEntry</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>79</x>
<y>210</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
<y>210</y>
</hint>
</hints>
</connection>
<connection>
<sender>dateFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
@ -259,5 +252,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>timeFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
<receiver>timeFormatEntry</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>89</x>
<y>190</y>
</hint>
<hint type="destinationlabel">
<x>273</x>
<y>190</y>
</hint>
</hints>
</connection>
</connections>
</ui>