mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
feat(datetime):when dock on left and right,time font size fit to dock
This commit is contained in:
parent
a77cf26bad
commit
bb00071d5b
@ -92,10 +92,6 @@ void DatetimePlugin::loadPlugin()
|
|||||||
m_centralWidget = new DatetimeWidget;
|
m_centralWidget = new DatetimeWidget;
|
||||||
|
|
||||||
connect(m_centralWidget, &DatetimeWidget::requestUpdateGeometry, [this] { m_proxyInter->itemUpdate(this, pluginName()); });
|
connect(m_centralWidget, &DatetimeWidget::requestUpdateGeometry, [this] { m_proxyInter->itemUpdate(this, pluginName()); });
|
||||||
|
|
||||||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
|
||||||
connect(m_centralWidget, &DatetimeWidget::requestUpdateGeometry, [this] { m_proxyInter->itemUpdate(this, pluginName()); });
|
|
||||||
|
|
||||||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
||||||
|
|
||||||
m_proxyInter->itemAdded(this, pluginName());
|
m_proxyInter->itemAdded(this, pluginName());
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
#define SHOW_DATE_MIN_HEIGHT 45
|
#define SHOW_DATE_MIN_HEIGHT 45
|
||||||
#define TIME_FONT DFontSizeManager::instance()->t5()
|
#define TIME_FONT DFontSizeManager::instance()->t4()
|
||||||
#define DATE_FONT DFontSizeManager::instance()->t10()
|
#define DATE_FONT DFontSizeManager::instance()->t10()
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
@ -68,7 +68,9 @@ void DatetimeWidget::set24HourFormat(const bool value)
|
|||||||
QSize DatetimeWidget::curTimeSize() const
|
QSize DatetimeWidget::curTimeSize() const
|
||||||
{
|
{
|
||||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||||
QFontMetrics fm(TIME_FONT);
|
|
||||||
|
m_timeFont = TIME_FONT;
|
||||||
|
QFontMetrics fm(m_timeFont);
|
||||||
QString format;
|
QString format;
|
||||||
if (m_24HourFormat)
|
if (m_24HourFormat)
|
||||||
format = "hh:mm";
|
format = "hh:mm";
|
||||||
@ -83,7 +85,21 @@ QSize DatetimeWidget::curTimeSize() const
|
|||||||
if (position == Dock::Bottom || position == Dock::Top) {
|
if (position == Dock::Bottom || position == Dock::Top) {
|
||||||
return QSize(timeSize.width(), DOCK_MAX_SIZE);
|
return QSize(timeSize.width(), DOCK_MAX_SIZE);
|
||||||
} else {
|
} else {
|
||||||
return QSize(DOCK_MAX_SIZE, timeSize.height() * 2);
|
// 宽度不够显示日期则隐藏日期,宽度不够显示时间,则缩小时间字体适应dock
|
||||||
|
if (width() < dateSize.width()) {
|
||||||
|
QString timeString = QDateTime::currentDateTime().toString(format);
|
||||||
|
|
||||||
|
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().width() > width()) {
|
||||||
|
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int timeHeight = QFontMetrics(m_timeFont).boundingRect(timeString).size().height();
|
||||||
|
|
||||||
|
return QSize(DOCK_MAX_SIZE, std::max(timeHeight, PLUGIN_BACKGROUND_MIN_SIZE));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return QSize(DOCK_MAX_SIZE, timeSize.height() + dateSize.height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,11 +131,11 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
|||||||
format = "hh:mm AP";
|
format = "hh:mm AP";
|
||||||
|
|
||||||
painter.setPen(Qt::white);
|
painter.setPen(Qt::white);
|
||||||
|
painter.setFont(m_timeFont);
|
||||||
|
|
||||||
if (rect().height() > SHOW_DATE_MIN_HEIGHT) {
|
if (rect().height() > SHOW_DATE_MIN_HEIGHT) {
|
||||||
QRect timeRect = rect();
|
QRect timeRect = rect();
|
||||||
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
||||||
painter.setFont(TIME_FONT);
|
|
||||||
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
||||||
|
|
||||||
QRect dateRect = rect();
|
QRect dateRect = rect();
|
||||||
|
@ -48,6 +48,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool m_24HourFormat;
|
bool m_24HourFormat;
|
||||||
int m_timeOffset;
|
int m_timeOffset;
|
||||||
|
mutable QFont m_timeFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATETIMEWIDGET_H
|
#endif // DATETIMEWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user