mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
feat(dde-dock): update the datetime plugin display for bug 15631
This commit is contained in:
parent
9c6be185e5
commit
0889159f74
@ -21,12 +21,13 @@
|
||||
|
||||
#include "dockitem.h"
|
||||
#include "components/hoverhighlighteffect.h"
|
||||
#include "pluginsitem.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QJsonObject>
|
||||
#include <QCursor>
|
||||
|
||||
#define PLUGIN_MARGEN 10
|
||||
#define PLUGIN_MARGIN 10
|
||||
|
||||
Position DockItem::DockPosition = Position::Top;
|
||||
DisplayMode DockItem::DockDisplayMode = DisplayMode::Efficient;
|
||||
@ -356,15 +357,22 @@ bool DockItem::checkAndResetTapHoldGestureState()
|
||||
return ret;
|
||||
}
|
||||
|
||||
const QPoint DockItem::popupMarkPoint() const
|
||||
const QPoint DockItem::popupMarkPoint()
|
||||
{
|
||||
QPoint p(topleftPoint());
|
||||
|
||||
int margin = PLUGIN_MARGIN;
|
||||
if (itemType() == Plugins){
|
||||
PluginsItem *pluginItem = dynamic_cast<PluginsItem*>(this);
|
||||
if (nullptr != pluginItem){
|
||||
if (pluginItem->pluginName() == "datetime")
|
||||
margin = 0;
|
||||
}
|
||||
}
|
||||
const QRect r = rect();
|
||||
switch (DockPosition) {
|
||||
case Top: {
|
||||
if (itemType() == Plugins) {
|
||||
p += QPoint(r.width() / 2, r.height() + PLUGIN_MARGEN);
|
||||
p += QPoint(r.width() / 2, r.height() + margin);
|
||||
} else {
|
||||
p += QPoint(r.width() / 2, r.height());
|
||||
}
|
||||
@ -372,7 +380,7 @@ const QPoint DockItem::popupMarkPoint() const
|
||||
}
|
||||
case Bottom: {
|
||||
if (itemType() == Plugins) {
|
||||
p += QPoint(r.width() / 2, 0 - PLUGIN_MARGEN);
|
||||
p += QPoint(r.width() / 2, 0 - margin);
|
||||
} else {
|
||||
p += QPoint(r.width() / 2, 0);
|
||||
}
|
||||
@ -380,7 +388,7 @@ const QPoint DockItem::popupMarkPoint() const
|
||||
}
|
||||
case Left: {
|
||||
if (itemType() == Plugins) {
|
||||
p += QPoint(r.width() + PLUGIN_MARGEN, r.height() / 2);
|
||||
p += QPoint(r.width() + margin, r.height() / 2);
|
||||
} else {
|
||||
p += QPoint(r.width(), r.height() / 2);
|
||||
}
|
||||
@ -388,7 +396,7 @@ const QPoint DockItem::popupMarkPoint() const
|
||||
}
|
||||
case Right: {
|
||||
if (itemType() == Plugins) {
|
||||
p += QPoint(0 - PLUGIN_MARGEN, r.height() / 2);
|
||||
p += QPoint(0 - margin, r.height() / 2);
|
||||
} else {
|
||||
p += QPoint(0, r.height() / 2);
|
||||
}
|
||||
@ -437,3 +445,4 @@ bool DockItem::isDragging()
|
||||
{
|
||||
return m_draging;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ protected:
|
||||
void leaveEvent(QEvent *e);
|
||||
|
||||
const QRect perfectIconRect() const;
|
||||
const QPoint popupMarkPoint() const;
|
||||
const QPoint popupMarkPoint() ;
|
||||
const QPoint topleftPoint() const;
|
||||
|
||||
void hideNonModel();
|
||||
|
@ -132,7 +132,6 @@ void MainPanelControl::init()
|
||||
// 插件
|
||||
m_pluginAreaWidget->setLayout(m_pluginLayout);
|
||||
m_pluginLayout->setMargin(0);
|
||||
m_pluginLayout->setContentsMargins(10, 10, 10, 10);
|
||||
m_pluginLayout->setSpacing(10);
|
||||
|
||||
//桌面
|
||||
@ -186,6 +185,7 @@ void MainPanelControl::updateMainPanelLayout()
|
||||
m_trayAreaLayout->setDirection(QBoxLayout::LeftToRight);
|
||||
m_appAreaSonLayout->setDirection(QBoxLayout::LeftToRight);
|
||||
m_trayAreaLayout->setContentsMargins(0, 10, 0, 10);
|
||||
m_pluginLayout->setContentsMargins(10, 0, 10, 0);
|
||||
break;
|
||||
case Position::Right:
|
||||
case Position::Left:
|
||||
@ -199,6 +199,7 @@ void MainPanelControl::updateMainPanelLayout()
|
||||
m_trayAreaLayout->setDirection(QBoxLayout::TopToBottom);
|
||||
m_appAreaSonLayout->setDirection(QBoxLayout::TopToBottom);
|
||||
m_trayAreaLayout->setContentsMargins(10, 0, 10, 0);
|
||||
m_pluginLayout->setContentsMargins(0, 10, 0, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -984,6 +985,7 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin,
|
||||
shutdownPlugin->setFixedSize(tray_item_size, h - 20);
|
||||
if (keyboardPlugin)
|
||||
keyboardPlugin->setFixedSize(tray_item_size, h - 20);
|
||||
|
||||
} else {
|
||||
m_tray->centralWidget()->setProperty("iconSize", tray_item_size);
|
||||
|
||||
@ -998,15 +1000,13 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin,
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
|
||||
if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin) {
|
||||
int width = pItem->sizeHint().width();
|
||||
if (pItem->pluginName() == "AiAssistant")
|
||||
width = tray_item_size;
|
||||
if (width > -1)
|
||||
pItem->setFixedWidth(width);
|
||||
else {
|
||||
pItem->setFixedWidth(h - 20);
|
||||
if (pItem->pluginName() == "datetime"){
|
||||
pItem->setFixedSize(pItem->sizeHint().width(), h);
|
||||
} else if (pItem->pluginName() == "AiAssistant"){
|
||||
pItem->setFixedSize(tray_item_size, h - 20);
|
||||
} else {
|
||||
pItem->setFixedSize(pItem->sizeHint().width(), h - 20);
|
||||
}
|
||||
pItem->setFixedHeight(h - 20);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1014,15 +1014,13 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin,
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
|
||||
if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin) {
|
||||
int height = pItem->sizeHint().height();
|
||||
if (pItem->pluginName() == "AiAssistant")
|
||||
height = tray_item_size;
|
||||
if (height > -1)
|
||||
pItem->setFixedHeight(height);
|
||||
else {
|
||||
pItem->setFixedHeight(w - 20);
|
||||
if (pItem->pluginName() == "datetime"){
|
||||
pItem->setFixedSize(w, pItem->sizeHint().height());
|
||||
} else if (pItem->pluginName() == "AiAssistant"){
|
||||
pItem->setFixedSize(w - 20, tray_item_size);
|
||||
} else {
|
||||
pItem->setFixedSize(w - 20, pItem->sizeHint().height());
|
||||
}
|
||||
pItem->setFixedWidth(w - 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,19 @@ QSize DatetimeWidget::curTimeSize() const
|
||||
if (m_24HourFormat)
|
||||
format = "hh:mm";
|
||||
else {
|
||||
format = "hh:mm AP";
|
||||
if (position == Dock::Top || position == Dock::Bottom)
|
||||
format = "hh:mm AP";
|
||||
else
|
||||
format = "hh:mm\nAP";
|
||||
}
|
||||
|
||||
QString timeString = QDateTime::currentDateTime().toString(format);
|
||||
QSize timeSize = fm.boundingRect(timeString).size();
|
||||
if (timeString.contains("\n")) {
|
||||
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());
|
||||
}
|
||||
|
||||
QSize dateSize = QFontMetrics(m_dateFont).boundingRect("0000/00/00").size();
|
||||
|
||||
if (position == Dock::Bottom || position == Dock::Top) {
|
||||
@ -84,19 +92,22 @@ QSize DatetimeWidget::curTimeSize() const
|
||||
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width());
|
||||
}
|
||||
}
|
||||
|
||||
return QSize(std::max(timeSize.width(), dateSize.width()) + 2, height());
|
||||
} else {
|
||||
while (std::max(QFontMetrics(m_timeFont).boundingRect(timeString).size().width(), QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width()) > width()) {
|
||||
while (std::max(QFontMetrics(m_timeFont).boundingRect(timeString).size().width(), QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width()) > (width() - 4)) {
|
||||
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
||||
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height());
|
||||
if (m_24HourFormat) {
|
||||
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height());
|
||||
} else {
|
||||
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height() * 2);
|
||||
}
|
||||
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().height());
|
||||
}
|
||||
}
|
||||
|
||||
return QSize(std::max(timeSize.width(), dateSize.width()), timeSize.height() + dateSize.height());
|
||||
m_timeOffset = (timeSize.height() - dateSize.height()) / 2 ;
|
||||
return QSize(width(), timeSize.height() + dateSize.height());
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +122,7 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
|
||||
const QDateTime current = QDateTime::currentDateTime();
|
||||
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
@ -118,30 +130,26 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
if (m_24HourFormat)
|
||||
format = "hh:mm";
|
||||
else {
|
||||
format = "hh:mm AP";
|
||||
if (position == Dock::Top || position == Dock::Bottom)
|
||||
format = "hh:mm AP";
|
||||
else
|
||||
format = "hh:mm\nAP";
|
||||
}
|
||||
|
||||
painter.setFont(m_timeFont);
|
||||
painter.setPen(QPen(palette().brightText(), 1));
|
||||
|
||||
//由于时间和日期字体不是同等缩小,会导致时间和日期位置不居中,需要整体往下移动几个像素,
|
||||
int offsetY = 0;
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
if (position == Dock::Bottom || position == Dock::Top) {
|
||||
if (height() >= 60)
|
||||
offsetY = 5;
|
||||
else if (height() >= 50)
|
||||
offsetY = 4;
|
||||
else if (height() >= 40)
|
||||
offsetY = 2;
|
||||
else if (height() >= 20)
|
||||
offsetY = 1;
|
||||
}
|
||||
QRect timeRect = rect();
|
||||
timeRect.setBottom(rect().center().y() + offsetY);
|
||||
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
||||
QRect dateRect = rect();
|
||||
dateRect.setTop(timeRect.bottom() - 2);
|
||||
|
||||
if (position == Dock::Top || position == Dock::Bottom){
|
||||
timeRect.setBottom(rect().center().y() + 6);
|
||||
dateRect.setTop(timeRect.bottom() - 4);
|
||||
} else {
|
||||
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
||||
dateRect.setTop(timeRect.bottom());
|
||||
}
|
||||
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
||||
format = "yyyy/MM/dd";
|
||||
painter.setFont(m_dateFont);
|
||||
painter.drawText(dateRect, Qt::AlignTop | Qt::AlignHCenter, current.toString(format));
|
||||
|
@ -48,6 +48,8 @@ private:
|
||||
bool m_24HourFormat;
|
||||
mutable QFont m_timeFont;
|
||||
mutable QFont m_dateFont;
|
||||
mutable int m_timeOffset;
|
||||
|
||||
};
|
||||
|
||||
#endif // DATETIMEWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user