fix: 英文环境下任务栏tips格式显示异常

根据英文环境的长时间显示格式去调整任务栏tips的显示

Log: 修复英文环境下任务栏tips格式显示异常的问题
Influence: 任务栏日期tips
Bug: https://pms.uniontech.com/bug-view-149971.html
Change-Id: Id14bd0fbd9d16d229356dac3ae58467130ebd4a6
This commit is contained in:
dengbo 2022-07-25 14:49:51 +08:00 committed by wubw
parent a725d63fa9
commit 57536dbc15
2 changed files with 49 additions and 24 deletions

View File

@ -220,17 +220,10 @@ void DatetimePlugin::pluginSettingsChanged()
void DatetimePlugin::updateCurrentTimeString()
{
const QDateTime currentDateTime = QDateTime::currentDateTime();
auto lang = QLocale::system().language();
bool isZhLocale = lang == QLocale::Chinese || lang == QLocale::Tibetan || lang == QLocale::Uighur;
// 实时刷新日期,防止日期显示错误
m_centralWidget->updateDateTimeString();
// 如果系统语言环境为中文(包含藏语和维语),按照中文的显示格式去显示,否则按照当地的日期格式显示
if (isZhLocale)
m_dateTipsLabel->setText(m_centralWidget->getDateTime());
else
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" HH:mm:ss"));
m_dateTipsLabel->setText(m_centralWidget->getDateTime());
const QString currentString = currentDateTime.toString("yyyy/MM/dd hh:mm");

View File

@ -255,29 +255,61 @@ void DatetimeWidget::updateLongTimeFormat()
*/
void DatetimeWidget::updateDateTimeString()
{
QString longTimeFormat("");
const QDateTime currentDateTime = QDateTime::currentDateTime();
int year = currentDateTime.date().year();
int month = currentDateTime.date().month();
int day = currentDateTime.date().day();
QString longTimeFormat = QString(tr("%1year%2month%3day")).arg(year).arg(month).arg(day);
auto lang = QLocale::system().language();
bool isZhLocale = lang == QLocale::Chinese || lang == QLocale::Tibetan || lang == QLocale::Uighur;
// 实时更新周的日期显示
updateWeekdayFormat();
// 根据相应语言去显示对应的格式
// 中文: 格式为xxxx年xx月xx日 星期x hh:mm:ss,如:2022年7月25日 星期- 120000
// 英文: 格式为x xxxxxx hh:mm:ss, 如July 252022Monday 12:00:00
// 其他语言:按照国际当地长时间格式显示
if (isZhLocale) {
longTimeFormat = QString(tr("%1year%2month%3day")).arg(year).arg(month).arg(day);
switch (m_longDateFormatType) {
case 0 :
m_dateTime = longTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
case 1:
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
break;
case 2:
m_dateTime = m_weekFormat + QString(" ") + longTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
default:
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
break;
// 实时更新周的日期显示
updateWeekdayFormat();
switch (m_longDateFormatType) {
case 0 :
m_dateTime = longTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
case 1:
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
break;
case 2:
m_dateTime = m_weekFormat + QString(" ") + longTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
default:
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
break;
}
} else if (lang == QLocale::English){
auto longDateString = currentDateTime.date().toString(Qt::SystemLocaleLongDate);
auto week = longDateString.split(",").at(0);
// 获取英文的日期格式字符串,-2是去掉","和" "
auto longDateTimeFormat = longDateString.right(longDateString.size() - week.size() -2);
switch (m_longDateFormatType) {
case 0 :
m_dateTime = longDateTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
case 1:
m_dateTime = longDateTimeFormat + QString(", ") + week + currentDateTime.toString(m_longTimeFormat);
break;
case 2:
m_dateTime = week + QString(", ") + longDateTimeFormat + currentDateTime.toString(m_longTimeFormat);
break;
default:
m_dateTime = longDateTimeFormat + QString(",") + week + currentDateTime.toString(m_longTimeFormat);
break;
}
}else {
m_dateTime = currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(m_longTimeFormat);
}
}