mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
feat(dde-dock): change the date plugin style for task 15768
This commit is contained in:
parent
f3c24fb5ce
commit
fd6cfa7842
@ -77,63 +77,35 @@ QSize DatetimeWidget::curTimeSize() const
|
|||||||
if (m_24HourFormat)
|
if (m_24HourFormat)
|
||||||
format = "hh:mm";
|
format = "hh:mm";
|
||||||
else {
|
else {
|
||||||
if (position == Dock::Top || position == Dock::Bottom)
|
format = "hh:mm AP";
|
||||||
format = "hh:mm AP";
|
|
||||||
else
|
|
||||||
format = "hh:mm\nAP";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString timeString = QDateTime::currentDateTime().toString(format);
|
QString timeString = QDateTime::currentDateTime().toString(format);
|
||||||
QSize timeSize = fm.boundingRect(timeString).size();
|
QSize timeSize = fm.boundingRect(timeString).size();
|
||||||
if (timeString.contains("\n")) {
|
QSize dateSize = QFontMetrics(m_dateFont).boundingRect("0000/00/00").size();
|
||||||
QStringList SL = timeString.split("\n");
|
|
||||||
timeSize = QSize(fm.boundingRect(SL.at(0)).width(), fm.boundingRect(SL.at(0)).height() + fm.boundingRect(SL.at(1)).height());
|
|
||||||
} else {
|
|
||||||
QSize dateSize = QFontMetrics(m_dateFont).boundingRect("0000/00/00").size();
|
|
||||||
if (timeSize.width() < dateSize.width() && rect().height() >= SHOW_DATE_MIN_HEIGHT)
|
|
||||||
timeSize.setWidth(dateSize.width());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (position == Dock::Bottom || position == Dock::Top) {
|
if (position == Dock::Bottom || position == Dock::Top) {
|
||||||
if (rect().height() >= SHOW_DATE_MIN_HEIGHT) {
|
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().height() + QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height() > height()) {
|
||||||
QStringList SL = timeString.split("\n");
|
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
||||||
int date_dec=m_timeFont.pixelSize()-m_dateFont.pixelSize();
|
|
||||||
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().height() + 11 > height()) {
|
|
||||||
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
|
||||||
m_dateFont.setPixelSize(m_timeFont.pixelSize() - date_dec);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().height() > height() + 10) {
|
|
||||||
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
|
||||||
}
|
|
||||||
timeSize.setWidth(QFontMetrics(m_timeFont).boundingRect(timeString).size().width());
|
timeSize.setWidth(QFontMetrics(m_timeFont).boundingRect(timeString).size().width());
|
||||||
|
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1){
|
||||||
|
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
||||||
|
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSize(timeSize.width(), height());
|
return QSize(std::max(timeSize.width(), dateSize.width()) + 2, height());
|
||||||
} else {
|
} else {
|
||||||
if (width() < timeSize.width()) {
|
while (std::max(QFontMetrics(m_timeFont).boundingRect(timeString).size().width(), QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width()) > width()) {
|
||||||
if (timeString.contains("\n")) {
|
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
||||||
QStringList SL = timeString.split("\n");
|
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height());
|
||||||
while (QFontMetrics(m_timeFont).boundingRect(SL.at(0)).size().width() > width()) {
|
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1){
|
||||||
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
||||||
}
|
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height());
|
||||||
} else {
|
|
||||||
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();
|
|
||||||
if (format.contains("\n")) {
|
|
||||||
QStringList SL = format.split("\n");
|
|
||||||
timeHeight = QFontMetrics(m_timeFont).boundingRect(SL.at(0)).size().height() + QFontMetrics(m_timeFont).boundingRect(SL.at(1)).size().height();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QSize(width(), std::max(timeHeight, PLUGIN_BACKGROUND_MIN_SIZE));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return QSize(width(), std::max(timeSize.height(), SHOW_DATE_MIN_HEIGHT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return QSize(std::max(timeSize.width(), dateSize.width()), timeSize.height() + dateSize.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +114,6 @@ QSize DatetimeWidget::sizeHint() const
|
|||||||
return curTimeSize();
|
return curTimeSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatetimeWidget::resizeEvent(QResizeEvent *e)
|
|
||||||
{
|
|
||||||
setMaximumSize(curTimeSize() + QSize(1, 1));
|
|
||||||
|
|
||||||
QWidget::resizeEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatetimeWidget::paintEvent(QPaintEvent *e)
|
void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e);
|
Q_UNUSED(e);
|
||||||
@ -157,38 +122,23 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
|||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
|
||||||
|
|
||||||
QString format;
|
QString format;
|
||||||
if (m_24HourFormat)
|
if (m_24HourFormat)
|
||||||
format = "hh:mm";
|
format = "hh:mm";
|
||||||
else {
|
else {
|
||||||
if (position == Dock::Top || position == Dock::Bottom)
|
format = "hh:mm AP";
|
||||||
format = "hh:mm AP";
|
|
||||||
else
|
|
||||||
format = "hh:mm\nAP";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setFont(m_timeFont);
|
painter.setFont(m_timeFont);
|
||||||
painter.setPen(QPen(palette().brightText(), 1));
|
painter.setPen(QPen(palette().brightText(), 1));
|
||||||
|
|
||||||
if (rect().height() >= SHOW_DATE_MIN_HEIGHT) {
|
QRect timeRect = rect();
|
||||||
|
timeRect.setBottom(rect().center().y() + 2);
|
||||||
QRect timeRect = rect();
|
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
||||||
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
QRect dateRect = rect();
|
||||||
|
dateRect.setTop(timeRect.bottom());
|
||||||
if (position == Dock::Top || position == Dock::Bottom) {
|
format = "yyyy/MM/dd";
|
||||||
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
painter.setFont(m_dateFont);
|
||||||
|
painter.drawText(dateRect, Qt::AlignTop | Qt::AlignHCenter, current.toString(format));
|
||||||
QRect dateRect = rect();
|
|
||||||
dateRect.setTop(timeRect.bottom());
|
|
||||||
format = "yyyy/MM/dd";
|
|
||||||
painter.setFont(m_dateFont);
|
|
||||||
painter.drawText(dateRect, Qt::AlignTop | Qt::AlignHCenter, current.toString(format));
|
|
||||||
} else {
|
|
||||||
painter.drawText(rect(), Qt::AlignVCenter | Qt::AlignHCenter, current.toString(format));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
painter.drawText(rect(), Qt::AlignCenter, current.toString(format));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ public slots:
|
|||||||
void set24HourFormat(const bool value);
|
void set24HourFormat(const bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeEvent(QResizeEvent *e);
|
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
QSize curTimeSize() const;
|
QSize curTimeSize() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user