Skip to content

Commit 3bb5bd5

Browse files
committed
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 6d52c8c commit 3bb5bd5

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
@@ -149,12 +149,19 @@ void DatetimeWidget::updateDateTime()
149149

150150
void DatetimeWidget::adjustFontSize()
151151
{
152+
const int MAX_DISTANCE = 999;
152153
const auto position = qApp->property(PROP_POSITION).value<Dock::Position>();
153154
int validDistance = m_dockSize.height() / devicePixelRatioF();
154155
if (position == Dock::Left || position == Dock::Right) {
155156
validDistance = m_dockSize.width() / devicePixelRatioF();
156157
}
157158

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

174181
int timeFontSize = 0;
@@ -235,10 +242,10 @@ void DatetimeWidget::dockPositionChanged()
235242
// 等待位置变换完成后再更新
236243
QTimer::singleShot(300, this, [this]{
237244
updateDateTime();
245+
adjustFontSize();
238246
});
239247

240248
adjustUI();
241-
adjustFontSize();
242249
}
243250

244251
void DatetimeWidget::initUI()

0 commit comments

Comments
 (0)