fix: timedate size issue

when the sum of the pixel dimensions of the time font and the date font is the same as the height,
leave some space so the text doesn't look too crowded.

log: adjust timedate size
This commit is contained in:
tsic404 2023-05-10 20:51:18 +08:00 committed by Tsic
parent 83f264720c
commit f0108d1c41
2 changed files with 12 additions and 7 deletions

View File

@ -189,6 +189,11 @@ DateTimeDisplayer::DateTimeInfo DateTimeDisplayer::dateTimeInfo(const Dock::Posi
info.m_time = getTimeString(position);
info.m_date = getDateString(position);
if (m_showMultiRow && m_dateFont.pixelSize() + m_timeFont.pixelSize() > height() - 8) {
m_dateFont.setPixelSize(height() / 2 - 5);
m_timeFont.setPixelSize(height() / 2 - 3);
}
// 如果是左右方向
if (position == Dock::Position::Left || position == Dock::Position::Right) {
int textWidth = rect().width();
@ -323,12 +328,12 @@ QFont DateTimeDisplayer::timeFont() const
return DFontSizeManager::instance()->t10();
}
QList<QFont> dateFontSize = { DFontSizeManager::instance()->t7(),
QList<QFont> dateFontSize = { DFontSizeManager::instance()->t8(),
DFontSizeManager::instance()->t7(),
DFontSizeManager::instance()->t6(),
DFontSizeManager::instance()->t5(),
DFontSizeManager::instance()->t4() };
DFontSizeManager::instance()->t5() };
// dock size >= 70 get max font(t4) size
// dock size >= 70 get max font(t5) size
int index = qMin(qMax(((rect().height() - MINHEIGHT) / 10), 0), dateFontSize.size() - 1);
return dateFontSize[index];
}

View File

@ -75,8 +75,8 @@ private Q_SLOTS:
private:
Timedate *m_timedateInter;
Dock::Position m_position;
QFont m_dateFont;
QFont m_timeFont;
mutable QFont m_dateFont;
mutable QFont m_timeFont;
Dock::TipsWidget *m_tipsWidget;
QMenu *m_menu;
QSharedPointer<DockPopupWindow> m_tipPopupWindow;