Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugins/dde-dock/datetime/datetimewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,19 @@ void DatetimeWidget::updateDateTime()

void DatetimeWidget::adjustFontSize()
{
const int MAX_DISTANCE = 999;
const auto position = qApp->property(PROP_POSITION).value<Dock::Position>();
int validDistance = m_dockSize.height() / devicePixelRatioF();
if (position == Dock::Left || position == Dock::Right) {
validDistance = m_dockSize.width() / devicePixelRatioF();
}

// dock position changed(from bottom to left), new dock size is not update, use bottom width to adjust font size,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Improve clarity of English comment

The comment is unclear and has grammatical errors. Please rewrite it to clearly explain the fallback logic, such as: "If dock position changes before m_dockSize updates, use previous dimensions to prevent font size assertions."

// then assert in timeFontSize != 0 && dateFontSize != 0
if (validDistance > MAX_DISTANCE) {
return;
}

// 根据时间和日期字体大小的跨度,将dock栏大小分为不同的区间,每个区域对应不同的字体大小,然后通过判断dock栏大小所在的区间来设置字体大小
// 如果任务栏小于37,则字体始终取最小值;如果任务栏大于61,则字体始终取最大值;如果任务栏在37和61之间,则字体大小随任务栏大小线性变化
static const QMap<int, QPair<int, int>> fontSizeMap {
Expand All @@ -171,7 +178,7 @@ void DatetimeWidget::adjustFontSize()
{55, {18, 12}},
{58, {19, 13}},
{61, {20, 14}},
{999, {20, 14}}
{MAX_DISTANCE, {20, 14}}
};

int timeFontSize = 0;
Expand Down Expand Up @@ -238,10 +245,10 @@ void DatetimeWidget::dockPositionChanged()
// 等待位置变换完成后再更新
QTimer::singleShot(300, this, [this]{
updateDateTime();
adjustFontSize();
});

adjustUI();
adjustFontSize();
}

void DatetimeWidget::initUI()
Expand Down