@@ -149,12 +149,19 @@ void DatetimeWidget::updateDateTime()
149149
150150void 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 ;
@@ -213,6 +220,7 @@ bool DatetimeWidget::eventFilter(QObject *watched, QEvent *event)
213220
214221void DatetimeWidget::setDockPanelSize (const QSize &dockSize)
215222{
223+ qInfo () << " setDockPanelSize:" << dockSize;
216224 // 任务栏高度最小是37,小于37说明在隐藏和显示动画中
217225 if (dockSize.width () < 37 ) {
218226 return ;
@@ -235,10 +243,10 @@ void DatetimeWidget::dockPositionChanged()
235243 // 等待位置变换完成后再更新
236244 QTimer::singleShot (300 , this , [this ]{
237245 updateDateTime ();
246+ adjustFontSize ();
238247 });
239248
240249 adjustUI ();
241- adjustFontSize ();
242250}
243251
244252void DatetimeWidget::initUI ()
0 commit comments