Skip to content

Commit 84965c2

Browse files
yixinsharkdeepin-bot[bot]
authored andcommitted
fix: timeDate plugin crash
dock position changed(from bottom to left), new dock size is not update, use bottom width to adjust font size, then assert in timeFontSize != 0 && dateFontSize != 0 Log: as title
1 parent 299b377 commit 84965c2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

plugins/dde-dock/datetime/datetimewidget.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,19 @@ void DatetimeWidget::updateDateTime()
152152

153153
void DatetimeWidget::adjustFontSize()
154154
{
155+
const int MAX_DISTANCE = 999;
155156
const auto position = qApp->property(PROP_POSITION).value<Dock::Position>();
156157
int validDistance = m_dockSize.height() / devicePixelRatioF();
157158
if (position == Dock::Left || position == Dock::Right) {
158159
validDistance = m_dockSize.width() / devicePixelRatioF();
159160
}
160161

162+
// dock position changed(from bottom to left), new dock size is not update, use bottom width to adjust font size,
163+
// then assert in timeFontSize != 0 && dateFontSize != 0
164+
if (validDistance > MAX_DISTANCE) {
165+
return;
166+
}
167+
161168
// 根据时间和日期字体大小的跨度,将dock栏大小分为不同的区间,每个区域对应不同的字体大小,然后通过判断dock栏大小所在的区间来设置字体大小
162169
// 如果任务栏小于37,则字体始终取最小值;如果任务栏大于61,则字体始终取最大值;如果任务栏在37和61之间,则字体大小随任务栏大小线性变化
163170
static const QMap<int, QPair<int, int>> fontSizeMap {
@@ -171,7 +178,7 @@ void DatetimeWidget::adjustFontSize()
171178
{55, {18, 12}},
172179
{58, {19, 13}},
173180
{61, {20, 14}},
174-
{999, {20, 14}}
181+
{MAX_DISTANCE, {20, 14}}
175182
};
176183

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

243251
adjustUI();
244-
adjustFontSize();
245252
}
246253

247254
void DatetimeWidget::initUI()

0 commit comments

Comments
 (0)