Browse Source

feat(dateformat): Edit the date format string

The edited date format string is saved in the qTox settings.
It is overwritten by selecting one of the default date format strings.
pull/3774/head
Nils Fenner 10 years ago committed by Diadlo
parent
commit
b3083250ff
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 37
      src/widget/form/settings/userinterfaceform.cpp
  2. 3
      src/widget/form/settings/userinterfaceform.h
  3. 13
      src/widget/form/settings/userinterfacesettings.ui

37
src/widget/form/settings/userinterfaceform.cpp

@ -52,9 +52,6 @@
static QStringList timeFormats = {"hh:mm AP", "hh:mm", "hh:mm:ss AP", "hh:mm:ss"}; static QStringList timeFormats = {"hh:mm AP", "hh:mm", "hh:mm:ss AP", "hh:mm:ss"};
// http://doc.qt.io/qt-4.8/qdate.html#fromString
static QStringList dateFormats = {"yyyy-MM-dd", "dd-MM-yyyy", "d-MM-yyyy", "dddd d-MM-yyyy", "dddd d-MM", "dddd dd MMMM"};
/** /**
* @brief Constructor of UserInterfaceForm. * @brief Constructor of UserInterfaceForm.
* @param myParent Setting widget which will contain this form as tab. * @param myParent Setting widget which will contain this form as tab.
@ -128,18 +125,26 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) :
bodyUI->timestamp->addItems(timestamps); bodyUI->timestamp->addItems(timestamps);
QLocale ql; QLocale ql;
QStringList datestamps; QStringList dateFormats;
dateFormats.append(ql.dateFormat()); dateFormats << QStringLiteral("yyyy-MM-dd") // ISO 8601
dateFormats.append(ql.dateFormat(QLocale::LongFormat));
// format strings from system locale
<< ql.dateFormat(QLocale::LongFormat)
<< ql.dateFormat(QLocale::ShortFormat)
<< ql.dateFormat(QLocale::NarrowFormat);
dateFormats.removeDuplicates(); dateFormats.removeDuplicates();
timeFormats.append(ql.timeFormat()); timeFormats.append(ql.timeFormat());
timeFormats.append(ql.timeFormat(QLocale::LongFormat)); timeFormats.append(ql.timeFormat(QLocale::LongFormat));
timeFormats.removeDuplicates(); timeFormats.removeDuplicates();
for (QString datestamp : dateFormats) for (QString format : dateFormats)
datestamps << QString("%1 - %2").arg(datestamp, QDate::currentDate().toString(datestamp)); {
QString dateExample = QDate::currentDate().toString(format);
QString element = QString("%1 - %2").arg(format, dateExample);
bodyUI->dateFormats->addItem(element, format);
}
bodyUI->dateFormats->addItems(datestamps);
bodyUI->timestamp->setCurrentText(QString("%1 - %2").arg(s.getTimestampFormat(), QTime::currentTime().toString(s.getTimestampFormat()))); bodyUI->timestamp->setCurrentText(QString("%1 - %2").arg(s.getTimestampFormat(), QTime::currentTime().toString(s.getTimestampFormat())));
bodyUI->dateFormats->setCurrentText(QString("%1 - %2").arg(s.getDateFormat(), QDate::currentDate().toString(s.getDateFormat()))); bodyUI->dateFormats->setCurrentText(QString("%1 - %2").arg(s.getDateFormat(), QDate::currentDate().toString(s.getDateFormat())));
@ -175,9 +180,19 @@ void UserInterfaceForm::on_timestamp_currentIndexChanged(int index)
Translator::translate(); Translator::translate();
} }
void UserInterfaceForm::on_dateFormats_currentIndexChanged(int index) void UserInterfaceForm::on_dateFormats_currentIndexChanged()
{
QString format = bodyUI->dateFormats->currentData().toString();
qDebug() << format;
Settings::getInstance().setDateFormat(format);
Translator::translate();
}
void UserInterfaceForm::on_dateFormats_editTextChanged()
{ {
Settings::getInstance().setDateFormat(dateFormats.at(index)); QString format = bodyUI->dateFormats->currentText();
qDebug() << format;
Settings::getInstance().setDateFormat(format);
Translator::translate(); Translator::translate();
} }

3
src/widget/form/settings/userinterfaceform.h

@ -40,7 +40,8 @@ private slots:
void on_emoticonSize_editingFinished(); void on_emoticonSize_editingFinished();
void on_styleBrowser_currentIndexChanged(QString style); void on_styleBrowser_currentIndexChanged(QString style);
void on_timestamp_currentIndexChanged(int index); void on_timestamp_currentIndexChanged(int index);
void on_dateFormats_currentIndexChanged(int index); void on_dateFormats_currentIndexChanged();
void on_dateFormats_editTextChanged();
void on_textStyleComboBox_currentTextChanged(); void on_textStyleComboBox_currentTextChanged();
void on_useEmoticons_stateChanged(); void on_useEmoticons_stateChanged();
void on_showWindow_stateChanged(); void on_showWindow_stateChanged();

13
src/widget/form/settings/userinterfacesettings.ui

@ -39,8 +39,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1296</width> <width>1298</width>
<height>1009</height> <height>1011</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0">
@ -490,7 +490,14 @@
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QComboBox" name="dateFormats"/> <widget class="QComboBox" name="dateFormats">
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

Loading…
Cancel
Save