mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: 修改长时间显示格式任务栏时间tips未生效
监听对应长时间显示格式的变化,使任务tips时间根据对应的显示格式变化 Log: 修复修改长时间显示格式任务栏时间tips未生效的问题 Influence: 任务栏tips弹框 Bug: https://pms.uniontech.com/bug-view-147321.html Change-Id: Ib364aa02874d73e4a2f9f54f29d76be2abbfe09c
This commit is contained in:
parent
a35d53efde
commit
94a55d3f58
@ -227,17 +227,10 @@ void DatetimePlugin::updateCurrentTimeString()
|
||||
m_centralWidget->updateDateTimeString();
|
||||
|
||||
// 如果系统语言环境为中文(包含藏语和维语),按照中文的显示格式去显示,否则按照当地的日期格式显示
|
||||
if (m_centralWidget->is24HourFormat()) {
|
||||
if (isZhLocale)
|
||||
m_dateTipsLabel->setText(m_centralWidget->getDateTime() + currentDateTime.toString(" hh:mm:ss"));
|
||||
else
|
||||
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" HH:mm:ss"));
|
||||
} else {
|
||||
if (isZhLocale)
|
||||
m_dateTipsLabel->setText(m_centralWidget->getDateTime() + currentDateTime.toString(" hh:mm:ss A"));
|
||||
else
|
||||
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" HH:mm:ss A"));
|
||||
}
|
||||
if (isZhLocale)
|
||||
m_dateTipsLabel->setText(m_centralWidget->getDateTime());
|
||||
else
|
||||
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" HH:mm:ss"));
|
||||
|
||||
const QString currentString = currentDateTime.toString("yyyy/MM/dd hh:mm");
|
||||
|
||||
|
@ -45,18 +45,22 @@ DatetimeWidget::DatetimeWidget(QWidget *parent)
|
||||
, m_timedateInter(new Timedate("com.deepin.daemon.Timedate", "/com/deepin/daemon/Timedate", QDBusConnection::sessionBus(), this))
|
||||
, m_shortDateFormat("yyyy-MM-dd")
|
||||
, m_shortTimeFormat("hh:mm")
|
||||
, m_longTimeFormat(" hh:mm:ss")
|
||||
{
|
||||
setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE);
|
||||
setShortDateFormat(m_timedateInter->shortDateFormat());
|
||||
setShortTimeFormat(m_timedateInter->shortTimeFormat());
|
||||
setWeekdayFormat(m_timedateInter->weekdayFormat());
|
||||
setLongDateFormat(m_timedateInter->longDateFormat());
|
||||
setLongTimeFormat(m_timedateInter->longTimeFormat());
|
||||
set24HourFormat(m_timedateInter->use24HourFormat());
|
||||
updateDateTimeString();
|
||||
|
||||
connect(m_timedateInter, &Timedate::ShortDateFormatChanged, this, &DatetimeWidget::setShortDateFormat);
|
||||
connect(m_timedateInter, &Timedate::ShortTimeFormatChanged, this, &DatetimeWidget::setShortTimeFormat);
|
||||
connect(m_timedateInter, &Timedate::LongDateFormatChanged, this, &DatetimeWidget::setLongDateFormat);
|
||||
connect(m_timedateInter, &Timedate::WeekdayFormatChanged, this, &DatetimeWidget::setWeekdayFormat);
|
||||
connect(m_timedateInter, &Timedate::LongTimeFormatChanged, this, &DatetimeWidget::setLongTimeFormat);
|
||||
//连接日期时间修改信号,更新日期时间插件的布局
|
||||
connect(m_timedateInter, &Timedate::TimeUpdate, this, [ = ]{
|
||||
if (isVisible()) {
|
||||
@ -72,6 +76,7 @@ void DatetimeWidget::set24HourFormat(const bool value)
|
||||
}
|
||||
|
||||
m_24HourFormat = value;
|
||||
updateLongTimeFormat();
|
||||
update();
|
||||
|
||||
if (isVisible()) {
|
||||
@ -149,6 +154,20 @@ void DatetimeWidget::setWeekdayFormat(int type)
|
||||
updateDateTimeString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DatetimeWidget::setLongTimeFormat 根据类型设置长时间的显示格式
|
||||
* @param type 自定义类型
|
||||
*/
|
||||
void DatetimeWidget::setLongTimeFormat(int type)
|
||||
{
|
||||
if (m_longTimeFormatType == type)
|
||||
return;
|
||||
|
||||
m_longTimeFormatType = type;
|
||||
updateLongTimeFormat();
|
||||
updateDateTimeString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DatetimeWidget::updateWeekdayFormat 更新周的显示格式
|
||||
*/
|
||||
@ -214,6 +233,23 @@ void DatetimeWidget::updateWeekdayFormat()
|
||||
}
|
||||
}
|
||||
|
||||
void DatetimeWidget::updateLongTimeFormat()
|
||||
{
|
||||
if (m_24HourFormat) {
|
||||
switch (m_longTimeFormatType) {
|
||||
case 0: m_longTimeFormat = " h:mm:ss"; break;
|
||||
case 1: m_longTimeFormat = " hh:mm:ss"; break;
|
||||
default: m_longTimeFormat = " hh:mm:ss"; break;
|
||||
}
|
||||
} else {
|
||||
switch (m_longTimeFormatType) {
|
||||
case 0: m_longTimeFormat = " h:mm:ss A"; break;
|
||||
case 1: m_longTimeFormat = " hh:mm:ss A"; break;
|
||||
default: m_longTimeFormat = " hh:mm:ss A"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DatetimeWidget::updateWeekdayTimeString 更新任务栏时间标签的显示
|
||||
*/
|
||||
@ -234,13 +270,13 @@ void DatetimeWidget::updateDateTimeString()
|
||||
m_dateTime = longTimeFormat;
|
||||
break;
|
||||
case 1:
|
||||
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat;
|
||||
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
|
||||
break;
|
||||
case 2:
|
||||
m_dateTime = m_weekFormat + QString(" ") + longTimeFormat;
|
||||
m_dateTime = m_weekFormat + QString(" ") + longTimeFormat + currentDateTime.toString(m_longTimeFormat);
|
||||
break;
|
||||
default:
|
||||
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat;
|
||||
m_dateTime = longTimeFormat + QString(" ") + m_weekFormat + currentDateTime.toString(m_longTimeFormat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -55,14 +55,17 @@ private Q_SLOTS:
|
||||
void setShortTimeFormat(int type);
|
||||
void setLongDateFormat(int type);
|
||||
void setWeekdayFormat(int type);
|
||||
void setLongTimeFormat(int type);
|
||||
|
||||
private:
|
||||
QSize curTimeSize() const;
|
||||
void updateWeekdayFormat();
|
||||
void updateLongTimeFormat();
|
||||
|
||||
private:
|
||||
bool m_24HourFormat;
|
||||
int m_longDateFormatType;
|
||||
int m_longTimeFormatType;
|
||||
int m_weekdayFormatType;
|
||||
mutable QFont m_timeFont;
|
||||
mutable QFont m_dateFont;
|
||||
@ -72,6 +75,7 @@ private:
|
||||
QString m_shortTimeFormat;
|
||||
QString m_dateTime;
|
||||
QString m_weekFormat;
|
||||
QString m_longTimeFormat;
|
||||
};
|
||||
|
||||
#endif // DATETIMEWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user